function_status()
{
a=`ps -A|grep "redis-server\>" -c`
if [ $a -ge 1 ];then
echo -e "The Redis is [\e[0;32;5m runing \e[0m]"
else
echo -e "The Redis is [\e[0;31;5m not run \e[0m]"
fi
}
function_status()
{
a=`ps -A|grep "redis-server\>" -c`
if [ $a -ge 1 ];then
echo -e "The Redis is [\e[0;32;5m runing \e[0m]"
else
echo -e "The Redis is [\e[0;31;5m not run \e[0m]"
fi
}
#在任意一台机器上操作
[iyunv@redis1 ~]# /usr/local/redis/src/redis-trib.rb create --replicas 1 172.16.1.46:6379 172.16.1.46:6380 172.16.1.47:6379 172.16.1.47:6380 172.16.1.48:6379 172.16.1.48:6380
>>> Creating cluster
Connecting to node 172.16.1.46:6379: OK
Connecting to node 172.16.1.46:6380: OK
Connecting to node 172.16.1.47:6379: OK
Connecting to node 172.16.1.47:6380: OK
Connecting to node 172.16.1.48:6379: OK
Connecting to node 172.16.1.48:6380: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
172.16.1.46:6379
172.16.1.47:6379
172.16.1.48:6379
Adding replica 172.16.1.47:6380 to 172.16.1.46:6379
Adding replica 172.16.1.46:6380 to 172.16.1.47:6379
Adding replica 172.16.1.48:6380 to 172.16.1.48:6379
M: 3c2279ff6333b98a233ebf541e2b75981d27751f 172.16.1.46:6379
slots:0-5460 (5461 slots) master
S: eb0b79b22797c14172c8f0f117a4839d6825ea1f 172.16.1.46:6380
replicates dd122d63def65b8bc62719cabbb468f7976b1b73
M: dd122d63def65b8bc62719cabbb468f7976b1b73 172.16.1.47:6379
slots:5461-10922 (5462 slots) master
S: c8136c436cec8146dbbbd1ff2e5468d1dd5dd195 172.16.1.47:6380
replicates 3c2279ff6333b98a233ebf541e2b75981d27751f
M: a0cf20f0ea29760dfdb3e4748417efaefc0c37f0 172.16.1.48:6379
slots:10923-16383 (5461 slots) master
S: c6df03cde4424b2b09752c89d236ee1cd4834709 172.16.1.48:6380
replicates a0cf20f0ea29760dfdb3e4748417efaefc0c37f0
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 172.16.1.46:6379)
M: 3c2279ff6333b98a233ebf541e2b75981d27751f 172.16.1.46:6379
slots:0-5460 (5461 slots) master
M: eb0b79b22797c14172c8f0f117a4839d6825ea1f 172.16.1.46:6380
slots: (0 slots) master
replicates dd122d63def65b8bc62719cabbb468f7976b1b73
M: dd122d63def65b8bc62719cabbb468f7976b1b73 172.16.1.47:6379
slots:5461-10922 (5462 slots) master
M: c8136c436cec8146dbbbd1ff2e5468d1dd5dd195 172.16.1.47:6380
slots: (0 slots) master
replicates 3c2279ff6333b98a233ebf541e2b75981d27751f
M: a0cf20f0ea29760dfdb3e4748417efaefc0c37f0 172.16.1.48:6379
slots:10923-16383 (5461 slots) master
M: c6df03cde4424b2b09752c89d236ee1cd4834709 172.16.1.48:6380
slots: (0 slots) master
replicates a0cf20f0ea29760dfdb3e4748417efaefc0c37f0
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
#检查集群状态
[iyunv@redis1 ~]# /usr/local/redis/src/redis-trib.rb check 127.0.0.1:6379
Connecting to node 127.0.0.1:6379: OK
Connecting to node 172.16.1.48:6379: OK
Connecting to node 172.16.1.48:6380: OK
Connecting to node 172.16.1.47:6379: OK
Connecting to node 172.16.1.47:6380: OK
Connecting to node 172.16.1.46:6380: OK
>>> Performing Cluster Check (using node 127.0.0.1:6379)
M: 3c2279ff6333b98a233ebf541e2b75981d27751f 127.0.0.1:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: a0cf20f0ea29760dfdb3e4748417efaefc0c37f0 172.16.1.48:6379
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: c6df03cde4424b2b09752c89d236ee1cd4834709 172.16.1.48:6380
slots: (0 slots) slave
replicates a0cf20f0ea29760dfdb3e4748417efaefc0c37f0
M: dd122d63def65b8bc62719cabbb468f7976b1b73 172.16.1.47:6379
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: c8136c436cec8146dbbbd1ff2e5468d1dd5dd195 172.16.1.47:6380
slots: (0 slots) slave
replicates 3c2279ff6333b98a233ebf541e2b75981d27751f
S: eb0b79b22797c14172c8f0f117a4839d6825ea1f 172.16.1.46:6380
slots: (0 slots) slave
replicates dd122d63def65b8bc62719cabbb468f7976b1b73
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
#测试集群,添加一个值
[iyunv@redis1 ~]# /usr/local/bin/redis-cli -c -p 6379
127.0.0.1:6379> set a a
-> Redirected to slot [15495] located at 172.16.1.48:6379 #可以看到值添加到了172.16.1.48:6379这个节点上
OK
172.16.1.48:6379> get a
"a"
#再次连接到集群上
[iyunv@redis1 ~]# /usr/local/bin/redis-cli -c -p 6379
127.0.0.1:6379> get a
-> Redirected to slot [15495] located at 172.16.1.48:6380
"a" #这里能看到之前设置的值,从172.16.1.48:6380拿到结果了