centos 添加开机自启动脚本

centos 设置服务开机自动启动的方式有好多种,这里介绍一下经过chkconfig命令添加脚本为开机自动启动的方法。

编写脚本autostart.sh(这里以开机启动redis服务为例),脚本内容以下:redis

`
#!/bin/sh
#chkconfig: 2345 80 90
#description:开机自启动脚本 power by https://www.shangmayuan.comshell

# redis
cd /data1/redis
redis-server /data1/redis/redis.confcentos

`server

脚本第一行 “#!/bin/sh” 告诉系统使用的shell;
脚本第二行 “#chkconfig: 2345 80 90” 表示在2/3/4/5运行级别启动,启动序号(S80),关闭序号(K90);
脚本第三行 表示的是服务的描述信息
注意: 第二行和第三行必写,负责会出现如“服务 autostart.sh 不支持 chkconfig”这样的错误。ip

将写好的autostart.sh脚本移动到/etc/rc.d/init.d/目录下,并给脚本赋可执行权限it

`
chmod +x autostart.sh
`io

添加脚本到开机自动启动项目中
`
chkconfig --add autostart.sh
chkconfig autostart.sh on
`权限

相关文章
相关标签/搜索