Redis集群搭建步骤-自行记录下

发布于:2023-01-26 ⋅ 阅读:(18) ⋅ 点赞:(0) ⋅ 评论:(0)

redis-cluster
host1:192.155.0.11        master1     port:7001,7002
host2: 192.155.0.12        master2     port:7003,7004
host3: 192.155.0.13        master3     port:7005,7006

yum install -y gcc-c++ automake autoconf libtool make tcl

tar -xf redis-5.0.7.tar.gz -C /tmp
cd /tmp/redis-5.0.7
make && make install PREFIX=/usr/local/redis-5.0.7/redis_cluster

cp src/redis-cli /usr/local/bin/
cp src/redis-server /usr/local/bin/
cp src/redis-sentinel /usr/local/bin/

cd /tmp/redis-5.0.7
make && make install PREFIX=/usr/local/redis-5.0.7/redis_cluster

cd /usr/local/redis-5.0.7/redis_cluster/
mkdir log &&  mkdir conf

cp /tmp/redis-5.0.7/redis.conf /usr/local/redis-5.0.7/redis_cluster/conf/
cd /usr/local/redis-5.0.7/redis_cluster/conf/

[root@host2 conf]# > redis.conf 
[root@host2 conf]# vim redis.conf 
[root@host2 conf]# mv redis.conf redis_7001.conf
[root@host2 conf]# cp -r redis_7001.conf redis_7002.conf 
mkdir -p /usr/local/redis-5.0.7/redis_cluster/redis_7001
mkdir -p /usr/local/redis-5.0.7/redis_cluster/redis_7002

[root@host3 conf]# > redis.conf 
[root@host3 conf]# mv redis.conf redis_7003.conf 
[root@host3 conf]# cp -r redis_7003.conf redis_7004.conf 
mkdir -p /usr/local/redis-5.0.7/redis_cluster/redis_7003
mkdir -p /usr/local/redis-5.0.7/redis_cluster/redis_7004

[root@host4 conf]# > redis.conf 
[root@host4 conf]# mv redis.conf redis_7005.conf 
[root@host4 conf]# cp -r redis_7005.conf redis_7006.conf 
mkdir -p /usr/local/redis-5.0.7/redis_cluster/redis_7005
mkdir -p /usr/local/redis-5.0.7/redis_cluster/redis_7006

[root@host2 conf]# cat redis_7001.conf 
bind 192.155.0.12
port 7001
daemonize yes
pidfile "/var/run/redis_7001.pid"
logfile "/usr/local/redis-5.0.7/redis_cluster/log/redis_7001.log"
dir "/usr/local/redis-5.0.7/redis_cluster/redis_7001"
masterauth 123456
requirepass 123456
appendonly yes
cluster-enabled yes
cluster-config-file nodes_7001.conf
cluster-node-timeout 15000
[root@host2 conf]# cat redis_7002.conf 
bind 192.155.0.12
port 7002
daemonize yes
pidfile "/var/run/redis_7002.pid"
logfile "/usr/local/redis-5.0.7/redis_cluster/redis_7002.log"
dir "/usr/local/redis-5.0.7/redis_cluster/redis_7002"
masterauth "123456"
requirepass "123456"
appendonly yes
cluster-enabled yes
cluster-config-file nodes_7002.conf
cluster-node-timeout 15000


[root@host3 conf]# cat redis_7003.conf 
bind 192.155.0.13
port 7003
daemonize yes
pidfile "/var/run/redis_7003.pid"
logfile "/usr/local/redis-5.0.7/redis_cluster/log/redis_7003.log"
dir "/usr/local/redis-5.0.7/redis_cluster/redis_7003"
masterauth 123456
requirepass 123456
appendonly yes
cluster-enabled yes
cluster-config-file nodes_7003.conf
cluster-node-timeout 15000

[root@host3 conf]# cat redis_7004.conf 
bind 192.155.0.13
port 7004
daemonize yes
pidfile "/var/run/redis_7004.pid"
logfile "/usr/local/redis-5.0.7/redis_cluster/log/redis_7004.log"
dir "/usr/local/redis-5.0.7/redis_cluster/redis_7004"
masterauth 123456
requirepass 123456
appendonly yes
cluster-enabled yes
cluster-config-file nodes_7004.conf
cluster-node-timeout 15000


[root@host4 conf]# cat redis_7005.conf 
bind 192.155.0.14
port 7005
daemonize yes
pidfile "/var/run/redis_7005.pid"
logfile "/usr/local/redis-5.0.7/redis_cluster/log/redis_7005.log"
dir "/usr/local/redis-5.0.7/redis_cluster/redis_7005"
masterauth 123456
requirepass 123456
appendonly yes
cluster-enabled yes
cluster-config-file nodes_7005.conf
cluster-node-timeout 15000

[root@host4 conf]# cat redis_7006.conf 
bind 192.155.0.14
port 7006
daemonize yes
pidfile "/var/run/redis_7006.pid"
logfile "/usr/local/redis-5.0.7/redis_cluster/log/redis_7006.log"
dir "/usr/local/redis-5.0.7/redis_cluster/redis_7006"
masterauth 123456
requirepass 123456
appendonly yes
cluster-enabled yes
cluster-config-file nodes_7006.conf
cluster-node-timeout 15000


[root@host2 conf]# redis-server /usr/local/redis-5.0.7/redis_cluster/conf/redis_7001.conf 
[root@host2 conf]# redis-server /usr/local/redis-5.0.7/redis_cluster/conf/redis_7002.conf 
[root@host3 conf]# redis-server /usr/local/redis-5.0.7/redis_cluster/conf/redis_7003.conf 
[root@host3 conf]# redis-server /usr/local/redis-5.0.7/redis_cluster/conf/redis_7004.conf
[root@host4 conf]# redis-server /usr/local/redis-5.0.7/redis_cluster/conf/redis_7005.conf 
[root@host4 conf]# redis-server /usr/local/redis-5.0.7/redis_cluster/conf/redis_7006.conf

redis-cli -a 123456 --cluster create 192.155.0.12:7001 192.155.0.12:7002 192.155.0.13:7003 192.155.0.13:7004 192.1155.0.14:7005 192.155.0.14:7006 --cluster-replicas 1

[root@host2 conf]# redis-cli -c -h 192.155.0.12 -p 7001 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.155.0.12:7001> 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:641
cluster_stats_messages_pong_sent:592
cluster_stats_messages_sent:1233
cluster_stats_messages_ping_received:587
cluster_stats_messages_pong_received:641
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:1233
192.155.0.12:7001> CLUSTER NODES
44eecc224b3c343b0597efccd0f 192.155.0.13:7004@17004 slave 12cf524aba199de19799b485411 0 1653992850201 4 connected
5179b0404c2e7b9f830e639a5047 192.155.0.13:7003@17003 master - 0 1653992847022 3 connected 5461-10922
12cf524aba19991d6c85de19799b485411 192.155.0.12:7001@17001 myself,master - 0 1653992848000 1 connected 0-5460
7991dee94d240f695e06e1768f02709b4ba 192.1155.0.14:7005@17005 master - 0 1653992848094 5 connected 10923-16383
4c47a8b6f443ceb9f046f0f3c7dc6 192.155.0.12:7002@17002 slave 7991de06e1768f02709b4ba 0 1653992849150 5 connected
3255b37b3113248506363fa3eacc52a9c 192.155.0.14:7006@17006 slave 5179b0404c229f83f94d7c0e639a5047 0 1653992847000 6 connected