此文章是文章reids双机热备的后续
将redis服务做成service并开机启动
将redis做成redis-server,将sentinel做成redis-sentinel服务
redis-server服务
将redis.conf文件复制到/etc/redis
下并且重命名为6379.conf
mkdir -p /etc/redis
cp ./redis.conf /etc/redis/6379.conf
将./utils/redis_init_script
复制到/etc/init.d
目录下,并重命名为redis-server
cp ./utils/redis_init_script /etc/init.d/redis-server
修改redis-server文件,内容如下
#!/bin/sh
## 这两行是加的
# chkconfig: 2345 10 90
# description: Start and Stop redis
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
## 将对应的地址填入即可
EXEC=/home/tmp/redis-test/redis-4.0.9/src/redis-server
CLIEXEC=/home/tmp/redis-test/redis-4.0.9/src/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"
AUTH="123456"
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 $AUTH -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
然后为其赋予权限即可通过service的方法进行服务的启动和停用。
打开redis命令:service redis-server start
关闭redis命令:service redis-server stop
设为开机启动:chkconfig redis-server on
设为开机关闭:chkconfig redis-server off
redis-sentinel服务
将sentinel.conf文件复制到/etc/redis
下并且重命名为26379.conf
mkdir -p /etc/redis
cp ./sentinel.conf /etc/redis/26379.conf
将./utils/redis_init_script
复制到/etc/init.d
目录下,并重命名为redis-sentinel
cp ./utils/redis_init_script /etc/init.d/redis-sentinel
修改redis-sentinel文件,内容如下
#!/bin/sh
## 这两行是加的
# chkconfig: 2345 10 90
# description: Start and Stop redis
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=26379
## 将对应的地址填入即可
EXEC=/home/tmp/redis-test/redis-4.0.9/src/redis-sentinel
CLIEXEC=/home/tmp/redis-test/redis-4.0.9/src/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"
AUTH="123456"
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 $AUTH -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