欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

redis-cluster集群安装(基于redis-3.2.10)

程序员文章站 2022-05-07 21:05:38
上节主要演示了redis单节点的安装部署,对于数据量更大的服务可以安装redis-cluster进行处理 1. 安装ruby 2.安装redis-cluster 3.到redis源码目录找到集群创建工具 4.创建redis-cluster集群节点 (1)创建节点目录,修改配置文件 ......

上节主要演示了redis单节点的安装部署,对于数据量更大的服务可以安装redis-cluster进行处理

1. 安装ruby

yum install ruby ruby-devel rubygems rpm-build -y
rpm -qa|grep ruby
ruby -v

2.安装redis-cluster

gem install redis --version 3.2.1
gem list

3.到redis源码目录找到集群创建工具

/bin/cp /server/tools/redis-3.2.10/src/redis-trib.rb /usr/local/redis/bin/

4.创建redis-cluster集群节点

(1)创建节点目录,修改配置文件

[root@redis-server tools]# mkdir -p /usr/local/redis/redis-cluster/{7001,7002,7003}
cluster-enabled yes cluster-config-file /usr/local/redis/redis-cluster/6379/nodes-6379.conf cluster-node-timeout 5000 appendonly yes

 

 

[root@redis-server tools]# sh -x add_redis-cluster-port_rc.sh 8001 8002 8003
+ echo '------ Start Create redis-cluster ------'
------ Start Create redis-cluster ------
+ redisport1=8001
+ redisport2=8002
+ redisport3=8003
+ redis_path=/usr/local/redis
+ redis_cluster_path=/usr/local/redis/redis-cluster
++ grep -v 127.0.0.1
++ grep -v inet6
++ grep inet
++ awk '{print $2}'
++ /sbin/ifconfig -a
++ tr -d addr:
+ localIP=192.168.1.71
+ '[' -z 8001 ']'
+ echo 'The redis-port is 8001'
The redis-port is 8001
+ '[' -z 8002 ']'
+ echo 'The redis-port is 8002'
The redis-port is 8002
+ '[' -z 8003 ']'
+ echo 'The redis-port is 8003'
The redis-port is 8003
+ echo /usr/local/redis/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
/usr/local/redis/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
+ sleep 1
+ mkdir -p /usr/local/redis/redis-cluster/8001 /usr/local/redis/redis-cluster/8002 /usr/local/redis/redis-cluster/8003
+ cd /server/tools/
+ /bin/cp democonf_redis-cluster_6379.conf /usr/local/redis/redis-cluster/8001/conf-8001.conf
+ sed -i s#6379#8001#g /usr/local/redis/redis-cluster/8001/conf-8001.conf
+ /bin/cp democonf_redis-cluster_6379.conf /usr/local/redis/redis-cluster/8002/conf-8002.conf
+ sed -i s#6379#8002#g /usr/local/redis/redis-cluster/8002/conf-8002.conf
+ /bin/cp democonf_redis-cluster_6379.conf /usr/local/redis/redis-cluster/8003/conf-8003.conf
+ sed -i s#6379#8003#g /usr/local/redis/redis-cluster/8003/conf-8003.conf
+ tree /usr/local/redis/redis-cluster
/usr/local/redis/redis-cluster
├── 8001
│   └── conf-8001.conf
├── 8002
│   └── conf-8002.conf
└── 8003
    └── conf-8003.conf

3 directories, 3 files
+ echo '------ Start redis-cluster nodes ------'
------ Start redis-cluster nodes ------
+ sleep 1
+ /usr/local/redis/bin/redis-server /usr/local/redis/redis-cluster/8001/conf-8001.conf
+ /usr/local/redis/bin/redis-server /usr/local/redis/redis-cluster/8002/conf-8002.conf
+ /usr/local/redis/bin/redis-server /usr/local/redis/redis-cluster/8003/conf-8003.conf
++ date +%F
+ echo '# redis-cluster-port for 8001,8002,8003 in 2017-09-21'
+ echo '/usr/local/redis/bin/redis-server /usr/local/redis/redis-cluster/8001/conf-8001.conf'
+ echo '/usr/local/redis/bin/redis-server /usr/local/redis/redis-cluster/8002/conf-8002.conf'
+ echo '/usr/local/redis/bin/redis-server /usr/local/redis/redis-cluster/8003/conf-8003.conf'
+ tail -4 /etc/rc.local
tail: 无法使用 inotify 机制,回归为 polling 机制
# redis-cluster-port for 8001,8002,8003 in 2017-09-21
/usr/local/redis/bin/redis-server /usr/local/redis/redis-cluster/8001/conf-8001.conf
/usr/local/redis/bin/redis-server /usr/local/redis/redis-cluster/8002/conf-8002.conf
/usr/local/redis/bin/redis-server /usr/local/redis/redis-cluster/8003/conf-8003.conf
+ echo '------ Create redis-cluster ------'
------ Create redis-cluster ------
+ sleep 1
+ /usr/local/redis/bin/redis-trib.rb create --replicas 0 192.168.1.71:8001 192.168.1.71:8002 192.168.1.71:8003
>>> Creating cluster
Connecting to node 192.168.1.71:8001: OK
Connecting to node 192.168.1.71:8002: OK
Connecting to node 192.168.1.71:8003: OK
>>> Performing hash slots allocation on 3 nodes...
Using 3 masters:
192.168.1.71:8001
192.168.1.71:8002
192.168.1.71:8003
M: 97ca887459268c2effca0af3263dcd00e83cae37 192.168.1.71:8001
   slots:0-5460 (5461 slots) master
M: e43cda13f069241a25786bb4916e21e7e8a5e1d5 192.168.1.71:8002
   slots:5461-10922 (5462 slots) master
M: 53383a751348ed8bd2ec88fd487ada344c7a7bc8 192.168.1.71:8003
   slots:10923-16383 (5461 slots) master
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join.
>>> Performing Cluster Check (using node 192.168.1.71:8001)
M: 97ca887459268c2effca0af3263dcd00e83cae37 192.168.1.71:8001
   slots:0-5460 (5461 slots) master
M: e43cda13f069241a25786bb4916e21e7e8a5e1d5 192.168.1.71:8002
   slots:5461-10922 (5462 slots) master
M: 53383a751348ed8bd2ec88fd487ada344c7a7bc8 192.168.1.71:8003
   slots:10923-16383 (5461 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
+ echo '------ Test redis-cluster ------'
------ Test redis-cluster ------
+ sleep 1
+ grep --color=auto redis-server
+ netstat -anptl
tcp        0      0 0.0.0.0:18001               0.0.0.0:*                   LISTEN      12377/redis-server  
tcp        0      0 0.0.0.0:18002               0.0.0.0:*                   LISTEN      12379/redis-server  
tcp        0      0 0.0.0.0:18003               0.0.0.0:*                   LISTEN      12383/redis-server  
tcp        0      0 0.0.0.0:8001                0.0.0.0:*                   LISTEN      12377/redis-server  
tcp        0      0 0.0.0.0:8002                0.0.0.0:*                   LISTEN      12379/redis-server  
tcp        0      0 0.0.0.0:8003                0.0.0.0:*                   LISTEN      12383/redis-server  
tcp        0      0 192.168.1.71:54496          192.168.1.71:18002          ESTABLISHED 12377/redis-server  
tcp        0      0 192.168.1.71:38063          192.168.1.71:18003          ESTABLISHED 12377/redis-server  
tcp        0      0 192.168.1.71:50397          192.168.1.71:18002          ESTABLISHED 12383/redis-server  
tcp        0      0 192.168.1.71:55957          192.168.1.71:18001          ESTABLISHED 12379/redis-server  
tcp        0      0 192.168.1.71:18003          192.168.1.71:38063          ESTABLISHED 12383/redis-server  
tcp        0      0 192.168.1.71:18001          192.168.1.71:55957          ESTABLISHED 12377/redis-server  
tcp        0      0 192.168.1.71:18001          192.168.1.71:34296          ESTABLISHED 12377/redis-server  
tcp        0      0 192.168.1.71:18002          192.168.1.71:54496          ESTABLISHED 12379/redis-server  
tcp        0      0 192.168.1.71:37840          192.168.1.71:18003          ESTABLISHED 12379/redis-server  
tcp        0      0 192.168.1.71:18003          192.168.1.71:37840          ESTABLISHED 12383/redis-server  
tcp        0      0 192.168.1.71:34296          192.168.1.71:18001          ESTABLISHED 12383/redis-server  
tcp        0      0 192.168.1.71:18002          192.168.1.71:50397          ESTABLISHED 12379/redis-server  
+ /usr/local/redis/bin/redis-cli -c -p 8001
127.0.0.1:8001> exit
+ echo '------ Create redis-cluster is OK! ------'
------ Create redis-cluster is OK! ------
[root@zstest1 tools]#