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 [root@192.168.56.181](mailto:root@192.168.56.181):/data/work/
`# 输出 181 机器明码即可传输数据。`
scp -r /data/work/redis-3.2.9 [root@192.168.56.182](mailto:root@192.168.56.182):/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