linux单节点安装redis三主三从
前言:一台服务器上安装三主三从,很少有公司这个做的,大部分都是三台服务器,每台服务器上面分别有主从。但都是大同小异
服务器IP:192.168.181.131
Redis版本:redis-3.2.1
Redis端口号:7000 7001 7002 7003 7004 7005
安装:
1)下载:http://download.redis.io/releases/redis-3.2.1.tar.gz
2)上传服务器、编译、安装
$yum -y install gcc
$ wget http://download.redis.io/releases/redis-3.2.1.tar.gz
$ tar xzf redis-3.2.1.tar.gz -C /opt
$cd /opt/redis-3.2.1
$make && make install PREFIX=/usr/local/redis-3.2.1
3)创建集群需要的目录并copy redis
$make /usr/local/cluster && cd /usr/local/cluster
$make -p 7000 7001 7002 7003 7004 7005
$cp -rf /usr/local/redis-3.2.1/* /usr/local/cluster/7000/
$cp -rf /usr/local/redis-3.2.1/* /usr/local/cluster/7001/
$cp -rf /usr/local/redis-3.2.1/* /usr/local/cluster/7002/
$cp -rf /usr/local/redis-3.2.1/* /usr/local/cluster/7003/
$cp -rf /usr/local/redis-3.2.1/* /usr/local/cluster/7004/
$cp -rf /usr/local/redis-3.2.1/* /usr/local/cluster/7005/
4)修改配置文件
$vim redis.conf
##修改配置文件中的下面选项
daemonize yes //后台启动
pidfile
port 7001 //默认是6379 ,更改端口号,每个节点都要更改成对应的端口号
bind
去掉注释:cluster-enabled yes
去掉注释并修改:cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
dbfilename
logfile
5)启动
$bin/redis-server ./redis.conf //每个节点下都要执行,可以编写一个脚本进行启动
6)查看启动
$netstat -ntlp |grep 700
7) 安装ruby的环境
yum -y install ruby
yum -y install rubygems
wget https://rubygems.global.ssl.fastly.net/gems/redis-3.2.1.gem
gem install -l ./redis-3.2.1.gem
8)
./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 |
常出现的问题:
6,创建redis集群
cd /usr/local/redis-3.2.1/src
./redis-trib.rb create --replicas 1 IP1:7001 IP1:7002 IP2:7001 IP2:7002 IP3:7001 IP3:7002
./redis-trib.rb create --replicas 1 10.25.244.240:7001 10.25.244.240:7002 10.25.244.240:7003
**************************************************************************************
6.1执行上面的命令的时候会报错,因为是执行的的脚本,需要
错误内容:/usr/bin/env: ruby: No such file or directory
所以需要安装ruby的环境,这里推荐使用yum install ruby
#yum install ruby
6.2然后再执行第步的创建集群命令,还会报错,提示缺少rubygems组件
错误内容:
./redis-trib.rb:24:in `require': no such file to load -- rubygems (LoadError)
from ./redis-trib.rb:24
#yum install rubygems
6.3再次执行第步的命令,还会报错,提示不能加载redis,是因为缺少redis的接口
错误内容:
/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 ./redis-trib.rb:25
gem install redis
这里可能无法安装,因为无法连接gem服务器:
[@zw_22_90 src]# gem install redis --version 3.0.0
ERROR: Could not find a valid gem 'redis' (= 3.0.0) in any repository
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
需要手工下载并安装:
wget https://rubygems.global.ssl.fastly.net/gems/redis-3.2.1.gem
gem install -l ./redis-3.2.1.gem