• Keepalived+redis主从配置


    一、环境检查

      1.1检查SELinux是否开启

        使用getenforce,查看状态,下图为关闭状态

        

         关闭SELinux:

          (1)临时关闭,不用重启

              #关闭:设置SELinux成为permissive模式

              setenforce 0

              #开启:设置SELinux成为enforcing模式

              setenforce 1

          (2)永久关闭,修改/etc/selinux/config文件

              将SELINUX=enforcing 改为 SELINUX=disabled,重启即可

      1.2检查防火墙是否关闭

        systemctl status firewalld  (7.0以上)

    一、安装配置

      2.1安装

        Keepalived安装

          使用yum安装  

          [root@host-192-168-100-139 /]# yum install keepalived    

        Redis安装,直接解压     

          [root@host-192-168-100-139 opt]# tar -xvf  redis-3.0.7.tar

      2.2配置脚本    

      需要创建/var/log/keepalived/的日志目录并修改redis_maste.sh中的REDISCLI="/opt/keepalived_redis_test/redis/redis-cli"redis_check.sh中的ALIVE=`/opt/keepalived_redis_test/redis/redis-cli PING`redis_backup.sh中的REDISCLI="/opt/keepalived_redis_test/redis/redis-cli "

    需要将路径改为redis-cli所在目录

      2.3配置Keepalived   

        目录:/etc/keepalived/keepalived.conf中的内容改为如下所示  

          

          Keepalived主(master

     

     

          state MASTER

     

          unicast_src_ip 192.168.1.1 #master的ip

                  unicast_peer {

                      192.168.2.2 #slave的ip

                  }

           virtual_ipaddress {

                    # Replace with Virtual IP虚拟IP

                    192.168.3.3 dev eth0

                }

                # Configure master and backup IPs

                notify_master "/etc/keepalived/scripts/redis_master.sh 192.168.3.3 6379" #虚拟IP

                notify_backup "/etc/keepalived/scripts/redis_backup.sh 192.168.2.2 6379" #slave的IP

        

          Keepalived从(slave 

          state BACKUP

           unicast_src_ip 192.168.2.2 #slave的IP

                unicast_peer {

                    192.168.1.1#master的IP

                }

          virtual_ipaddress {

                    # Replace with Virtual IP虚拟IP

                    192.168.3.3 dev eth0 

                }

                # Configure master and backup IPs

                notify_master "/etc/keepalived/scripts/redis_master.sh 192.168.3.3 6379" #虚拟IP

                notify_backup "/etc/keepalived/scripts/redis_backup.sh 192.168.1.1 6379" #master的IP

      2.4测试  

         启动 keepalived    

          [root@host-192-168-100-139 keepalived]# service keepalived start 

        启动 redis      

          [root@host-192-168-100-139 redis-3.0.7]#./startup.sh

          停掉主redis进程,然后使用redis-cli连接slave,查看角色是否转换为master使用redis-cli连接,查询命令info replication | grep "role"

  • 相关阅读:
    SAP系统玩阴的?
    SAP MM 采购信息记录中价格单位转换因子的修改
    SAP MM 特殊库存之T库存初探
    Gnome增加消息提醒extension ( Fedora 28 )
    Arch Linux 更新源(以清华 arch 源为例)
    fedora 28 , firewalld 防火墙控制,firewall-cmd 管理防火墙规则
    apache 访问权限出错,apache selinux 权限问题, (13) Permission Denied
    什么是中间件? (保持更新)
    systemd 和 如何修改和创建一个 systemd service (Understanding and administering systemd)
    进入正在运行的 docker 容器(docker container)
  • 原文地址:https://www.cnblogs.com/xp0813/p/11765952.html
Copyright © 2020-2023  润新知