LINUX开机自启动redis服务

1.编写配置脚本 [** vim /etc/init.d/redis** ]
#!/bin/sh
# chkconfig: 2345 10 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
EXEC=/usr/local/redis/redis-server #redis-server路径
CLIEXEC=/usr/local/redis/redis-cli #redis-cli路径

PIDFILE=/var/run/redis_${REDISPORT}.pid #redis_${REDISPORT}.pid路径
CONF="/usr/local/redis/redis.conf" #redis.conf路径
AUTH="School1502" #redis 密码

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 -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.修改redis.conf,打开后台运行选项
daemonize yes
3.修改文件执行权限
chmod +x /etc/init.d/redis
4.设置开机启动
# 尝试启动或停止 redis
service redis start
service redis stop
# 开启服务自启动
chkconfig redis on
5.reboot

猜你喜欢

转载自blog.csdn.net/weixin_36691991/article/details/88671918