Linux學習筆記(3)linux服務管理與啟停
阿新 • • 發佈:2018-10-31
重啟 禁用 multi etc 刪除服務 shel ive 系統 運行級別
一、LINUX 系統服務管理
1、RHEL/OEL 6.X及之前
service命令用於對系統服務進行管理,比如啟動(start)、停止(stop)、重啟(restart)、查看狀態(status)等。
chkconfig用於查看、設置服務器的運行級別。ntsysv用於直觀方便的設置各個服務是否自動啟動。
service命令本身是一個shell腳本,它在/etc/init.d/目錄查找指定的服務器腳本,然後調用該服務腳本來完成任務。
2、RHEL/OEL 7.X之後
systemctl是新的服務管理器命令,該命令是用來替代service和chkconfig的;
systemctl是一個systemd工具,主要負責控制systemd系統的服務管理器。
啟用服務就是在當前的 "runlevel" 的配置文件目錄 /etc/systemd/system/multi-user.target.wants/ 裏,建立 /usr/lib/systemd/system 裏面對應服務配置文件的軟鏈接。禁用服務就是刪除此軟鏈接。
3.指令對照表
舊指令指的是redhat 6.X之前,新指令指定是紅帽7.X之後
任務 | 舊指令(redhat 6.x及之前) | 新指令(redhat 7.X及之後) |
使某服務自動啟動 | chkconfig --level 3 httpd on | systemctl enable httpd service |
使某服務不自動啟動 | chkconfig --level 3 httpd off |
systemctl disable httpd service |
檢查服務狀態 | service httpd status |
systemctl status httpd.service(詳細信息) systemctl is-active test.service(僅顯示是否活躍) |
加入自定義服務 | chkconfig --add test | systemctl load test.service |
刪除服務 | chkconfig --del test | 停掉應用,刪除對應配置文件 |
顯示所有已啟動的服務 | chkconfig --list | systemctl list-units --type = service |
啟動某服務 | service httpd start | systemctl start httpd.service |
停止某服務 | service httpd stop | systemctl stop httpd.service |
重啟某服務 service httpd restart systemctl restart httpd.service
Linux學習筆記(3)linux服務管理與啟停