redis集群部署
/data/app/redis/redis-5.0.0/src/redis-server /data/app/redis/redis-5.0.0/7001/redis.conf
/data/app/redis/redis-5.0.0/src/redis-server /data/app/redis/redis-5.0.0/7002/redis.conf
/data/app/redis/redis-5.0.0/src/redis-server /data/app/redis/redis-5.0.0/7003/redis.conf
/data/app/redis/redis-5.0.0/src/redis-server /data/app/redis/redis-5.0.0/7004/redis.conf
/data/app/redis/redis-5.0.0/src/redis-server /data/app/redis/redis-5.0.0/7005/redis.conf
/data/app/redis/redis-5.0.0/src/redis-server /data/app/redis/redis-5.0.0/7006/redis.conf
/data/app/redis/redis-5.0.0/src/redis-cli --cluster create --cluster-replicas 1 192.168.254.131:7001 192.168.254.131:7002 192.168.254.131:7003 192.168.254.131:7004 192.168.254.131:7005 192.168.254.131:7006 -a ivrRedis@2022
根据提示输入yes
Linux 配置Redis集群为开机自启动==========
1.vim /etc/init.d/redisc
将下方脚本写入redisc文件中
!/bin/sh
chkconfig: 2345 80 90
Simple Redis init.d script conceived to work on Linux systems
as it does use of the /proc filesystem.
REDISPORT1=7001
REDISPORT2=7002
REDISPORT3=7003
REDISPORT4=7004
REDISPORT5=7005
REDISPORT6=7006
HOSTIP=192.168.70.156
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
PIDFILE=/usr/local/redis-cluster/${REDISPORT1}/redis_${REDISPORT1}.pid
CONF1="/usr/local/redis-cluster/${REDISPORT1}/${REDISPORT1}.conf"
CONF2="/usr/local/redis-cluster/${REDISPORT2}/${REDISPORT2}.conf"
CONF3="/usr/local/redis-cluster/${REDISPORT3}/${REDISPORT3}.conf"
CONF4="/usr/local/redis-cluster/${REDISPORT4}/${REDISPORT4}.conf"
CONF5="/usr/local/redis-cluster/${REDISPORT5}/${REDISPORT5}.conf"
CONF6="/usr/local/redis-cluster/${REDISPORT6}/${REDISPORT6}.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis cluster server..."
$EXEC $CONF1 &
$EXEC $CONF2 &
$EXEC $CONF3 &
$EXEC $CONF4 &
$EXEC $CONF5 &
$EXEC $CONF6 &
echo "启动成功..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -h $HOSTIP -p $REDISPORT1 shutdown
$CLIEXEC -h $HOSTIP -p $REDISPORT2 shutdown
$CLIEXEC -h $HOSTIP -p $REDISPORT3 shutdown
$CLIEXEC -h $HOSTIP -p $REDISPORT4 shutdown
$CLIEXEC -h $HOSTIP -p $REDISPORT5 shutdown
$CLIEXEC -h $HOSTIP -p $REDISPORT6 shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis cluster to shutdown ..."
sleep 1
done
echo "Redis cluster stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
注册为系统服务
chkconfig --add redisc
配置为开机自启动
chkconfig redisc on
以后可以使用命令来控制Redis 集群的启动和关闭
启动:service redisc start
关闭:service redisc stop
权限不够时
chmod a+x /etc/init.d/redisc
启动redis报错:/var/run/redis_6379.pid exists, process is already running or crashed
这是由于redis在停止时,直接使用kill命令,导致进程没有杀干净。
解决方案:执行命令 删除redis_6379.pid 文件
rm -rf /data/app/redis/redis-5.0.0/7001/redis_7001.pid
rm -rf /data/app/redis/redis-5.0.0/7002/redis_7002.pid
rm -rf /data/app/redis/redis-5.0.0/7003/redis_7003.pid
rm -rf /data/app/redis/redis-5.0.0/7004/redis_7004.pid
rm -rf /data/app/redis/redis-5.0.0/7005/redis_7005.pid
rm -rf /data/app/redis/redis-5.0.0/7006/redis_7006.pid