centos7开机自启脚本

目标:通过centos 7开机自启脚本来启动redis、Tomcat、nginx、zookeeper等服务.

第一步:创建你需要启动的脚本auto_start.sh(我这里只启动了redis)

#!/bin/sh
#redis启动
/home/zhouwen/redis/redis-5.0.0/src/redis-server /home/zhouwen/redis/redis-5.0.0/redis.conf

第二步:给脚本授权

chmod +x auto_start.sh

第三步:将脚本的运行路径添加到/etc/rc.d/rc.local中加入执行脚本命令。在/etc/rc.d/rc.local文件末尾追加/root/hbk/hbk.sh

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
#这是我的启动脚本路径
/home/zhouwen/auto_start.sh

第四步:并设置 /etc/rc.d/rc.local 的执行权限

chmod +x /etc/rc.d/rc.local

简单的四步操作之后,重启下linux系统,验证下redis服务已经开机启动了。

 

你可能感兴趣的:(java,Nginx,Redis,Linux)