621
汽車大全
CentOS6.5 Redis3.x集群安裝配置
準備三台機器做redis
192.168.99.5
192.168.99.28
192.168.99.29
操作係統:
CentOS6.5 64bit
軟件包:
redis-3.2.7.tar.gz
redis-3.3.3.gem
rubygems-1.3.7-5.el6.noarch.rpm
1.編譯安裝redis
tar zxf redis-3.2.7.tar.gz
cd redis-3.2.7
[
Centos6.5上需要修改一下Makefile文件
$redis/src下
修改如下屬性
FINAL_LIBS = -lm -lrt
]
make
sudo make install
2.安裝rubygems
sudo yum install -y rubygems-1.3.7-5.el6.noarch.rpm
3.gem 安裝集群用的redis
sudo gem install -l redis-3.3.3.gem
在每一台幾點上都要執行以下步驟
1.創建集群配置文件夾
sudo mkdir /usr/local/redis-cluster/{7000,7001,7002}
2.7000,7001,7002下,每個文件夾下創建redis.conf,
sudo touch /usr/local/redis-cluster/7000(7001,7002)/redis.conf
並添加如下配置:
#監聽的端口,7000,7001,7002
port 7000
#redis本機ip
bind 192.168.99.5
daemonize yes
#按端口號修改pid的序號
pidfile /var/run/redis_7000.pid
#啟用集群模式
cluster-enabled yes
#也是按照端口號修改序號
cluster-config-file nodes_7000.conf
cluster-node-timeout 15000
appendonly yes
3.指定配置文件啟動3個redis實例
sudo /usr/local/bin/redis-server /usr/local/redis-cluster/7000/redis.conf
sudo /usr/local/bin/redis-server /usr/local/redis-cluster/7001/redis.conf
sudo /usr/local/bin/redis-server /usr/local/redis-cluster/7002/redis.conf
4.查看端口
sudo netstat -tnlp
會有7000,7001,7002 ,17000 ,17001 ,17002 這幾個redis進程
創建集群
1.在任一台機器,解壓後的redis的/src/目錄下執行以下程序,選出三台機器上的三個節點作為redis集群的三個master節點
./redis-trib.rb create 192.168.99.5:7000 192.168.99.28:7000 192.168.99.29:7000
輸出:
Using 3 masters:
192.168.99.29:7000
192.168.99.28:7000
192.168.99.5:7000
M: 29608e1a8b3d3e28315d1231b3a79dc3349bde21 192.168.99.5:7000
slots:10923-16383 (5461 slots) master
M: eeb89dca7b91e683e77a443f03187eef4ab26cda 192.168.99.28:7000
slots:5461-10922 (5462 slots) master
M: 0d589ff3efc479fc4acae086045ee1293767bdc6 192.168.99.29:7000
slots:0-5460 (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.99.5:7000)
M: 29608e1a8b3d3e28315d1231b3a79dc3349bde21 192.168.99.5:7000
slots:10923-16383 (5461 slots) master
0 additional replica(s)
M: 0d589ff3efc479fc4acae086045ee1293767bdc6 192.168.99.29:7000
slots:0-5460 (5461 slots) master
0 additional replica(s)
M: eeb89dca7b91e683e77a443f03187eef4ab26cda 192.168.99.28:7000
slots:5461-10922 (5462 slots) master
0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
You have new mail in /var/spool/mail/mobileoa
2.檢查集群:選定集群中一個master節點的ip就可以查詢整個集群
[mobileoa@db2test1 src]$ ./redis-trib.rb check 192.168.99.5:7000
>```
```javascript
>> Performing Cluster Check (using node 192.168.99.5:7000)
M: 29608e1a8b3d3e28315d1231b3a79dc3349bde21 192.168.99.5:7000
slots:10923-16383 (5461 slots) master
0 additional replica(s)
M: 0d589ff3efc479fc4acae086045ee1293767bdc6 192.168.99.29:7000
slots:0-5460 (5461 slots) master
0 additional replica(s)
M: eeb89dca7b91e683e77a443f03187eef4ab26cda 192.168.99.28:7000
slots:5461-10922 (5462 slots) master
0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
3.給集群每個主節點分散配置從節點,
添加節點 類型 要給那個master添加從節點 從節點ip 要添加到的集群
./redis-trib.rb add-node --slave --master-id 29608e1a8b3d3e28315d1231b3a79dc3349bde21 192.168.99.28:7001 192.168.99.5:7000
./redis-trib.rb add-node --slave --master-id 29608e1a8b3d3e28315d1231b3a79dc3349bde21 192.168.99.29:7001 192.168.99.5:7000
./redis-trib.rb add-node --slave --master-id 0d589ff3efc479fc4acae086045ee1293767bdc6 192.168.99.5:7002 192.168.99.5:7000
./redis-trib.rb add-node --slave --master-id 0d589ff3efc479fc4acae086045ee1293767bdc6 192.168.99.28:7002 192.168.99.5:7000
./redis-trib.rb add-node --slave --master-id eeb89dca7b91e683e77a443f03187eef4ab26cda 192.168.99.5:7001 192.168.99.5:7000
./redis-trib.rb add-node --slave --master-id eeb89dca7b91e683e77a443f03187eef4ab26cda 192.168.99.29:7002 192.168.99.5:7000
4.查看集群狀態
./redis-trib.rb check 192.168.99.5:7000
測試集群
redis-cli -h 192.168.99.28 -c -p 7002 ,加參數 -C 可連接到集群,因為上麵 redis.conf 將 bind 改為了ip地址,所以 -h 參數不可以省略。
set hello world
查看key
在另一個節點連接redis ,並查詢
redis-cli -h 192.168.99.5 -c -p 7001
get hello
最後更新:2017-08-13 22:47:10