redis集群搭建和部署,参考下面文章
https://www.cnblogs.com/molson/p/13531163.html
创建集群目录redis_cluster, 再为六个节点创建六个节点目录,例如 redis_6380,redis_6381....., redis_6385
拷贝 redis.conf 到每个节点目录,例如:redis_6380
修改对应的配置文件:
port 6380 //端口6380
logfile "/home/work/redis_cluster/redis_6380/log/redis.log"
dir /home/work/redis_cluster/redis_6380/
cluster-enabled yes //开启集群 把注释#去掉
cluster-config-file nodes-6380.conf //集群的配置 配置文件首次启动自动生成
masterauth password //密码
requirepass password //密码
启动所有节点,例如6380节点的命令:
./redis-server /redis_cluster/redis_6380/redis.conf
查看服务
ps -ef | grep redis #查看是否启动成功
遇到的坑:
gem install redis时出现ruby版本过低的情况
Centos7系统上解决Ruby版本过低的情况-----源码安装ruby
https://www.cnblogs.com/molson/p/13522146.html
gem install redis时出现下面的错误, 可以采用替换可用的源:
ERROR: SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR: You must add /OU=GlobalSign Root CA - R3/O=GlobalSign/CN=GlobalSign to your local trusted store
ERROR: SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR: You must add /OU=GlobalSign Root CA - R3/O=GlobalSign/CN=GlobalSign to your local trusted store
ERROR: SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR: You must add /OU=GlobalSign Root CA - R3/O=GlobalSign/CN=GlobalSign to your local trusted store
ERROR: Could not find a valid gem 'redis' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (unable to get local issuer certificate) (https://api.rubygems.org/specs.4.8.gz)
ERROR: SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR: You must add /OU=GlobalSign Root CA - R3/O=GlobalSign/CN=GlobalSign to your local trusted store
ERROR: SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR: You must add /OU=GlobalSign Root CA - R3/O=GlobalSign/CN=GlobalSign to your local trusted store
gem 更换源及目前能用的源
https://www.jianshu.com/p/b1df911d32f3
执行redis-trib.rb create --replicas 1 命令出现,Sorry, can't connect to node,解决办法如下:
https://blog.csdn.net/xiaobo060/article/details/80616718
解释下, --replicas 1 表示 自动为每一个master节点分配一个slave节点 上面有6个节点,程序会按照一定规则生成 3个master(主)3个slave(从)。防火墙一定要开放监听的端口,否则会创建失败。
搭建集群至少需要3主3从6台服务器或进程,否则你会遇到这错误
./redis-trib.rb create --replicas 1 192.168.22.43:6380 192.168.22.54:6379
./redis-trib.rb:1573: warning: key "threshold" is duplicated and overwritten on line 1573
>>> Creating cluster
*** ERROR: Invalid configuration for cluster creation.
*** Redis Cluster requires at least 3 master nodes.
*** This is not possible with 2 nodes and 1 replicas per node.
*** At least 6 nodes are required.
如果你就想只搭建几台主服务器,那么请使用下边的方式(可以在其中一台服务器cli下MEET其他服务器即可,各服务器可以相互连接)
127.0.0.1:6383> CLUSTER MEET 192.168.22.43 6384
OK
这种方式可以由你自己定义集群有多少台服务器,但是必须指定插槽,且必须分配完毕16384个槽位才可以正常工作
分配指定范围的槽位的方法,例如:
redis-cli -h 服务器IP -p 端口号 cluster addslots {0..5460}