linux开机自启动服务

1.在/etc/init.d/下创建一个bootstart.sh脚本

cd /etc/init.d
vim bootstart.sh

脚本内容如下

#!/bin/sh
#chkconfig: 2345 80 90
#description:开机自动启动的脚本程序

# 开启redis服务 端口为6379
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf

#tomcat 端口8060
/usr/local/tomcat/tomcat-admin/bin/./startup.sh

#nginx 目录/wwww
/usr/local/nginx/sbin/nginx

脚本第一行 “#!/bin/sh” 告诉系统使用的shell;
脚本第二行 “#chkconfig: 2345 80 90” 表示在2/3/4/5运行级别启动,启动序号(S80),关闭序号(K90);
脚本第三行 表示的是服务的描述信息

注意: 第二行和第三行必写,否则会出现如“服务 *.sh 不支持 chkconfig”这样的错误。

2. 给脚本赋可执行权限

chmod +x bootstart.sh

3.添加脚本到开机自动启动项目中

chkconfig --add bootstart.sh
chkconfig bootstart.sh on

4.重启linux系统

reboot

你可能感兴趣的:(linux开机自启动服务)