wget http://download.redis.io/releases/redis-4.0.10.tar.gz
Setp1:cd /data/pkgs && tar axf redis-4.0.10.tar.gz && cd redis-4.0.10
Setp2:make
Setp3:make install
这里端口规划为7001、7002、7003、7004、7005、7006,当前集群默认是cluster模式,三主三从。
./utils/install_server.sh
如下图所示:
说明:
1、分别在需要部署redis的主机上执行上述脚本,根据实际情况设置,端口、配置文件路径、日志文件路径、数据目录可以自定义。
2、这里需手动填写redis-server命令路径。
bind 0.0.0.0
daemonize yes
appendonly yes
requirepass "AhspHJ2l0ychcves"
masterauth "AhspHJ2l0ychcves" #这里必须添加,不然主从故障无法切换
cluster-enabled yes
cluster-node-timeout 15000
说明:每个redis实例配置文件均需要修改。
echo "65535" > /proc/sys/net/core/somaxconn
echo never > /sys/kernel/mm/transparent_hugepage/enabled
echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.local
echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
sysctl vm.overcommit_memory=1
说明:ruby版本必须高于2.3.0
cd /data/pkgs
wget https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.5.tar.gz
tar -zxf ruby-2.5.5.tar.gz && cd ruby-2.5.5
./configure && make && make install
/usr/local/bin/gem install redis
问题一、使用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
解决方法
进入ruby安装目录
Setp1:yum -y install zlib-devel
Setp2:
cd /data/pkgs/ruby-2.5.5/ext/zlib/
/usr/local/bin/ruby ./extconf.rb
make
vim Makefile
#zlib.o: $(top_srcdir)/include/ruby.h #找到此行修改为下面一行的代码,保存退出
zlib.o: ../../include/ruby.h
Setp3:
make && make install
问题二、使用gem install redis安装时报错
ERROR: While executing gem ... (Gem::Exception) Unable to require openssl
install OpenSSL and rebuild Ruby (preferred) or use non-HTTPS sources
解决方法
Setp1:cd /data/pkgs/ruby-2.5.5/ext/openssl
Setp2:yum install openssl-devel -y
Setp3:/usr/local/bin/ruby ./extconf.rb
Setp4:在Makefile顶部中的增加top_srcdir = ../..
vim Makefile(如下图所示)
Setp5:make && make install
cp /usr/local/bin/redis-* /usr/bin
cp /usr/local/bin/ruby /usr/bin
/data/pkgs/redis-4.0.10/src/redis-trib.rb create --replicas 1 x.x.x:7001 x.x.x:7002 x.x.x:7003 x.x.x:7004 x.x.x:7005 x.x.x:7006
如下图所示:
至此,redis4.0.10 cluster集群部署完成。
问题一:构建redis集群失败
/usr/bin/env: ruby: No such file or directory
解决方法:cp /usr/local/bin/ruby /usr/bin
问题二:构建redis集群失败
Traceback (most recent call last):
2: from /data/pkgs/redis-4.0.10/src/redis-trib.rb:25:in `<main>'
1: from /usr/local/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/usr/local/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- redis (LoadError)
解决方法:
cp /usr/local/bin/gem /usr/bin
gem install redis
问题三:构建redis集群失败
>>> Creating cluster
[ERR] Sorry, can't connect to node 172.18.1.112:7001
vim /usr/local/lib/ruby/gems/2.5.0/gems/redis-4.2.5/lib/redis/client.rb
说明:连接集群不管是写入数据还是读取数据都需要加入-c的参数。
a、往集群里面写入一百条数据。
for line in {1..100};do redis-cli -h 127.0.0.1 -p 7001 -c -a AhspHJ2l0ychcves set ops_${line} ${line}; done
b、读取数据看一下是否能读取到
for line in {1..100};do redis-cli -h 127.0.0.1 -p 7001 -c -a AhspHJ2l0ychcves get ops_${line}; done
a、关闭7001
redis-cli -h 127.0.0.1 -p 7001 -c -a AhspHJ2l0ychcves shutdown
等待2分钟
redis-cli -h 127.0.0.1 -p 7002 -c -a AhspHJ2l0ychcves
b、再次验证数据是否正常
for line in {1..100};do redis-cli -h 127.0.0.1 -p 7001 -c -a AhspHJ2l0ychcves get ops_${line}; done
更多详细内容请参考:Linux运维实战总结