以设置httpd开机自启动为例
| 指令 |
service指令
|
systemctl指令
|
launchctl指令(Mac)
|
| 编写启动脚本目录 |
vi /etc/init.d/httpd
|
vi /usr/lib/systemd/system/httpd.service
vi /etc/systemd/system/httpd.service
|
~/Library/LaunchAgents 由用户自己定义的任务项
/Library/LaunchAgents 由管理员为用户定义的任务项
/Library/LaunchDaemons 由管理员定义的守护进程任务项
/System/Library/LaunchAgents 由Mac OS X为用户定义的任务项
/System/Library/LaunchDaemons 由Mac OS X定义的守护进程任务项
|
| 脚本赋权 |
chmod +x /etc/init.d/httpd
|
chmod +x /usr/lib/systemd/system/httpd.service
| |
|
使某服务自动启动
|
Centos:
chkconfig -–level 3 httpd on
chkconfig --add httpd
Ubuntu:
update-rc.d httpd defaults
|
systemctl enable httpd.service
|
launchctl load -w com.httpd.plist
|
|
使某服务不自动启动
|
Centos:
chkconfig –-level 3 httpd off
chkconfig —del httpd
Ubuntu:
update-rc.d -f httpd remove
|
systemctl disable httpd.service
|
launchctl unload -w com.httpd.plist
|
|
检查服务状态
|
service httpd status
|
systemctl status httpd.service
| |
|
显示所有已启动的服务
|
chkconfig –-list
|
systemctl list-units --type service
|
launchctl list | grep 'com.httpd'
|
|
启动某服务
|
service httpd start
|
systemctl start httpd.service
|
launchctl start com.httpd.plist
|
|
停止某服务
|
service httpd stop
|
systemctl stop httpd.service
|
launchctl stop com.httpd.plist
|
|
重启某服务
|
service httpd restart
|
systemctl restart httpd.service
|
launchctl restart com.httpd.plist
|
|
重载某服务
|
systemctl reload httpd.service
|
本文详细介绍了如何在Centos和Ubuntu系统中使用service、systemctl和launchctl指令设置httpd开机自启动,包括创建启动脚本、赋权、启动/停止/重启/重载服务,以及如何通过chkconfig和systemctl管理服务。同时涵盖了Mac上的launchctl操作和常用状态检查命令。





