• keepalived搭建


    1.环境准备

    主机IP身份
    web01 172.16.1.7  
    web03 172.16.1.9  
    nfs 172.16.1.31  
    db01 172.16.1.51  
    lb01 172.16.1.4 master
    lb02 172.16.1.5 backup
      10.0.0.3 VIP

    2.保证两台七层负载配置一致

    [root@lb01 ~]# scp /etc/nginx/conf.d/* 172.16.1.5:/etc/nginx/conf.d/
    
    #访问测试
    10.0.0.5 linux.blog.com
    10.0.0.4 linux.blog.com

    3.安装keepalived

    [root@lb01 ~]# yum install -y keepalived
    [root@lb02 ~]# yum install -y keepalived

    4.配置keepalived主节点

    #查找配置文件
    [root@lb01 ~]# rpm -qc keepalived
    /etc/keepalived/keepalived.conf
    
    [root@lb01 ~]# vim /etc/keepalived/keepalived.conf
    global_defs {                #全局配置
       router_id lb01            #身份识别(唯一)
    }
    vrrp_instance VI_1 {        #VRPP协议配置
        state MASTER            #告诉你一开始这台机器是主
        interface eth0            #绑定的网卡
        virtual_router_id 51    #虚拟路由标识,就是编组,将master和backup分为一组                            
        priority 100            #优先级(真正判断是主还是备的条件)
        advert_int 1            #检测心跳的时间间隔     
        authentication {        #认证相关
            auth_type PASS        #以密码的形式认证
            auth_pass 1111        #密码
        }
        virtual_ipaddress {        #指定VIP地址
            10.0.0.3
        }   
    }
    
    [root@lb01 ~]# vim /etc/keepalived/keepalived.conf
    global_defs {
       router_id lb01
    }
    vrrp_instance VI_1 {
        state MASTER
        interface eth0
        virtual_router_id 51
        priority 100
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
            10.0.0.3
        }   
    }

    5.配置keepalived备节点

    [root@lb02 ~]# vim /etc/keepalived/keepalived.conf 
    global_defs {
       router_id lb02
    }
    vrrp_instance VI_1 {
        state BACKUP
        interface eth0
        virtual_router_id 51
        priority 90
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
            10.0.0.3
        }
    }

    6.主备节点配置区别

    区别master主节点backup备节点
    router_id(唯一标识符) lb01 lb02
    state(角色状态) MASTER BACKUP
    priority(优先级) 100 90


    7.启动服务

    [root@lb02 ~]# systemctl start keepalived.service
    [root@lb02 ~]# tail -f /var/log/messages
    
    [root@lb01 ~]# systemctl start keepalived.service
    [root@lb02 ~]# tail -f /var/log/messages

    8.配置keepalived日志

    #配置keepalived
    [root@lb02 ~]# vim /etc/sysconfig/keepalived
    KEEPALIVED_OPTIONS="-D -d -S 0"
    
    #配置rsyslog
    [root@lb02 ~]# vim /etc/rsyslog.conf
    local0.*               /var/log/keepalived.log
    
    #重启服务
    [root@lb02 ~]# systemctl restart rsyslog 
    [root@lb02 ~]# systemctl restart keepalived
    
    #查看日志
    [root@lb02 ~]# tail -f /var/log/keepalived.log
  • 相关阅读:
    MySQL 抓包工具
    php安全配置记录和常见错误梳理
    Mongodb副本集+分片集群环境部署记录
    线上mongodb 数据库用户到期时间修改的操作记录
    Redis+TwemProxy(nutcracker)集群方案部署记录
    Linux下Redis主从复制以及SSDB主主复制环境部署记录
    以多个实例方式打开Notepad++
    什么才是程序员的核心竞争力?zz
    谈谈如何在面试中发掘程序猿的核心竞争力zz
    解决Android SDK Manager更新时出现问题
  • 原文地址:https://www.cnblogs.com/chenlifan/p/13652420.html
Copyright © 2020-2023  润新知