李士朝
发布于

redis5.0.14 集群搭建

1. redis5.0.14 集群搭建

1.1 服务部署

1.1.1 安装包下载

https://download.redis.io/releases/redis-5.0.14.tar.gz

1.1.2 服务安装

tar -xzvf redis-5.0.14.tar.gz 
cd redis-5.0.14/
make
cd src/
make install PREFIX=/usr/local/redis
mkdir /usr/local/redis/etc
cp /data01/software/redis-5.0.14/redis.conf /usr/local/redis/etc/

1.1.3 配置文件修改

创建所需目录

mkdir -p /data01/redis/data/6380
mkdir -p /data01/redis/data/6381
mkdir -p /data01/redis/data/6382
mkdir -p /data01/redis/data/6383
mkdir -p /data01/redis/data/6384
mkdir -p /data01/redis/data/6385
mkdir -p /data01/redis/log

集群最少 6 台机器

修改 demo 配置文件

cp /usr/local/redis/etc/redis.conf cp /usr/local/redis/etc/redis_demo.conf
VIM /usr/local/redis/etc/redis_demo.conf

# 修改如下配置
bind 10.0.8.7
daemonize yes
port 6380
pidfile /var/run/redis_6380.pid
logfile "/data01/redis/log/6380.log"
dir /data01/redis/data/6380
cluster-config-file nodes_6380.conf # 不需要创建会自动生成
cluster-node-timeout 15000
cluster-enabled yes

拷贝配置文件

# 按照所需要的port依次修改6个配置文件
mkdir /usr/local/redis/etc/cluster
cp /usr/local/redis/etc/redis_demo.conf /usr/local/redis/etc/cluster/redis_6380.conf
cp /usr/local/redis/etc/redis_demo.conf /usr/local/redis/etc/cluster/redis_6381.conf
cp /usr/local/redis/etc/redis_demo.conf /usr/local/redis/etc/cluster/redis_6382.conf
cp /usr/local/redis/etc/redis_demo.conf /usr/local/redis/etc/cluster/redis_6383.conf
cp /usr/local/redis/etc/redis_demo.conf /usr/local/redis/etc/cluster/redis_6384.conf
cp /usr/local/redis/etc/redis_demo.conf /usr/local/redis/etc/cluster/redis_6385.conf

1.1.4 启动服务

# 启动脚本 start_all.sh
/usr/local/redis/bin/redis-server /usr/local/redis/etc/cluster/redis_6380.conf
/usr/local/redis/bin/redis-server /usr/local/redis/etc/cluster/redis_6381.conf
/usr/local/redis/bin/redis-server /usr/local/redis/etc/cluster/redis_6382.conf
/usr/local/redis/bin/redis-server /usr/local/redis/etc/cluster/redis_6383.conf
/usr/local/redis/bin/redis-server /usr/local/redis/etc/cluster/redis_6384.conf
/usr/local/redis/bin/redis-server /usr/local/redis/etc/cluster/redis_6385.conf
# 停止脚本 shutdown_all.sh
/usr/local/redis/bin/redis-cli -h 10.0.8.7 -p 6380 shutdown
/usr/local/redis/bin/redis-cli -h 10.0.8.7 -p 6381 shutdown
/usr/local/redis/bin/redis-cli -h 10.0.8.7 -p 6382 shutdown
/usr/local/redis/bin/redis-cli -h 10.0.8.7 -p 6383 shutdown
/usr/local/redis/bin/redis-cli -h 10.0.8.7 -p 6384 shutdown
/usr/local/redis/bin/redis-cli -h 10.0.8.7 -p 6385 shutdown

1.1.5 检查服务

ps -ef|grep Redis

1.2 创建集群

/usr/local/redis/bin/redis-cli --cluster create --cluster-replicas 1 10.0.8.7:6380 10.0.8.7:6381 10.0.8.7:6382 10.0.8.7:6383 10.0.8.7:6384 10.0.8.7:6385

1.3 验证集群

/usr/local/redis/bin/redis-cli -c -h 10.0.8.7 -p 6380

cluster info

cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:79
cluster_stats_messages_pong_sent:81
cluster_stats_messages_sent:160
cluster_stats_messages_ping_received:76
cluster_stats_messages_pong_received:79
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:160

cluster nodes

6712931aa76a8cda68a99a700f321f90675d4a2e 10.0.8.7:6381@16381 master - 0 1659686309926 2 connected 5461-10922
39bc253d7f82e363085ec2dde4c7b26ea9687e76 10.0.8.7:6382@16382 master - 0 1659686310000 3 connected 10923-16383
1dfd39e529cd48b83053f00b1f0fdc30a5b33b6b 10.0.8.7:6384@16384 slave 39bc253d7f82e363085ec2dde4c7b26ea9687e76 0 1659686310928 5 connected
1b18fa01df047cbe547b92072caa5b83790447be 10.0.8.7:6380@16380 myself,master - 0 1659686307000 1 connected 0-5460
173bde13d3b406798338b300d0bc39f0a7b7e82f 10.0.8.7:6383@16383 slave 6712931aa76a8cda68a99a700f321f90675d4a2e 0 1659686311930 4 connected
85d760d329d26d256ac91419d1c0cd47fa79aba1 10.0.8.7:6385@16385 slave 1b18fa01df047cbe547b92072caa5b83790447be 0 1659686308925 6 connected
评论
    test