centos7部署redis_3.2.9 cluster部署(三主三从
1,虚拟机环境
使用的Linux环境已经版本:
Centos 7 64位系统
主机ip :
192.168.56.180
192.168.56.181
192.168.56.182
每台服务器是1主1从,实验3台服务器课成为3主3从。
Redis安装的项目目录,日志,配置文件等都存放在/ root / svr /目录下。
2,下载相关的安装包以及解压
首先在192.168.56.180机器操作:
cd /data/work/
wget http://download.redis.io/releases/redis-3.2.9.tar.gz
tar -zxvf redis-3.2.9.tar.gz
3,安装
在/data/work/redis-3.2.9/目录下执行:
make && make install PREFIX = / data / work / redis-3.2.9
4,配置信息
创建性能配置,日志日志,数据所在的文件夹:
cd /data/work/redis-3.2.9/`
mkdir cluster-conf`
mkdir -pv /data/work/redis-3.2.9/logs
创建可用端口文件夹:
cd cluster-conf
mkdir 7777
mkdir 8888
配置复制文件到/数据/工作/redis-3.2.9/cluster-conf/7777目录下:
cp /data/work/redis-3.2.9/redis.conf /data/work/redis-3.2.9/cluster-conf/7777
- 修改7777目录下redis.conf(主)配置文件:
bind 192.168.56.181 127.0.0.1
protected-mode yes
masterauth "xxxxx"
requirepass "xxxxx"
port 8888
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /data/work/redis-3.2.9/cluster-conf/8888/redis_8888.pid
loglevel notice
logfile "/data/work/redis-3.2.9/logs/redis_8888.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
maxclients 100000
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file /data/work/redis-3.2.9/cluster-conf/8888/nodes-8888.conf
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
- 群集配置文件/data/work/redis-3.2.9/cluster-conf/8888/redis.conf (从)
bind 192.168.56.181 127.0.0.1
protected-mode yes
masterauth "xxxxx"
requirepass "xxxxx"
port 8888
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /data/work/redis-3.2.9/cluster-conf/8888/redis_8888.pid
loglevel notice
logfile "/data/work/redis-3.2.9/logs/redis_8888.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
maxclients 100000
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file /data/work/redis-3.2.9/cluster-conf/8888/nodes-8888.conf
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
5,使用scp复制安装和配置好的redis复制到其他服务器上
已经在192.168.56.180机器配置好,复制到181和182机器
在两台新机器上创建文件夹
scp -r /data/work/redis-3.2.9 [[email protected]](mailto:[email protected]):/data/work/
`#输入181机器密码即可传输数据。`
scp -r /data/work/redis-3.2.9 [[email protected]](mailto:[email protected]):/data/work/`
`#输入182机器密码即可传输数据。`
6,启动3台机器的redis
3台机器执行启动方式:
/data/work/redis-3.2.9/bin/redis-server /root/svr/redis-3.2.9/cluster-conf/7777/redis.conf &
/data/work/redis-3.2.9/bin/redis-server /root/svr/redis-3.2.9/cluster-conf/8888/redis.conf &
查看状态是否:
ps -ef|grep redis
7,安装ruby2.4.0
gpg2 --recv键409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
`yum -y update nss`
curl -sSL [https://get.rvm.io](https://get.rvm.io/) | bash -s稳定
源/etc/profile.d/rvm.sh
rvm安装2.4.0
rvm使用2.4.0
gem install redis
yum install rubygems
8,创造实力
/data/work/redis-3.2.9/src/redis-trib.rb create --replicas 1 192.168.56.180:7777 192.168.56.180:8888 192.168.56.181:7777 192.168.56.181:8888 192.168.56.182:7777 192.168.56.182:8888
无法创建,提示错误信息:
>>> Creating cluster
[ERR] Sorry, can't connect to node 192.168.56.180:7777
修改配置文件redis.conf的权限设置安全密码(密码自定义设置)
requirepass "xxxxx" #权限密码`
masterauth "xxxxx"
- 设置密码之后如果需要使用redis-trib.rb的各种命令
如:./redis-trib.rb check 127.0.0.1:7000,则会报错ERR] Sorry, can’t connect to node 127.0.0.1:7000
解决办法:vim /usr/local/rvm/gems/ruby-2.3.3/gems/redis-4.0.0/lib/redis/client.rb,然后修改passord
find / -name client.rb
vim /usr/local/rvm/gems/ruby-2.4.0/gems/redis-4.2.5/lib/redis/client.rb
1 # frozen_string_literal: true
.
.
18 connect_timeout: nil,
19 timeout: 5.0,
20 password: "xxxxx", #######修改这里的密码(每台机器做同样的操作)
**注意:client.rb路径可以通过find命令查找:find / -name 'client.rb'**
带密码访问集群
/data/work/redis-3.2.9/bin/redis-cli -c -p 8888 -a xxxxx
>>> Performing Cluster Check (using node 127.0.0.1:7777)
M: d8xxxefxxxxxxxxxxxxxxxxxx2 127.0.0.1:7777
slots: (0 slots) master
0 additional replica(s)
[OK] All nodes agree about slots configuration.
9、测试集群
### 192.168.56.180
/data/work/redis-3.2.9/bin/redis-cli -c -p 8888 -a xxxxx
127.0.0.1:8888> set test hellokugou
-> Redirected to slot [6918] located at 192.168.56.180:7777
OK
### 192.168.56.182
/data/work/redis-3.2.9/bin/redis-cli -c -p 7777 -a xxxxx
127.0.0.1:7777> get test
-> Redirected to slot [6918] located at 192.168.56.182:7777
"hellokugou"
172.22.15.245:7777> CLUSTER NODES
6xxxxxxxxxxxx7c 192.168.56.180:8888 slave 7xxxxxxxxxxxxxxxxxxxxx7 0 1606114181062 4 connected
3xxxxxxxxxxxxx1 192.168.56.181:8888 slave dxxxxxxxxxxxxxxxxxxxxxx2 0 1606114179060 6 connected
7xxxxxxxxxxxxxa 192.168.56.182:8888 slave 8xxxxxxxxxxxxxxxxxxxxx9 0 1606114182064 3 connected
dxxxxxxxxxxxxx2 192.168.56.180:7777 master - 0 1606114180062 5 connected 10923-16383
8xxxxxxxxxxxxx9 192.168.56.181:7777 myself,master - 0 0 3 connected 5461-10922
7xxxxxxxxxxxxx7 192.168.56.182:7777 master - 0 1606114182564 1 connected 0-5460
192.168.56.182:7777> exit