keepalived 安装篇-个人实践-编译安装

官网地址:http://www.keepalived.org/
官网文档:http://www.keepalived.org/documentation.html

Keepalived的作用是检测服务器的状态,如果有一台服务器死机或工作出现故障

Keepalived将检测到,并将有故障的web服务器从系统中剔除,当服务器工作正常后
Keepalived自动将服务器加入到服务器群中,这些工作全部自动完成,不需要人工干涉
需要人工做的只是修复故障的服务器。

Layer3,4,5工作在IP/TCP协议栈的IP层,TCP层,及应用层,原理分别如下:

Layer3:Keepalived使用Layer3的方式工作式时,Keepalived会定期向服务器群中的服务器
发送一个ICMP的数据包(既我们平时用的Ping程序),如果发现某台服务的IP地址没有激活
Keepalived便报告这台服务器失效,并将它从服务器群中剔除,这种情况的典型例子是某台
服务器被非法关机。

Layer3的方式是以服务器的IP地址是否有效作为服务器工作正常与否的标准。

Layer4:如果您理解了Layer3的方式,Layer4就容易了。Layer4主要以TCP端口的状态来
定服务器工作正常与否。如web server的服务端口一般是80,如果Keepalived检测到80端
口没有启动,则Keepalived将把这台服务器从服务器群中剔除。

Layer5:Layer5就是工作在具体的应用层了,比Layer3,Layer4要复杂一点,在网络上占用
的带宽也要大一些。Keepalived将根据用户的设定检查服务器程序的运行是否正常,如果与
用户的设定不相符,则Keepalived将把服务器从服务器群中剔除。

[root@rhel ~]#wget -c http://www.keepalived.org/software/keepalived-1.2.12.tar.gz
[root@rhel ~]# tar zxvf keepalived-1.2.12.tar.gz
[root@rhel ~]# cd keepalived-1.2.12
安装编译环境:
[root@rhel ~]# yum install -y gcc gcc-c++ openssl openssl-devel

如果不安装openssl-devel,可能报错:

!!! OpenSSL is not properly installed on your system. !!!

  !!! Can not include OpenSSL headers files. 

1
[root@rhel keepalived-1.2.12]# ./configure --prefix=/usr/local/keepalived //指定安装路径

[root@rhel keepalived-1.2.12]# make && make install //安装
将keepalived命令软连接到/usr/bin下
[root@rhel keepalived-1.2.12]# ln -s /usr/local/keepalived/sbin/keepalived /usr/bin/keepalived

添加启动脚本且方便用service keepalived start/stop/restart管理
[root@rhel keepalived-1.2.12]# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/keepalived
[root@rhel keepalived-1.2.12]# chmod 755 /etc/init.d/keepalived //添加执行权限
[root@rhel keepalived-1.2.12]# chkconfig keepalived on //开机启动

修改/etc/init.d/keepalived中的程序路径
# Source configuration file (we set KEEPALIVED_OPTIONS there)
. /etc/sysconfig/keepalived

改为:
# Source configuration file (we set KEEPALIVED_OPTIONS there)
. /usr/local/keepalived/etc/sysconfig/keepalived

默认情况下,keepalived 会读取 /etc/keepalived 下keepalived.conf 文件
如果没有建立这个文件,keepalived也不会报错,但是会发现,所创建的关于keepalived的相关参数根本就没有生效。
[root@rhel keepalived-1.2.12]# mkdir /etc/keepalived
[root@rhel keepalived-1.2.12]# ln -s /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf

启动测试:
[root@rhel keepalived-1.2.12]# service keepalived restart
停止 keepalived: [确定]
启动 keepalived: [确定]

安装完成

posted @ 2018-03-28 10:58  大数据从业者FelixZh  阅读(602)  评论(0编辑  收藏  举报