haproxy + keepalived 安装配置
haproxy + keepalived 安装配置备注:
web server:192.168.10.53
web server:192.168.10.81
haproxy + keepalived1:192.168.10.124
haproxy + keepalived1:192.168.10.94
-----------------------------------------------
yum install -y gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libgcrypt* libtool*
groupadd haproxy
useradd -g haproxy haproxy
mkdir /usr/local/haproxy
wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.20.tar.gz
cd /usr/src/haproxy-1.4.20/
mkdir conf
cd conf/
vim haproxy.cfg
---------------------------------------------------------------------------------------
global
log 127.0.0.1 local0
maxconn 65535 #最大连接数
chroot /usr/local/haproxy
uid 500
gid 500
daemon
#debug
#quiet
nbproc 1 #负载均衡的并发进程数
pidfile /var/run/haproxy.pid
defaults
log global
mode http #工作模式,目前支持3种(tcp/http/health)
optionhttplog #日志类别
optiondontlognull
optionredispatch #当serverid对应的服务器宕机后,强制定向到其他健康的服务器上
log 127.0.0.1 local0
retries 3 #重试次数
maxconn 32000
stats enable
stats uri /haproxy-stats
stats realm Haproxy\ Statistics #提示信息
stats auth admin:admin #用户认证/用户名、密码
stats hide-version #隐藏版本信息
stats refresh 10s #刷新时间
contimeout 5000 #超时时间
clitimeout 50000
srvtimeout 50000
listenappserver*:80
hash-type consistent
balanceuri len 100
option httpclose #启用被动的http连接关闭
serverweb1-53 192.168.10.53cookie 10 weight 3 check inter 2000 rise 2 fall 3
serverweb2-81 192.168.10.81cookie 20 weight 3 check inter 2000 rise 2 fall 3
-----------------------------------------------------------------------------------------------
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg # 启动haproxy服务
yum -y install openssl openssl-devel
wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz
cd /usr/src/keepalived-1.1.19/
./configure --prefix=/usr/local/keepalived
make
make install
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
mkdir /etc/keepalived
cd /etc/keepalived/
vim keepalived.conf
--------------------------------------------------------------------------------------
global_defs {
notification_email {
2669660794@qq.com
}
notification_email_from 2669660794@qq.com
smtp_server smtp.exmail.qq.com
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER #从为BACKUP
interface eth0
virtual_router_id 50 #路由ID,可通过#tcpdump vrrp查看。
mcast_src_ip 192.168.10.124
priority 100 #从为50
advert_int 1 #(VRRP Multicast广播周期秒数)
garp_master_delay 1 #主从切换时间,单位为秒。
authentication {
auth_type PASS
auth_pass wameide
}
track_interface {
eth0 #其他要监测状态的接口
}
virtual_ipaddress {
192.168.10.204
}
}
virtual_server 192.168.10.204 {
delay_loop 20
lb_algo rr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.10.124 80 {
weight 1
TCP_CHECK {
connect_timeout 3
}
}
real_server 192.168.10.83 80 {
weight 1
TCP_CHECK {
connect_timeout 3
}
}
}
-------------------------------------------------------------------------------------------
/etc/init.d/keepalived restart
backup机器在此就不重复了。按照上述文档里一样。只须稍微更改下里面的参数即可。
页:
[1]