|
一、环境准备:
系统OS: CentOS6.8
集群环境:三台主机9个节点
软件版本:redis-4.0.11.tar.gz
redis cluster节点信息:
redis01
172.16.8.13:7000
172.16.8.13:7001
172.16.8.13:7002
redis02
172.16.8.14:7003
172.16.8.14:7004
172.16.8.14:7005
redis03
172.16.8.15:7006
172.16.8.15:7007
172.16.8.15:7008
二、redis安装及配置
安装所需的包
#yum install -y gcc g++ make gcc-c++ kernel-devel automake autoconf libtool make wget tcl vim ruby rubygems unzip
yum -y install zlib zlib-devel openssl openssl-devel gcc gcc-c++
百度云 链接:https://pan.baidu.com/s/1L9KdpWieYlr5K1qPRMuK_w 密码:t8ru
离线安装ruby
下载ruby-2.4.4并上传至服务器
https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.1.tar.gz
把包放到改目录下
tar -xvf ruby-2.4.4.tar.gz
cd ruby-2.4.4
./configure --prefix=/usr/local/ruby
echo $?
make && make install
echo "PATH=$PATH:/usr/local/ruby/bin" >> /etc/profile
source /etc/profile
which ruby
/usr/bin/ruby
rm -rf /usr/bin/ruby
ln -s /usr/local/ruby/bin/ruby /usr/bin/ruby
[root@localhost ruby-2.4.4]# ruby -v
ruby 2.4.4p296 (2018-03-28 revision 63013) [x86_64-linux]
离线安装rubygems
下载rubygems-2.7.6.tgz并上传至服务器
https://rubygems.org/rubygems/rubygems-2.7.6.tgz
tar -xvf rubygems-2.7.6.tgz
chown -R root.root rubygems-2.7.6
mv rubygems-2.7.6 /usr/local/
cd /usr/local/rubygems-2.7.6/
ruby setup.rb
echo "PATH=$PATH:/usr/local/rubygems-2.7.6" >> /etc/profile
source /etc/profile
查看当前版本
[root@localhost tools]# gem -v
2.7.6
-------------------------------------------------------------------------------------------------------------------
离线配置rubygems的redisapi
下载redis的gem并上传至服务器
https://rubygems.org/downloads/redis-3.3.0.gem
下载新的版本
https://rubygems.org/downloads/redis-4.0.2.gem
gem install -l redis-3.3.0.gem
[root@localhost tools]# gem list redis
*** LOCAL GEMS ***
redis (3.3.0)
如果安装是旧的版本
卸载
gem uninstal redis
安装
gem install -l redis-4.0.2.gem
[root@localhost tools]# gem list redis
*** LOCAL GEMS ***
redis (4.0.2)
离线安装tcl
下载tcl8并上传至服务器
https://sourceforge.net/projects/tcl/files/Tcl/8.6.0/
unzip tcl868-src.zip
cd tcl8.6.8/unix/
./configure --prefix=/usr/local/tcl
echo $?
make
echo $?
make install
echo $?
make install-private-headers
ln -v -sf tclsh8.6 /usr/local/tcl/bin/tclsh
chmod -v 755 /usr/local/tcl/lib/libtcl8.6.so
echo "PATH=$PATH:/usr/local/tcl/bin" >> /etc/profile
source /etc/profile
创建用户
useradd qasuser
echo devops | passwd --stdin qasuser
下载redis安装包
http://download.redis.io/releases/redis-4.0.11.tar.gz
安装及配置
tar -xvf redis-4.0.11.tar.gz -C /app
chown -R qasuser.qasuser /app/redis-4.0.11
cd /app/redis-4.0.11
------------------------------------------------------------------------------------------------------------
如果因为上次编译失败,有残留的文件,做法如下:
[qasuser@localhost redis-4.0.11]$make distclean
------------------------------------------------------------------------------------------------------------
[qasuser@localhost redis-4.0.11]$ make
查看是否编译是否成功
[qasuser@localhost redis-4.0.11]$ echo $?
0
节点1上执行(172.16.8.13)
su - qasuser
mkdir /app/redis-4.0.11/redis-cluster
cd /app/redis-4.0.11/redis-cluster
mkdir {7000,7001,7002}
cat 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 172.16.8.13:7000)
M: 6a4175a51250ed6a88b6caaf1667d055c6f226cd 172.16.8.13:7000
slots:0-4095 (4096 slots) master
2 additional replica(s)
M: 3f9239d43ad592947c7c842de7cce1814ab159d5 172.16.8.15:7006
slots:8192-12287 (4096 slots) master
1 additional replica(s)
S: a63a2751d14ff5ba19bdb2ace3eab3a2617f0b87 172.16.8.13:7002
slots: (0 slots) slave
replicates ecd312c581df995c352c67fc89f8a72993109df4
M: 3eeeb535acd80c239a09797cad611cb51ef76845 172.16.8.13:7001
slots:12288-16383 (4096 slots) master
1 additional replica(s)
S: 95016481a4df1c9fbbc3c34e1e434627b266d144 172.16.8.15:7008
slots: (0 slots) slave
replicates 3eeeb535acd80c239a09797cad611cb51ef76845
S: 9a5700fd232689579cb48f810162ed0a27c28948 172.16.8.14:7005
slots: (0 slots) slave
replicates 3f9239d43ad592947c7c842de7cce1814ab159d5
S: b7e4c7cf7da64114967a8a69acaa3aa4f809173f 172.16.8.14:7004
slots: (0 slots) slave
replicates 6a4175a51250ed6a88b6caaf1667d055c6f226cd
M: ecd312c581df995c352c67fc89f8a72993109df4 172.16.8.14:7003
slots:4096-8191 (4096 slots) master
1 additional replica(s)
S: a5ec006d814acce1bf18b77a767291f407fbb7fe 172.16.8.15:7007
slots: (0 slots) slave
replicates 6a4175a51250ed6a88b6caaf1667d055c6f226cd
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
集群验证
/app/redis-4.0.11/src/redis-cli -h 172.16.8.13 -c -p 7000
[qasuser@localhost ~]$ /app/redis-4.0.11/src/redis-cli -h 172.16.8.13 -c -p 7000
172.16.8.14:7003> set name qas
OK
172.16.8.14:7003> get name
"qas"
/app/redis-4.0.11/src/redis-cli -h 172.16.8.14 -c -p 7004
[qasuser@localhost redis-cluster]$ /app/redis-4.0.11/src/redis-cli -h 172.16.8.14 -c -p 7004
172.16.8.14:7004> get name
-> Redirected to slot [5798] located at 172.16.8.14:7003
"qas"
/app/redis-4.0.11/src/redis-cli -h 172.16.8.15 -c -p 7008
[qasuser@localhost redis-cluster]$ /app/redis-4.0.11/src/redis-cli -h 172.16.8.15 -c -p 7008
172.16.8.15:7008> get name
-> Redirected to slot [5798] located at 172.16.8.14:7003
"qas"
----------------------------------------------------------------------------------------------------------------------------
/app/redis-4.0.11/src/redis-trib.rb check 172.16.8.13:7000
[qasuser@localhost ~]$ /app/redis-4.0.11/src/redis-trib.rb check 172.16.8.13:7000
/usr/local/ruby/lib/ruby/gems/2.4.0/gems/redis-3.3.0/lib/redis/client.rb:459: warning: constant ::Fixnum is deprecated
>>> Performing Cluster Check (using node 172.16.8.13:7000)
M: 6a4175a51250ed6a88b6caaf1667d055c6f226cd 172.16.8.13:7000
slots:0-4095 (4096 slots) master
2 additional replica(s)
M: 3f9239d43ad592947c7c842de7cce1814ab159d5 172.16.8.15:7006
slots:8192-12287 (4096 slots) master
1 additional replica(s)
S: a63a2751d14ff5ba19bdb2ace3eab3a2617f0b87 172.16.8.13:7002
slots: (0 slots) slave
replicates ecd312c581df995c352c67fc89f8a72993109df4
M: 3eeeb535acd80c239a09797cad611cb51ef76845 172.16.8.13:7001
slots:12288-16383 (4096 slots) master
1 additional replica(s)
S: 95016481a4df1c9fbbc3c34e1e434627b266d144 172.16.8.15:7008
slots: (0 slots) slave
replicates 3eeeb535acd80c239a09797cad611cb51ef76845
S: 9a5700fd232689579cb48f810162ed0a27c28948 172.16.8.14:7005
slots: (0 slots) slave
replicates 3f9239d43ad592947c7c842de7cce1814ab159d5
S: b7e4c7cf7da64114967a8a69acaa3aa4f809173f 172.16.8.14:7004
slots: (0 slots) slave
replicates 6a4175a51250ed6a88b6caaf1667d055c6f226cd
M: ecd312c581df995c352c67fc89f8a72993109df4 172.16.8.14:7003
slots:4096-8191 (4096 slots) master
1 additional replica(s)
S: a5ec006d814acce1bf18b77a767291f407fbb7fe 172.16.8.15:7007
slots: (0 slots) slave
replicates 6a4175a51250ed6a88b6caaf1667d055c6f226cd
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
列出集群节点
/app/redis-4.0.11/src/redis-cli -h 172.16.8.13 -c -p 7000
[qasuser@localhost ~]$ /app/redis-4.0.11/src/redis-cli -h 172.16.8.13 -c -p 7000
172.16.8.13:7000> cluster nodes
3f9239d43ad592947c7c842de7cce1814ab159d5 172.16.8.15:7006@17006 master - 0 1536205999000 7 connected 8192-12287
a63a2751d14ff5ba19bdb2ace3eab3a2617f0b87 172.16.8.13:7002@17002 slave ecd312c581df995c352c67fc89f8a72993109df4 0 1536205998105 4 connected
3eeeb535acd80c239a09797cad611cb51ef76845 172.16.8.13:7001@17001 master - 0 1536205999000 2 connected 12288-16383
95016481a4df1c9fbbc3c34e1e434627b266d144 172.16.8.15:7008@17008 slave 3eeeb535acd80c239a09797cad611cb51ef76845 0 1536205999000 9 connected
9a5700fd232689579cb48f810162ed0a27c28948 172.16.8.14:7005@17005 slave 3f9239d43ad592947c7c842de7cce1814ab159d5 0 1536206000136 7 connected
6a4175a51250ed6a88b6caaf1667d055c6f226cd 172.16.8.13:7000@17000 myself,master - 0 1536205997000 1 connected 0-4095
b7e4c7cf7da64114967a8a69acaa3aa4f809173f 172.16.8.14:7004@17004 slave 6a4175a51250ed6a88b6caaf1667d055c6f226cd 0 1536205999121 5 connected
ecd312c581df995c352c67fc89f8a72993109df4 172.16.8.14:7003@17003 master - 0 1536205997000 4 connected 4096-8191
a5ec006d814acce1bf18b77a767291f407fbb7fe 172.16.8.15:7007@17007 slave 6a4175a51250ed6a88b6caaf1667d055c6f226cd 0 1536206001139 8 connected
集群信息
172.16.8.13:7000> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:9
cluster_size:4
cluster_current_epoch:9
cluster_my_epoch:1
cluster_stats_messages_ping_sent:1443
cluster_stats_messages_pong_sent:1494
cluster_stats_messages_sent:2937
cluster_stats_messages_ping_received:1486
cluster_stats_messages_pong_received:1443
cluster_stats_messages_meet_received:8
cluster_stats_messages_received:2937
关闭集群
推荐做法:
[qasuser@localhost redis-cluster]$ pkill redis
[qasuser@localhost redis-cluster]$ pkill redis
[qasuser@localhost redis-cluster]$ pkill redis
或者循环节点逐个关闭
[qasuser@localhost redis-cluster]$ for((i=0;i |
|
|
|
|
|
|