redis开机自启配置
1、复制redis启动文件到/etc/init.d下
redis安装路径/usr/local/redis cp /usr/local/redis/utils/redis_init_script /etc/rc.d/init.d/redis-6379 vi /etc/rc.d/init.d/redis-6379 cat /etc/rc.d/init.d/redis-6379 ################### #!/bin/sh # # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. ### BEGIN INIT INFO # Provides: redis_6379 # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Redis data structure server # Description: Redis data structure server. See https://redis.io ### END INIT INFO REDISPORT=6379 EXEC=/usr/local/redis/bin/redis-server CLIEXEC=/usr/local/redis/bin/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pid CONF="/etc/redis/${REDISPORT}.conf" case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..." $EXEC $CONF fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $CLIEXEC -a root123 -p $REDISPORT shutdown while [ -x /proc/${PID} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; *) echo "Please use start or stop as first argument" ;; esac
2、将配置文件加到开机启动项
chkconfig --add redis-6379 #加入到开机启动项中
检查是否加到开机启动项
命令:chkconfig --list redis-6379 结果:redis-6379 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
sentinel开机自启配置
1、拷贝redis启动文件到/etc/init.d/下
cp /usr/local/redis/utils/redis_init_script /etc/rc.d/init.d/sentinel-26379 vi /etc/rc.d/init.d/sentinel-26379 cat /etc/rc.d/init.d/sentinel-26379 ############################# #!/bin/sh # # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. ### BEGIN INIT INFO # Provides: sentinel_26379 # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Redis data structure server # Description: Redis data structure server. See https://redis.io ### END INIT INFO SENTINELPORT=26379 MASTERAUTH="root123" EXES=/usr/local/redis/bin/redis-sentinel CLIEXEC=/usr/local/redis/bin/redis-cli SlCONF="/usr/local/redis/sentinel/sentinel.conf" PID=`ps aux |grep redis-sentinel |grep 26379| grep -v grep |awk ‘{print $2}‘` case "$1" in start) if [ $PID ] then echo "$PID exists, process is already running or crashed" else echo "Starting Sentinel server..." $EXES $SlCONF fi ;; stop) if [ ! $PID ] then echo "$PID does not exist, process is not running" else echo "Stopping ..." $CLIEXEC -a $MASTERAUTH -p $SENTINELPORT shutdown while [ -x /proc/$PID ] do echo "Waiting for Sentinel to shutdown ..." sleep 1 done echo "Sentinel stopped" fi ;; *) echo "Please use start or stop as first argument" ;; esac
2、设置开机启动项
chkconfig --add sentinel-26379 #加入到开机启动项中
检查是否加入到开机启动项
命令:chkconfig --list sentinel-26379 结果:sentinel-26379 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
完成!
原文:https://www.cnblogs.com/quanyao/p/13725752.html