redis集群安装过程
内网redis主从列表
master1:172.168.1.201:6379 slave1:172.168.1.208:6379
master2:172.168.1.205:6379 slave2:172.168.1.206:6379
master3:172.168.1.207:6379 slave3:172.168.1.202:6379
安装ruby
保证1.87以上,因为咱们要使用redis-trib.rb搭建集群,而redis-trib.rb采用ruby实现的redis集群管理工具。
wget https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.3.tar.gz
tar -zxvf ruby-2.5.3.tar.gz
cd ruby-2.5.3
./configure --prefix=/usr/local/ruby
make && make install
/usr/local/ruby/bin/ruby -v
ln -s /usr/local/ruby/bin/ruby /usr/bin/ruby
echo "export PATH=$PATH:/usr/local/ruby/bin" >> /etc/profile
source /etc/profile
安装Rubygems
如果缺少rubygems组件,就安装
yum install rubygems
安装rubygem 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
解决方法:
yum install zlib-devel
cd /usr/local/src/ruby-2.5.3 进入ruby的源码包目录下
cd ext/zlib
ruby extconf.rb
make 报错*** No rule to make target `/include/ruby.h', needed by `zlib.o'. Stop.
打开:ext/zlib/Makefile文件,找到#zlib.o: $(top_srcdir)/include/ruby.h换成zlib.o: ../../include/ruby.h
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
yum install openssl-devel
cd /usr/local/src/ruby-2.5.3
cd ext/openssl
ruby extconf.rb
make && make install 报错:make: *** No rule to make target `/thread_native.h', needed by `ossl.o'. Stop.
修改makefile中的$(top_srcdir)为../..
再执行gem install redis
安装 tcl
yum -y install gcc
cd /usr/local/soft/
tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/
cd /usr/local/tcl8.6.1/unix/
./configure
make
make install
安装gcc
yum install gcc-c++ -y
安装redis
cd /usr/local/soft/
tar xzf redis-3.0.6.tar.gz
cd redis-3.0.6
make MALLOC=libc
make test(检查,必须安装tcl)
make install
mv /usr/local/soft/redis-3.0.6 /usr/local/redis
cd /usr/local/redis
mkdir conf dump logs bin pid
mv redis.conf conf/
cd src && mv redis-benchmark redis-sentinel redis-server redis-cli redis-trib.rb ../bin/
修改redis配置文件
vim /usr/local/soft/redis-3.0.6/redis.conf
daemonize yes port 7379 cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 appendonly no appendfilename appendonly.aof appendfsync everysec pidfile /usr/local/redis/pid/redis.pid #指定Redis可接收请求的IP地址,不设置将处理所有请求,建议生产环境中设置 # bind 127.0.0.1 #客户端连接的超时时间,单位为秒,超时后会关闭连接,0标识不超时 timeout 5 #tcp-backlog 10240 # debug (适合开发和测试)、# verbose (详细)、# notice (比较适合生产环境)、# warning (警告信息) #日志记录等级,4个可选值 loglevel notice #配置 log 文件地址,默认打印在命令行终端的窗口上,也可设为/dev/null屏蔽日志 logfile /usr/local/redis/logs/redis.log #设置 Redis 自动进行数据库镜像的频率。保存数据到disk的策略,不设置认为自动不保存 #900秒之内有1个keys发生变化时 #30秒之内有10个keys发生变化时 #60秒之内有10000个keys发生变化时 save 900 1 save 3600 100 save 60 10000 #在进行镜像备份时,是否进行压缩,默认为yes rdbcompression yes #镜像备份文件的文件名 dbfilename dump.rdb #数据库镜像备份的文件放置的路径 dir /usr/local/redis/dump/
单点启动redis
/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf &
/usr/local/redis/bin/redis-cli -p 7379 shutdown
启动集群
/usr/local/soft/redis-3.0.6/src/redis-trib.rb create --replicas 1 172.168.1.201:6379 172.168.1.208:6379 172.168.1.205:6379 172.168.1.206:6379 172.168.1.207:6379 172.168.1.202:6379
报错:
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- redis (LoadError)
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /opt/cachecloud/redis/src/redis-trib.rb:25
解决方法:
执行一次gem install redis
检查集群状态
/usr/local/soft/redis-3.0.6/src/redis-trib.rb check 172.168.1.201:6379
线上测试服redis集群
/data/redis/src/redis-trib.rb create --replicas 1 192.168.1.11:6379 192.168.1.11:7379 192.168.1.37:6379 192.168.1.37:7379 192.168.1.39:6379 192.168.1.39:7379
/data/redis/src/redis-trib.rb check 192.168.1.11:6379
redis从节点的作用
1. 备份
2. 容灾,若主节点fail,通过投票选举其中一个从节点作为主节点

浙公网安备 33010602011771号