redis集群搭建+三节点

环境:三台centos7 redis:5.0.7
目的:得到6个节点的集群,三主三从
1 安装解压

 yum install gcc-c++ -y
 wget https://download.redis.io/releases/redis-5.0.7.tar.gz
 tar xzf redis-6.2.3.tar.gz

2 编译安装

cd redis-5.0.7
make
make test
make install

make test 出现的错误:
You need tcl 8.5 or newer in order to run the Redis test
解决:

wget http://mirror.centos.org/centos/7/os/x86_64/Packages/tcl-8.5.13-8.el7.x86_64.rpm
rpm -ivh tcl-8.5.13-8.el7.x86_64.rpm
make test   #成功 

3 配置文件设置
注意:21001/ 和21002/路径下的 redis.conf 中端口不一样,还有一些其他的配置(pidfile logfile cluster-config-file) 分别为21001 21002
还有一个登录密码

mkdir -p /etc/redis-cluster/21001
mkdir -p /etc/redis-cluster/21002
mkdir /var/log/redis
mkdir /var/lib/redis
cp /app/redis-5.0.7/redis.conf /etc/redis-cluster/21001
cp /app/redis-5.0.7/redis.conf /etc/redis-cluster/21002

redis文件配置:

bind 0.0.0.0
protected-mode yes
port 21001
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_21001.pid
loglevel notice
logfile /var/log/redis/redis_21001.log
databases 16
save ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump-21001.rdb
dir /var/lib/redis
slave-serve-stale-data no
slave-read-only yes
repl-diskless-sync yes
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
maxclients 10000
maxmemory 10737418240
maxmemory-policy volatile-lru
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 nodes-21001.conf
cluster-node-timeout 15000
cluster-require-full-coverage no
slowlog-log-slower-than 15000
slowlog-max-len 1000
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 512mb 218mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 50
aof-rewrite-incremental-fsync yes
masterauth 登陆密码
requirepass 登陆密码
rename-command FLUSHALL "amlajg"
rename-command FLUSHDB "xlkged"
rename-command EVAL "lmakdg"
rename-command KEYS "dglkmz"

4 启动
(1)使用绝对路径启动

nohup /app/redis-5.0.7/src/redis-server  /etc/redis-cluster/21001/redis.conf >21001.txt &
nohup /app/redis-5.0.7/src/redis-server  /etc/redis-cluster21002/redis.conf  >21002.txt &
ps aux|grep redis

在这里插入图片描述
5 做成服务

vim /usr/lib/systemd/system/redis-21001.service

[Unit]
Description=Redis persistent key-value database
After=network.target

[Service]
LimitNOFILE=65535
ExecStart=/app/redis-5.0.7/src/redis-server /etc/redis-cluster/21001/redis.conf --daemonize no
ExecStop=/app/redis-5.0.7/src/redis-cli -h 127.0.0.1 -p 21001 shutdown
# User=redis
# Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target


vim /usr/lib/systemd/system/redis-21002.service

[Unit]
Description=Redis persistent key-value database
After=network.target

[Service]
LimitNOFILE=65535
ExecStart=/app/redis-5.0.7/src/redis-server /etc/redis-cluster/21002/redis.conf --daemonize no
ExecStop=/app/redis-5.0.7/src/redis-cli -h 127.0.0.1 -p 21002 shutdown
# User=redis
# Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target



#修改完后  
systemctl daemon-reload
systemctl start redis-21001
systemctl start redis-21002
ps aux|grep redis

6 添加集群
注意点:密码包含特殊字符可能需要转义

redis-cli -a 123456 --cluster create 192.168.70.61:21001  192.168.70.61:21002 192.168.70.62:21001 192.168.70.62:21002 192.168.70.63:21001 192.168.70.63:21002 --cluster-replicas 1

# 查看集群节点状态和个数
redis-cli -a 123456 -c -h 192.168.70.61 -p 21001
cluster info 
cluster nodes

在这里插入图片描述
7 特殊情况 当集群创建失败时

systemctl stop redis-21001.service redis-21002.service && rm -fr /var/lib/redis/*
rm -f /var/log/redis/redis*
rm -f /var/run/redis_210*
rm -f /var/lib/redis/*
rm -f /app/redis-5.0.7/src/nodes*
chown redis:redis /var/log/redis
chown redis:redis /var/lib/redis

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值