原文连接: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