操作环境
服务器centos7.3, ip:47.52.41.245,所包含的集群节点有7003,7004,7005
开启防火墙
systemctl eable firewalld.service
redis集群设置开启自启动
这里是设置的是集群里面某个redis节点开机启动,没有使用集群,这里设置的是7003服务
- 根据启动脚本要求,将某个节点的配置文件以端口为名复制一份到指定目录,这里复制到/etc/redis_cluster
cd /etc
mkdir redis_cluster
cd redis_cluster
cp /tmp/frank/redis/redis-3.2.1/redis_cluster/* /etc/redis_cluster/
- 在/etc/init.d目录下面新建启动脚本并且命名为redis7003
vim redis7003
完整配置信息为
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /pro filesystem.
# chkconfig:2345 90 10
# description:Redis is a persistent key-value database
REDISPORT=7003
EXEC=/tmp/frank/redis/redis-3.2.1/src/redis-server
CLIEXEC=/tmp/frank/redis/redis-3.2.1/src/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis_cluster/${REDISPORT}/redis.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists,process is already running or crashed"
else
echo "Starting Redis server $REDISPORT ..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exit,process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping"
$CLIEXEC -p $REDISPORT shutdow
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
- 修改启动文件的权限
chmod +x /etc/init.d/redis7003
- 设定开机启动服务
chkconfig redis7003 on
- 启动,停止redis
service redis start #或者 /etc/init.d/redis start
service redis stop #或者 /etc/init.d/redis stop
-
reboot重启服务器
-
测试服务是否启动
[root@iZj6c7eeosj2t5vjw8rf4xZ init.d]# redis-cli -c -p 7003
127.0.0.1:7003>
8.其余节点按上面步骤继续
网友评论