I.准备vm Centos7 64位
master:10.1.125.152
slave1:10.1.125.89
slave2:10.1.125.212
slave3:10.1.125.203
slave4:10.1.125.129
slave5:10.1.125.180
II.linux设置控制台等代理上网
vi /etc/profile
http_proxy=proxy1.xxx.cn:8080
https_proxy=proxy1.xxx.cn:8080
export http_proxy
export https_proxy
用户注销重新进入
II.安装依赖的服务:
yum install gcc tcl
I.下载安装
cd /usr/local/src
wget http://download.redis.io/releases/redis-3.0.3.tar.gz
mkdir /usr/local/redis3
tar -zxvf redis-3.0.3.tar.gz
cd redis-3.0.3
make PREFIX=/usr/local/redis3 install
出现问题,需要下载依赖
zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录
make MALLOC=libc PREFIX=/usr/local/redis3 install
I.配置节点
mkdir -p /usr/local/redis3/cluster/7111
cp /usr/local/src/redis-3.0.3/redis.conf /usr/local/redis3/cluster/7111/redis-7111.conf
daemonize yes
pidfile /var/run/redis-7111.pid
port 7111
databases 1
cluster-enabled yes
cluster-config-file /usr/local/redis3/cluster/7111/nodes.conf
cluster-node-timeout 15000
cluster-migration-barrier 1
cluster-require-full-coverage yes
appendonly yes
dir /usr/local/redis3/cluster/7111
II.修改redis-711*.conf配置文件 其它节点配置文件修改端口即可
# 操作slave1
# mkdir -p /usr/local/redis3/cluster/7112
cd /usr/local/redis3/cluster/7112/
rz redis-7112.conf
# 操作slave2
# mkdir -p /usr/local/redis3/cluster/7113
cd /usr/local/redis3/cluster/7113/
rz redis-7113.conf
# 操作slave3
# mkdir -p /usr/local/redis3/cluster/7114
cd /usr/local/redis3/cluster/7114/
rz redis-7114.conf
# 操作slave4
# mkdir -p /usr/local/redis3/cluster/7115
cd /usr/local/redis3/cluster/7115/
rz redis-7115.conf
# 操作slave5
# mkdir -p /usr/local/redis3/cluster/7116
cd /usr/local/redis3/cluster/7116/
rz redis-7116.conf
II.启动
/usr/local/redis3/bin/redis-server /usr/local/redis3/cluster/7111/redis-7111.conf
/usr/local/redis3/bin/redis-server /usr/local/redis3/cluster/7112/redis-7112.conf
/usr/local/redis3/bin/redis-server /usr/local/redis3/cluster/7113/redis-7113.conf
/usr/local/redis3/bin/redis-server /usr/local/redis3/cluster/7114/redis-7114.conf
/usr/local/redis3/bin/redis-server /usr/local/redis3/cluster/7115/redis-7115.conf
/usr/local/redis3/bin/redis-server /usr/local/redis3/cluster/7116/redis-7116.conf
II.检查节点启动
ps -ef|grep redis
I.安装ruby
yum install ruby rubygems
# ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]
# gem install redis
Successfully installed redis-3.2.1
I.启动:
# cd /usr/local/src/redis-3.0.3/src/
# cp redis-trib.rb /usr/local/bin/redis-trib
[root@localhost bin]# /usr/local/bin/redis-trib create --replicas 1 10.1.125.152:7111 10.1.125.89:7112 10.1.125.212:7113 10.1.125.203:7114 10.1.125.129:7115 10.1.125.180:7116
>>> Creating cluster
Connecting to node 10.1.125.152:7111: OK
Connecting to node 10.1.125.89:7112: [ERR] Sorry, can't connect to node 10.1.125.89:7112
II.安装服务关闭防火墙
yum -y install telnet
关闭防火墙:centos7 默认用的是firewall
systemctl stop firewalld.service
service iptables stop
II.再次启动
*** Aborting...
[root@localhost ~]# /usr/local/bin/redis-trib create --replicas 1 10.1.125.152:7111 10.1.125.89:7112 10.1.125.212:7113 10.1.125.203:7114 10.1.125.129:7115 10.1.125.180:7116
>>> Creating cluster
Connecting to node 10.1.125.152:7111: OK
Connecting to node 10.1.125.89:7112: OK
Connecting to node 10.1.125.212:7113: OK
Connecting to node 10.1.125.203:7114: OK
Connecting to node 10.1.125.129:7115: OK
Connecting to node 10.1.125.180:7116: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
10.1.125.152:7111
10.1.125.89:7112
10.1.125.212:7113
Adding replica 10.1.125.203:7114 to 10.1.125.152:7111
Adding replica 10.1.125.129:7115 to 10.1.125.89:7112
Adding replica 10.1.125.180:7116 to 10.1.125.212:7113
M: 2b85ef3681cac8cbdc95a9efe1cba261c77b5fd8 10.1.125.152:7111
slots:0-5460 (5461 slots) master
M: 859c8c7c9c26244ee1eb1cccb7d0b8007d0a8203 10.1.125.89:7112
slots:5461-10922 (5462 slots) master
M: c85495af7335ab8cff332b007682e6f88e1041c4 10.1.125.212:7113
slots:10923-16383 (5461 slots) master
S: 58e90e8149d334abe17641ec75bd5d6f2bbe4227 10.1.125.203:7114
replicates 2b85ef3681cac8cbdc95a9efe1cba261c77b5fd8
S: 8bc2f4b20b445eebb7bb3ea75fb8b437de26c813 10.1.125.129:7115
replicates 859c8c7c9c26244ee1eb1cccb7d0b8007d0a8203
S: c0fcd23d8c9dbd425b158ca98fbefe2a73b3ee68 10.1.125.180:7116
replicates c85495af7335ab8cff332b007682e6f88e1041c4
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 10.1.125.152:7111)
M: 2b85ef3681cac8cbdc95a9efe1cba261c77b5fd8 10.1.125.152:7111
slots:0-5460 (5461 slots) master
M: 859c8c7c9c26244ee1eb1cccb7d0b8007d0a8203 10.1.125.89:7112
slots:5461-10922 (5462 slots) master
M: c85495af7335ab8cff332b007682e6f88e1041c4 10.1.125.212:7113
slots:10923-16383 (5461 slots) master
M: 58e90e8149d334abe17641ec75bd5d6f2bbe4227 10.1.125.203:7114
slots: (0 slots) master
replicates 2b85ef3681cac8cbdc95a9efe1cba261c77b5fd8
M: 8bc2f4b20b445eebb7bb3ea75fb8b437de26c813 10.1.125.129:7115
slots: (0 slots) master
replicates 859c8c7c9c26244ee1eb1cccb7d0b8007d0a8203
M: c0fcd23d8c9dbd425b158ca98fbefe2a73b3ee68 10.1.125.180:7116
slots: (0 slots) master
replicates c85495af7335ab8cff332b007682e6f88e1041c4
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
I.测试:slave2节点:
[root@localhost ~]# /usr/local/redis3/bin/redis-cli -c -p 7113
127.0.0.1:7113> set name dingsia
-> Redirected to slot [5798] located at 10.1.125.89:7112
OK
10.1.125.89:7112>
回到master节点:
[root@localhost ~]# /usr/local/redis3/bin/redis-cli -c -p 7113
127.0.0.1:7113> set name dingsia
-> Redirected to slot [5798] located at 10.1.125.89:7112
OK
10.1.125.89:7112>
10.1.125.89:7112> cluster nodes
2b85ef3681cac8cbdc95a9efe1cba261c77b5fd8
10.1.125.152:7111 master - 0 1459221618217 1 connected 0-5460
c85495af7335ab8cff332b007682e6f88e1041c4
10.1.125.212:7113 master - 0 1459221615191 3 connected 10923-16383
8bc2f4b20b445eebb7bb3ea75fb8b437de26c813
10.1.125.129:7115 slave 859c8c7c9c26244ee1eb1cccb7d0b8007d0a8203 0 1459221617209 2 connected
c0fcd23d8c9dbd425b158ca98fbefe2a73b3ee68
10.1.125.180:7116 slave c85495af7335ab8cff332b007682e6f88e1041c4 0 1459221614184 3 connected
859c8c7c9c26244ee1eb1cccb7d0b8007d0a8203
10.1.125.89:7112 myself,master
- 0 0 2 connected 5461-10922
58e90e8149d334abe17641ec75bd5d6f2bbe4227
10.1.125.203:7114 slave 2b85ef3681cac8cbdc95a9efe1cba261c77b5fd8 0 1459221616200 4 connected
10.1.125.89:7112>
三主三从
初步测试完毕
参考:
http://redis.io/topics/cluster-tutorial