Contents

[hide

Introduction

Keepalived provides a strong and robust health checking for LVS clusters.
It implements a framework of health checking on multiple layers for
server failover, and VRRPv2 stack to handle director failover.

How do I install and configure Keepalived for reverse proxy server such as nginx or lighttpd?

If your are using a LVS director to loadbalance a server pool in a
production environment, you may want to have a robust solution for
healthcheck & failover.

This will also work with reverse proxy server such as nginx.

Our Sample Setup

Internet--
|
=============
| ISP Router|
=============
|
|
| |eth0 -> 192.168.1.11 (connected to lan)
|-lb0==|
| |eth1 -> 202.54.1.1 (vip master)
|
| |eth0 -> 192.168.1.10 (connected to lan)
|-lb1==|
|eth1 -> 202.54.1.1 (vip backup)

Where:

  • lb0 - Linux box directly connected to the Internet via eth1. This is master load balancer.
  • lb1 - Linux box directly connected to the Internet via eth1. This is backup load balancer. This will become active if master networking failed.
  • 202.54.1.1 - This ip moves between lb0 and lb1 server. It is called virtual IP address and it is managed by keepalived.
  • eth0 is connected to LAN and all other backend software such as Apache, MySQL and so on.

You need to install the following software on both lb0 and lb1:

  • keepalived for IP failover.
  • iptables to filter traffic
  • nginx or lighttpd revers proxy server.

DNS settings should be as follows:
loadbalancer.com - Our sample domain name.
lb0.loadbalancer.com - 202.54.1.11 (real ip assigned to eth1)
lb1.loadbalancer.com - 202.54.1.12 (real ip assigned to eth1)
www.loadbalancer.com - 202.54.1.1 (VIP for web server) do not assign this IP to any interface.

Install Keepalived

Visit keepalived.org to grab latest source code.
You can use the wget command to download the same (you need to install keepalived on both lb0 and lb1):

# cd /opt
# wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz
# tar -zxvf keepalived-1.1.19.tar.gz
# cd keepalived-1.1.19

Install Kernel Headers

You need to install the following packages:

  1. Kernel-headers - includes the C header files that specify the
    interface between the Linux kernel and userspace libraries and programs.
    The header files define structures and constants that are needed for
    building most standard programs and are also needed for rebuilding the
    glibc package.
  2. kernel-devel - this package provides kernel headers and makefiles sufficient to build modules against the kernel package.

Make sure kernel-headers and kernel-devel packages are installed. If not type the following install the same:

# yum -y install kernel-headers kernel-devel

Compile keepalived

Type the following command:

# ./configure --with-kernel-dir=/lib/modules/$(uname -r)/build
此时,

keepalived出现configure: error: Popt libraries is required的解决方法,有需要的朋友可以参考下。

出现此错误的原因:
未安装popt的开发包

解决方法:
yum install popt-devel
安装好popt的开发包。

重新./configure 即可。

Sample outputs:
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
...
.....
..
config.status: creating keepalived/check/Makefile
config.status: creating keepalived/libipvs-2.6/Makefile Keepalived configuration
------------------------
Keepalived version  : 1.1.19
Compiler  : gcc
Compiler flags  : -g -O2
Extra Lib  : -lpopt -lssl -lcrypto
Use IPVS Framework  : Yes
IPVS sync daemon support : Yes
Use VRRP Framework  : Yes
Use Debug flags  : No

Compile and install the same:

# make && make install

Create Required Softlinks

Type the following commands to create service and run it at RHEL / CentOS run level #3 :

# cd /etc/sysconfig
# ln -s /usr/local/etc/sysconfig/keepalived .
# cd /etc/rc3.d/
# ln -s /usr/local/etc/rc.d/init.d/keepalived S100keepalived
# cd /etc/init.d/
# ln -s /usr/local/etc/rc.d/init.d/keepalived .

Configuration

Your main configuration directory is located at
/usr/local/etc/keepalived and configuration file name is
keepalived.conf. First, make backup of existing configuration:

# cd /usr/local/etc/keepalived
# cp keepalived.conf keepalived.conf.bak

Edit keepalived.conf as follows on lb0:

vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 101
authentication {
auth_type PASS
auth_pass Add-Your-Password-Here
}
virtual_ipaddress {
202.54.1.1/29 dev eth1
}
}

Edit keepalived.conf as follows on lb1 (note priority set to 100 i.e. backup load balancer):

vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 100
authentication {
auth_type PASS
auth_pass Add-Your-Password-Here
}
virtual_ipaddress {
202.54.1.1/29 dev eth1
}
}

Save and close the file. Finally start keepalived on both lb0 and lb1 as follows:

# /etc/init.d/keepalived start

Verify: Keepalived Working Or Not

/var/log/messages will keep track of VIP:

# tail -f /var/log/messages

Sample outputs

Feb 21 04:06:15 lb0 Keepalived_vrrp: Netlink reflector reports IP 202.54.1.1 added
Feb 21 04:06:20 lb0 Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 202.54.1.1

Verify that VIP assigned to eth1:

# ip addr show eth1

Sample outputs:

3: eth1:  mtu 1500 qdisc pfifo_fast qlen 10000
link/ether 00:30:48:30:30:a3 brd ff:ff:ff:ff:ff:ff
inet 202.54.1.11/29 brd 202.54.1.254 scope global eth1
inet 202.54.1.1/29 scope global secondary eth1

ping failover test

Open UNIX / Linux / OS X desktop terminal and type the following command to ping to VIP:

# ping 202.54.1.1
Login to lb0 and halt the server or take down networking:
# halt

Within seconds VIP should move from lb0 to lb1 and you should not see any drops in ping.
On lb1 you should get the following in /var/log/messages:

Feb 21 04:10:07 lb1 Keepalived_vrrp: VRRP_Instance(VI_1) forcing a new MASTER election
Feb 21 04:10:08 lb1 Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Feb 21 04:10:09 lb1 Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Feb 21 04:10:09 lb1 Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Feb 21 04:10:09 lb1 Keepalived_healthcheckers: Netlink reflector reports IP 202.54.1.1 added

install keepalived on RedHat/CentOS to provide IP failover for web cluster的更多相关文章

  1. IP Failover Setup using Keepalived on CentOS/Redhat 6

    source url:http://tecadmin.net/ip-failover-setup-using-keepalived-on-centos-redhat-6/ Keepalived is ...

  2. Centos Install Keepalived

    Keepalived简介Keepalived 的作用是检测 web 服务器的状态,如果有一台 web 服务器死机,或工作出现故障,Keepalived 将检测到,并将有故障的 web 服务器从系统中剔 ...

  3. influxdb-1.7.2.x86_64安装 install influxdb-1.7.2.x86_64 on RedHat & CentOS

    1.下载安装 wget http://dl.influxdata.com/influxdb/releases/influxdb-1.7.2.x86_64.rpm https://portal.infl ...

  4. [转载]How to Install Firefox 33 on CentOS, Redhat and Other Linux Distributions

    FROM: http://tecadmin.net/install-firefox-on-linux/ Firefox 33 has been released for Systems and And ...

  5. 在RedHat/CentOS下安装Docker(不升级内核)

    由于内核版本问题,最初仅Ubuntu可以较好的支持Docker.不过,由于RedHat系列OS(REHL.CentOS)是目前主流的Linux服务器操作系统,所以令RedHat系列OS支持Docker ...

  6. 【liunx】使用xshell连接虚拟机上的CentOS 7,使用xhell连接本地虚拟机上的Ubuntu, 获取本地虚拟机中CentOS 7的IP地址,获取本地虚拟机中Ubuntu 的IP地址,Ubuntu开启22端口

    注意,如果想用xshell去连接本地虚拟机中的linux系统,需要本地虚拟机中的系统是启动的才能连接!!!!! ============================================ ...

  7. RedHat/CentOS 7通过nmcli命令管理网络教程

    Red Hat Enterprise Linux 7 和CentOS 7 的网络管理实际上是对NetworkManager的管理,可通过nmcli命令进行控制,下面小编就给大家介绍下RedHat/Ce ...

  8. (转)RedHat/CentOS安装和配置kerberos

    RedHat/CentOS安装和配置kerberos 需要在kerberos server和客户端都先安装ntp (Internet时间协议,保证服务器和客户机时间同步 ) 1  kerberos 服 ...

  9. linux(Ubuntu/Centos) iproute 路由IP地址等命令集合,查看端口链接

    原 linux(Ubuntu/Centos) iproute 路由IP地址等命令集合,查看端口链接 2017年03月20日 16:55:57 风来了- 阅读数:2291 标签: centoslinux ...

随机推荐

  1. Ninja Blocks物联网平台简介

    Ninja Blocks是一个物联网控制平台,其平台架构包括硬件层.处理器层.软件层以及平台层,请看下图: 最底层是硬件层,包括传感器(Sensors)和驱动器(Actuators),例如温度传感器. ...

  2. Android视觉规范-间距规范与文字规范单位换算(dip、sp与px)

    http://blog.csdn.net/shimiso/article/details/29826073 1.dip与px Android工程师在写页面时,margin值的单位是dip,而视觉设计师 ...

  3. NEWS - InstallShield 2015 正式发布

    如果您需要为Windows®应用程序创建安装,InstallShield®便是您的最佳解决方案.在为桌面.服务器.云.Web和虚拟环境构建可靠的Windows Installer (MSI)和Inst ...

  4. mysqld.exe 占了400M内存的问题

    最近遇到了服务器总是停机的问题,虽然它自己只有2G的内存,不过实际部署的应用访问量非常小,也不至于2G就不够用,所以开始了给服务器瘦身的计划. 看着任务管理器里面的各个进程,发现吃内存最厉害的是mys ...

  5. windows地址转发

    netsh interface portproxy add v4tov4 listenport=8080 connectaddress=192.168.8.108 connectport=8080 把 ...

  6. SSD在SQLServer中的应用

        一. 首先,回顾一下 SSD 的读写特性 (1)有限次数写:        (2)随机读性能最好:        (3)顺序读性能好:        (4)顺序写性能差:        (5) ...

  7. asp.net“服务器应用程序不可用” 解决方法

    服务器应用程序不可用 您试图在此 Web 服务器上访问的 Web 应用程序当前不可用.请点击 Web 浏览器中的“刷新”按钮重试您的请求. 管理员注意事项: 详述此特定请求失败原因的错误消息可在 We ...

  8. “代理XP”组件已作为此服务器安全配置的一部分被关闭的解决办法

    代理XP”组件已作为此服务器安全配置的一部分被关闭.系统管理员可以使用sp_configure来启用“代理XP”.有关启用“代理XP”的详细信息,请参阅SQL Server联机丛书中的“外围应用配置器 ...

  9. Hadoop学习篇1 快速入门

    Hadoop是Apache Lucene创始人Doug Cutting创建的,Hadoop起源于Apache Nutch,一个开源的网络搜索引擎.最先引起注意是2003年google的一篇论文,该论文 ...

  10. selenium实战练习之:粉丝反馈表单的自动化脚本

    链接 粉丝反馈表 要求 服务质量5颗星 喜欢的内容选择各种公开课 对交流群的意见需要填写 留下自己正确的联系方式 点击提交 断言 不需要断言,能符合上面的要求成功提交就可以