Keepalived搭建LVS高可用集群

一 基础环境 1.1 IP规划

OS:CentOS 6.8 64位

节点类型

 

IP规划

 

主机名

 

类型

 

主 Director Server

 

eth0:172.24.8.10

 

DR1

 

公共IP

 

eth1:192.168.56.100

 

心跳

 

私有IP

 

eth0:0:172.24.8.100

 

 

虚拟IP

 

主 Director Server

 

eth0:172.24.8.11

 

DR2

 

公共IP

 

eth1:192.168.56.101

 

心跳

 

私有IP

 

Real Server 1

 

eth0:172.24.8.12

 

rs1

 

公共IP

 

lo:0:172.24.8.100

 

 

虚拟IP

 

Real Server 1

 

eth0:172.24.8.13

 

rs2

 

公共IP

 

lo:0:172.24.8.100

 

 

虚拟IP

 

1.2 架构规划

01

二 高可用LVS负载均衡集群部署 2.1 NTP部署

操作略,具体可参考N01.1.1-常见服务《NTP》。

注意:为了保证集群的稳定性,强烈建议在所有节点均部署NTP同步服务,保证所有时钟一致。

2.2 部署httpd集群

[root@RServer01 ~]# yum -y install httpd
[root@RServer01 ~]# service iptables stop
[root@RServer01 ~]# chkconfig iptables off
[root@RServer01 ~]# vi /etc/selinux/config
SELINUX=disabled
[root@master ~]# setenforce 0                    #关闭SELinux及防火墙

注意:后端所有Real服务器节点都需要安装,用于模拟测试。

建议:为了测试方便,建议所��节点关闭防火墙和SELinux,若未关闭防火墙也可通过下列方式放通:

firewall-cmd --permanent–-add-service=keepalived
firewall-cmd --reload

2.3 安装Keepalived

[root@lvsmaster ~]# yum -y install gcc gcc-c++ make kernel-devel kernel-tools kernel-tools-libs kernel libnl libnl-devel libnfnetlink-devel openssl-devel wget openssh-clients        #安装基础环境及依赖
[root@lvsmaster ~]# ln -s /usr/src/kernels/`uname -r` /usr/src/linux
[root@lvsmaster ~]# wget
[root@lvsmaster ~]# tar -zxvf keepalived-1.3.6.tar.gz        #编译安装Keepalived
[root@lvsmaster ~]# cd keepalived-1.3.6/
[root@lvsmaster keepalived-1.3.6]# ./configure --prefix=/usr/local/keepalived
[root@Master keepalived-1.3.9]# make && make install

注意:CentOS6.8安装高于1.3.6版本会出现未知错误。

2.4 添加启动相关服务

[root@lvsmaster ~]# mkdir /etc/keepalived
[root@lvsmaster ~]# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
[root@lvsmaster ~]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
[root@lvsmaster ~]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
[root@lvsmaster ~]# vi /etc/init.d/keepalived  #创建Keepalived启动脚本,如附件
#!/bin/sh
#
# keepalived  High Availability monitor built upon LVS and VRRP
#
# chkconfig:  - 86 14
# description: Robust keepalive facility to the Linux Virtual Server project \
#              with multilayer TCP/IP stack checks.

### BEGIN INIT INFO
# Provides: keepalived
# Required-Start: $local_fs $network $named $syslog
# Required-Stop: $local_fs $network $named $syslog
# Should-Start: smtpdaemon httpd
# Should-Stop: smtpdaemon httpd
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: High Availability monitor built upon LVS and VRRP
# Description:      Robust keepalive facility to the Linux Virtual Server
#                    project with multilayer TCP/IP stack checks.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

exec="/usr/sbin/keepalived"
prog="keepalived"
config="/etc/keepalived/keepalived.conf"

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/keepalived

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/c17e43d5114c22d46c579986050c7819.html