点此查看如何安装环境

redis服务器说明

10.0.0.5 6379

10.0.0.5 6380

10.0.0.5 6381

 

10.0.0.6 6382

10.0.0.6 6383

10.0.0.6 6384

#安装完毕后

#两台机子均安装Ruby,rubygems

yum -y install gcc openssl-devel libyaml-devel libffi-devel readline-devel   autoconf

yum -y install ruby rubygems zlib-devel gdbm-devel ncurses-devel gcc-c++ automake

 

#换源

gem source -l  

gem source –remove http://rubygems.org/ 

gem sources –add https://gems.ruby-china.org/ –remove https://rubygems.org/ 

gem source -l

gem install redis

 

执行gem install redis报错

gem install redis

ERROR:  Error installing redis:

redis requires Ruby version >= 2.2.2.

#原因rvm版本过低

执行以下命令升级rvm

gpg2 keyserver hkp://keys.gnupg.net –recv-keys D39DC0E3

curl -L get.rvm.io | bash -s stable

source /usr/local/rvm/scripts/rvm

rvm install 2.3.3

rvm use 2.3.3

rvm use 2.3.3 –default

rvm remove 2.0.0

#查看现在版本为2.3.3则

ruby –version

gem install redis

vim /redis-3.2.8/redis.conf

两台主机均修改以下配置文件

port  6379                                        //先默认端口,等会再改

bind 本机ip                                     //默认ip为127.0.0.1 需要改为其他节点机器可访问的ip 否则创建集群时无法访问对应的端口,无法创建集群

daemonize    yes                               //redis后台运行

pidfile  /var/run/redis_6379.pid          //pidfile文件对应

cluster-enabled  yes                           //开启集群  把注释#去掉

cluster-config-file  nodes_6379.conf   //集群的配置文件

cluster-node-timeout  15000                //请求超时  默认15秒,可自行设置

appendonly  yes                           //aof日志开启  有需要就开启,它会每次写操作都记录一条日志

实例10.0.0.5

mkdir /data/redis/conf/

cp /redis-3.2.8/redis.conf /data/redis/conf/6379.conf

 

 

cp /redis-3.2.8/redis.conf /data/redis/conf/6380.conf

sed -i “s/6379/6380/g” /date/redis/conf/6380.conf  

cp /redis-3.2.8/redis.conf /data/redis/conf/6381.conf

sed -i “s/6379/6381/g” /date/redis/conf/6381.conf

#启动

redis-server /data/redis/conf/6379.conf

redis-server /data/redis/conf/6380.conf

redis-server /data/redis/conf/6381.conf

实例    10.0.0.6

mkdir /data/redis/conf/

cp /redis-3.2.8/redis.conf /data/redis/conf/6382.conf

sed -i “s/6379/6382/g” /date/redis/conf/6382.conf

cp /redis-3.2.8/redis.conf /data/redis/conf/6383.conf

sed -i “s/6379/6383/g” /date/redis/conf/6383.conf

cp /redis-3.2.8/redis.conf /data/redis/conf/6384.conf

sed -i “s/6379/6384/g” /date/redis/conf/6384.conf

#启动

redis-server /data/redis/conf/6382.conf

redis-server /data/redis/conf/6383.conf

redis-server /data/redis/conf/6384.conf

 

启动集群

/redis-3.2.8/src/redis-trib.rb create –replicas 1 10.0.0.5:6379 10.0.0.5:6380 10.0.0.5:6381 10.0.0.6:6382 10.0.0.6:6383 10.0.0.6:6384

 

#出现如下内容为成功

[root@lb01 etc]# /redis-3.2.8/src/redis-trib.rb create –replicas 1 10.0.0.5:6379 10.0.0.5:6380 10.0.0.5:6381 10.0.0.6:6382 10.0.0.6:6383 10.0.0.6:6384

>>> Creating cluster

>>> Performing hash slots allocation on 6 nodes…

Using 3 masters:

10.0.0.5:6379

10.0.0.6:6382

10.0.0.5:6380

Adding replica 10.0.0.6:6383 to 10.0.0.5:6379

Adding replica 10.0.0.5:6381 to 10.0.0.6:6382

Adding replica 10.0.0.6:6384 to 10.0.0.5:6380

M: d0b49faff3332cdf7389948593d4fb59caca1613 10.0.0.5:6379

slots:0-5460 (5461 slots) master

M: 8c8a578c750b820ce074026e59d4df059eeefd9b 10.0.0.5:6380

slots:10923-16383 (5461 slots) master

S: 731a69f9df773823be182e27e5001b95766b5528 10.0.0.5:6381

replicates b73a3a4528920064cba668aa9452f32387292ab6

M: b73a3a4528920064cba668aa9452f32387292ab6 10.0.0.6:6382

slots:5461-10922 (5462 slots) master

S: 139c02ceb5a2afe9eb0e350ed3170bceb3aa4c4b 10.0.0.6:6383

replicates d0b49faff3332cdf7389948593d4fb59caca1613

S: af498152476cd4732c47292aff44a57bcd57bb63 10.0.0.6:6384

replicates 8c8a578c750b820ce074026e59d4df059eeefd9b

Can I set the above configuration? (type ‘yes’ to accept): yes     #输入yes即可

 

 

集群测试

[root@lb01 redis-3.2.8]# redis-cli -h 10.0.0.5 -c -p 6379

10.0.0.5:6379> set tank tank1

OK

10.0.0.5:6379> quit

[root@lb01 redis-3.2.8]# redis-cli -h 10.0.0.6 -c -p 6382

10.0.0.6:6382> get tank

-> Redirected to slot [4407] located at 10.0.0.5:6379

“tank1”

10.0.0.5:6379>

发表评论

电子邮件地址不会被公开。 必填项已用*标注