Linux环境 安装 Redis-6.2.6 配置运行_01
https://gblfy.blog.csdn.net/article/details/105583077
Redis 分布式集群能解决的问题 | 集群 概念 |
---|---|
解决现有系统单节点并发压力和物理上限问题 | 通过添加服务器的数量,提供相同的服务,从而让服务器达到一个稳定、高效的状态 |
演示案例
3主3从 横向扩展
服务器 | 端口 | 节点说明 |
---|---|---|
192.168.0.80 | 7001 | master |
192.168.0.80 | 7002 | slave |
192.168.0.80 | 7003 | master |
192.168.0.80 | 7004 | slave |
192.168.0.80 | 7005 | master |
192.168.0.80 | 7006 | slave |
2.1~2.5属于公共部分,101/102/103服务器需要依次执行
wget https://download.redis.io/releases/redis-6.2.6.tar.gz
cd /app
tar -zxvf redis-6.2.6.tar.gz
cd redis-6.2.6/
make install
mkdir /app/redis-cluster/
cp /app/redis-6.2.6/redis.conf /app/redis-cluster/
vim /app/redis-cluster/redis.conf
直接复制即可
# 绑定访问ip信息
bind 0.0.0.0
# # 修改对应的端口
port 7001
#修改为后台启动
daemonize yes
#关闭保护模式
protected-mode no
#启动AOF文件
appendonly yes
#指定数据文件存放位置,必须要指定不同的目录位置,不然会丢失数据
dir /usr/local/redis-cluster/redis-7001
# 日志文件名
logfile "redis-7001.log"
# .pid文件初始化
pidfile /var/run/redis_7001.pid
# 启动集群模式
cluster-enabled yes
# 节点离线的超时时间
cluster-node-timeout 15000
# 注释打开并修改node节点
cluster-config-file nodes-7001.conf
#如果要设置密码需要增加如下配置:
#设置redis访问密码
requirepass pwd@2022gblfy
#设置集群节点间访问密码,跟上面一致
masterauth pwd@2022gblfy
cp /app/redis-cluster/redis.conf /app/redis-cluster/redis-7001.conf
cp /app/redis-cluster/redis.conf /app/redis-cluster/redis-7002.conf
cp /app/redis-cluster/redis.conf /app/redis-cluster/redis-7003.conf
cp /app/redis-cluster/redis.conf /app/redis-cluster/redis-7004.conf
cp /app/redis-cluster/redis.conf /app/redis-cluster/redis-7005.conf
cp /app/redis-cluster/redis.conf /app/redis-cluster/redis-7006.conf
vim /app/redis-cluster/redis-7002.conf
将7001替换为7002
:%s/7001/7002/cg
按y依次替换
vim /app/redis-cluster/redis-7003.conf
将7001替换为7003
:%s/7001/7003/cg
按y依次替换
vim /app/redis-cluster/redis-7004.conf
将7001替换为7004
:%s/7001/7004/cg
按y依次替换
vim /app/redis-cluster/redis-7005.conf
将7001替换为7005
:%s/7001/7005/cg
按y依次替换
vim /app/redis-cluster/redis-7006.conf
将7001替换为7006
:%s/7001/7006/cg
按y依次替换
mkdir /usr/local/redis-cluster/redis-7001 -p
mkdir /usr/local/redis-cluster/redis-7002 -p
mkdir /usr/local/redis-cluster/redis-7003 -p
mkdir /usr/local/redis-cluster/redis-7004 -p
mkdir /usr/local/redis-cluster/redis-7005 -p
mkdir /usr/local/redis-cluster/redis-7006 -p
/app/redis-6.2.6/src/redis-server /app/redis-cluster/redis-7001.conf
/app/redis-6.2.6/src/redis-server /app/redis-cluster/redis-7002.conf
/app/redis-6.2.6/src/redis-server /app/redis-cluster/redis-7003.conf
/app/redis-6.2.6/src/redis-server /app/redis-cluster/redis-7004.conf
/app/redis-6.2.6/src/redis-server /app/redis-cluster/redis-7005.conf
/app/redis-6.2.6/src/redis-server /app/redis-cluster/redis-7006.conf
ps -ef|grep redis
上面仅仅是搭建了集群,6个节点之间还没有关系,下面通过 节点握手让集群各节点之间,发生关系。
centos7.x
firewall-cmd --zone=public --add-port=7001/tcp --permanent
firewall-cmd --zone=public --add-port=7002/tcp --permanent
firewall-cmd --zone=public --add-port=7003/tcp --permanent
firewall-cmd --zone=public --add-port=7004/tcp --permanent
firewall-cmd --zone=public --add-port=7005/tcp --permanent
firewall-cmd --zone=public --add-port=7006/tcp --permanent
firewall-cmd --zone=public --add-port=17001/tcp --permanent
firewall-cmd --zone=public --add-port=17002/tcp --permanent
firewall-cmd --zone=public --add-port=17003/tcp --permanent
firewall-cmd --zone=public --add-port=17004/tcp --permanent
firewall-cmd --zone=public --add-port=17005/tcp --permanent
firewall-cmd --zone=public --add-port=17006/tcp --permanent
firewall-cmd --reload
redis-cli -a pwd@2022gblfy --cluster create --cluster-replicas 1 192.168.0.80:7001 192.168.0.80:7004 192.168.0.80:7003 192.168.0.80:7006 192.168.0.80:7005 192.168.0.80:7002
执行完后会出现下面的界面,输入yes回车即可,我们可以得到以下信息,每一个主服务的哈希槽是多少
谁是主谁是从,谁是谁的主,谁是谁的从
成功标识
[root@VM-24-10-centos redis-cluster]# redis-cli -a pwd@2022gblfy --cluster create --cluster-replicas 1 192.168.0.80:7001 192.168.0.80:7004 192.168.0.80:7003 192.168.0.80:7006 192.168.0.80:7005 192.168.0.80:7002
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.0.80:7005 to 192.168.0.80:7001
Adding replica 192.168.0.80:7002 to 192.168.0.80:7004
Adding replica 192.168.0.80:7006 to 192.168.0.80:7003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 64ab97133edd09d0de90d7646f158cc0c27c6dbc 192.168.0.80:7001
slots:[0-5460] (5461 slots) master
M: a3fbce0abdd2555a966d778aece4827a70e133e9 192.168.0.80:7004
slots:[5461-10922] (5462 slots) master
M: 13f76c0f3b16f251ffc4802c3af89bb3dccfa664 192.168.0.80:7003
slots:[10923-16383] (5461 slots) master
S: d3e0ed7ec783a368602130af5ef405581b20246f 192.168.0.80:7006
replicates 13f76c0f3b16f251ffc4802c3af89bb3dccfa664
S: 3ab99d5dc392b2011b34a52478c4a8ef0152e187 192.168.0.80:7005
replicates 64ab97133edd09d0de90d7646f158cc0c27c6dbc
S: 8b2f5b506b1bdbef9e9fed5844a0bfdc5f88dcc6 192.168.0.80:7002
replicates a3fbce0abdd2555a966d778aece4827a70e133e9
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
.
>>> Performing Cluster Check (using node 192.168.0.80:7001)
M: 64ab97133edd09d0de90d7646f158cc0c27c6dbc 192.168.0.80:7001
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 8b2f5b506b1bdbef9e9fed5844a0bfdc5f88dcc6 192.168.0.80:7002
slots: (0 slots) slave
replicates a3fbce0abdd2555a966d778aece4827a70e133e9
M: a3fbce0abdd2555a966d778aece4827a70e133e9 192.168.0.80:7004
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 3ab99d5dc392b2011b34a52478c4a8ef0152e187 192.168.0.80:7005
slots: (0 slots) slave
replicates 64ab97133edd09d0de90d7646f158cc0c27c6dbc
M: 13f76c0f3b16f251ffc4802c3af89bb3dccfa664 192.168.0.80:7003
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: d3e0ed7ec783a368602130af5ef405581b20246f 192.168.0.80:7006
slots: (0 slots) slave
replicates 13f76c0f3b16f251ffc4802c3af89bb3dccfa664
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
redis-cli -h 192.168.0.80 -p 7001 -a pwd@2022gblfy
cluster info
cluster nodes