redis5 cluster 集群HA安装部署

一、安装环境:centos7、Redis5.0.5 stable

二、集群安装

2.1 下载源文件:

pwd
/home/yzh
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
tar xzf redis-5.0.5.tar.gz
cd redis-5.0.5/

或者本地下载好后winscp传到Linux服务器:http://download.redis.io/releases/redis-5.0.5.tar.gz

2.2 redis是C语言写的,下载C语言运行环境:

[root@centos60 redis-5.0.5]# yum install gcc

编译源码与安装:

[root@centos60 redis-5.0.5]# make MALLOC=libc
[root@centos60 redis-5.0.5]# cd ..
[root@centos60 yzh]# mkdir redis01
[root@centos60 yzh]# cd redis-5.0.5/
[root@centos60 redis-5.0.5]# make install PREFIX=/home/yzh/redis01/

注意:make后跟着MALLOC=libc,原因是 jemalloc 重载了Linux下的 ANSIC 的 malloc 和 free 函数,否则报错:

zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory

2.3 默认配置文件redis.conf的修改:

[root@centos60 redis-5.0.5]# cd ../redis01/bin/
[root@centos60 bin]# cp /home/yzh/redis-5.0.5/redis.conf /home/yzh/redis01/bin/
[root@centos60 bin]# ls
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis.conf  redis-sentinel  redis-server
[root@centos60 bin]# vim redis.conf

需要修改的地方有3处:

2.3.1 daemonize no 改为 daemonize yes,后台启动。(/dae然后回车,vi下的搜索模式)

2.3.2 #cluster-enabled yes 的注释放开,集群模式支持开启。

2.3.3 port 6379 改为 port 7001,修改默认端口号(可选)。

三、启动集群

3.1 先复制5份redis-server文件夹:

[root@centos60 bin]# cd ../..
[root@centos60 yzh]# ls
redis01  redis-5.0.5  redis-5.0.5.tar.gz
[root@centos60 yzh]# cp -r redis01 redis02
[root@centos60 yzh]# cp -r redis01 redis03
[root@centos60 yzh]# cp -r redis01 redis04
[root@centos60 yzh]# cp -r redis01 redis05
[root@centos60 yzh]# cp -r redis01 redis06
[root@centos60 yzh]# ls
redis01  redis02  redis03  redis04  redis05  redis06  redis-5.0.5  redis-5.0.5.tar.gz

3.2 修改另外5份文件夹的redis.conf的port 7001:

[root@centos60 yzh]# vim redis02/bin/redis.conf 
[root@centos60 yzh]# vim redis03/bin/redis.conf 
[root@centos60 yzh]# vim redis04/bin/redis.conf 
[root@centos60 yzh]# vim redis05/bin/redis.conf 
[root@centos60 yzh]# vim redis06/bin/redis.conf 

分别修改为:port 7002,port 7003,port 7004,port 7005,port 7006。

3.3 启动6个redis-server:

[root@centos60 yzh]# cd redis01/bin/
[root@centos60 bin]# ./redis-server redis.conf 
1697893:C 10 Jul 2019 14:40:57.292 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1697893:C 10 Jul 2019 14:40:57.292 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=1697893, just started
1697893:C 10 Jul 2019 14:40:57.292 # Configuration loaded

[root@centos60 bin]# cd ../../redis02/bin/
[root@centos60 bin]# ./redis-server redis.conf 

[root@centos60 bin]# cd ../../redis03/bin/
[root@centos60 bin]# ./redis-server redis.conf 

[root@centos60 bin]# cd ../../redis04/bin/
[root@centos60 bin]# ./redis-server redis.conf 

[root@centos60 bin]# cd ../../redis05/bin/
[root@centos60 bin]# ./redis-server redis.conf 

[root@centos60 bin]# cd ../../redis06/bin/
[root@centos60 bin]# ./redis-server redis.conf 

[root@centos60 bin]# ps aux | grep redis
root     1697894  0.1  0.0 144532  2548 ?        Ssl  14:40   0:00 ./redis-server 127.0.0.1:7001 [cluster]
root     1698862  0.0  0.0 144532  2548 ?        Ssl  14:41   0:00 ./redis-server 127.0.0.1:7002 [cluster]
root     1699094  0.0  0.0 144532  2544 ?        Ssl  14:41   0:00 ./redis-server 127.0.0.1:7003 [cluster]
root     1699330  0.0  0.0 144532  2544 ?        Ssl  14:41   0:00 ./redis-server 127.0.0.1:7004 [cluster]
root     1699512  0.0  0.0 144532  2544 ?        Ssl  14:41   0:00 ./redis-server 127.0.0.1:7005 [cluster]
root     1699688  0.0  0.0 144532  2544 ?        Ssl  14:41   0:00 ./redis-server 127.0.0.1:7006 [cluster]
root     1699974  0.0  0.0 112712   988 pts/8    S+   14:41   0:00 grep --color=auto redis

3.4 创建集群:

redis3、4使用的是redis-trib.rb工具包来管理集群,可参考我的另一篇https://blog.csdn.net/yzh_1346983557/article/details/91044739

redis5使用redis-cli客户端直接管理集群:

[root@centos60 yzh]# redis-cli --cluster create --cluster-replicas 1  127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006 

检查集群状态:

[root@centos60 yzh]# redis-cli --cluster check 127.0.0.1:7001
...
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

或者使用redis-cli客户端登录:

[root@centos60 yzh]# redis-cli -c -p 7001
127.0.0.1:7001> cluster nodes
c9ebeb669d4f325959f2e172271349a83ae5b15c 127.0.0.1:7004@17004 slave 11a82bf9c5f59783911c1437bc327d7964c46515 0 1562742181000 4 connected
d8cecea8ac6376c46d184c1efc47eb6686449c35 127.0.0.1:7006@17006 slave 338b19575f516df229fee30ffef64b2c9708ece5 0 1562742182671 6 connected
e9e60742e53c19df7852d6bbc136291e468b1018 127.0.0.1:7001@17001 myself,master - 0 1562742183000 1 connected 0-5460
8d136d07dfdb1a61c8d3de70bf26e777a19acc88 127.0.0.1:7005@17005 slave e9e60742e53c19df7852d6bbc136291e468b1018 0 1562742182000 5 connected
338b19575f516df229fee30ffef64b2c9708ece5 127.0.0.1:7002@17002 master - 0 1562742183674 2 connected 5461-10922
11a82bf9c5f59783911c1437bc327d7964c46515 127.0.0.1:7003@17003 master - 0 1562742181000 3 connected 10923-16383

127.0.0.1:7001> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:187
cluster_stats_messages_pong_sent:172
cluster_stats_messages_sent:359
cluster_stats_messages_ping_received:167
cluster_stats_messages_pong_received:187
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:359

参考redis官网:https://redis.io/topics/cluster-tutorial

补充:make时的报错:

cc: error: ../deps/hiredis/libhiredis.a: No such file or directory
cc: error: ../deps/lua/src/liblua.a: No such file or directory
make[1]: *** [redis-server] Error 1
make[1]: Leaving directory `/home/yzh/redis-5.0.5/src'
make: *** [all] Error 2

解决:进入redis源码下的deps目录,运行如下命令,就OK了。

make lua hiredis linenoise

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值