Centos 設置服務開機自啓動

一、systemctl是一個系統管理守護進程、工具和庫的集合,
用於取代system、service 和 chkconfig 命令,
初始進程主要負責控制systemd系統和服務管理器。

通過systemctl -help可以看到該命令主要分爲:
查詢或發送控制命令給systemd服務,
管理單元服務的命令,
服務文件的相關命令,任務、環境、快照相關命令,
systemd服務的配置重載,系統開機關機相關的命令。

1. 列出所有可用單元 

# systemctl list-unit-files

2. 列出所有運行中單元 

# systemctl list-units

3. 查看已啓動的服務

systemctl list-units --type=service

4. 列出所有失敗單元 

# systemctl –failed

5. 檢查某個單元(如 docker.service)是否啓用 

[root@cloud-container ~]# systemctl is-enabled docker.service
enabled


6. 列出所有服務 

# systemctl list-unit-files –type=service

7. 查看是否設置開機啓動
systemctl list-unit-files | grep enable

8. 設置開機啓動
systemctl enable docker.service

9. 關閉開機啓動
systemctl disable docker.service

 

二、docker容器設置自動啓動

[root@cloud-container docker]# chkconfig docker.service on
error reading information on service docker.service: No such file or directory
[root@cloud-container docker]# chkconfig docker on
Note: Forwarding request to 'systemctl enable docker.service'.
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@cloud-container docker]#
[root@cloud-container docker]# systemctl enable docker.service
[root@cloud-container docker]#
[root@cloud-container ~]# systemctl list-unit-files | grep enable | grep docker
docker.service                                enabled
[root@cloud-container ~]#

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章