zoukankan      html  css  js  c++  java
  • 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"

  • 相关阅读:
    AmazonS3 替换HDFS 方案
    SQL Server 内存管理
    SQL Server I/O 问题的诊断分析
    共享内存 设计原理-shm
    机器学习经典算法笔记-Support Vector Machine SVM
    ACGAN 论文笔记
    CGAN 论文笔记
    《Image Generation with PixelCNN Decoders》论文笔记
    《Iterative-GAN》的算法伪代码整理
    《Deep Learning Face Attributes in the Wild》论文笔记
  • 原文地址:https://www.cnblogs.com/xp0813/p/11765952.html
Copyright © 2011-2022 走看看