Centos7 build a Redis cluster

1. Preparation

CPU name operating system IP address Main software
Master1 Centos7 192.168.1.2 redis-3.2.9.tar.gz
Master2 Centos7 192.168.1.3 redis-3.2.9.tar.gz
Master3 Centos7 192.168.1.4 redis-3.2.9.tar.gz
slave1 Centos7 192.168.1.5 redis-3.2.9.tar.gz
slave2 Centos7 192.168.1.6 redis-3.2.9.tar.gz
slave3 Centos7 192.168.1.7 redis-3.2.9.tar.gz

2. Install Redis

The operation steps of the 6 machines are the same:
the source code package to be installed:
https://pan.baidu.com/s/1_1gpGjh6Gt3P-mIcuoBofA
Extraction code: ra36

[root@Master-1 ~]# tar zxf redis-3.2.9.tar.gz -C /usr/src/
[root@Master-1 ~]# cd /usr/src/redis-3.2.9/
[root@Master-1 redis-3.2.9]# make && make PREFIX=/usr/local/redis install

Insert picture description here

[root@Master-1 redis-3.2.9]# ln -s /usr/local/redis/bin/* /usr/local/bin/
[root@Master-1 redis-3.2.9]# cd utils/
[root@Master-1 utils]# ./install_server.sh
依次回车即可

Insert picture description here

3. Edit the main configuration file

[root@Master-1 utils]# vim /etc/redis/6379.conf
62 bind 127.0.0.1         #修改成各自的IP地址
以下是6台主机相同配置:
81 protected-mode no      #将yes修改为no,表示关闭保护模式
85 port 6379		      #默认端口号即可
594 appendonly yes        #将no改为yes,表示以独立进程启动
将以下#号去掉:
722 cluster-enabled yes       #开启群集模式
730 cluster-config-file nodes-6379.conf    #群集名称文件设置
736 cluster-node-timeout 15000		       #群集超时时间设置
[root@Master-1 utils]# /etc/init.d/redis_6379 restart

If you can’t find the data, you can use / to search for keywords
Insert picture description here

4. Perform cluster redis-trib.rb deployment on any node

1) Install the ruby ​​tool
ruby source code package can be downloaded from the following link:
https://pan.baidu.com/s/1KsvU9Gf0jlTd3U1EyjC-GQ
extraction code: 4fp4

[root@Master-1 ~]# mount /dev/cdrom /media/cdrom
[root@Master-1 ~]# yum -y install ruby rubygems
[root@Master-1 ~]# gem install redis --version 3.2.0
[root@Master-1 ~]# cd /usr/src/redis-3.2.9/src/
使用脚本安装redis群集:
[root@Master-1 src]# ./redis-trib.rb create --replicas 1 192.168.1.2:6379 192.168.1.3:6379 192.168.1.4:6379 192.168.1.5:6379 192.168.1.6:6379 192.168.1.7:6379      

Insert picture description here
Insert picture description here

5. Verification

1) View the cluster status

[root@Master-1 src]# ./redis-trib.rb check 192.168.1.2:6379

Insert picture description here
2) Log in to the redis cluster and set up the key value test

[root@Master-1 src]# redis-cli -h 192.168.1.2 -p 6379 -c
192.168.1.2:6379> set xingming zhangsan
OK
192.168.1.2:6379> get xingming
"zhangsan"
192.168.1.2:6379> quit

Insert picture description here
Enter the 192.168.1.3 host to check whether it is synchronized. In fact, any host can be synchronized.

[root@Master-2 ~]# redis-cli -h 192.168.1.3 -p 6379 -c
192.168.1.3:6379> keys *
(empty list or set)
192.168.1.3:6379> get xingming
-> Redirected to slot [1657] located at 192.168.1.2:6379
"zhangsan"
192.168.1.2:6379> keys *
1) "xingming"

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_46902396/article/details/109035408