Keepalived+haproxy
实验目的:实现可以ssision保持的高可用负载均衡
Keepalived作用高可用,配置管理为互为主从设置
Haproxy 用于负载均衡会话保持
同一个使用yum 安装
配置拓扑图
实验目的:实现可以ssision保持的高可用负载均衡
Keepalived作用高可用,配置管理为互为主从设置
Haproxy 用于负载均衡会话保持
同一个使用yum 安装
配置拓扑图
Vip keep1 192.168.6.226
Vip keep2 192.168.6.227
Web1 192.168.6.1
Web2 192.168.6.2
Web3 192.168.6.3
http1 192.168.6.5
http2 192.168.6.6
http3 192.168.6.7
keepalived 1 步骤
yum install keepalived –y
vim /etc/keepalived/keepalived.conf
! Configuration Fileforkeepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from admin@lnmmp.com
smtp_connect_timeout 3
smtp_server 127.0.0.1
router_id LVS_DEVEL
}
vrrp_script chk_maintaince_down {
script"[[ -f /etc/keepalived/down ]] && exit 1 || exit0"
interval 1
weight 2
}
vrrp_script chk_haproxy {
script"killall -0 haproxy"
interval 1
weight 2
}
vrrp_instance VI_1 {
interface br0
state BACKUP
priority 50
virtual_router_id 125
garp_master_delay 1
authentication {
auth_type PASS
auth_pass 1e3459f77aba4ded
}
track_interface {
br0
}
virtual_ipaddress {
192.168.6.226/32 dev br0 label br0:0
}
track_script {
chk_haproxy
}
notify_master"/etc/keepalived/notify.sh master 192.168.6.227"
notify_fault"/etc/keepalived/notify.sh fault 192.168.6.227"
}
vrrp_instance VI_2 {
interface br0
state MASTER
priority 100
virtual_router_id 126
garp_master_delay 1
authentication {
auth_type PASS
auth_pass 7615c4b7f518cede
}
track_interface {
br0
}
virtual_ipaddress {
192.168.6.227/32 dev br0 label br0:1
}
track_script {
chk_haproxy
chk_maintaince_down
}
notify_master"/etc/keepalived/notify.sh master 192.168.6.228"
notify_backup"/etc/keepalived/notify.sh backup 192.168.6.228"
notify_fault"/etc/keepalived/notify.sh fault 192.168.6.228"
}
Keepalived2配置步骤
! Configuration Fileforkeepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from admin@lnmmp.com
smtp_connect_timeout 3
smtp_server 127.0.0.1
router_id LVS_DEVEL
}
vrrp_script chk_maintaince_down {
script"[[ -f /etc/keepalived/down ]] && exit 1 || exit0"
interval 1
weight 2
}
vrrp_script chk_haproxy {
script"killall -0 haproxy"
interval 1
weight 2
}
vrrp_instance VI_1 {
interface br0
state MASTER
priority 100
virtual_router_id 125
garp_master_delay 1
authentication {
auth_type PASS
auth_pass 1e3459f77aba4ded
}
track_interface {
br0
}
virtual_ipaddress {
192.168.6.227/32 dev br0 label br0:0
}
track_script {
chk_haproxy
}
notify_master"/etc/keepalived/notify.sh master 192.168.6.227"
notify_fault"/etc/keepalived/notify.sh fault 192.168.6.227"
}
vrrp_instance VI_2 {
interface br0
state BACKUP
priority 50
virtual_router_id 126
garp_master_delay 1
authentication {
auth_type PASS
auth_pass 7615c4b7f518cede
}
track_interface {
br0
}
virtual_ipaddress {
192.168.6.228/32 dev br0 label br0:1
}
track_script {
chk_haproxy
chk_maintaince_down
}
notify_master"/etc/keepalived/notify.sh master 192.168.6.228"
notify_backup"/etc/keepalived/notify.sh backup 192.168.6.228"
notify_fault"/etc/keepalived/notify.sh fault 192.168.6.228"
}
Keepalived配置完成
查看配置
Ip add
Keepalived 1
inet 192.168.6.223/24 brd 192.168.6.255scope global br0
inet 192.168.6.226/32scope global br0:0
keepalived2
inet192.168.6.224/24 brd 192.168.6.255 scope global br0
inet192.168.6.227/32 scope global br0:0
haproxy 配置
yum installhaproxy
vim/etc/haproxy/haproxy.cfg
global #全局设置
log 127.0.0.1 local0 #日志输出配置,所有日志都记录在本机,通过local0输出
#log loghost local0 info
maxconn 4096 #最大连接数
chroot /usr/local/haproxy
uid 99 #所属运行的用户uid
gid 99 #所属运行的用户组
daemon #以后台形式运行haproxy
nbproc 2 #启动2个haproxy实例
pidfile/usr/local/haproxy/haproxy.pid #将所有进程写入pid文件
#debug
#quiet
defaults #默认设置
#log global
log 127.0.0.1 local3 #日志文件的输出定向
mode http #所处理的类别,默认采用http模式,可配置成tcp作4层消息转发
option httplog #日志类别,采用httplog
option dontlognull
option forwardfor #如果后端服务器需要获得客户端真实ip需要配置的参数,可以从Http Header中获得客户端ip
option httpclose #每次请求完毕后主动关闭http通道,haproxy不支持keep-alive,只能模拟这种模式的实现
retries 3 #3次连接失败就认为服务器不可用,主要通过后面的check检查
option redispatch #当serverid对应的服务器挂掉后,强制定向到其他健康服务器
maxconn 2000 #最大连接数
stats uri /haproxy-admin #haproxy 监控页面的访问地址
timeoutconnect 5000 #连接超时时间
timeout client 50000 #客户端连接超时时间
timeoutserver 50000
stats auth Frank:Frank #设置监控页面的用户和密码:Frank
statshide-version #隐藏统计页面的HAproxy版本信息
frontend main *:5000
acl url_static path_beg -i /static /images /javascript/stylesheets
acl url_static1 path_end -i .jpg .gif .png .css .js .html .php
use_backend static if url_static
default_backend web
use_backend static if url_static1
default_backend http
backend static
balance roundrobin
server static 127.0.0.1:4331 check
#---------------------------------------------------------------------
# round robinbalancing between the various backends
#---------------------------------------------------------------------
backend web
balance roundrobin 负载均衡算法
cookie SESSION_COOKIE insert indirect nocache 会话保持
server web1 192.168.6.1:80 cookie 1weight 5 check inter 2000 rise 2 fall 3
server web2 192.168.6.2:80 cookie 1 weight 2 check inter 2000 rise 2 fall3
server web3 192.168.6.3:80 cookie 1 weight 3 check inter 2000 rise 2 fall3
backend http
balance roundrobin 负载均衡算法
cookie SESSION_COOKIE insert indirect nocache 会话保持
server web1 192.168.6.5:80 cookie 1 weight 5 check inter 2000 rise 2fall 3
server web2 192.168.6.6:80 cookie 1 weight 2 check inter 2000 rise 2fall 3
server web3 192.168.6.7:80 cookie 1 weight 3 check inter 2000 rise 2fall 3
haproxy2同 haproxy1
查看haproxy图
编辑回复