紧接上一篇文章的末尾,本文主要讲述了redis6.0.6注册本地服务及配置开机自启动的流程
--请在安装完成后注册服务
$ cd redis-6.0.6/utils/
$ ./install_server.sh
启动脚本后会跳出如下输入框,红色字体为需要输入部分
<--------------------------------------------------------------------------------------------------------------------------->
Welcome to the redis service installer This script will help you easily set up a running redis server
//指定redis端口 默认为6379
//输入为修改端口,无需修改直接空格即可
Please select the redis port for this instance: [6379] Selecting default: 6379
//指定配置文件路径
Please select the redis config file name [/etc/redis/6379.conf] /usr/local/hurys/redis/redis-6.0.6/redis.conf
//指定日志文件路径
Please select the redis log file name [/var/log/redis_6379.log] /usr/local/hurys/redis/redis_6379.log
//指定数据目录
Please select the data directory for this instance [/var/lib/redis/6379] /usr/local/hurys/redis/6379
//指定你的redis-server安装路径
Please select the redis executable path [] /usr/local/hurys/redis/redis-6.0.6/src/redis-server
<--------------------------------------------------------------------------------------------------------------------------->
接下来步骤回车即可,注册成功后输入(注**若没有修改默认密码此步骤直接跳过即可)
默认服务注册名为 redis_6379
vim /etc/init.d/redis_6379
修改脚本为
#!/bin/sh
#Configurations injected by install_server below....
EXEC=/usr/local/hurys/redis/redis-6.0.6/src/redis-server
CLIEXEC=/usr/local/hurys/redis/redis-6.0.6/src/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/usr/local/hurys/redis/redis-6.0.6/redis.conf"
REDISPORT="6379"
###############
# SysV Init Information
# chkconfig: - 58 74
# description: redis_6379 is the redis daemon.
### BEGIN INIT INFO
# Provides: redis_6379
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Should-Start: $syslog $named
# Should-Stop: $syslog $named
# Short-Description: start and stop redis_6379
# Description: Redis daemon
### END INIT INFO
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 -a hurys@123 shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
status)
PID=$(cat $PIDFILE)
if [ ! -x /proc/${PID} ]
then
echo 'Redis is not running'
else
echo "Redis is running ($PID)"
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Please use start, stop, restart or status as first argument"
;;
esac
接下来执行:
$ rm -rf /var/run/redis_6379.pid
$ systemctl daemon-reload
$ systemctl restart redis_6379
即可使用systemctl status/start/restart/stop redis_6379
控制redis启停及查看状态
到此步骤为止redis注册本地服务已全部完成
开机自启:
//ubuntu
chmod +x /etc/init.d/redis_6379
update-rc.d redis_6379 defaults
//centos
systemctl enable redis_6379.service