杭州市建设工程质量安全监督总站网站媒体广告投放平台
news/
2025/9/23 12:20:05/
文章来源:
杭州市建设工程质量安全监督总站网站,媒体广告投放平台,做二手家具回收哪个网站好,那个网站的详情做的好转载自 超详细的 Redis Cluster 官方集群搭建指南
今天从 0 开始搭建 Redis Cluster 官方集群#xff0c;解决搭建过程中遇到的问题#xff0c;超详细。
安装ruby环境
因为官方提供的创建集群的工具是用ruby写的#xff0c;需要ruby2.2.2版本支持#xff0c;ruby安装需…转载自 超详细的 Redis Cluster 官方集群搭建指南
今天从 0 开始搭建 Redis Cluster 官方集群解决搭建过程中遇到的问题超详细。
安装ruby环境
因为官方提供的创建集群的工具是用ruby写的需要ruby2.2.2版本支持ruby安装需要指定openssl。
安装openssl
$ wget https://www.openssl.org/source/openssl-1.0.2m.tar.gz
$ tar -zxvf openssl-1.0.2m.tar.gz
$ cd openssl-1.0.2m
$ ./config --prefix/usr/local/openssl
$ ./config -t
$ make
$ make install
$ openssl version安装ruby
$ yum remove ruby
$ wget https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.2.tar.gz
$ tar -zxvf ruby-2.4.2.tar.gz
$ cd ruby-2.4.2
$ ./configure --with-openssl-dir/usr/local/openssl
$ make
$ make install
$ sudo ln -s /usr/local/bin/ruby /usr/bin/ruby安装rubygems
$ wget https://rubygems.org/rubygems/rubygems-2.3.0.tgz
$ tar -zxvf rubygems-2.3.0.tgz
$ cd rubygems-2.3.0
$ ruby setup.rb安装zlib
$ vi /ruby-2.4.2/ext/zlib/Makefilezlib.o: $(top_srcdir)/include/ruby.h
修改为
zlib.o: ../../include/ruby.h$ yum install zlib*
$ cd /ruby-2.4.2/ext/zlib
$ ruby extconf.rb
$ make
$ make install安装redis库
$ gem install redisERROR: While executing gem ... (Gem::Exception)Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources报这个错安装openssl-devel并重新编译ruby即可。 参考 https://www.larshaendler.com/2015/05/20/unable-to-require-openssl-install-openssl-and-rebuild-ruby-on-ubuntu-14-lts/ 搭建集群
1、创建集群目录
首先进入一个新目录创建六个以端口号为名字的子目录。
$ mkdir redis-cluster
$ cd redis-cluster
$ mkdir 9001 9002 9003 9004 9005 90062、添加集群配置文件
在文件夹9001~9006中各建一个redis.conf文件修改对应文件夹的端口内容如下
port 9001
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yescluster-enabled用于开实例的集群模式 cluster-conf-file设定了保存节点配置文件的路径默认值为nodes.conf节点配置文件无须人为修改它由 Redis集群在启动时创建 并在有需要时自动进行更新。
要让集群正常运作至少需要三个主节点不过在刚开始试用集群功能时 强烈建议使用六个节点 其中三个为主节点 而其余三个则是各个主节点的从节点。
3、添加redis服务文件
把编译好的redis-server文件复制到redis-cluster文件夹中。
4、启动集群实例
进入到9001~90066每个目录下启动每个实例
$ cd 9001
$ ../redis-server ./redis.conf5、创建集群
现在我们已经有了六个正在运行中的Redis实例接下来我们需要使用这些实例来创建集群并为每个节点编写配置文件。通过使用Redis集群命令行工具redis-trib编写节点配置文件的工作可以非常容易地完成redis-trib位于Redis源码的src文件夹中它是一个Ruby程序这个程序通过向实例发送特殊命令来完成创建新集群检查集群或者对集群进行重新分片reshared等工作。
$ ./redis-trib.rb create --replicas 1 127.0.0.1:9001 127.0.0.1:9002 127.0.0.1:9003 127.0.0.1:9004 127.0.0.1:9005 127.0.0.1:9006Creating clusterPerforming hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:9001
127.0.0.1:9002
127.0.0.1:9003
Adding replica 127.0.0.1:9004 to 127.0.0.1:9001
Adding replica 127.0.0.1:9005 to 127.0.0.1:9002
Adding replica 127.0.0.1:9006 to 127.0.0.1:9003
M: bd330d41ffcc57a5a5d32e3f738ddf82c48cfed0 127.0.0.1:9001slots:0-5460 (5461 slots) master
M: 688b8cdbdc38fe6b9e81b410aae2f1c048f5907c 127.0.0.1:9002slots:5461-10922 (5462 slots) master
M: 33b757db6091e486af2032f1463d1fb07e8e89a7 127.0.0.1:9003slots:10923-16383 (5461 slots) master
S: b00b464e4deb93a661755923641d36cadf648fcd 127.0.0.1:9004replicates bd330d41ffcc57a5a5d32e3f738ddf82c48cfed0
S: b3ec3a9c125cf168807231a16bacab946974d563 127.0.0.1:9005replicates 688b8cdbdc38fe6b9e81b410aae2f1c048f5907c
S: 06a207f7a4dd3023f88e01fad8635cb471d004eb 127.0.0.1:9006replicates 33b757db6091e486af2032f1463d1fb07e8e89a7
Can I set the above configuration? (type yes to accept): yesNodes configuration updatedAssign a different config epoch to each nodeSending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join....Performing Cluster Check (using node 127.0.0.1:9001)
M: bd330d41ffcc57a5a5d32e3f738ddf82c48cfed0 127.0.0.1:9001slots:0-5460 (5461 slots) master1 additional replica(s)
S: 06a207f7a4dd3023f88e01fad8635cb471d004eb 127.0.0.1:9006slots: (0 slots) slavereplicates 33b757db6091e486af2032f1463d1fb07e8e89a7
S: b00b464e4deb93a661755923641d36cadf648fcd 127.0.0.1:9004slots: (0 slots) slavereplicates bd330d41ffcc57a5a5d32e3f738ddf82c48cfed0
M: 688b8cdbdc38fe6b9e81b410aae2f1c048f5907c 127.0.0.1:9002slots:5461-10922 (5462 slots) master1 additional replica(s)
S: b3ec3a9c125cf168807231a16bacab946974d563 127.0.0.1:9005slots: (0 slots) slavereplicates 688b8cdbdc38fe6b9e81b410aae2f1c048f5907c
M: 33b757db6091e486af2032f1463d1fb07e8e89a7 127.0.0.1:9003slots:10923-16383 (5461 slots) master1 additional replica(s)
[OK] All nodes agree about slots configuration.Check for open slots...Check slots coverage...
[OK] All 16384 slots covered.这表示集群中的 16384 个槽都有至少一个主节点在处理 集群运作正常。
6、查看集群节点
192.168.10.38:9001 cluster nodes
bd330d41ffcc57a5a5d32e3f738ddf82c48cfed0 127.0.0.1:900119001 myself,master - 0 1511774435000 1 connected 0-5460
06a207f7a4dd3023f88e01fad8635cb471d004eb 127.0.0.1:900619006 slave 33b757db6091e486af2032f1463d1fb07e8e89a7 0 1511774436000 6 connected
b00b464e4deb93a661755923641d36cadf648fcd 127.0.0.1:900419004 slave bd330d41ffcc57a5a5d32e3f738ddf82c48cfed0 0 1511774436557 4 connected
688b8cdbdc38fe6b9e81b410aae2f1c048f5907c 127.0.0.1:900219002 master - 0 1511774436557 2 connected 5461-10922
b3ec3a9c125cf168807231a16bacab946974d563 127.0.0.1:900519005 slave 688b8cdbdc38fe6b9e81b410aae2f1c048f5907c 0 1511774436657 5 connected
33b757db6091e486af2032f1463d1fb07e8e89a7 127.0.0.1:900319003 master - 0 1511774436000 3 connected 10923-16383连接使用集群
$ ./redis-cli -c -h 192.168.1.8 -p 9002 -a 123456-ccluster连接到集群模式否则key不落在本实例将会报错。
-hhost指定连接主机。
-pport指定连接端口。
-aauth指定密码集群模式需要指定不然移动会认证失败。
$ ./redis-cli -c -h 192.168.1.8 -p 9002 -a 123456
127.0.0.1:9002 set hnad 21233
- Redirected to slot [2114] located at 127.0.0.1:9001
OK如上键hnad被转移到实例9001。
主从复制不能同步问题解决
搭建一个3主3从的Redis Cluster集群发现从实例不能同步主实例的数据但确认搭建的步骤和参数都没啥问题啊官网也没有给出对应的问题解决方案。
解决方案
后来查各种资料发现是因为主实例设置了密码从实例配置中需要配置主实例的连接密码才能实现主从复制同步。
就是下面这个配置
# If the master is password protected (using the requirepass configuration
# directive below) it is possible to tell the slave to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the slave request.
#
# masterauth master-password翻译
如果master是密码保护的下面的配置就是可以告诉从实例在启动集群同步复制进程之前要经过认证否则主实例会拒绝从实例的请求。解决流程
所以要解决不同步问题先停止6个从实例然后在每个实例的redis.conf文件中加入对应主备实例的认证密码然后再启动各个从实例。如
masterauth 123456然后主实例上的数据实时变化都会同步到从实例问题解决。
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/912518.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!