redis集群离线安装环境搭建过程
本文是继上次redis集群重新整理的离线搭建环境,关于前期的redis集群准备工作参考我另一篇博客:
http://www.cnblogs.com/qlqwjy/p/8566573.html
由于集群搭建redis的安装环境甚是复杂,在这里新开一篇记录搭建安装环境的过程。
离线安装需要准备的软件:下载地址在文章最后贴出:
一、安装ruby运行环境
1.将ruby-2.3.7.tar.gz上传到服务器
2.解压文件
tar -zxvf ./ruby-2.3.7.tar.gz
3.编译安装
# 配置 ./configure #编译 make #编译安装 make install
4.测试ruby运行环境
[root@iz2ze46xi6pjjj69ailg9lz ruby-2.3.7]# ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [x86_64-linux]
二、安装redis接口
1.直接安装报错
[root@iz2ze46xi6pjjj69ailg9lz ruby-2.3.7]# gem install redis ERROR: Loading command: install (LoadError) cannot load such file -- zlib ERROR: While executing gem ... (NoMethodError) undefined method `invoke_with_build_args' for nil:NilClass
2.修改gem镜像
[root@iz2ze46xi6pjjj69ailg9lz ruby-2.3.7]# gem sources -l *** CURRENT SOURCES *** https://rubygems.org/ [root@iz2ze46xi6pjjj69ailg9lz ruby-2.3.7]# gem sources -a http://gems.ruby-china.org/ ERROR: While executing gem ... (NameError) uninitialized constant Gem::RemoteFetcher::Zlib
发现报错,需要安装zlib
3.安装zlib
(1)将zlib-1.2.11.tar.gz上传到服务器
(2)解压安装
mkdir zlib tar -vxf zlib-1.2.11.tar.gz cd zlib-1.2.11/ ./configure --prefix=/usr/local/zlib make make install
(3)编译 ruby 中的zlib
进入到/opt/ruby/ruby-2.3.7/ext/zlib目录下:
[root@iz2ze46xi6pjjj69ailg9lz zlib]# ruby ./extconf.rb checking for deflateReset() in -lz... yes checking for zlib.h... yes checking for crc32_combine() in zlib.h... yes checking for adler32_combine() in zlib.h... yes checking for z_crc_t in zlib.h... yes creating Makefile
接着编译安装
make
make install
4.接着继续修改gem镜像地址安装redis接口
- 修改gem镜像
gem sources -a http://gems.ruby-china.org/
- 查看镜像
[root@iz2ze46xi6pjjj69ailg9lz ruby]# gem source -l *** CURRENT SOURCES *** https://rubygems.org/ http://gems.ruby-china.org/
- 离线安装redis接口(前提是下载好redis-3.2.1.gem)
[root@iz2ze46xi6pjjj69ailg9lz ruby]# gem install -l redis-3.2.1.gem #安装本地的redis接口 Successfully installed redis-3.2.1 Parsing documentation for redis-3.2.1 Installing ri documentation for redis-3.2.1 Done installing documentation for redis after 1 seconds 1 gem installed
至此redis集群的环境基本算是安装完成
三、启动集群进行测试
1.将/usr/local/redis-4.0.2/src目录下的redis-trib.rb文件拷贝到/usr/local/redis/bin/目录下
[root@iz2ze46xi6pjjj69ailg9lz src]# pwd /usr/local/redis-4.0.2/src [root@iz2ze46xi6pjjj69ailg9lz src]# ls | grep rb redis-trib.rb [root@iz2ze46xi6pjjj69ailg9lz src]# cp ./redis-trib.rb /usr/local/redis/bin/redis-trib/ cp: cannot create regular file 鈥usr/local/redis/bin/redis-trib/鈥 Not a directory [root@iz2ze46xi6pjjj69ailg9lz src]# cp ./redis-trib.rb /usr/local/redis/bin/ [root@iz2ze46xi6pjjj69ailg9lz src]# ls /usr/local/redis/bin/ | grep rb redis-trib.rb
2.进入/usr/local/redis/bin/目录下创建集群
[root@iz2ze46xi6pjjj69ailg9lz bin]# ./redis-trib.rb create --replicas 1 127.0.0.1:7000 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
>>> Creating cluster
[ERR] Node 127.0.0.1:7000 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.
错误:
将集群目录下的nodes-700x.conf和appendonly-700x.aof文件删除后重启集群
...删除文件操作...
[root@iz2ze46xi6pjjj69ailg9lz redis]# cd cluster/ [root@iz2ze46xi6pjjj69ailg9lz cluster]# ls redis7000 redis7001 redis7002 redis7003 redis7004 redis7005 [root@iz2ze46xi6pjjj69ailg9lz cluster]# cd .. [root@iz2ze46xi6pjjj69ailg9lz redis]# ./startcluster.sh #启动6个redis 10398:C 16 Apr 20:16:33.460 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 10398:C 16 Apr 20:16:33.461 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=10398, just started 10398:C 16 Apr 20:16:33.461 # Configuration loaded 10400:C 16 Apr 20:16:33.481 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 10400:C 16 Apr 20:16:33.481 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=10400, just started 10400:C 16 Apr 20:16:33.481 # Configuration loaded 10404:C 16 Apr 20:16:33.499 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 10404:C 16 Apr 20:16:33.499 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=10404, just started 10404:C 16 Apr 20:16:33.499 # Configuration loaded 10412:C 16 Apr 20:16:33.514 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 10412:C 16 Apr 20:16:33.514 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=10412, just started 10412:C 16 Apr 20:16:33.514 # Configuration loaded 10417:C 16 Apr 20:16:33.544 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 10417:C 16 Apr 20:16:33.545 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=10417, just started 10417:C 16 Apr 20:16:33.545 # Configuration loaded 10419:C 16 Apr 20:16:33.565 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 10419:C 16 Apr 20:16:33.565 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=10419, just started 10419:C 16 Apr 20:16:33.565 # Configuration loaded [root@iz2ze46xi6pjjj69ailg9lz redis]# ps -le | grep redis 5 S 0 10399 1 0 80 0 - 36823 ep_pol ? 00:00:00 redis-server 5 S 0 10401 1 0 80 0 - 36823 ep_pol ? 00:00:00 redis-server 5 S 0 10406 1 0 80 0 - 36823 ep_pol ? 00:00:00 redis-server 5 S 0 10413 1 0 80 0 - 36823 ep_pol ? 00:00:00 redis-server 5 S 0 10418 1 0 80 0 - 36823 ep_pol ? 00:00:00 redis-server 5 S 0 10421 1 0 80 0 - 36823 ep_pol ? 00:00:00 redis-server [root@iz2ze46xi6pjjj69ailg9lz redis]# cd bin/ [root@iz2ze46xi6pjjj69ailg9lz bin]# ./redis-trib.rb create --replicas 1 127.0.0.1:7000 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 #创建集群 >>> Creating cluster >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 Adding replica 127.0.0.1:7003 to 127.0.0.1:7000 Adding replica 127.0.0.1:7004 to 127.0.0.1:7001 Adding replica 127.0.0.1:7005 to 127.0.0.1:7002 M: 1bf9a0eed5e0add7790b09557e36842bb4c2b925 127.0.0.1:7000 slots:0-5460 (5461 slots) master M: c7a14c5963783ae9b7cebb39eadfa4f02f4e6b6c 127.0.0.1:7001 slots:5461-10922 (5462 slots) master M: a86d777008d1e7933805a538e2d65db9a4013286 127.0.0.1:7002 slots:10923-16383 (5461 slots) master S: f5fdc874642c219412cb6429e45cf41652df3de9 127.0.0.1:7003 replicates 1bf9a0eed5e0add7790b09557e36842bb4c2b925 S: 710f238a33d494b4ec0c5a18208337dcd8b59c5e 127.0.0.1:7004 replicates c7a14c5963783ae9b7cebb39eadfa4f02f4e6b6c S: 03b76c043fe6745bc49a7881b1c61c9f37f4aff3 127.0.0.1:7005 replicates a86d777008d1e7933805a538e2d65db9a4013286 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 127.0.0.1:7000) M: 1bf9a0eed5e0add7790b09557e36842bb4c2b925 127.0.0.1:7000 slots:0-5460 (5461 slots) master 1 additional replica(s) M: a86d777008d1e7933805a538e2d65db9a4013286 127.0.0.1:7002 slots:10923-16383 (5461 slots) master 1 additional replica(s) S: 710f238a33d494b4ec0c5a18208337dcd8b59c5e 127.0.0.1:7004 slots: (0 slots) slave replicates c7a14c5963783ae9b7cebb39eadfa4f02f4e6b6c S: 03b76c043fe6745bc49a7881b1c61c9f37f4aff3 127.0.0.1:7005 slots: (0 slots) slave replicates a86d777008d1e7933805a538e2d65db9a4013286 M: c7a14c5963783ae9b7cebb39eadfa4f02f4e6b6c 127.0.0.1:7001 slots:5461-10922 (5462 slots) master 1 additional replica(s) S: f5fdc874642c219412cb6429e45cf41652df3de9 127.0.0.1:7003 slots: (0 slots) slave replicates 1bf9a0eed5e0add7790b09557e36842bb4c2b925 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
3.登录集群的一个节点进行测试:
[root@iz2ze46xi6pjjj69ailg9lz bin]# ./redis-cli -c -p 7000 127.0.0.1:7000> CLUSTER NODES a86d777008d1e7933805a538e2d65db9a4013286 127.0.0.1:7002@17002 master - 0 1523881191237 3 connected 10923-16383 710f238a33d494b4ec0c5a18208337dcd8b59c5e 127.0.0.1:7004@17004 slave c7a14c5963783ae9b7cebb39eadfa4f02f4e6b6c 0 1523881192311 5 connected 03b76c043fe6745bc49a7881b1c61c9f37f4aff3 127.0.0.1:7005@17005 slave a86d777008d1e7933805a538e2d65db9a4013286 0 1523881191000 6 connected c7a14c5963783ae9b7cebb39eadfa4f02f4e6b6c 127.0.0.1:7001@17001 master - 0 1523881190000 2 connected 5461-10922 f5fdc874642c219412cb6429e45cf41652df3de9 127.0.0.1:7003@17003 slave 1bf9a0eed5e0add7790b09557e36842bb4c2b925 0 1523881191000 4 connected 1bf9a0eed5e0add7790b09557e36842bb4c2b925 127.0.0.1:7000@17000 myself,master - 0 1523881189000 1 connected 0-5460 127.0.0.1:7000> set test test1 -> Redirected to slot [6918] located at 127.0.0.1:7001 OK 127.0.0.1:7001> get test "test1"
附上三个文件的下载地址:
http://qiaoliqiang.cn/fileDown/redis-3.2.1.gem
http://qiaoliqiang.cn/fileDown/ruby-2.3.7.tar.gz
http://qiaoliqiang.cn/fileDown/zlib-1.2.11.tar.gz
【当你用心写完每一篇博客之后,你会发现它比你用代码实现功能更有成就感!】