redis三主三從搭建
Redis 三主三從叢集搭建
方式一:原始碼安裝
下載原始碼包:
wget http://download.redis.io/releases/redis-3.2.10.tar.gz
解壓並進入目錄:
tar xf redis-3.2.10 && cd redis-3.2.10
make
redis命令做軟連線
ln -s /root/redis-3.2.10/src/* /usr/bin/
方式二:yum安裝
yum install –y redis
複製redis多節點的啟動指令碼至/etc/init.d下
新增執行許可權
chmod +x /etc/init.d/redis_8001
CentOS 7.2 安裝ruby較高版本
環境需求:在centos中通過yum安裝的ruby版本為2.0.0 但是有些應用需要較高的ruby環境,比如我這裡就是使用redis官方的工具,redis-trib.rb工具構建redis叢集
RVM安裝方式:
[[email protected] ~]# gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
執行官方命令:
[[email protected] ~]# \curl -sSL https://get.rvm.io | bash -s stable
如果看到如下提示證明執行成功:
按照提示執行source命令:
[[email protected] ~]# source /etc/profile.d/rvm.sh
list檢視可供安裝的版本:
[[email protected] ~]# rvm list known
我這裡安裝的2.4的版本
[[email protected] ~]# rvm install 2.4.1
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
使用gem命令安裝redis:
[[email protected] ~]# gem install redis
Fetching: redis-4.0.3.gem (100%)
Successfully installed redis-4.0.3
Parsing documentation for redis-4.0.3
Installing ri documentation for redis-4.0.3
Done installing documentation for redis after 0 seconds
1 gem installed
複製redis-trib.rb命令指令碼(redis原始碼包的src目錄下):
[[email protected] src]# cp redis-trib.rb /usr/bin/
建立三主三從叢集:
[[email protected] ~]# redis-trib.rb create --replicas 1 10.211.55.8:8002 10.211.55.8:8003 10.211.55.8:8004 10.211.55.8:8005 10.211.55.8:8006 10.211.55.8:8007
>>> Creating cluster
Connecting to node 10.211.55.8:8002: OK
Connecting to node 10.211.55.8:8003: OK
Connecting to node 10.211.55.8:8004: OK
Connecting to node 10.211.55.8:8005: OK
Connecting to node 10.211.55.8:8006: OK
Connecting to node 10.211.55.8:8007: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
10.211.55.8:8002
10.211.55.8:8003
10.211.55.8:8004
Adding replica 10.211.55.8:8005 to 10.211.55.8:8002
Adding replica 10.211.55.8:8006 to 10.211.55.8:8003
Adding replica 10.211.55.8:8007 to 10.211.55.8:8004
M: 37774d8ffe1fbeb70023552ccd55f83e63cbf9e0 10.211.55.8:8002
slots:0-5460 (5461 slots) master
M: 179523cb9cedd09e76757cd0ad104ed81fd3111d 10.211.55.8:8003
slots:5461-10922 (5462 slots) master
M: d15b186356f131aaf72137a0efc84c58fcea3349 10.211.55.8:8004
slots:10923-16383 (5461 slots) master
S: 74fd46c3e2deb003a23a6f65bbdf37c2962a4b58 10.211.55.8:8005
replicates 37774d8ffe1fbeb70023552ccd55f83e63cbf9e0
S: a79439d9b33f710d0ab7dee708e0da908bc15b6d 10.211.55.8:8006
replicates 179523cb9cedd09e76757cd0ad104ed81fd3111d
S: 3f5c804d7eaea288c540296c5ada818f4d7b85a5 10.211.55.8:8007
replicates d15b186356f131aaf72137a0efc84c58fcea3349
Can I set the above configuration? (type 'yes' to accept): yes需要輸入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 10.211.55.8:8002)
M: 37774d8ffe1fbeb70023552ccd55f83e63cbf9e0 10.211.55.8:8002
slots:0-5460 (5461 slots) master
M: 179523cb9cedd09e76757cd0ad104ed81fd3111d 10.211.55.8:8003
slots:5461-10922 (5462 slots) master
M: d15b186356f131aaf72137a0efc84c58fcea3349 10.211.55.8:8004
slots:10923-16383 (5461 slots) master
M: 74fd46c3e2deb003a23a6f65bbdf37c2962a4b58 10.211.55.8:8005
slots: (0 slots) master
replicates 37774d8ffe1fbeb70023552ccd55f83e63cbf9e0
M: a79439d9b33f710d0ab7dee708e0da908bc15b6d 10.211.55.8:8006
slots: (0 slots) master
replicates 179523cb9cedd09e76757cd0ad104ed81fd3111d
M: 3f5c804d7eaea288c540296c5ada818f4d7b85a5 10.211.55.8:8007
slots: (0 slots) master
replicates d15b186356f131aaf72137a0efc84c58fcea3349
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
搭建完成
檢視叢集狀態指定其中一個節點即可:
[[email protected] src]# redis-trib.rb check 10.211.55.8:8003