redis服务器说明
1
2
3
4
5
6
7
|
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
1
2
|
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
|
#换源
1
2
3
4
5
|
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报错
1
2
3
|
gem
install
redis
ERROR: Error installing redis:
redis requires Ruby version >= 2.2.2.
|
#原因rvm版本过低
执行以下命令升级rvm
1
2
3
4
5
6
7
|
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则对
1
2
|
ruby –version
gem
install
redis
|
# vim /redis-3.2.8/redis.conf
两台主机均修改以下配置文件
1
2
3
4
5
6
7
8
|
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
1
2
3
4
5
6
7
8
|
mkdir
/data/redis/conf/
cp
/redis-3
.2.8
/redis
.conf
/data/redis/conf/6379
.conf
sed
-i “s
/6379/6380/g
”
/etc/redis/redis-6380
.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/6382/g
”
/date/redis/conf/6381
.conf
|
#启动
1
2
3
|
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
1
2
3
4
5
6
7
|
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/6382/g
”
/date/redis/conf/6383
.conf
cp
/redis-3
.2.8
/redis
.conf
/data/redis/conf/6384
.conf
sed
-i “s
/6379/6382/g
”
/date/redis/conf/6384
.conf
|
#启动
1
2
3
|
redis-server
/data/redis/conf/6382
.conf
redis-server
/data/redis/conf/6383
.conf
redis-server
/data/redis/conf/6384
.conf
|
启动集群
1
|
/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
|
#出现如下内容为成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
[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即可
|
集群测试
1
2
3
4
5
6
7
8
9
|
[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>
|
本文转自 蓝叶子Sheep 51CTO博客,原文链接:http://blog.51cto.com/dellinger/1973780,如需转载请自行联系原作者