之前在Linux centos 7 上安裝了apache 和mysql,當時並沒有設置開機自動啟動。
最近又重新練習網頁,每次開機總是要手動啟動httpd和mysqld,不方便,就想設置成開機自動啟動apache和mysql。
Linux centos 7 怎樣設置開機自動啟動httpd和mysqld服務呢?
我在網上找到了下面兩條命令:
systemctl enable httpd.service
systemctl enable mysqld.service
如果要取消開機自動啟動apache和mysql,則用下面的命令
systemctl disable httpd.service
systemctl disable mysqld.service
可是,我想起了以前我看過開機自動運行httpd服務好像不是上面的命令,而是
chkconfig –level 3 httpd on
那么chkconfig 和systemctl 這兩個命令又有什么區別與聯系呢?
我在網上找到了下面這個關於systemctl 和chkconfig 指令用法比較的表格
任務 | 舊指令 | 新指令 |
使某服務自動啟動 | 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 |
顯示所有已啟動的服務 | 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 |