• heartbeat高可用


    一、基本了解

    1、Hearbeat和keepalived区别
    Keepalived使用的vrrp协议方式,虚拟路由冗余协议 (Virtual Router Redundancy Protocol,简称VRRP);
    Heartbeat是基于主机或网络的服务的高可用方式;
    keepalived的目的是模拟路由器的双机
    heartbeat的目的是用户service的双机
    lvs的高可用建议用keepavlived
    业务的高可用用heartbeat
    heartbeat有主备模式,双主模式

    2、heartbeat 主要配置文件
    ha.cf           参数配置文件
    authkey        认证文件
    3haresource     资源配置文件,如配置ip资源及脚本程序

    3、拓展:一个网卡接口配置两个ip

    [root@slave ~]# cd /etc/sysconfig/network-scripts/

    [root@slave network-scripts]# vim ifcfg-ens33:0 

    DEVICE=ens33:0
    TYPE=Ethernet
    ONBOOT=yes
    BOOTPROTO=static
    IPADDR=192.168.40.222
    NETMASK=255.255.255.0
    GATEWAY=192.168.40.1

     二、源码安装

    1、搭建环境

    #hostnamectl set-hostname master (132) ------>      192.168.40.221 (心跳线)

    #hostnamectl set-hostname slave (211)    ------->     192.168.40.220  (心跳线)

    vip :192.168.40.222 (后续的操作,暂时列出来)

    [root@master ~]# vim /etc/hosts

    192.168.40.132 master  
    192.168.40.211 slave

    关闭防火墙、selinux

    yum安装nginx

    2、源码安装(两台机子一样)

    #yum install gcc gcc-c++ autoconf automake libtool glib2-devel libxml2-devel bzip2 bzip2-devel e2fsprogs-devel libxslt-devel libtool-ltdl-devel asciidoc

    rz 上传源码包

    安装glue

    #tar xf 0a7add1d9996.tar.bz2

    #cd Reusable-Cluster-Components-glue--0a7add1d9996/

    ./autogen.sh

    ./configure --prefix=/usr/local/heartbeat --with-daemon-user=hacluster --with-daemon-group=haclient --enable-fatal-warnings=no LIBS='/lib64/libuuid.so.1'

    make && make install

    echo $?

    安装Resource Agents

    tar xf v3.9.6.tar.gz

    cd resource-agents-3.9.6/

    ./autogen.sh

    ./configure --prefix=/usr/local/heartbeat --with-daemon-user=hacluster --with-daemon-group=haclient --enable-fatal-warnings=no LIBS='/lib64/libuuid.so.1'

    make && make install

    echo $?

    cd ..

    安装HeartBeat

    #tar xf 958e11be8686.tar.bz2

    cd Heartbeat-3-0-958e11be8686/

    ./bootstrap

    export CFLAGS="$CFLAGS -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib"

    ./configure --prefix=/usr/local/heartbeat --with-daemon-user=hacluster --with-daemon-group=haclient --enable-fatal-warnings=no LIBS='/lib64/libuuid.so.1'

    make && make install

    echo $?

    配置网卡支持插件文件

    #mkdir -pv /usr/local/heartbeat/usr/lib/ocf/lib/heartbeat/

    #cp /usr/lib/ocf/lib/heartbeat/ocf-* /usr/local/heartbeat/usr/lib/ocf/lib/heartbeat/

    注意:一般启动时会报错因为 ping和ucast这些配置都需要插件支持 需要将lib64下面的插件软连接到lib目录 才不会抛出异常

    #ln -svf /usr/local/heartbeat/lib64/heartbeat/plugins/RAExec/* /usr/local/heartbeat/lib/heartbeat/plugins/RAExec/

    #ln -svf /usr/local/heartbeat/lib64/heartbeat/plugins/* /usr/local/heartbeat/lib/heartbeat/plugins/

    拷贝三个模版配置文件到 /usr/local/heartbeat/etc/ha.d 目录下

    #cp /root/Heartbeat-3-0-958e11be8686/doc/{ha.cf,haresources,authkeys} /usr/local/heartbeat/etc/ha.d/

    三、heartbeat配置文件

    #vim /usr/local/heartbeat/etc/ha.d/ha.cf

    1. debugfile /var/log/ha-debug
    2. logfile /var/log/ha-log
    3. logfacility local0
    4. keepalive 2
    5. warntime 10
    6. deadtime 5
    7. initdead 120
    8. udpport 694
    9. ucast ens33 192.168.40.221 (对方的心跳线)
    10. auto_failback on
    11. node master
    12. node slave
    13. ping 192.168.0.1

    #vim /usr/local/heartbeat/etc/ha.d/authkeys(主备一样)

    auth 3
    #1 crc
    #2 sha1 HI!
    3 md5 Hello!

    #vim /usr/local/heartbeat/etc/ha.d/haresources (主备一样)

     master IPaddr::192.168.40.222/24/ens33  (虚拟IP)

    四、测试

    1、[root@master ~]# echo  web1  >   /usr/share/nginx/html/index.html  (修改主页文件,好区分,方法多样)

    2、[root@master ~]# cat  /usr/share/nginx/html/index.html
    web2  (132机子)
    3、[root@slave ~]# cat  /usr/share/nginx/html/index.html  
    we1    (211机子)

     4、虚拟ip访问(主机正常)

     5、[root@master ~]# systemctl stop  heartbeat  (停掉master的heartbeat)

    6、虚拟ip转移到从机

    [root@slave ~]# ip a
      1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host
           valid_lft forever preferred_lft forever
      2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        link/ether 00:0c:29:17:c0:db brd ff:ff:ff:ff:ff:ff
        inet 192.168.40.211/24 brd 192.168.40.255 scope global ens33
           valid_lft forever preferred_lft forever
        inet 192.168.40.222/24 brd 192.168.40.255 scope global secondary ens33:0
           valid_lft forever preferred_lft forever
        inet6 fe80::20c:29ff:fe17:c0db/64 scope link
           valid_lft forever preferred_lft forever

  • 相关阅读:
    linux基本命令
    操作系统
    罗马数字和整型的关系
    LightOJ 1234 Harmonic Number(打表 + 技巧)
    LightOJ 1236 Pairs Forming LCM (LCM 唯一分解定理 + 素数筛选)
    LightOJ 1245 Harmonic Number (II)(找规律)
    LightOJ 1259 Goldbach`s Conjecture (哥德巴赫猜想 + 素数筛选法)
    LightOJ 1282 Leading and Trailing (快数幂 + 数学)
    LightOJ 13361336
    hdu 5510 Bazinga
  • 原文地址:https://www.cnblogs.com/zjz20/p/11580282.html
Copyright © 2020-2023  润新知