Linux安装Redis 4.0.14组建集群时报错处理

一、问题描述

在某次IPv6改造过程中,因Redis现场版本实际使用3.0.4,并不支持ipv6,需升级到Redis 4.0.14(4.0版本的最新版),然后在部署过程中报错:

internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require': /usr/local/lib/ruby/site_ruby/3.0.0/x86_64-linux/zlib.so: undefined symbol: inflateReset - /usr/local/lib/ruby/site_ruby/3.0.0/x86_64-linux/zlib.so (LoadError)
	from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
	from /usr/local/lib/ruby/3.0.0/rubygems/package.rb:188:in `initialize'
	from /usr/local/lib/ruby/3.0.0/rubygems/package.rb:153:in `new'
	from /usr/local/lib/ruby/3.0.0/rubygems/package.rb:153:in `new'
	from /usr/local/lib/ruby/3.0.0/rubygems/source/specific_file.rb:19:in `initialize'
	from /usr/local/lib/ruby/3.0.0/rubygems/dependency_installer.rb:293:in `new'
	from /usr/local/lib/ruby/3.0.0/rubygems/dependency_installer.rb:293:in `resolve_dependencies'
	from /usr/local/lib/ruby/3.0.0/rubygems/commands/install_command.rb:198:in `install_gem'
	from /usr/local/lib/ruby/3.0.0/rubygems/commands/install_command.rb:223:in `block in install_gems'
	from /usr/local/lib/ruby/3.0.0/rubygems/commands/install_command.rb:216:in `each'
	from /usr/local/lib/ruby/3.0.0/rubygems/commands/install_command.rb:216:in `install_gems'
	from /usr/local/lib/ruby/3.0.0/rubygems/commands/install_command.rb:164:in `execute'
	from /usr/local/lib/ruby/3.0.0/rubygems/command.rb:323:in `invoke_with_build_args'
	from /usr/local/lib/ruby/3.0.0/rubygems/command_manager.rb:178:in `process_args'
	from /usr/local/lib/ruby/3.0.0/rubygems/command_manager.rb:147:in `run'
	from /usr/local/lib/ruby/3.0.0/rubygems/gem_runner.rb:53:in `run'
	from /usr/local/bin/gem:21:in `<main>'

二、原因分析及处理

1、上述报错是在执行如下命令时报错的:

gem install -l ./redis-4.2.1.gem #本地安装Redis gem包

在这里插入图片描述

2、现场验证是因为zlib的库文件,so文件所致,执行如下:

ruby --version
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]

yum install zlib-devel -y
yum list installed|grep zlib
zlib.x86_64                           1.2.7-18.el7                    @centos7u3
zlib-devel.x86_64                     1.2.7-18.el7     
cd /home/software/ruby-3.0.0/ext/zlib
make&make install

#之后再执行安装
gem install -l ./redis-4.2.1.gem  //输出如下
Successfully installed redis-4.2.1
Parsing documentation for redis-4.2.1
Installing ri documentation for redis-4.2.1
Done installing documentation for redis after 0 seconds
1 gem installed

三、Redis-Cluster集群部署

#ruby环境
yum install -y ruby  //默认安装的,安装redis时会提示版本低,需下载高版本的重新编译
yum install rubygems

#安装基础环境
yum install gcc* gcc++*  -y
#对应clang安装对gcc,g++,cmake等有版本要求,尽量安装版本不要太低,软件地址:http://llvm.org/releases/download.html,redis此处可不安装
# ruby编译安装
./configure 
make && make install
#验证:
ruby --version
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]

#安装zlib库文件
cd ext/zlib/
./bin/ruby ./extconf.rb
make
make install
#
gem install -l ./redis-4.2.1.gem

在这里插入图片描述
1)启动Redis集群实例:

cd /home/software/redis/redis-4.0.14
make //编译后会再src下生产redismingl
#编辑redis实例文件,之后启动,注意,集群的配置文件node_xxx.conf是redis启动后监测到集群模式自动生成的,无需手动创建,如果配置文件写错,会报如下错误,如上图所示:
Can't open /usr/local/redis/redis-4.0.14/nodes_7000.conf in order to acquire a lock: No such file or directory

#启动实例
28587:M 11 Nov 17:53:04.351 * No cluster configuration found, I'm f18418f119a528a730dfb365a30bd90cab0e14c9
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.14 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in cluster mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 7000
 |    `-._   `._    /     _.-'    |     PID: 28587
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                  

#启动执行:
./src/redis-server ./redis_7000.conf
./src/redis-server ./redis_7001.conf
./src/redis-server ./redis_7002.conf
./src/redis-server ./redis_7003.conf
./src/redis-server ./redis_7004.conf
#验证
ps aux|grep redis
root      1413  0.0  0.0 155556 13732 ?        Ssl  19:37   0:00 ./src/redis-server 0.0.0.0:7000 [cluster]
root      1423  0.0  0.0 155556 13736 ?        Ssl  19:37   0:00 ./src/redis-server 0.0.0.0:7001 [cluster]
root      1430  0.0  0.0 155556 13732 ?        Ssl  19:37   0:00 ./src/redis-server 0.0.0.0:7002 [cluster]
root      1437  0.1  0.0 155556 13732 ?        Ssl  19:37   0:00 ./src/redis-server 0.0.0.0:7003 [cluster]
root      1445  0.0  0.0 155556 13732 ?        Ssl  19:37   0:00 ./src/redis-server 0.0.0.0:7004 [cluster]

#创建集群
./src/redis-trib.rb create --replicas 1 10.24.8.15:7000 10.24.8.15:7001 10.24.8.15:7002 10.24.8.15:7003 10.24.8.15:7004  10.24.8.16:7000 10.24.8.16:7001 10.24.8.16:7002 10.24.8.16:7003 10.24.8.16:7004

>>> Creating cluster
>>> Performing hash slots allocation on 10 nodes...
Using 5 masters:
10.24.8.15:7000
10.24.8.16:7000
10.24.8.15:7001
10.24.8.16:7001
10.24.8.15:7002
Adding replica 10.24.8.16:7003 to 10.24.8.15:7000
Adding replica 10.24.8.15:7003 to 10.24.8.16:7000
Adding replica 10.24.8.16:7004 to 10.24.8.15:7001
Adding replica 10.24.8.15:7004 to 10.24.8.16:7001
Adding replica 10.24.8.16:7002 to 10.24.8.15:7002
M: f18418f119a528a730dfb365a30bd90cab0e14c9 10.24.8.15:7000
   slots:0-3276 (3277 slots) master
M: 7e1dc0412e8b8cbf3c9ac7ac8a5abc4c1eb7588b 10.24.8.15:7001
   slots:6554-9829 (3276 slots) master
M: 10bfdc24bea4480c7ee7bee8b58346d0f9d2d37a 10.24.8.15:7002
   slots:13107-16383 (3277 slots) master
S: 269b9cf2bd8f51ac6aea07d596df34bb74333355 10.24.8.15:7003
   replicates fa0c9f9c25b183497d6ebf65420430e926465967
S: e7d4f59a5cca4c7b9766abdd079f309275c76435 10.24.8.15:7004
   replicates d611a8ad1c71ae3fec2a75a6095c80d93062be4f
M: fa0c9f9c25b183497d6ebf65420430e926465967 10.24.8.16:7000
   slots:3277-6553 (3277 slots) master
M: d611a8ad1c71ae3fec2a75a6095c80d93062be4f 10.24.8.16:7001
   slots:9830-13106 (3277 slots) master
S: 471580705f4176c06b73b2901a98d3ea8d2c4b3e 10.24.8.16:7002
   replicates 10bfdc24bea4480c7ee7bee8b58346d0f9d2d37a
S: 60401263db82b95ac30099dc589ce2fd0e72466f 10.24.8.16:7003
   replicates f18418f119a528a730dfb365a30bd90cab0e14c9
S: c04dff35499da4ba1b897da6a33824ba7cde7a70 10.24.8.16:7004
   replicates 7e1dc0412e8b8cbf3c9ac7ac8a5abc4c1eb7588b
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 10.24.8.15:7000)
M: f18418f119a528a730dfb365a30bd90cab0e14c9 10.24.8.15:7000
   slots:0-3276 (3277 slots) master
   1 additional replica(s)
S: 60401263db82b95ac30099dc589ce2fd0e72466f 10.24.8.16:7003
   slots: (0 slots) slave
   replicates f18418f119a528a730dfb365a30bd90cab0e14c9
S: c04dff35499da4ba1b897da6a33824ba7cde7a70 10.24.8.16:7004
   slots: (0 slots) slave
   replicates 7e1dc0412e8b8cbf3c9ac7ac8a5abc4c1eb7588b
S: 269b9cf2bd8f51ac6aea07d596df34bb74333355 10.24.8.15:7003
   slots: (0 slots) slave
   replicates fa0c9f9c25b183497d6ebf65420430e926465967
S: e7d4f59a5cca4c7b9766abdd079f309275c76435 10.24.8.15:7004
   slots: (0 slots) slave
   replicates d611a8ad1c71ae3fec2a75a6095c80d93062be4f
M: fa0c9f9c25b183497d6ebf65420430e926465967 10.24.8.16:7000
   slots:3277-6553 (3277 slots) master
   1 additional replica(s)
M: 7e1dc0412e8b8cbf3c9ac7ac8a5abc4c1eb7588b 10.24.8.15:7001
   slots:6554-9829 (3276 slots) master
   1 additional replica(s)
S: 471580705f4176c06b73b2901a98d3ea8d2c4b3e 10.24.8.16:7002
   slots: (0 slots) slave
   replicates 10bfdc24bea4480c7ee7bee8b58346d0f9d2d37a
M: d611a8ad1c71ae3fec2a75a6095c80d93062be4f 10.24.8.16:7001
   slots:9830-13106 (3277 slots) master
   1 additional replica(s)
M: 10bfdc24bea4480c7ee7bee8b58346d0f9d2d37a 10.24.8.15:7002
   slots:13107-16383 (3277 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

#验证
./redis-cli -c -h 10.24.8.15 -p 7000  #-c表集群模式
10.100.1.172:7000> keys *
(empty list or set)
10.100.1.172:7000> CLUSTER nodes
10.24.8.15:7000> CLUSTER INFO
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:10
cluster_size:5
cluster_current_epoch:10
cluster_my_epoch:1
cluster_stats_messages_ping_sent:513
cluster_stats_messages_pong_sent:512
cluster_stats_messages_sent:1025
cluster_stats_messages_ping_received:503
cluster_stats_messages_pong_received:513
cluster_stats_messages_meet_received:9
cluster_stats_messages_received:1025
10.24.8.16:7000> cluster slots   #查看集群架构
10.24.8.16:7000> cluster failover  #手动故障切换
10.24.8.16:7000> cluster replicate master_node_id #手动指定主节点的从节点
10.24.8.15:7000> config set masterauth 1234
10.24.8.15:7000> config set requirepass 1234
10.24.8.15:7000> set testkey test
10.24.8.15:7000> get testkey
10.24.8.16:7000> get testkey

#向集群中添加节点
./src/redis-trib.rb add-node 10.24.8.16:7005  10.24.8.16:7006
#向集群中添加从节点,并指定为7007的从节点(指定7007的id):
./src/redis-trib.rb add-node --slave --master-id 25b32b2ca5d43e714ad1dc63f316d71abb430173
#重新分配卡槽
./src/redis-trib.rb reshard 10.24.8.16:7004
#删除从节点(优先删除对应的从节点):
./src/redis-trib.rb del-node 10.24.8.16:7005 7c5530250786d4064ce14ad199597f258b9192c3
#删除主节点:
./redis-trib.rb reshard 10.24.8.16:7004
./redis-trib.rb del-node 10.24.8.16:7005 25b10b2ca5d43e680ad1dc63f316e71abb42f923

#集群关停脚本shutdownall.sh
touch shutdownall.sh
./src/redis-cli -p 7001 shutdown
./src/redis-cli -p 7002 shutdown
./src/redis-cli -p 7003 shutdown
./src/redis-cli -p 7004 shutdown
./src/redis-cli -p 7005 shutdown
./src/redis-cli -p 7006 shutdown

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/ximenjianxue/article/details/127808393