centos7中redis主从搭建

原文连接:http://www.duozhi.online/2023/10/20/centos7%e4%b8%adredis%e4%b8%bb%e4%bb%8e%e6%90%ad%e5%bb%ba/

1.节点信息

192.168.0.208

192.168.0.209

ansible上的hosts配置

[root@MES-203 ~]# cat /etc/ansible/hosts 
[k8s]
192.168.0.203 ansible_ssh_user=root ansible_ssh_pass=admin
192.168.0.204 ansible_ssh_user=root ansible_ssh_pass=admin
[pg]
192.168.0.205 ansible_ssh_user=root ansible_ssh_pass=admin
192.168.0.206 ansible_ssh_user=root ansible_ssh_pass=admin
[redis]
192.168.0.208 ansible_ssh_user=root ansible_ssh_pass=admin
192.168.0.209 ansible_ssh_user=root ansible_ssh_pass=admin

2.关闭防火墙

我是通过203上的ansible操作的
[root@MES-203 ansible]# ansible redis -m shell -a "systemctl disable firewalld&&systemctl stop firewalld&&systemctl daemon-reload"

3.yum 源配置

[root@MES-203 ansible]# ansible redis -m shell -a "mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak"

[root@MES-203 ansible]# ansible redis -m shell -a "cd /etc/yum.repos.d&&wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo"

[root@MES-203 ansible]# ansible redis -m shell -a "wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo"

4.时间同步

[root@MES-203 ansible]# ansible redis -m shell -a "yum install chrony -y"

[root@MES-203 ansible]# ansible redis -m shell -a "systemctl enable chronyd&&systemctl start chronyd&&chronyc sources"

5.安装redis

5.1安装redis源

[root@MES-203 ~]# ansible redis -m shell -a "yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm"

5.2查看有哪些版本的redis

[root@MES-203 ~]# ansible redis -m shell -a “yum --enablerepo=remi list redis --showduplicates sort -r”

5.3安装指定版本的redis

[root@MES-203 ~]# ansible redis -m shell -a "yum --enablerepo=remi install redis-5.0.13 -y"

5.4设置开机启动

[root@MES-203 ~]# ansible redis -m shell -a "systemctl enable redis"

5.5修改配置文件(两个节点都操作)

主节点
/etc/redis.conf
Bind 0.0.0.0
requirpass:123456
protected-mode no

从节点
/etc/redis.conf
Bind 0.0.0.0
requirpass:123456
protected-mode no
slaveof 192.168.0.208 6379
masterauth 123456

5.6启动redis

[root@MES-203 ~]# ansible redis -m shell -a "systemctl start redis"

5.7验证

master节点上查看

关键目录

[root@TRANSIT-209 yum.repos.d]# find / -type d -name redis
/run/redis
/etc/selinux/targeted/active/modules/100/redis
/var/lib/redis
/var/log/redis --报错信息可以在这里查看
/usr/lib64/redis
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值