linux

centos7中redis主从搭建

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

留言

您的邮箱地址不会被公开。 必填项已用 * 标注

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。
转载请注明来源:centos7中redis主从搭建 - 多知在线