本文主要是介绍centos7+redis6集群安装,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
注意
需要yum install gcc
redis安装
1)redis下载:https://redis.io/
2)rz命令上传到centos7的/opt目录下
3)gcc --version、yum install gcc
4)tar zxf redis-6.2.5.tar.gz、cd /opt/redis-6.2.5/、make、make install
redis单机部署
- cp /opt/redis-6.2.5/redis.conf /data/redis
- 修改redis.conf文件
daemonize yes
# bind 127.0.0.1 -::1
protected-mode no
- 启动并验证
[root@mac1 redis]# redis-server /data/redis/redis.conf
[root@mac1 redis]# redis-cli -p 6379
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> get k1
"v1"
127.0.0.1:6379> shutdown
集群
1)配置
/data/redis目录新建redis-6380.conf, 内容如下:
include /data/redis/redis.conf
pidfile "/var/run/redis_6380.pid"
port 6380
dbfilename "dump_6380.rdb"cluster-enabled yes
cluster-config-file nodes-6380.conf
cluster-node-timeout 15000
同理,新建redis-6381.conf、redis-6382.conf、redis-6383.conf、redis-6384.conf、redis-6385.conf,内容分布是 将上面4个6380改为对应的端口6381、6382、6383、6384、6385
2)启动6个redis
[root@mac1 redis]# redis-server /data/redis/redis-6380.conf
[root@mac1 redis]# redis-server /data/redis/redis-6381.conf
[root@mac1 redis]# redis-server /data/redis/redis-6382.conf
[root@mac1 redis]# redis-server /data/redis/redis-6383.conf
[root@mac1 redis]# redis-server /data/redis/redis-6384.conf
[root@mac1 redis]# redis-server /data/redis/redis-6385.conf
[root@mac1 redis]# ps -ef | grep redis
root 15740 1 0 22:58 ? 00:00:00 redis-server *:6380 [cluster]
root 15746 1 0 22:58 ? 00:00:00 redis-server *:6381 [cluster]
root 15752 1 0 22:58 ? 00:00:00 redis-server *:6382 [cluster]
root 15758 1 0 22:58 ? 00:00:00 redis-server *:6383 [cluster]
root 15764 1 0 22:58 ? 00:00:00 redis-server *:6384 [cluster]
root 15770 1 0 22:58 ? 00:00:00 redis-server *:6385 [cluster]
root 15778 10490 0 22:59 pts/0 00:00:00 grep --color=auto redis
3)创建集群:redis-cli --cluster create --cluster-replicas 1 192.168.11.131:6380 192.168.11.131:6381 192.168.11.131:6382 192.168.11.131:6383 192.168.11.131:6384 192.168.11.131:6385,中间需要输入yes,详细过程如下所示:
[root@mac1 src]# redis-cli --cluster create --cluster-replicas 1 192.168.11.131:6380 192.168.11.131:6381 192.168.11.131:6382 192.168.11.131:6383 192.168.11.131:6384 192.168.11.131:6385
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.11.131:6384 to 192.168.11.131:6380
Adding replica 192.168.11.131:6385 to 192.168.11.131:6381
Adding replica 192.168.11.131:6383 to 192.168.11.131:6382
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 5e4dce806b0443408b7005bfd07d4e0b4609fad7 192.168.11.131:6380slots:[0-5460] (5461 slots) master
M: 7e1d4ca6623c5774d50ba847f7c7201fba1afe3c 192.168.11.131:6381slots:[5461-10922] (5462 slots) master
M: ca9bdd49b864e58f9cf5de0b063b5f8d00fbe716 192.168.11.131:6382slots:[10923-16383] (5461 slots) master
S: 37c2cc5d778c48b420e82f734d15c98be43b8dd7 192.168.11.131:6383replicates 7e1d4ca6623c5774d50ba847f7c7201fba1afe3c
S: 62276b3f34133a72edaa5c6d31fd5b73e07dc771 192.168.11.131:6384replicates ca9bdd49b864e58f9cf5de0b063b5f8d00fbe716
S: 830e6f106da660b179081f1e6abfb563df026aa4 192.168.11.131:6385replicates 5e4dce806b0443408b7005bfd07d4e0b4609fad7
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.11.131:6380)
M: 5e4dce806b0443408b7005bfd07d4e0b4609fad7 192.168.11.131:6380slots:[0-5460] (5461 slots) master1 additional replica(s)
S: 830e6f106da660b179081f1e6abfb563df026aa4 192.168.11.131:6385slots: (0 slots) slavereplicates 5e4dce806b0443408b7005bfd07d4e0b4609fad7
S: 37c2cc5d778c48b420e82f734d15c98be43b8dd7 192.168.11.131:6383slots: (0 slots) slavereplicates 7e1d4ca6623c5774d50ba847f7c7201fba1afe3c
M: ca9bdd49b864e58f9cf5de0b063b5f8d00fbe716 192.168.11.131:6382slots:[10923-16383] (5461 slots) master1 additional replica(s)
M: 7e1d4ca6623c5774d50ba847f7c7201fba1afe3c 192.168.11.131:6381slots:[5461-10922] (5462 slots) master1 additional replica(s)
S: 62276b3f34133a72edaa5c6d31fd5b73e07dc771 192.168.11.131:6384slots: (0 slots) slavereplicates ca9bdd49b864e58f9cf5de0b063b5f8d00fbe716
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
即主为80、81、82三台,从为83、84、85三台,slot一共有16384
4)验证
[root@mac1 src]# redis-cli -c -p 6380
127.0.0.1:6380> set k1 v1
-> Redirected to slot [12706] located at 192.168.11.131:6382
OK
192.168.11.131:6382> set k2 v2
-> Redirected to slot [449] located at 192.168.11.131:6380
OK
192.168.11.131:6380> set k3 v3
OK
192.168.11.131:6380> set k4 v4
-> Redirected to slot [8455] located at 192.168.11.131:6381
OK
192.168.11.131:6381>
其他
默认安装在/usr/local/bin下
这篇关于centos7+redis6集群安装的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!