大家好,我是考100分的小小码 ,祝大家学习进步,加薪顺利呀。今天说一说redis集群搭建(非常详细,适合新手)_redis集群配置,希望您对编程的造诣更进一步.
redis集群的搭建
redis集群的三种模式
- 主从复制
- 哨兵模式
- cluster集群
redis-cluster集群的搭建(在一台linux中搭建,三主三从)
下载安装redis5.0.3
- cd /opt 下载redis安装包 wget http://download.redis.io/releases/redis-5.0.3.tar.gz
- tar -zxvf redis-5.0.3.tar.gz 解压
- make 编译
- cd redis-5.0.3/ 进入redis文件夹
- mkdir -p /usr/local/redis-5.0.3 创建redis-5.0.3安装文件夹
- make install PREFIX=/usr/local/redis-5.0.3 安装redis到/usr/local/redis-5.0.3
创建redis-cluster集群文件
- mkdir -p /usr/local/redis-cluster 创建redis集群文件夹
- cd /usr/local/
- cp redis-5.0.3 ./redis-cluster -R 复制redis到集群目录中
- 分别创建config、log、run、dbfile目录
- cd /usr/local/redis-cluster/redis-5.0.3
- mkdir log
- mkdir run
- mkdir dbfile
- mkdir -p config/6380
- mkdir -p config/6381
- mkdir -p config/6382
- mkdir -p config/6383
- mkdir -p config/6384
- mkdir -p config/6385
修改redis.conf文件
- cp /opt/redis-5.0.3/redis.conf /usr/local/redis-cluster/redis-5.0.3/conf/6380/6380.conf
- 找到并修改以下配置
bind 这里修改为本机的网卡ip
protected-mode no
daemonize yes
appendonly yes
port 6380
pidfile /usr/local/redis-cluster/redis-5.0.3/run/redis_6380.pid
appendfilename "appendonly_6380.aof"
logfile "/usr/local/redis-cluster/redis-5.0.3/log/redis_6380.log"
requirepass password
cluster-enabled yes
cluster-node-timeout 5000
cluster-config-file nodes-6380.conf
dbfilename dump_6380.rdb
dir /usr/local/redis-cluster/redis-5.0.3/dbfile
save 900 1
save 300 10
save 60 10000
- 复制该配置文件到其他的配置文件夹中,修改相应的配置(6380改为638?)
开启相应的端口(centos7端口默认关闭)
- systemctl start firewalld 如果防火墙未开启,需要先开启
- firewall-cmd –zone=public –add-port=6380/tcp –permanent 开启数据端口
- firewall-cmd –zone=public –add-port=16380/tcp –permanent 开启总线端口 数据端口和总线端口必须全部开启
- 其他相应端口同样开启
- firewall-cmd –reload 重新载入配置
- filewall-cmd –list-ports 查询已开放端口
开启redis服务
- 创建redis启动脚本
- cd /usr/local/redis-cluster
- vim startup.sh
#!/bin/bash
/usr/local/redis-cluster/redis-5.0.3/bin/redis-server /usr/local/redis-cluster/redis-5.0.3/conf/6380/6380.conf
/usr/local/redis-cluster/redis-5.0.3/bin/redis-server /usr/local/redis-cluster/redis-5.0.3/conf/6381/6381.conf
/usr/local/redis-cluster/redis-5.0.3/bin/redis-server /usr/local/redis-cluster/redis-5.0.3/conf/6382/6382.conf
/usr/local/redis-cluster/redis-5.0.3/bin/redis-server /usr/local/redis-cluster/redis-5.0.3/conf/6383/6383.conf
/usr/local/redis-cluster/redis-5.0.3/bin/redis-server /usr/local/redis-cluster/redis-5.0.3/conf/6384/6384.conf
/usr/local/redis-cluster/redis-5.0.3/bin/redis-server /usr/local/redis-cluster/redis-5.0.3/conf/6385/6385.conf
- ps -ef|grep redis 查询redis是否开启
加入集群
cd /usr/local/redis-cluster/redis-5.0.3/bin
./redis-cli -a password --cluster create 192.168.75.101:6380 192.168.75.101:6381 192.168.75.101:6382 192.168.75.101:6383 192.168.75.101:6384 192.168.75.101:6385 --cluster-replicas 1
客户端连接集群
连接的时候需要加上-c参数,集群模式连接
注意点
- centos7端口默认关闭,需要手动开启数据端口和总线端口
- 配置文件的设置,开启集群模式,bind需要设置本机的ip地址
- 连接集群的时候需要,设置集群模式连接-c
参考链接:https://blog.csdn.net/xukang77/article/details/121613391
原文地址:https://www.cnblogs.com/Yaodada/archive/2022/09/16/16698701.html
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/4763.html