Redis6集群搭建

一、准备工作

1、redis防火墙的配置

a.配置firewall端口

firewall-cmd --zone=public --add-port=80/tcp --permanent         #开放端口(--permanent永久生效,没有此参数重启后失效)
firewall-cmd --reload                                            #重新载入规则
firewall-cmd --zone= public --query-port=80/tcp                  #查看端口是否开放
firewall-cmd --zone= public --remove-port=80/tcp --permanent     #取消开放端口

b.firewall的具体命令

systemctl start firewalld.service          # 启动
systemctl restart firewalld.service        # 重启
systemctl enable firewalld.service         # 开机启动
systemctl stop firewalld.service           # 关闭
systemctl disable firewalld.service        # 取消开机启动
firewall-cmd --state                       #查看默认防火墙状态(关闭后显示not running,开启后显示running)

接下来是iptables

安装

yum install -y iptables-services

a.配置iptables端口

vim /etc/sysconfig/iptables

按下英文的i,加入下面的几行;添加需要开放的端口只需将21替换成你想开放的端口即可

对于使用nginx的小伙伴需要把21端口加进去,没有加入21端口导致nginx服务启动之后访问不了主界面

-A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
 
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
 
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
 
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT

22是默认存在的,供ssh访问;80、8080端口是http服务访问的;以后用到https,也需要打开443端口的访问权限。

按下esc键,输入英文冒号(:)和英文字母wq,接下来回车,保存

b.重启iptables服务

systemctl restart iptables.service     #重启iptables服务  
systemctl enable iptables.service     #设置iptables服务开机启动  
systemctl status iptables.service      #查询防火墙状态  
systemctl stop iptables.service        #停止防火墙  
systemctl start iptables.service       #启动防火墙  
systemctl restart iptables.service    #重启防火墙  
chkconfig iptables off                     #永久关闭防火墙  
chkconfig iptables on                     #永久关闭后启用  

准备工作部分转载于iptables和firewall防火墙配置_樊先知樊先知的博客-CSDN博客


2、修改redis.config

进入redis安装目录

1、在根目录下创建一个文件夹
mkdir /myRedis

2、进入redis.conf所在目录
cd /opt/redis-6.2.1

3、复制redis.conf
cp redis.conf /myRedis

4、配置redis.conf
cd /myRedis
vi redis.conf

进入编辑模式以后,修改以下配置


3、制作6个实例,6379,6380,6381,6389,6390,6391

vi redis6379.conf

进入编辑模式后

在文件内加入以下内容

include ./redis.conf
port 6379
pidfile /var/run/redis_6379.pid
dbfilename dump6379.rdb

cluster-enabled yes    #打开集群模式
cluster-config-file nodes-6379.conf  #设定节点配置文件名
cluster-node-timeout 15000   #设定节点失联时间,超过该时间(毫秒),集群自动进行主从切换。

利用cp命令将文件复制5份

cp redis6379.conf redis6380.conf

cp redis6379.conf redis6381.conf

cp redis6379.conf redis6389.conf

cp redis6379.conf redis6390.conf

cp redis6379.conf redis6391.conf

将这5个文件的内部的端口号利用以下命令全部替换,例如:

将redis6380.conf文件内进行替换

:%s/6379/6380

4、启动这6个实例

redis-server redis6379.conf

redis-server redis6380.conf

redis-server redis6381.conf

redis-server redis6389.conf

redis-server redis6390.conf

redis-server redis6391.conf

5、将六个节点合成一个集群

组合之前,请确保所有redis实例启动后,nodes-xxxx.conf文件都生成正常。

 合体

1、进入如下目录
cd  /opt/redis-6.2.1/src

2、执行如下命令,将ip地址改为自己的主机的真实ip地址
redis-cli --cluster create --cluster-replicas 1 192.168.134.133:6379 192.168. 134.133:6380 192.168.134.133:6381 192.168.134.133:6389 192.168. 134.133:6390 192.168.134.133:6391

接下来输入yes,就完成了集群的配置。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HelloWorld高级工程师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值