Linux 开机启动的三种方法

 一、修改开机启动文件:/etc/rc.local(或者/etc/rc.d/rc.local)

# 1.编辑rc.local文件
[root@localhost ~]# vi /etc/rc.local

如下图保存并退出。 (命令后面让得加&号,表示后台运行)
# 2.最后修改rc.local文件的执行权限
[root@localhost ~]# chmod +x  /etc/rc.local

 

 二、自己写一个shell脚本

将写好的脚本(.sh文件)放到目录 /etc/profile.d/ 下,系统启动后就会自动执行该目录下的所有shell脚本。

 

三、通过chkconfig命令设置

# 1.将(脚本)启动文件复制到 /etc/init.d/或者/etc/rc.d/init.d/目录下。(前者是后者的软连接)
[root@localhost ~]# cp /root/lvs.sh /etc/init.d
#
2.启动lvs.sh程序前面务必添加如下三行代码,否侧会提示chkconfig不支持。 #!/bin/sh 告诉系统使用的shell,所以的shell脚本都是这样 #chkconfig: 35 20 80 分别代表运行级别,启动优先权,关闭优先权,此行代码必须 #description: tomcat server 自己随便发挥!!!,此行代码必须
# 3.增加脚本的可执行权限 chmod +x /etc/rc.d/init.d/lvs.sh # 4.添加脚本到开机自动启动项目中。添加到chkconfig,开机自启动。 [root@localhost ~]# cd /etc/init.d [root@localhost ~]# chkconfig --add lvs.sh (centos 6) [root@localhost ~]# chkconfig lvs.sh on (centos 6)
[root@localhost ~]# systemctl start lvs.sh (centos 7)
#
5.关闭开机启动 [root@localhost ~]# chkconfig lvs.sh off (centos 6)
[root@localhost ~]# systemctl disable lvs.sh (centos 7) #
6.从chkconfig管理中删除test.sh [root@localhost ~]# chkconfig --del lvs.sh # 7.查看chkconfig管理 [root@localhost ~]# chkconfig --list lvs.sh
posted @ 2019-12-25 14:22  区域管理员  阅读(4626)  评论(0编辑  收藏  举报