CentOS 6.3 安装 Keepalived

Keepalived is a routing software written in C. The main goal of this project is to provide simple and robust facilities for loadbalancing and high-availability to Linux system and Linux based infrastructures. Loadbalancing framework relies on well-known and widely used Linux Virtual Server (IPVS) kernel module providing Layer4 loadbalancing. Keepalived implements a set of checkers to dynamically and adaptively maintain and manage loadbalanced server pool according their health. On the other hand high-availability is achieved by VRRP protocol. VRRP is a fundamental brick for router failover. In addition, Keepalived implements a set of hooks to the VRRP finite state machine providing low-level and high-speed protocol interactions. Keepalived frameworks can be used independently or all together to provide resilient infrastructures.

Keepalived is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

OSI七层模型与TCP/IP五层模型:

OSI七层模型:

OSI中的层    功能                                            TCP/IP协议族
应用层          文件传输,电子邮件,文件服务,虚拟终 端          TFTP,HTTP,SNMP,FTP,SMTP,DNS,Telnet

表示层          数据格式化,代码转换,数据加密                   没有协议

会话层          解除或建立与别的接点的联系                       没有协议

传输层          提供端对端的接口                                 TCP,UDP

网络层          为数据包选择路由                                 IP,ICMP,RIP,OSPF,BGP,IGMP

数据链路层      传输有地址的帧以及错误检测功能                   SLIP,CSLIP,PPP,ARP,RARP,MTU

物理层          以二进制数据形式在物理媒体上传输数据             ISO2110,IEEE802,IEEE802.2

*******************************************************************************

TCP/IP五层模型:
应用层
传输层:四层交换机、也有工作在四层的路由器
网络层:路由器、三层交换机
数据链路层:网桥(现已很少使用)、以太网交换机(二层交换机)、网卡(其实网卡是一半工作在物理层、一半工作在数据链路层)
物理层:中继器、集线器、还有我们通常说的双绞线也工作在物理层

*******************************************************************************

如果将TCP/IP划分为5层,则Keepalived就是一个类似于3~5层交换机制的软件,具有3~5层交换功能,其主要作用是检测web服务器的状 态,如果某台web服务器故障,Keepalived将检测到并将其从系统中剔除,当该web服务器工作正常后Keepalived自动将其加入到服务器群中,这些工作全部自动完成,而不需要人工干预,只需要人工修复故障的web服务器即可。


Keepalived基于VRRP协议来实现高可用解决方案,利用其避免单点故障,通常这个解决方案中,至少有2台服务器运行Keepalived,即一 台为MASTER,另一台为BACKUP,但对外表现为一个虚拟IP,MASTER会发送特定消息给BACKUP,当BACKUP收不到该消息时,则认为 MASTER故障了,BACKUP会接管虚拟IP,继续提供服务,从而保证了高可用性。

3层机理是:发送ICMP数据包即PING给某台服务器,如果不通,则认为其故障,并从服务器群中剔除。

4层机理是:检测TCP端口号状态来判断某台服务器是否故障,如果故障,则从服务器群中剔除。

5层机理是:根据用户的设定检查某个服务器应用程序是否正常运行,如果不正常,则从服务器群中剔除。


VIP: Virtual IP
RIP: Real IP
CIP: Client IP
DIP: Director IP

1.下载 keepalived-1.2.12.tar.gz

2.解包

# tar -zvxf keepalived-1.2.12.tar.gz

3.切换目录

# cd keepalived-1.2.12

4.配置

# ./configure -prefix=/usr/local/keepalived

5.编译和安装

# make; make install

顺利的话就这些步骤了,如果出现错误提示,那么根据具体的错误具体处理,一般可能出现的错误: 
 
1)、OpenSSL,提示可能如下 
 
!!! OpenSSL is not properly installed on your system. !!! 
 
!!! Can not include OpenSSL headers files. 
 
解决方案:运行yum install -y openssl openssl-devel
 
2)、提示没有gcc编译器 
 
解决方案:运行yum install ncurses-devel gcc gcc-c++ make rpm-build 


6.运行

# mkdir /etc/keepalived/
# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ 
# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
# ln -s /usr/local/keepalived/sbin/keepalived /sbin/

# service keepalived start [stop|restart|status]
Starting keepalived: [  OK  ]

# service keepalived status
keepalived (pid  12092) is running...

# chkconfig keepalived on

7.验证

# tail -f /var/log/messages

# ip addr

# yum -y install ipvsadm

# ipvsadm -L -n







猜你喜欢

转载自maosheng.iteye.com/blog/2238747