1.redis开启守护进程
vi /etc/redis.conf
2.添加开启启动配置文件,修改相应值为实际值,完整文件见最后
vi /etc/init.d/redis
3.修改添加redis启动脚本权限为可执行
chmod +x redis
4./etc/init.d/stop 出现Stopping ... (error) NOAUTH Authentication required. 错误,需要添加密码访问方式即可
5.配置redis开机启动
chkconfig redis on
6.重启系统,发现服务已经可以自启动了啦。
附完整redis自启动脚本:
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/bin/redis-server
CLIEXEC=/usr/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis.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 123456 -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