keepalive haproxy
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Keepalived haproxy高可用负载均衡
一所要软件
keepalived-1.1.15.tar.gz haproxy-1.4.15.tar.gz
二安装软件
1 安装keepalive
Tar zxvf keepalived-1.1.15.tar.gz
编译安装LVS_mastr && LVS_backup
# ./configure
Keepalived configuration
------------------------
Keepalived version : 1.1.15
Compiler : gcc
Compiler flags : -g -O2
Extra Lib : -lpopt -lssl -lcrypto
Use IPVS Framework : Yes
IPVS sync daemon support : Yes
Use VRRP Framework : Yes
Use LinkWatch : No
Use Debug flags : No
如果编译时出现以上内容就证明可以下一步编译安装
# make && make install
2配置keepalived
LVS_mastr && LVS_backup
# mkdir /etc/keepalived
# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/ # cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
# cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/
# ln -s /usr/local/sbin/keepalived /usr/sbin/keepalived
# vi /etc/keepalived/keepalived.conf
global_defs {
notification_email {
报警邮箱地址
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL_1
}
vrrp_sync_group GLVS {
group {
LVS_1
}
}
vrrp_instance LVS_1 {
state MASTER
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 51
mcast_src_ip 192.168.0.148
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
# track_script {
# chk_http_port
#}
virtual_ipaddress {
192.168.0.99
}
track_interface { 检测网卡
eth0
}
garp_master_delay 10 切换为主服务器时间为妙
}
一所要软件 (1)
二安装软件 (1)
1 安装keepalive (1)
2配置keepalived (1)
3 安装haproxy (3)
三 haproxy配置 (3)
3 安装haproxy
Tar zxcvf haproxy-1.4.15.tar.gz
make TARGET=linux26 PREFIX=/home/admin/haproxy
make install PREFIX=/home/admin/haproxy
TARGET=linux26为内核版本,根据系统参数安装用 uname –r 查看内核版本
Mkdir /home/admin/haproxy/conf
Mkdir /home/admin/haproxy/logs
三 haproxy配置
Master salve 相同配置
‘
‘# this config needs haproxy-1.1.28 or haproxy-1.2.1
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
#chroot /usr/share/haproxy
chroot /home/admin/haproxy
uid 99
gid 99
daemon
#debug
#quiet
pidfile /home/admin/haproxy/logs/haproxy.pid
nbproc 1
defaults
log global
mode http
option httplog
option dontlognull
option forwardfor
retries 3
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen feiyang 192.168.0.99:80
# bind 0.0.0.0:80
# stats uri /haproxy-stats
# stats auth feiyang:feiyang
mode http
cookie SERVERID rewrite
balance roundrobin
stats realm Haproxy\ statistics
option httpclose
server app1_1 192.168.0.161:80 cookie applinst1 check inter 2000 rise 2 fall 5 weight 3
server app1_2 192.168.0.115:80 cookie applinst2 check inter 2000 rise 2 fall 5 weight 1
# server app1_3 192.168.34.27:8080 cookie app1inst3 check inter 2000 rise 2 fall 5
# server app1_4 192.168.34.42:8080 cookie app1inst4 check inter 2000 rise 2 fall 5
listen stats_auth 192.168.0.148:80 从服务器填写自己的ip
stats enable
stats uri /admin-status
stats auth feiyang:feiyang
stats admin if TRUE
其他的配置没变化。
Iptables设置在主从服务器执行 iptables –I INPUT –d 224.0.0.18 –j ACCEPT
支持 vrrp通信。否则主从keepalived无法切换