码迷,mamicode.com
首页 > Web开发 > 详细

Keepalived + nginx 实现高可用web负载均衡 -- 配置文件

时间:2016-07-18 01:57:27      阅读:499      评论:0      收藏:0      [点我收藏+]

标签:

keepalived-master配置:

技术分享
! Configuration File for keepalived
global_defs {
    ## keepalived 自带的邮件提醒需要开启 sendmail 服务。建议用独立的监控或第三方 SMTP
    router_id debiao02  ## 标识本节点的字条串,通常为 hostname
}
## keepalived 会定时执行脚本并对脚本执行的结果进行分析,动态调整 vrrp_instance 的优先级。如果
## 脚本执行结果为 0, 并且 weight 配置的值大于 0, 则优先级相应的增加。 如果脚本执行结果非 0,
## 并且weight配置的值小于 0,则优先级相应的减少。其他情况,维持原本配置的优先级,即配置文件中
## priority对应的值。
vrrp_script chk_nginx {
    script "/etc/keepalived/nginx_check.sh"  ## 检测 nginx 状态的脚本路径
    interval 2  ## 检测时间间隔
    weight -20  ## 如果条件成立,权重-20
}
## 定义虚拟路由,VI_1 为虚拟路由的标示符,自己定义名称
vrrp_instance VI_1 {
    state MASTER  ## 主节点为 MASTER,对应的备份节点为 BACKUP
    interface eth0 ## 绑定虚拟 IP 的网络接口,与本机 IP 地址所在的网络接口相同,我的是 eth1
    virtual_router_id 172  ## 虚拟路由的 ID 号, 两个节点设置必须一样, 可选 IP 最后一段使用, 
    ## 相同的 VRID 为一个组,他将决定多播的 MAC 地址
    mcast_src_ip 192.168.1.172  ## 本机 IP 地址
    priority 100  ## 节点优先级,值范围 0-254,MASTER 要比 BACKUP 高
    nopreempt ## 优先级高的设置 nopreempt 解决异常恢复后再次抢占的问题
    advert_int 1  ## 组播信息发送间隔,两个节点设置必须一样,默认 1s
    ## 设置验证信息,两个节点必须一致
    authentication {
        auth_type PASS
        auth_pass 1111 ## 真实生产,按需求对应该过来
    }
    ## 将 track_script 块加入 instance 配置块
    track_script {
        chk_nginx ## 执行 Nginx 监控的服务
    }
    ## 虚拟 IP 池, 两个节点设置必须一样
    virtual_ipaddress {
        192.168.1.007  ## 虚拟 ip,可以定义多个
    }
}
View Code

keepalived-backup配置:

技术分享
! Configuration File for keepalived
global_defs {
    router_id debiao04
}
vrrp_script chk_nginx {
    script "/etc/keepalived/nginx_check.sh"
    interval 2
    weight -20
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 172
    mcast_src_ip 192.168.1.174
    priority 90
    advert_int 1
    authentication {
        uth_type PASS
        auth_pass 1111
    }
    track_script {
        chk_nginx
    }
    virtual_ipaddress {
        192.168.1.007
    }
}
View Code

nginx_check.sh脚本:

技术分享
#!/bin/bash
A=`ps -C nginx –no-header |wc -l`
if [ $A -eq 0 ];then
    /usr/local/nginx/sbin/nginx
    sleep 2
    if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
        killall keepalived
    fi
fi
View Code

已测试配置正常,示例:

技术分享
Xshell 5 (Build 0991)
Copyright (c) 2002-2016 NetSarang Computer, Inc. All rights reserved.

Type `help to learn how to use Xshell prompt.
[c:\~]$ 

Connecting to 192.168.1.172:22...
Connection established.
To escape to local shell, press Ctrl+Alt+].

Last login: Sun Jul 17 13:49:47 2016 from 192.168.1.100
[root@localhost ~]# cd /usr/local/src
[root@localhost src]# tar -zxvf keepalived-1.2.18.tar.gz
keepalived-1.2.18/
keepalived-1.2.18/keepalived.spec.in
keepalived-1.2.18/Makefile.in
keepalived-1.2.18/genhash/
keepalived-1.2.18/genhash/Makefile.in
keepalived-1.2.18/genhash/INSTALL
keepalived-1.2.18/genhash/ChangeLog
keepalived-1.2.18/genhash/VERSION
keepalived-1.2.18/genhash/COPYING
keepalived-1.2.18/genhash/include/
keepalived-1.2.18/genhash/include/ssl.h
keepalived-1.2.18/genhash/include/http.h
keepalived-1.2.18/genhash/include/sock.h
keepalived-1.2.18/genhash/include/layer4.h
keepalived-1.2.18/genhash/include/main.h
keepalived-1.2.18/genhash/include/hash.h
keepalived-1.2.18/genhash/http.c
keepalived-1.2.18/genhash/main.c
keepalived-1.2.18/genhash/README
keepalived-1.2.18/genhash/layer4.c
keepalived-1.2.18/genhash/AUTHOR
keepalived-1.2.18/genhash/sock.c
keepalived-1.2.18/genhash/ssl.c
keepalived-1.2.18/INSTALL
keepalived-1.2.18/ChangeLog
keepalived-1.2.18/bin/
keepalived-1.2.18/bin/.gitignore
keepalived-1.2.18/VERSION
keepalived-1.2.18/COPYING
keepalived-1.2.18/CONTRIBUTORS
keepalived-1.2.18/keepalived/
keepalived-1.2.18/keepalived/Makefile.in
keepalived-1.2.18/keepalived/libipvs-2.4/
keepalived-1.2.18/keepalived/libipvs-2.4/Makefile.in
keepalived-1.2.18/keepalived/libipvs-2.4/libipvs.h
keepalived-1.2.18/keepalived/libipvs-2.4/libipvs.c
keepalived-1.2.18/keepalived/etc/
keepalived-1.2.18/keepalived/etc/init.d/
keepalived-1.2.18/keepalived/etc/init.d/keepalived.init
keepalived-1.2.18/keepalived/etc/init.d/keepalived.sysconfig
keepalived-1.2.18/keepalived/etc/init.d/keepalived.rh.init
keepalived-1.2.18/keepalived/etc/init.d/keepalived.suse.init
keepalived-1.2.18/keepalived/etc/keepalived/
keepalived-1.2.18/keepalived/etc/keepalived/keepalived.conf
keepalived-1.2.18/keepalived/libipvs-2.6/
keepalived-1.2.18/keepalived/libipvs-2.6/Makefile.in
keepalived-1.2.18/keepalived/libipvs-2.6/ip_vs.h
keepalived-1.2.18/keepalived/libipvs-2.6/libipvs.h
keepalived-1.2.18/keepalived/libipvs-2.6/libipvs.c
keepalived-1.2.18/keepalived/libipvs-2.6/ip_vs_nl_policy.c
keepalived-1.2.18/keepalived/include/
keepalived-1.2.18/keepalived/include/vrrp_ipsecah.h
keepalived-1.2.18/keepalived/include/smtp.h
keepalived-1.2.18/keepalived/include/check_misc.h
keepalived-1.2.18/keepalived/include/check_smtp.h
keepalived-1.2.18/keepalived/include/vrrp_iproute.h
keepalived-1.2.18/keepalived/include/check_daemon.h
keepalived-1.2.18/keepalived/include/snmp.h
keepalived-1.2.18/keepalived/include/vrrp_if.h
keepalived-1.2.18/keepalived/include/layer4.h
keepalived-1.2.18/keepalived/include/vrrp_daemon.h
keepalived-1.2.18/keepalived/include/vrrp_print.h
keepalived-1.2.18/keepalived/include/check_snmp.h
keepalived-1.2.18/keepalived/include/pidfile.h
keepalived-1.2.18/keepalived/include/check_parser.h
keepalived-1.2.18/keepalived/include/vrrp_snmp.h
keepalived-1.2.18/keepalived/include/vrrp_ndisc.h
keepalived-1.2.18/keepalived/include/vrrp_index.h
keepalived-1.2.18/keepalived/include/check_tcp.h
keepalived-1.2.18/keepalived/include/vrrp_arp.h
keepalived-1.2.18/keepalived/include/ipwrapper.h
keepalived-1.2.18/keepalived/include/vrrp_notify.h
keepalived-1.2.18/keepalived/include/vrrp_sync.h
keepalived-1.2.18/keepalived/include/check_api.h
keepalived-1.2.18/keepalived/include/vrrp_scheduler.h
keepalived-1.2.18/keepalived/include/ipvswrapper.h
keepalived-1.2.18/keepalived/include/global_parser.h
keepalived-1.2.18/keepalived/include/main.h
keepalived-1.2.18/keepalived/include/check_data.h
keepalived-1.2.18/keepalived/include/check_ssl.h
keepalived-1.2.18/keepalived/include/vrrp_ipaddress.h
keepalived-1.2.18/keepalived/include/vrrp_parser.h
keepalived-1.2.18/keepalived/include/vrrp.h
keepalived-1.2.18/keepalived/include/vrrp_data.h
keepalived-1.2.18/keepalived/include/vrrp_track.h
keepalived-1.2.18/keepalived/include/global_data.h
keepalived-1.2.18/keepalived/include/check_http.h
keepalived-1.2.18/keepalived/include/daemon.h
keepalived-1.2.18/keepalived/include/vrrp_netlink.h
keepalived-1.2.18/keepalived/include/vrrp_vmac.h
keepalived-1.2.18/keepalived/vrrp/
keepalived-1.2.18/keepalived/vrrp/vrrp_ndisc.c
keepalived-1.2.18/keepalived/vrrp/vrrp_ipaddress.c
keepalived-1.2.18/keepalived/vrrp/vrrp_netlink.c
keepalived-1.2.18/keepalived/vrrp/vrrp_daemon.c
keepalived-1.2.18/keepalived/vrrp/vrrp_iproute.c
keepalived-1.2.18/keepalived/vrrp/vrrp_if.c
keepalived-1.2.18/keepalived/vrrp/Makefile.in
keepalived-1.2.18/keepalived/vrrp/vrrp_notify.c
keepalived-1.2.18/keepalived/vrrp/vrrp_sync.c
keepalived-1.2.18/keepalived/vrrp/vrrp_arp.c
keepalived-1.2.18/keepalived/vrrp/vrrp_ipsecah.c
keepalived-1.2.18/keepalived/vrrp/vrrp_index.c
keepalived-1.2.18/keepalived/vrrp/vrrp.c
keepalived-1.2.18/keepalived/vrrp/vrrp_data.c
keepalived-1.2.18/keepalived/vrrp/vrrp_snmp.c
keepalived-1.2.18/keepalived/vrrp/vrrp_track.c
keepalived-1.2.18/keepalived/vrrp/vrrp_parser.c
keepalived-1.2.18/keepalived/vrrp/vrrp_print.c
keepalived-1.2.18/keepalived/vrrp/vrrp_vmac.c
keepalived-1.2.18/keepalived/vrrp/vrrp_scheduler.c
keepalived-1.2.18/keepalived/core/
keepalived-1.2.18/keepalived/core/pidfile.c
keepalived-1.2.18/keepalived/core/smtp.c
keepalived-1.2.18/keepalived/core/global_data.c
keepalived-1.2.18/keepalived/core/Makefile.in
keepalived-1.2.18/keepalived/core/main.c
keepalived-1.2.18/keepalived/core/snmp.c
keepalived-1.2.18/keepalived/core/daemon.c
keepalived-1.2.18/keepalived/core/layer4.c
keepalived-1.2.18/keepalived/core/global_parser.c
keepalived-1.2.18/keepalived/check/
keepalived-1.2.18/keepalived/check/check_snmp.c
keepalived-1.2.18/keepalived/check/Makefile.in
keepalived-1.2.18/keepalived/check/check_ssl.c
keepalived-1.2.18/keepalived/check/check_daemon.c
keepalived-1.2.18/keepalived/check/check_data.c
keepalived-1.2.18/keepalived/check/check_tcp.c
keepalived-1.2.18/keepalived/check/check_parser.c
keepalived-1.2.18/keepalived/check/ipwrapper.c
keepalived-1.2.18/keepalived/check/check_misc.c
keepalived-1.2.18/keepalived/check/check_api.c
keepalived-1.2.18/keepalived/check/check_http.c
keepalived-1.2.18/keepalived/check/check_smtp.c
keepalived-1.2.18/keepalived/check/ipvswrapper.c
keepalived-1.2.18/README
keepalived-1.2.18/configure
keepalived-1.2.18/configure.in
keepalived-1.2.18/AUTHOR
keepalived-1.2.18/doc/
keepalived-1.2.18/doc/NOTE_vrrp_vmac.txt
keepalived-1.2.18/doc/VRRP-MIB
keepalived-1.2.18/doc/keepalived.conf.SYNOPSIS
keepalived-1.2.18/doc/man/
keepalived-1.2.18/doc/man/man5/
keepalived-1.2.18/doc/man/man5/keepalived.conf.5
keepalived-1.2.18/doc/man/man8/
keepalived-1.2.18/doc/man/man8/keepalived.8
keepalived-1.2.18/doc/man/man1/
keepalived-1.2.18/doc/man/man1/genhash.1
keepalived-1.2.18/doc/KEEPALIVED-MIB
keepalived-1.2.18/doc/samples/
keepalived-1.2.18/doc/samples/keepalived.conf.SSL_GET
keepalived-1.2.18/doc/samples/keepalived.conf.IPv6
keepalived-1.2.18/doc/samples/keepalived.conf.status_code
keepalived-1.2.18/doc/samples/keepalived.conf.vrrp.static_ipaddress
keepalived-1.2.18/doc/samples/keepalived.conf.vrrp.localcheck
keepalived-1.2.18/doc/samples/client.pem
keepalived-1.2.18/doc/samples/keepalived.conf.virtual_server_group
keepalived-1.2.18/doc/samples/keepalived.conf.quorum
keepalived-1.2.18/doc/samples/keepalived.conf.vrrp.sync
keepalived-1.2.18/doc/samples/root.pem
keepalived-1.2.18/doc/samples/keepalived.conf.track_interface
keepalived-1.2.18/doc/samples/keepalived.conf.vrrp.scripts
keepalived-1.2.18/doc/samples/keepalived.conf.misc_check
keepalived-1.2.18/doc/samples/keepalived.conf.sample
keepalived-1.2.18/doc/samples/keepalived.conf.vrrp.lvs_syncd
keepalived-1.2.18/doc/samples/keepalived.conf.virtualhost
keepalived-1.2.18/doc/samples/keepalived.conf.vrrp.routes
keepalived-1.2.18/doc/samples/sample.misccheck.smbcheck.sh
keepalived-1.2.18/doc/samples/keepalived.conf.fwmark
keepalived-1.2.18/doc/samples/keepalived.conf.misc_check_arg
keepalived-1.2.18/doc/samples/keepalived.conf.inhibit
keepalived-1.2.18/doc/samples/dh1024.pem
keepalived-1.2.18/doc/samples/keepalived.conf.vrrp
keepalived-1.2.18/doc/samples/keepalived.conf.SMTP_CHECK
keepalived-1.2.18/doc/samples/keepalived.conf.HTTP_GET.port
keepalived-1.2.18/install-sh
keepalived-1.2.18/lib/
keepalived-1.2.18/lib/utils.h
keepalived-1.2.18/lib/notify.c
keepalived-1.2.18/lib/bitops.h
keepalived-1.2.18/lib/Makefile.in
keepalived-1.2.18/lib/memory.h
keepalived-1.2.18/lib/timer.h
keepalived-1.2.18/lib/list.h
keepalived-1.2.18/lib/logger.c
keepalived-1.2.18/lib/list.c
keepalived-1.2.18/lib/html.c
keepalived-1.2.18/lib/html.h
keepalived-1.2.18/lib/utils.c
keepalived-1.2.18/lib/config.h.in
keepalived-1.2.18/lib/timer.c
keepalived-1.2.18/lib/parser.c
keepalived-1.2.18/lib/vector.h
keepalived-1.2.18/lib/notify.h
keepalived-1.2.18/lib/scheduler.c
keepalived-1.2.18/lib/signals.h
keepalived-1.2.18/lib/memory.c
keepalived-1.2.18/lib/parser.h
keepalived-1.2.18/lib/logger.h
keepalived-1.2.18/lib/vector.c
keepalived-1.2.18/lib/scheduler.h
keepalived-1.2.18/lib/signals.c
keepalived-1.2.18/TODO
[root@localhost src]# cd keepalived-1.2.18
[root@localhost keepalived-1.2.18]# ./configure --prefix=/usr/local/keepalived
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for a BSD-compatible install... /usr/bin/install -c
checking for strip... strip
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking syslog.h usability... yes
checking syslog.h presence... yes
checking for syslog.h... yes
checking for unistd.h... (cached) yes
checking sys/ioctl.h usability... yes
checking sys/ioctl.h presence... yes
checking for sys/ioctl.h... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking openssl/ssl.h usability... yes
checking openssl/ssl.h presence... yes
checking for openssl/ssl.h... yes
checking openssl/md5.h usability... yes
checking openssl/md5.h presence... yes
checking for openssl/md5.h... yes
checking openssl/err.h usability... yes
checking openssl/err.h presence... yes
checking for openssl/err.h... yes
checking whether ETHERTYPE_IPV6 is declared... yes
checking for crypt in -lcrypt... yes
checking for MD5_Init in -lcrypto... yes
checking for SSL_CTX_new in -lssl... yes
checking for nl_socket_alloc in -lnl-3... no
checking for nl_socket_modify_cb in -lnl... no
configure: WARNING: keepalived will be built without libnl support.
checking for kernel version... 2.6.32
checking for IPVS syncd support... yes
checking for kernel macvlan support... yes
checking whether SO_MARK is declared... yes
checking for an ANSI C-conforming const... yes
checking for pid_t... yes
checking whether time.h and sys/time.h may both be included... yes
checking whether gcc needs -traditional... no
checking for working memcmp... yes
checking return type of signal handlers... void
checking for gettimeofday... yes
checking for select... yes
checking for socket... yes
checking for strerror... yes
checking for strtol... yes
checking for uname... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating genhash/Makefile
config.status: creating keepalived/core/Makefile
config.status: creating lib/config.h
config.status: creating keepalived.spec
config.status: creating keepalived/Makefile
config.status: creating lib/Makefile
config.status: creating keepalived/vrrp/Makefile
config.status: creating keepalived/check/Makefile
config.status: creating keepalived/libipvs-2.6/Makefile

Keepalived configuration
------------------------
Keepalived version       : 1.2.18
Compiler                 : gcc
Compiler flags           : -g -O2
Extra Lib                : -lssl -lcrypto -lcrypt 
Use IPVS Framework       : Yes
IPVS sync daemon support : Yes
IPVS use libnl           : No
fwmark socket support    : Yes
Use VRRP Framework       : Yes
Use VRRP VMAC            : Yes
SNMP support             : No
SHA1 support             : No
Use Debug flags          : No
[root@localhost keepalived-1.2.18]# make && make install
make -C lib || exit 1;
make[1]: Entering directory `/usr/local/src/keepalived-1.2.18/libgcc -I. -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_WITHOUT_SNMP_ -c memory.c
gcc -I. -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_WITHOUT_SNMP_ -c utils.c
gcc -I. -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_WITHOUT_SNMP_ -c notify.c
gcc -I. -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_WITHOUT_SNMP_ -c timer.c
gcc -I. -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_WITHOUT_SNMP_ -c scheduler.c
gcc -I. -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_WITHOUT_SNMP_ -c vector.c
gcc -I. -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_WITHOUT_SNMP_ -c list.c
gcc -I. -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_WITHOUT_SNMP_ -c html.c
gcc -I. -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_WITHOUT_SNMP_ -c parser.c
gcc -I. -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_WITHOUT_SNMP_ -c signals.c
gcc -I. -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_WITHOUT_SNMP_ -c logger.c
make[1]: Leaving directory `/usr/local/src/keepalived-1.2.18/libmake -C keepalived
make[1]: Entering directory `/usr/local/src/keepalived-1.2.18/keepalivedmake[2]: Entering directory `/usr/local/src/keepalived-1.2.18/keepalived/coregcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c main.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c daemon.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c pidfile.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c layer4.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c smtp.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c global_data.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c global_parser.c
make[2]: Leaving directory `/usr/local/src/keepalived-1.2.18/keepalived/coremake[2]: Entering directory `/usr/local/src/keepalived-1.2.18/keepalived/checkgcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c check_daemon.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c check_data.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c check_parser.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c check_api.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c check_tcp.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c check_http.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c check_ssl.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c check_smtp.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c check_misc.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c ipwrapper.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_WITH_VRRP_ -D_WITHOUT_SNMP_ -D_WITH_SO_MARK_  -c ipvswrapper.c
make[2]: Leaving directory `/usr/local/src/keepalived-1.2.18/keepalived/checkmake[2]: Entering directory `/usr/local/src/keepalived-1.2.18/keepalived/vrrpgcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_daemon.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_print.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_data.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_parser.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_notify.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_scheduler.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_sync.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_index.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_netlink.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_arp.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_if.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_track.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_ipaddress.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_iproute.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_ipsecah.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_ndisc.c
gcc -I../include -I../../lib -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes -D_KRNL_2_6_ -D_WITH_LVS_ -D_HAVE_IPVS_SYNCD_ -D_HAVE_VRRP_VMAC_ -D_WITHOUT_SNMP_  -c vrrp_vmac.c
make[2]: Leaving directory `/usr/local/src/keepalived-1.2.18/keepalived/vrrpmake[2]: Entering directory `/usr/local/src/keepalived-1.2.18/keepalived/libipvs-2.6gcc -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -DLIBIPVS_DONTUSE_NL -Wall -Wunused -c -o libipvs.o libipvs.c
gcc -g -O2  -I/usr/src/linux/include -I/usr/src/linux/include -DLIBIPVS_DONTUSE_NL -Wall -Wunused -c -o ip_vs_nl_policy.o ip_vs_nl_policy.c
ar rv libipvs.a libipvs.o ip_vs_nl_policy.o
ar: creating libipvs.a
a - libipvs.o
a - ip_vs_nl_policy.o
rm libipvs.o ip_vs_nl_policy.o
make[2]: Leaving directory `/usr/local/src/keepalived-1.2.18/keepalived/libipvs-2.6Building ../bin/keepalived
strip ../bin/keepalived

Make complete
make[1]: Leaving directory `/usr/local/src/keepalived-1.2.18/keepalivedmake -C genhash
make[1]: Entering directory `/usr/local/src/keepalived-1.2.18/genhashgcc -I../lib -g -O2 -D_WITH_SO_MARK_  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes   -c -o main.o main.c
gcc -I../lib -g -O2 -D_WITH_SO_MARK_  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes   -c -o sock.o sock.c
gcc -I../lib -g -O2 -D_WITH_SO_MARK_  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes   -c -o layer4.o layer4.c
gcc -I../lib -g -O2 -D_WITH_SO_MARK_  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes   -c -o http.o http.c
gcc -I../lib -g -O2 -D_WITH_SO_MARK_  -I/usr/src/linux/include -I/usr/src/linux/include -Wall -Wunused -Wstrict-prototypes   -c -o ssl.o ssl.c
Building ../bin/genhash
strip ../bin/genhash

Make complete
make[1]: Leaving directory `/usr/local/src/keepalived-1.2.18/genhash
Make complete
make -C keepalived install
make[1]: Entering directory `/usr/local/src/keepalived-1.2.18/keepalivedinstall -d /usr/local/keepalived/sbin
install -m 700 ../bin/keepalived /usr/local/keepalived/sbin/
install -d /usr/local/keepalived/etc/rc.d/init.d
install -m 755 etc/init.d/keepalived.init /usr/local/keepalived/etc/rc.d/init.d/keepalived
install -d /usr/local/keepalived/etc/sysconfig
install -m 644 etc/init.d/keepalived.sysconfig /usr/local/keepalived/etc/sysconfig/keepalived
install -d /usr/local/keepalived/etc/keepalived/samples
install -m 644 etc/keepalived/keepalived.conf /usr/local/keepalived/etc/keepalived/
install -m 644 ../doc/samples/* /usr/local/keepalived/etc/keepalived/samples/
install -d /usr/local/keepalived/share/man/man5
install -d /usr/local/keepalived/share/man/man8
install -m 644 ../doc/man/man5/keepalived.conf.5 /usr/local/keepalived/share/man/man5
install -m 644 ../doc/man/man8/keepalived.8 /usr/local/keepalived/share/man/man8
make[1]: Leaving directory `/usr/local/src/keepalived-1.2.18/keepalived‘
make -C genhash install
make[1]: Entering directory `/usr/local/src/keepalived-1.2.18/genhash‘
install -d /usr/local/keepalived/bin
install -m 755 ../bin/genhash /usr/local/keepalived/bin/
install -d /usr/local/keepalived/share/man/man1
install -m 644 ../doc/man/man1/genhash.1 /usr/local/keepalived/share/man/man1
make[1]: Leaving directory `/usr/local/src/keepalived-1.2.18/genhash‘
mkdir -p /usr/share/snmp/mibs/
cp -f doc/VRRP-MIB /usr/share/snmp/mibs/
cp -f doc/KEEPALIVED-MIB /usr/share/snmp/mibs/
[root@localhost keepalived-1.2.18]# mkdir /etc/keepalived
[root@localhost keepalived-1.2.18]# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
[root@localhost keepalived-1.2.18]# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
[root@localhost keepalived-1.2.18]# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
[root@localhost keepalived-1.2.18]# ln -s /usr/local/sbin/keepalived /usr/sbin/
[root@localhost keepalived-1.2.18]# ln -s /usr/local/keepalived/sbin/keepalived /sbin/
[root@localhost keepalived-1.2.18]# chkconfig keepalived on
[root@localhost keepalived-1.2.18]# vi /usr/local/nginx/conf/nginx.conf
[root@localhost keepalived-1.2.18]# vi /etc/keepalived/keepalived.conf
[root@localhost keepalived-1.2.18]# vi /etc/keepalived/keepalived.conf
[root@localhost keepalived-1.2.18]# vi /etc/keepalived/nginx_check.sh
[root@localhost keepalived-1.2.18]# chmod +x /etc/keepalived/nginx_check.sh
[root@localhost keepalived-1.2.18]# service keepalived start
Starting keepalived:                                       [  OK  ]
[root@localhost keepalived-1.2.18]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:04:e2:ec brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.172/24 brd 192.168.1.255 scope global eth0
    inet6 fe80::20c:29ff:fe04:e2ec/64 scope link 
       valid_lft forever preferred_lft forever
3: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN 
    link/ether 5a:31:55:e5:67:af brd ff:ff:ff:ff:ff:ff
[root@localhost keepalived-1.2.18]# vi /etc/keepalived/keepalived.conf
[root@localhost keepalived-1.2.18]# service keepalived stop
Stopping keepalived:                                       [  OK  ]
[root@localhost keepalived-1.2.18]# service keepalived start
Starting keepalived:                                       [  OK  ]
[root@localhost keepalived-1.2.18]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:04:e2:ec brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.172/24 brd 192.168.1.255 scope global eth0
    inet 192.168.1.170/32 scope global eth0
    inet6 fe80::20c:29ff:fe04:e2ec/64 scope link 
       valid_lft forever preferred_lft forever
3: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN 
    link/ether 5a:31:55:e5:67:af brd ff:ff:ff:ff:ff:ff
[root@localhost keepalived-1.2.18]# service keepalived stop
Stopping keepalived:                                       [  OK  ]
[root@localhost keepalived-1.2.18]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:04:e2:ec brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.172/24 brd 192.168.1.255 scope global eth0
    inet6 fe80::20c:29ff:fe04:e2ec/64 scope link 
       valid_lft forever preferred_lft forever
3: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN 
    link/ether 5a:31:55:e5:67:af brd ff:ff:ff:ff:ff:ff
[root@localhost keepalived-1.2.18]# service keepalived start
Starting keepalived:                                       [  OK  ]
[root@localhost keepalived-1.2.18]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:04:e2:ec brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.172/24 brd 192.168.1.255 scope global eth0
    inet 192.168.1.170/32 scope global eth0
    inet6 fe80::20c:29ff:fe04:e2ec/64 scope link 
       valid_lft forever preferred_lft forever
3: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN 
    link/ether 5a:31:55:e5:67:af brd ff:ff:ff:ff:ff:ff
[root@localhost keepalived-1.2.18]# service keepalived stop
Stopping keepalived:                                       [  OK  ]
[root@localhost keepalived-1.2.18]# service keepalived start
Starting keepalived:                                       [  OK  ]
[root@localhost keepalived-1.2.18]# service keepalived start
View Code

 

Keepalived + nginx 实现高可用web负载均衡 -- 配置文件

标签:

原文地址:http://www.cnblogs.com/debiao/p/5679643.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!