Haproxy+keepalived(2)

原创 2017年11月09日 22:45:18

一、实现haproxy跨网段访问,要求172.17网段为公网网段,后端server为192.168.153网段,haproxy检测后端realserver是基于index.html内的内容,“ok”字段,并能够在haproxy停止时,切换VI

1.实现haproxy跨网段访问,要求172.17网段为公网网段,后端server192.168.153网段
2.haproxy检测后端realserver是基于index.html内的内容,“ok”字段
3.并能够在haproxy停止时,切换VI

1.keepalived配置文件

vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   notification_email {
     root@localhost 
   }
   notification_email_from root_keepalived
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
} 

vrrp_script chk_haproxy {
        script "killall -0 haproxy" 
        interval 2 
        weight -150 
        fall 2 
        rise 2 
}


vrrp_instance VI_1 {
    state BACKUP
    interface eth2
    virtual_router_id 14
    priority 200
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 2121
    }
    virtual_ipaddress {
        172.17.17.1
    }

    track_script {
    chk_haproxy
        } 
}
vrrp_instance VI_2 {
    state BACKUP
    interface eth1
    virtual_router_id 15
    priority 200
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 2121
    }
    virtual_ipaddress {
        192.168.17.1
    }
    track_script {
    chk_haproxy
    } 
}

2.haproxy配置

/etc/haproxy/haproxy.cfg
global
    log         127.0.0.1 local2
    nbproc      1
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    stats socket /var/lib/haproxy/stats

defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000
frontend static
        mode http 
        bind *:80
        acl url_static path_beg -i /static /images /javascript /stylesheets
        acl url_static path_end -i .img .jpg .gif .jpeg .png .css .js
        use_backend  server_static if url_static
        use_backend  cook if ! url_static
frontend ip_acl
        bind *:80
        acl src_ip src 172.17.0.0
        block if ! src_ip
backend cook
        mode http
        option  httpchk  GET /index.html
        http-check expect string ok 
        cookie SERVERID insert indirect nocache
        server  cook_175  192.168.17.175:80 check cookie 175

backend server_static
        balance     roundrobin
        option  httpchk  GET /index.html
        http-check expect string ok   
        server  static_175  192.168.17.175:80 check
        server  static_176  192.168.17.176:80 check

listen stats #定义一个统计报告服务
        mode http #基于http协议
        bind *:1900 #监听1080端口
        stats enable #开启统计报告服务
        stats hide-version #隐藏统计报告版本信息
        stats uri /haproxy?111 #统计报告访问url
        stats realm Haproxy\ Statistics #页面登陆信息
        stats auth admin:admin #验证账号信息
        stats admin if TRUE #验证模式
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

HAproxy+Keepalived 负载均衡架构搭建

  • 2017年08月25日 10:57
  • 914KB
  • 下载

Haproxy+Keepalived+MySQL高可用均衡负载部署

一、安装主从MySQL 1. 按照Linux-rpm安装MySQL步骤完成MySQL安装; 2. 修改启动的配置文件 (1)复制/usr/share/mysql路径下的my-default.cnf文件...

HaProxy + Keepalived实现高可用

  • 2017年08月26日 09:53
  • 352KB
  • 下载

[App] Haproxy + Keepalived 实现高可用负载均衡WEB服务器

角色 IP 软件包 端口 master 192.168.1.151 Haproxy v1.5.18、Keepalived v1.3...

Haproxy+keepalived负载均衡配置

Haproxy本文主要介绍Haproxy负载均衡的安装配置以及结合keepalived保证高可用,概要如下: -安装haproxy -配置haporxy -单台haproxy负载均衡配置 -安...
  • aa168b
  • aa168b
  • 2015年12月21日 16:06
  • 5060
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Haproxy+keepalived(2)
举报原因:
原因补充:

(最多只允许输入30个字)