一、修改redis.conf
1、打开后台运行选项,默认情况下,Redis不在后台运行;
daemonize yes
2、配置log文件地址,默认使用标准输入,即打印在命令行终端 的窗口上
logfile "/var/log/redis.log"
二、脚本设置
cp /redis的源码目录/utils/redis_init_scripts /etc/init.d/redis
添加执行权限:chmod +x /etc/init.d/redis
三、设置开机自动启动,关机自动关闭
update-rc.d redis defaults
会提示 insserv: warning: script 'redis6379' missing LSB tags and overrides
则修改脚本,添加前面几行
#!/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: redis6379
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis6379
# Description: penavico redis 6379
### END INIT INFO REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/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 -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
~
update-rc.d redis defaults
尝试启动或停止redis
service redis start
service redis stop
四、服务检查
进行常规测试
如果有错误,可以使用一下命令查看详细信息
systemctl status redis.service
journalctl -xe