CentOS7,keepalived+ httpd 搭建双机热备

参考了这篇博文http://blog.csdn.net/envon123/article/details/76612593,自己做了验证实验,原文写的很好。

实验环境:
centos7  192.168.200.131   ceph-node1  master(主服务器)

centos7  192.168.200.130   ceph-node2  backup (备用服务器)

vip    192.168.200.16


两台机器做相同的操作,先以ceph-node1这台机器为例:

关闭防火墙

[root@ceph-node1 ]# systemctl stop firewalld
[root@ceph-node1 ]# systemctl status firewalld

关闭selinux

[root@ceph-node1 ]# setenforce 0

[root@ceph-node1 ]# sed -i "s/^SELINUX\=enforcing/SELINUX\=disabled/g" /etc/selinux/config


安装httpd:

yum install httpd -y

[root@ceph-node1 ]# systemctl status httpd

[root@ceph-node1 ]# systemctl start httpd

浏览器输入IP:192.168.200.131,看到Apache测试界面:

CentOS7,keepalived+ httpd 搭建双机热备_第1张图片

下载了keepalived-1.3.8.tar.gz

解压:

[root@ceph-node1 ~]# tar zxvf keepalived-1.3.8.tar.gz

[root@ceph-node1 ~]# cd keepalived-1.3.8/

[root@ceph-node2 keepalived-1.3.8]# ./configure
遇到以下报错:
CentOS7,keepalived+ httpd 搭建双机热备_第2张图片

解决方法:

[root@ceph-node2 keepalived-1.3.8]# yum list | grep openssl

CentOS7,keepalived+ httpd 搭建双机热备_第3张图片

[root@ceph-node2 keepalived-1.3.8]# yum install openssl-devel -y

重新编译安装:

[root@ceph-node2 keepalived-1.3.8]# ./configure

还是出现warning.............

CentOS7,keepalived+ httpd 搭建双机热备_第4张图片

参考:https://www.cnblogs.com/succeed/p/6697185.html 提供的解决办法

[root@ceph-node1 keepalived-1.3.8]# yum -y install libnl libnl-devel

重新编译安装

[root@cepch-node2 keepalived-1.3.8]# ./configure

报错:configure: error: libnfnetlink headers missing

重新编译安装

[root@cepch-node2 keepalived-1.3.8]# ./configure  

CentOS7,keepalived+ httpd 搭建双机热备_第5张图片

[root@ceph-node1 keepalived-1.3.8]# make

CentOS7,keepalived+ httpd 搭建双机热备_第6张图片

[root@ceph-node1 keepalived-1.3.8]# make install

至此安装完成。安装成功后,默认在/usr/local/etc/keepalived目录下生成配置文件keepalived.conf



这里两台机器的配置文件不一样:

ceph-node1 节点上的配置:
global_defs {
  router_id LVS_DEVEL_A
}

vrrp_instance VI_1 {
    state MASTER
    interface eno16777736
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.200.16
    }
}

CentOS7,keepalived+ httpd 搭建双机热备_第7张图片


ceph-node2 节点上的配置:

! Configuration File for keepalived

global_defs {
  router_id LVS_DEVEL_B
}

vrrp_instance VI_1 {
    state BACKUP
    interface eno16777736
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.200.16/24
    }
}

CentOS7,keepalived+ httpd 搭建双机热备_第8张图片

这里贴一份配置说明:来源:http://blog.csdn.net/envon123/article/details/76612593

  1. global_defs {
  2. router_id LVS_DEVEL_A #这个id自已改下,不重复即可
  3. #这里可能有一些发邮件的相关配置,可以直接删除,保留上面那行router_id即可
  4. }
  5. vrrp_instance VI_1 {
  6. state MASTER #主服务器就写MASTER,备用的就写BACKUP
  7. interface ens33 #网络接口名,这个根据情况写
  8. virtual_router_id 51 #主、备必须一样
  9. priority 100 #主、备机取不同的优先级,主机值较大,备份机值较小,值越大优先级越高
  10. advert_int 1 #VRRP Multicast广播周期秒数
  11. authentication {
  12. auth_type PASS #VRRP认证方式,主备必须一致 
  13. auth_pass 1111 #密码
  14. }
  15. virtual_ipaddress {
  16. 192.168.1.230/24 #VRRP HA虚拟地址
  17. }
  18. }

在两台机器上启动keepalived:

执行启动,因为装下 /usr/local 下了,要指定配置文件咯,如下:

[root@ceph-node1 keepalived]# keepalived -D -f /usr/local/etc/keepalived/keepalived.conf

如果想看下log消息,如下:

[root@ceph-node1 keepalived]# tailf /var/log/messages

通过 ip a 可查看到 192.168.200.16/24 绑定到了 eno16777736 接口上,如图:

CentOS7,keepalived+ httpd 搭建双机热备_第9张图片

然后在浏览器上输入vip:192.168.200.16 可以访问到apache的 测试页面。

断开这个apache的服务器,另外一个服务器回顶上,用户感受不到其中的变化。

你可能感兴趣的:(CentOS7,keepalived+ httpd 搭建双机热备)