centos设置程序开机自启或禁止加载

1. 可以直接把需要启动的脚本写到/etc/rc.d/rc.local文件里,例如

vim /etc/rc.d/rc.local

/usr/local/apache/bin/apachectl start

 2. Chkconfig用法(旧版)

(1)chkconfig --level [0123456] [service name] [on|off]

   chkconfig --level 23 dhcp3-server off ----设定dhcp server服务在level2,3下关闭.

 

(2)chkconfig --list 查看服务的自动开启状态

(3)chkconfig --add 增加一个服务给chkconfig来管理,但是该服务必须在/etc/init.d内。

3. systemctl(新版,现在)单元控制

服务自启动  systemctl enable httpd.service

服务不再自启动  systemctl disable httpd.service

服务状态  systemctl status httpd,service

加入自定义服务  systemctl load test.service

显示已启动的服务  systemctl list-util --type=service(systemctl -t help可以看到type后面可以接的类型)

启停 systemctl httpd start/stop/restart

systemctl 后的服务名在/lib/systemd/system和/usr/lib/systemd/system目录查看

服务的配置文件在/etc/systemd/system

或/usr/lib/systemd/system/xx.service

 

而在systemd的管理体系里面,默认的target(相当于以前的默认运行级别)是通过软链来实现。如:

ln -s /lib/systemd/system/runlevel3.target /etc/systemd/system/default.targ

 

一旦设定了自动启动(enbale),就在/etc/systemd/system/.wants/下面建了一个httpd.service的软链接,连接到/lib/systemd/system/下的相应服务那里 。

所以显示自动启动状态的unit (类似于chkconfig --list命令的结果),可以通过下面的方法:

#ls /etc/systemd/system/multi-user.target.wants/

posted @ 2018-01-08 21:45  NoYone  阅读(487)  评论(0编辑  收藏  举报