`

centos 安装keepalived-1.3.5并配置nginx

阅读更多

 

Keepalived是一个免费开源的,用C编写的类似于layer3,
4 & 7
交换机制软件,具备我们平时说的第3层、第4层和第7层交换机的功能。主要提供loadbalancing(负载均衡)和high-availability(高可用)功能,负载均衡实现需要依赖Linux的虚拟服务内核模块(ipvs),而高可用是通过VRRP协议实现多台机器之间的故障转移服务。

 

官网源码包下载地址(2017-07-31 Keepalived最新版keepalived-1.3.5.tar.gz):http://www.keepalived.org/download.html

 

[root@iZ256w2hluuZ local]# tar -zxvf /tmp/keepalived-1.3.5.tar.gz 

[root@iZ256w2hluuZ local]# cd keepalived-1.3.5/

[root@iZ256w2hluuZ keepalived-1.3.5]# ./configure --prefix=/usr/local/keepalived

 

 

 

1. 系统出现警告信息“*** WARNING - this build will not support IPVS with IPv6. Please install libnl/libnl-3 dev libraries to support IPv6 with IPVS.”,具体日志如下:

 

Keepalived configuration

------------------------

Keepalived version       : 1.3.5

Compiler                 : gcc

Preprocessor flags       : 

Compiler flags           : -Wall -Wunused -Wstrict-prototypes -Wextra -g -O2

Linker flags             : 

Extra Lib                :  -lcrypto  -lssl 

Use IPVS Framework       : Yes

IPVS use libnl           : No

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

SNMP vrrp support        : No

SNMP checker support     : No

SNMP RFCv2 support       : No

SNMP RFCv3 support       : No

DBUS support             : No

SHA1 support             : No

Use Debug flags          : No

Stacktrace support       : No

Memory alloc check       : No

libnl version            : None

Use IPv4 devconf         : No

Use libiptc              : No

Use libipset             : No

init type                : upstart

Build genhash            : Yes

Build documentation      : No

 

*** WARNING - this build will not support IPVS with IPv6. Please install libnl/libnl-3 dev libraries to support IPv6 with IPVS.

 

 

 

解决方案一:(在线安装)

 

执行yum命令yum -y install libnl libnl-devel解决上述警告问题

 

[root@iZ256w2hluuZ keepalived-1.3.5]# yum -y install libnl libnl-devel

 

 

 

解决方案二:(离线安装)

 

离线安装libnl-devel包,从网上下载libnl-devel-1.1.4-2.el6.x86_64.rpm包,执行rpm -ivh libnl-devel-1.1.4-2.el6.x86_64.rpm命令。

 

[root@iZ256w2hluuZ other-packages]# wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libnl-devel-1.1.4-2.el6.x86_64.rpm

####执行wget命令是从另外一台可以连接外网的服务器上下载libnl-devel-1.1.4-2.el6.x86_64.rpm包的命令,可以忽略,只是为大家提供个下载libnl-devel地址####

 

[root@iZ256w2hluuZ other-packages]# rpm -ivh libnl-devel-1.1.4-2.el6.x86_64.rpm 

Preparing...                ########################################### [100%]

        package libnl-devel-1.1.4-2.el6.x86_64 is already installed

 

 

 

安装完成以后,重新执行configure命令

 

[root@iZ256w2hluuZ keepalived-1.3.5]# ./configure --prefix=/usr/local/keepalived

 

 

 

2. 系统出现错误信息“configure: error: libnfnetlink headers missing”,具体日志如下:

 

checking for nl_socket_modify_cb in -lnl... yes

checking for linux/rtnetlink.h... yes

checking libnfnetlink/libnfnetlink.h usability... no

checking libnfnetlink/libnfnetlink.h presence... no

checking for libnfnetlink/libnfnetlink.h... no

configure: error: libnfnetlink headers missing

 

 

 

解决方案一:(在线安装)

 

执行yum命令yum install -y libnfnetlink-devel解决上述错误问题

 

[root@iZ256w2hluuZ keepalived-1.3.5]# yum install -y libnfnetlink-devel

 

 

 

解决方案二:(离线安装)

 

Linux执行wget下载rpm包(离线安装libnfnetlink包时所需rpm包,执行wget下载libnfnetlink rpm包命令,此步可以忽略,只是为大家提供个下载libnfnetlink地址),具体命令如下:

 

wget ftp://mirror.switch.ch/mirror/centos/6/os/x86_64/Packages/libnfnetlink-1.0.0-1.el6.x86_64.rpm

wget ftp://mirror.switch.ch/mirror/centos/6/os/x86_64/Packages/libnfnetlink-devel-1.0.0-1.el6.x86_64.rpm

 

执行rpm -ivh libnfnetlink-1.0.0-1.el6.x86_64.rpm命令安装libnfnetlink-1.0.0-1.el6.x86_64.rpm包,具体如下:

 

[root@iZ256w2hluuZ other-packages]# rpm -ivh libnfnetlink-1.0.0-1.el6.x86_64.rpm 

Preparing...                ########################################### [100%]

   1:libnfnetlink           ########################################### [100%]

 

执行rpm -ivh libnfnetlink-devel-1.0.0-1.el6.x86_64.rpm命令安装libnfnetlink-devel-1.0.0-1.el6.x86_64.rpm包,具体如下:

 

[root@iZ256w2hluuZ other-packages]# rpm -ivh libnfnetlink-devel-1.0.0-1.el6.x86_64.rpm

Preparing...                ########################################### [100%]

   1:libnfnetlink-devel     ########################################### [100%]

 

 

 

安装完成以后,重新执行configure命令

 

[root@iZ256w2hluuZ keepalived-1.3.5]# ./configure --prefix=/usr/local/keepalived

 

 

 

3. 编译keepalived不会出现上述警告和其他错误,执行make && make install命令进行安装:

 

[root@iZ256w2hluuZ keepalived-1.3.5]# make && make install

 

至此Keepalived编译并安装结束,在下一篇文章中会详解介绍Nginx搭配Keepalived的详细配置和使用方法,欢迎大家收藏本站素文宅博客。

 

启动命令:

 

[root@iZ256w2hluuZ keepalived-1.3.5]# ./sbin/keepalived -f /usr/local/keepalived/etc/keepalived.conf

 

 

 

制作快捷启动,在源文件的目录./keepalived-1.3.5/keepalived/etc/init.d下有两个个快捷启动文件和生成/usr/local/keepalived目录下一个配置文件需要复制,具体执行如下命令:

 

[root@iZ256w2hluuZ keepalived-1.3.5]#  cp ./keepalived/etc/init.d/keepalived /etc/init.d/

[root@iZ256w2hluuZ keepalived-1.3.5]# mkdir /etc/keepalived

[root@iZ256w2hluuZ keepalived-1.3.5]#  cp  /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/

[root@iZ256w2hluuZ keepalived-1.3.5]#  cp ./keepalived/etc/sysconfig/keepalived /etc/sysconfig/keepalived

[root@yoodb /]# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/

 

这样就可以执行service keepalived [start | stop | reload | restart ]命令。

 

启动keepalived服务报错

 

[html] view plain copy

 

1.  # service keepalived start  

 

错误如下

 

Job for keepalived.service failed because a configured resource limit was exceeded. See "systemctl status keepalived.service" and "journalctl -xe" for details.

 

Job for keepalived.service failed because a configured resource limit was exceeded. See "systemctl status keepalived.service" and "journalctl -xe" for

 

 details.

 


查看错误

 

1.  # systemctl status keepalived.service  

 

我们可以看到日志,是写日志出了问题

 

1.  [root@zk-02 sbin]# systemctl status keepalived.service  

2.  ● keepalived.service - LVS and VRRP High Availability Monitor  

3.     Loaded: loaded (/usr/lib/systemd/system/keepalived.service; enabled; vendor preset: disabled)  

4.     Active: failed (Result: resources) since Fri 2017-08-04 15:32:31 CST; 4min 59s ago  

5.    Process: 16764 ExecStart=/usr/local/program/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS (code=exitedstatus=0/SUCCESS)  

6.    

7.  Aug 04 15:32:25 zk-02 Keepalived_healthcheckers[16768]: Activating healthchecker for service [10.10.10.2]:1358  

8.  Aug 04 15:32:25 zk-02 Keepalived_healthcheckers[16768]: Activating healthchecker for service [10.10.10.3]:1358  

9.  Aug 04 15:32:25 zk-02 Keepalived_healthcheckers[16768]: Activating healthchecker for service [10.10.10.3]:1358  

10.Aug 04 15:32:25 zk-02 Keepalived_vrrp[16769]: (VI_1): No VIP specified; at least one is required  

11.Aug 04 15:32:26 zk-02 Keepalived[16766]: Keepalived_vrrp exited with permanent error CONFIG. Terminating  

12.Aug 04 15:32:26 zk-02 Keepalived[16766]: Stopping  

13.Aug 04 15:32:31 zk-02 systemd[1]: keepalived.service never wrote its PID file. Failing.    ##写日志出了问题  

14.Aug 04 15:32:31 zk-02 systemd[1]: Failed to start LVS and VRRP High Availability Monitor.  

15.Aug 04 15:32:31 zk-02 systemd[1]: Unit keepalived.service entered failed state.  

16.Aug 04 15:32:31 zk-02 systemd[1]: keepalived.service failed.  

17.[root@zk-02 sbin]# vi /var/run/keepalived.pid  

18.[root@zk-02 sbin]# vim /lib/systemd/system/keepalived.service  

19.[root@zk-02 sbin]# vim /lib/systemd/system/keepalived.service  

 

 

 

查看keepalived.service

 

[html] view plain copy

 

1.  # vi /lib/systemd/system/keepalived.service  

 

内容如下

 

[html] view plain copy

 

1.  [Unit]  

2.  Description=LVS and VRRP High Availability Monitor  

3.  After=syslog.target network-online.target  

4.    

5.  [Service]  

6.  Type=forking  

7.  PIDFile=/usr/local/program/keepalived/var/run/keepalived.pid      ##发现这个目录不存在,无法写入keepalived.pid  

8.  KillMode=process  

9.  EnvironmentFile=-/usr/local/program/keepalived/etc/sysconfig/keepalived  

10.ExecStart=/usr/local/program/keepalived/sbin/keepalived $KEEPALIVED_OPTIONS  

11.ExecReload=/bin/kill -HUP $MAINPID  

12.  

13.[Install]  

14.WantedBy=multi-user.target  

 


问题见

 

[html] view plain copy

 

1.  PIDFile=/usr/local/program/keepalived/var/run/keepalived.pid      ##发现这个目录不存在,无法写入keepalived.pid  

 

修改成

 

[html] view plain copy

 

1.  PIDFile=/var/run/keepalived.pid    

 

 

 

运行命令

 

[html] view plain copy

 

1.  # systemctl daemon-reload    #重新载入 systemd,扫描新的或有变动的单元  

 

在运行就Ok

 

[html] view plain copy

 

1.  service keepalived start  

2.  Starting keepalived (via systemctl):                       [  OK  ]  

 

 

 

分享到:
评论

相关推荐

    centos 安装keepalived1.3.5并配置nginx

    "CentOS 安装 Keepalived 1.3.5 并配置 Nginx" Keepalived 是一个免费开源的、用 C 编写的类似于 Layer 3, 4 & 7 交换机制软件,具备我们平时说的第 3 层、第 4 层和第 7 层交换机的功能。主要提供负载均衡(Load ...

    keepalived-1.3.5-8离线rpm包

    因为没有可行的二进制安装方式,而且rpm找起来比较费劲,所以直接给大家分享了 已在64位的centos7.3-1611 / centos-7.5-1804系统验证可行。 解压命令: tar -xvf xxxxxx.tar 安装命令:yum install -y ./*.rpm

    CentOS7 nginx+keepalived 离线安装包

    本文将详细介绍如何在CentOS7系统上,离线环境下安装nginx和keepalived,以实现主从热备负载均衡反向代理功能。 首先,我们关注的两个主要组件是`nginx`和`keepalived`。`nginx`是一款高性能的HTTP和反向代理服务器...

    keepalived.zip

    keepalived-1.3.5压缩包,可直接在centos下解压、编译后可直接使用,含回环IP设置脚本, 配套keepalived搭建教程:https://www.cnblogs.com/flying607/p/8882617.html

    CentOS-6.6-x86_64 nginx 依赖 pcre-devel zlib-devel openssl-devel rpm

    标题提到的"CentOS-6.6-x86_64 nginx 依赖 pcre-devel zlib-devel openssl-devel rpm",这暗示我们需要关注几个关键组件: 1. **Nginx**: Nginx以其事件驱动的架构而著名,能够处理高并发的HTTP请求,它的工作模式...

    CentOS系统安装配置Nginx+keepalived实现负载均衡

    CentOS系统安装配置Nginx+keepalived实现负载均衡 本文将详细介绍CentOS系统安装配置Nginx+keepalived实现负载均衡的步骤和配置过程。通过本文,读者将了解如何使用Nginx和keepalived来实现高可靠性的负载均衡架构...

    CentOS6.5安装keepalived-1.2.7.tar.gz

    在本教程中,我们将探讨如何在 CentOS6.5 和 Red Hat Enterprise Linux 6.5(RHEL6.5)环境下,通过源码编译方式安装 Keepalived 的 1.2.7 版本。 首先,了解 Keepalived 的功能至关重要。Keepalived 是 LVS(Linux...

    keepalived 离线 rpm 安装包

    【标题】"keepalived 离线 RPM 安装包"涉及的主要知识点是Linux系统中的服务高可用性工具...安装和配置过程中,用户需要理解Keepalived的工作原理、配置选项以及如何结合Nginx进行健康检查,以确保服务的稳定和可靠。

    Centos7镜像-百度网盘下载链接

    CentOS-7.2-x86_64-DVD-1511 CentOS-7.3-x86_64-DVD-1611 CentOS-7.4-x86_64-DVD-1708 CentOS-7.5-x86_64-DVD-1804 CentOS-7.6-aarch64-Everything-1810 CentOS-7.6-x86_64-DVD-1810 CentOS-7.7-x86_64-DVD-1908 ...

    CentOS-7-x86_64-DVD-2003镜像文件

    # CentOS-7-x86_64-DVD-1810.iso CentOS 7.6 DVD 版 4G http://mirrors.163.com/centos/7.6.1810/isos/x86_64/CentOS-7-x86_64-DVD-1810.iso # CentOS-7-x86_64-Everything-1810.iso CentOS 7.6 Everything版 10G ...

    CentOS-7-x86_64-Everything-1611的版本安装nginx.rar

    在本主题中,我们将深入探讨如何在CentOS 7操作系统上使用"CentOS-7-x86_64-Everything-1611"版本安装Nginx Web服务器。Nginx是一个流行的开源Web服务器,以其高效能、稳定性和低内存占用而闻名,常用于处理静态内容...

    keepalived-2.2.2-1.el8.x86_64.rpm

    keepalived 最新版编译打包20210619 keepalived-2.2.2-1.el8.x86_64 包含SSL与IPV6支持 操作系统CENTOS8.4 Keepalive服务的两大用途:healthcheck和failover ha failover功能:实现LB Master主机和Backup主机之间...

    Linux-Centos6.9-keepalived-1.4.5-离线安装资源包

    keepalived-1.4.5.tar.gz execserver.sh nginx_check.sh rhel6.9依赖rpm 含: rpm -ivh zlib-1.2.3-29.el6.x86_64.rpm rpm -ivh zlib-devel-1.2.3-29.el6.x86_64.rpm rpm -ivh keyutils-libs-devel-1.4-5.el6.x86_64...

    CentOS7.3.1611下,离线安装keepalived1.4.4+nginx1.14.0所需要的一些RPM包

    在CentOS7.3.1611操作系统中,离线安装keepalived 1.4.4和nginx 1.14.0是一项技术挑战,因为通常我们依赖于网络来下载必要的RPM包。然而,对于那些在没有互联网连接或者网络受限的环境中工作的IT专业人员来说,离线...

    zabbix5安装文档-centos7.7-mysql-nginx

    zabbix5安装文档-centos7.8-mysql5.7-nginx;zabbix5安装文档-centos7.8-mysql5.7-nginx

    Linux下tcping安装包及教程

    在提供的资料中,有一个名为"tcping-1.3.5-for-linux.tar.gz"的压缩包,这包含了适用于Linux系统的tcping源代码。该文件是用gzip压缩的tar归档文件,我们可以使用以下命令解压: ```bash tar -zxvf tcping-1.3.5-...

    CentOS7.6.1810下,安装keepalived1.4.2+nginx1.14.2离线安装所需要的系统RPM包

    安装完成后,需要对Nginx和Keepalived进行配置。配置文件通常位于`/etc/nginx/nginx.conf`和`/etc/keepalived/keepalived.conf`。根据实际需求修改配置后,启动服务: ``` systemctl start nginx systemctl ...

    Centos7.6镜像文件:CentOS-7-x86-64-DVD-1810.iso

    "CentOS-7-x86_64-DVD-1810.iso" 指的是该文件是为64位x86系统准备的CentOS 7.6版本,文件名中的“DVD”表明这是一个完整的安装介质,包含全部安装所需的数据。而“1810”很可能是文件的版本或者发行号,用来区分...

    CentOS-7.6-x86_64-DVD-1810.iso.txt

    CentOS-7.6-x86_64-DVD-1810.isoCentOS-7.6-x86_64-DVD-1810.iso

    centos源码安装nginx-1.20.2+nginx负载均衡

    centos源码安装nginx-1.20.2+nginx负载均衡

Global site tag (gtag.js) - Google Analytics