Keepalived 2.0.6编译安装

简介: 时间:2018.7.31作者:李强参考:man,info,magedu讲义,万能的internet实验环境:VMware® Workstation 12 Pro ,Centos 7.4,SecureCRT Version 8.1.4声明:以下英文纯属个人翻译,英文B级,欢迎纠正,以下内容纯属个人理解,并没有对错,只是参考,盗版不纠,才能有限,希望不误人子弟为好。

时间:2018.7.31
作者:李强
参考:man,info,magedu讲义,万能的internet
实验环境:VMware® Workstation 12 Pro ,Centos 7.4,SecureCRT Version 8.1.4
声明:以下英文纯属个人翻译,英文B级,欢迎纠正,以下内容纯属个人理解,并没有对错,只是参考,盗版不纠,才能有限,希望不误人子弟为好。
版本:v1-2018.7.31

一、 参考资料

1、https://www.cnblogs.com/succeed/p/6697185.html
2、https://www.cnblogs.com/waynechou/p/keepalived.html
3、http://www.keepalived.org/doc/installing_keepalived.html
4、https://blog.csdn.net/liyuling52011/article/details/80033229

二、安装前环境准备

yum install curl gcc openssl-devel libnl3-devel net-snmp-devel

三、软件目录规划

软件安装目录:/usr/local/app/keepalived_v

日志文件单独存放在/var/log/keepalived/keepalived.log下

四、开始编译

1、下载源码包

 下载站点:
 1、http://www.keepalived.org/download.html
 2、http://keepalived.org/software

 cd /tmp
 curl --progress http://keepalived.org/software/keepalived-2.0.6.tar.gz | tar xz

2、编译

cd keepalived-2.0.6
./configure   
# 此处可以--prefix 来指定编译的软件安装路径usr/local/ewifi/keepalived_v/keepalived-2.0.6
make && make install

编译出现错误:

configure: error: libnfnetlink headers missing

此时需要安装:

yum -y install libnfnetlink-devel

PS:编译时出现问题,基本上安装xx-devel即可

此时在执行./configure  --prefix=usr/local/ewifi/keepalived_v/keepalived-2.0.6 

出现如下提示,即编译成功。

Keepalived configuration
------------------------
Keepalived version       : 2.0.6
Compiler                 : gcc
Preprocessor flags       :  -I/usr/include/libnl3 
Compiler flags           : -Wall -Wunused -Wstrict-prototypes -Wextra -Winit-self -g -D_GNU_SOURCE -fPIE -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -O2  
Linker flags             :  -pie
Extra Lib                :  -lcrypto  -lssl  -lnl-genl-3 -lnl-3 
Use IPVS Framework       : Yes
IPVS use libnl           : Yes
IPVS syncd attributes    : No
IPVS 64 bit stats        : No
fwmark socket support    : Yes
Use VRRP Framework       : Yes
Use VRRP VMAC            : Yes
Use VRRP authentication  : Yes
With ip rules/routes     : Yes
Use BFD Framework        : No
SNMP vrrp support        : No
SNMP checker support     : No
SNMP RFCv2 support       : No
SNMP RFCv3 support       : No
DBUS support             : No
SHA1 support             : No
Use Json output          : No
libnl version            : 3
Use IPv4 devconf         : No
Use libiptc              : No
Use libipset             : No
init type                : systemd
Build genhash            : Yes
Build documentation      : No

3、自启动脚本

yum 安装的目录结构

/etc/keepalived
/etc/keepalived/keepalived.conf
/etc/sysconfig/keepalived
/usr/bin/genhash
/usr/lib/systemd/system/keepalived.service
/usr/libexec/keepalived
/usr/sbin/keepalived
/usr/share/doc/keepalived-1.3.5

编译安装后,会根据系统环境,生成启动脚本。

[root@zabbix_server keepalived]# cat /usr/lib/systemd/system/keepalived.service 
[Unit]
Description=LVS and VRRP High Availability Monitor
After= network-online.target syslog.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/keepalived.pid
KillMode=process
EnvironmentFile=-/usr/local/ewifi/keepalived_v/keepalived-2.0.6/etc/sysconfig/keepalived
ExecStart=/usr/local/ewifi/keepalived_v/keepalived-2.0.6/sbin/keepalived $KEEPALIVED_OPTIONS
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

!!!!这里需要检查配置文件是否正确。然后是sysconfig/keepalived需要进行改造。这里建立软链接都没用。
否则启动会报错

Unable to find configuration file /etc/keepalived/keepalived.conf (glob returned 3)
7月 31 11:52:58 zabbix_server systemd[1]: PID file /var/run/keepalived.pid not readable (yet?) after start.

cd /usr/local/ewifi/keepalived_v/keepalived-2.0.6/etc/sysconfig/

sed -i 's@KEEPALIVED_OPTIONS=.*@KEEPALIVED_OPTIONS="-f /usr/local/ewifi/keepalived_v/keepalived-2.0.6/etc/keepalived/keepalived.conf -D -S 0"@' keepalived

这里需要使用-f指定配置文件路径才能正常启动。

!!!!默认的日志存放位置在/var/log/messages中。

echo 'local0.* /var/log/keepalived/keepalived.log' >>/etc/rsyslog.conf                             

然后需要修改keepalived.conf 配置文件才可以启动成功,备份原始文件,删除里面定义的vrrp和lvs相关信息。

重启服务即可。

4、设置开机启动

systemctl enable keepalived.service 

5、 建立备忘录

cd /usr/local/app/keepalived_v/keepalived-2.0.6
cat >>README <<eof
1、启动服务在/usr/lib/systemd/system/keepalived.service,并设置了开机启动
2、修改日志文件存放位置/var/log/keepalived/keepalived.log
echo 'local0.* /var/log/keepalived/keepalived.log' >>/etc/rsyslog.conf  

eof
相关文章
|
6月前
|
运维 Linux
keepalived详解(二)——keepalived安装与配置文件
keepalived详解(二)——keepalived安装与配置文件
236 1
|
负载均衡 网络协议 应用服务中间件
高可用 - 04 Keepalived编译安装
高可用 - 04 Keepalived编译安装
287 0
高可用 - 04 Keepalived编译安装
|
数据安全/隐私保护 网络架构
Keepalived 安装与配置
安装好之后, 下一步就开始去来写这个配置文件了,就在这里面去建一个 etc 当中,就是在这个 etc 当中建一个这个 Keepalived 的 config 这样的一个文件:
193 1
|
Linux 应用服务中间件 nginx
|
Unix 测试技术 调度