haproxy配置示例
1.最基础的的配置
global
daemon
maxconn 25600 defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms frontend http-in
bind *:80
default_backend servers backend servers
server server1 127.0.0.1:8080 maxconn 32
2.http服务器实例
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log log 127.0.0.1 local2 chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon 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 30000 listen stats
mode http
bind 0.0.0.0:1080
stats enable
stats hide-version
stats uri /haproxyadmin?stats
stats realm Haproxy\ Statistics
stats auth admin:admin
stats admin if TRUE frontend http-in
bind *:80
mode http
log global
option httpclose
option logasap
option dontlognull
capture request header Host len 20
capture request header Referer len 60
default_backend servers frontend healthcheck
bind :1099
mode http
option httpclose
option forwardfor
default_backend servers backend servers
balance roundrobin
server websrv1 192.168.10.11:80 check maxconn 2000
server websrv2 192.168.10.12:80 check maxconn 2000
3.负载均衡MySQL服务的配置示例
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2 chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon defaults
mode tcp
log global
option httplog
option dontlognull
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 600 listen stats
mode http
bind 0.0.0.0:1080
stats enable
stats hide-version
stats uri /haproxyadmin?stats
stats realm Haproxy\ Statistics
stats auth admin:admin
stats admin if TRUE frontend mysql
bind *:3306
mode tcp
log global
default_backend mysqlservers backend mysqlservers
balance leastconn
server dbsrv1 192.168.10.11:3306 check port 3306 intval 2 rise 1 fall 2 maxconn 300
server dbsrv2 192.168.10.12:3306 check port 3306 intval 2 rise 1 fall 2 maxconn 300
4.动静分离示例
global
log 127.0.0.1 local2 chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon # turn on stats unix socket
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 30000 listen stats
mode http
bind 0.0.0.0:1080
stats enable
stats hide-version
stats uri /haproxyadmin?stats
stats realm Haproxy\ Statistics
stats auth admin:admin
stats admin if TRUE frontend http-in
bind *:80
mode http
log global
option httpclose
option logasap
option dontlognull
capture request header Host len 20
capture request header Referer len 60
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .jpeg .gif .png .css .js use_backend static_servers if url_static
default_backend dynamic_servers backend static_servers
balance roundrobin
server imgsrv1 172.16.200.7:80 check maxconn 6000
server imgsrv2 172.16.200.8:80 check maxconn 6000 backend dynamic_servers
cookie srv insert nocache
balance roundrobin
server websrv1 172.16.200.7:80 check maxconn 1000 cookie websrv1
server websrv2 172.16.200.8:80 check maxconn 1000 cookie websrv2
server websrv3 172.16.200.9:80 check maxconn 1000 cookie websrv3
5.实例:keepcalived + haproxy
# this config needs haproxy-1.1.28 or haproxy-1.2.1 global
log 127.0.0.1 local0
log 127.0.0.1 local3 warning
#log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 3000
chroot /usr/share/haproxy
uid nobody
gid nobody
daemon
#debug
#quiet defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 20000
timeout connect 5000
timeout client 50000
timeout server 50000 backend varnish_www
#option httpchk
option forwardfor
balance uri
#server varnish1 172.18.203.134:6081 check inter 3000 rise 2 fall 5
#server varnish2 172.18.203.135:6081 check inter 3000 rise 2 fall 5
server varnish1 172.18.203.134:6081
server varnish2 172.18.203.135:6081 backend varnish_m
#option httpchk
option forwardfor
balance uri
hash-type consistent
#server varnish3 172.18.203.136:6081 check
#server varnish4 172.18.203.137:6081 check
server varnish3 172.18.203.136:6081
server varnish4 172.18.203.137:6081 frontend host
bind *:80
acl host_m hdr(host) -i m.tycoon.com
acl host_www hdr(host) -i www.tycoon.com
acl host_www path_end -i .jpg .jpeg .png .gif .js .css .html .htm
use_backend varnish_www if host_www
use_backend varnish_m if host_m listen stats *:8901
stats enable
stats refresh 30s
stats hide-version
stats uri /haproxy?stats
stats realm HAProxy\ Statistics
stats auth admin:tycoon
! Configuration File for keepalived
global_defs {
   notification_email {
     root@localhost
   }
   notification_email_from admin@tycoon.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id lb-haproxy
   vrrp_mcast_group4 224.0.203.10
}
vrrp_script chk_haproxy {
    script "killall -0 haproxy"
    interval 5
    weight -8
}
vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass tUPEA8I5
    }
    track_script {
        chk_haproxy
    }
    virtual_ipaddress {
        172.18.203.253/16
    }
}
! Configuration File for keepalived
global_defs {
   notification_email {
     root@localhost
   }
   notification_email_from admin@tycoon.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id lb-haproxy
   vrrp_mcast_group4 224.0.203.10
}
vrrp_script chk_haproxy {
    script "killall -0 haproxy"
    interval 5
    weight -8
}
vrrp_instance VI_1 {
    state SLAVE
    interface eth0
    virtual_router_id 71
    priority 95
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass tUPEA8I5
    }
    track_script {
        chk_haproxy
    }
    virtual_ipaddress {
        172.18.203.253/16
    }
}
6.实例2:ACL匹配子网站
global
log 127.0.0.1 local0 info
maxconn 4096
user nobody
group nobody daemon
nbproc 1
pidfile /usr/local/haproxy/logs/haproxy.pid defaults
mode http
retries 3
timeout connect 5s
timeout client 30s
timeout server 30s
timeout check 2s listen admin_stats
bind 0.0.0.0:19088
mode http
log 127.0.0.1 local0 err
stats refresh 30s
stats uri /haproxy-status
stats realm welcome login\ Haproxy
stats auth admin:admin
stats auth user1:passwd1
stats hide-version
stats admin if TRUE front www
bind *:80
mode http
option httpdlog
option forwardfor
log global acl host_www hdr_reg(host) -i ^(www.tb.com|tb.com)
acl host_bbs hdr_dom(host) -i bbs.tb.com
acl host_blog hdr_beg(host) -i blog.tb.com use_backend server_www if host_www
use_backend server_bbs if host_bbs
use_backend server_blog if host_blog
default_backend server_default backend server_default
mode http
option redispatch
option abortonclose
balance roundrobin
cookie SERVER option httpcheck GET /check_status.html
server default1 192.168.88.90:8000 cookie default1 weight 3 check inter 2000 rise 2 fail 3
server default2 192.168.88.91:8000 cookie default2 weight 3 check inter 2000 rise 2 fail 3 backend server_www
mode http
option redispatch
option abortonclose
balance source
cookie SERVERID option httpcheck GET /check_status.jsp
server www1 192.168.88.80:80 cookie www1 weight 6 check inter 2000 rise 2 fail 3
server www2 192.168.88.81:80 cookie www2 weight 6 check inter 2000 rise 2 fail 3
server www3 192.168.88.82:80 cookie www3 weight 6 check inter 2000 rise 2 fail 3 backend server_bbs
mode http
option redispatch
option abortonclose
balance source
cookie SERVERID option httpcheck GET /check_status.php
server bbs1 192.168.88.83:8080 cookie bbs1 weight 8 check inter 2000 rise 2 fail 3
server bbs2 192.168.88.84:8090 cookie bbs2 weight 8 check inter 2000 rise 2 fail 3 backend server_blog
mode http
option redispatch
option abortonclose
balance roundrobin
cookie SERVERID option httpcheck GET /check_status.php
server blog1 192.168.88.85:8000 cookie blog1 weight 5 check inter 2000 rise 2 fail 3
server blog2 192.168.88.86:8000 cookie blog2 weight 5 check inter 2000 rise 2 fail 3
haproxy配置示例的更多相关文章
- haproxy配置示例和需要考虑的问题
		HaProxy系列文章:http://www.cnblogs.com/f-ck-need-u/p/7576137.html haproxy是一个非常优秀的负载均衡工具,它的特性非常丰富,功能也非常非常 ... 
- Haproxy的安装和配置示例
		1.ha proxy简介ha proxy是一个开源的,高性能的,基于tcp第四层和http第七层应用的负载均衡软件优点:可靠性和稳定性非常好 最高可以同时维护40000-50000个 ... 
- haproxy反向代理配置示例
		*/ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ... 
- HAPRoxy(一):HAProxy基本配置、调度算法与tcp、http、heath模式配置示例
		一.HAProxy安装 1.HAProxy简单介绍 HAProxy虽然名字前有HA,但它并不是一款高可用软件,而是一款用于实现负载均衡的软件,可实现四层与七层的负载均衡. 2.yum安装HAProxy ... 
- HAProxy(三):Keeplived+HAProxy搭建高可用负载均衡动静分离架构基础配置示例
		一.安装环境 1.软件版本 HAProxy:1.5.18 Keepalived:1.3.5 Nginx:1.12.2 PHP:7.2 系统版本:CentOS 7.4 2.IP分配与架构图 3.安装软件 ... 
- openstack私有云布署实践【4.1 上层代理haproxy配置 (科兴环境)】
		官方文档上的高可用配置,它推荐的是使用haproxy的上层代理来实现服务组件的主备访问.或者负载均衡访问 一开始我也是使用haproxy来做的,但后来方式改了 测试环境:haproxy + n ... 
- Mysql半同步复制模式说明及配置示例 - 运维小结
		MySQL主从复制包括异步模式.半同步模式.GTID模式以及多源复制模式,默认是异步模式 (如之前详细介绍的mysql主从复制).所谓异步模式指的是MySQL 主服务器上I/O thread 线程将二 ... 
- Python-day3作业-haproxy配置文件管理脚本
		#!/usr/bin/env python import os,sys,time,re,prettytable,json from collections import defaultdict,Ord ... 
- Nginx 简单的负载均衡配置示例(转载)
		原文地址:Nginx 简单的负载均衡配置示例(转载) 作者:水中游于 www.s135.com 和 blog.s135.com 域名均指向 Nginx 所在的服务器IP. 用户访问http://www ... 
随机推荐
- Mysql中unique与primary约束的区别分析(转)
			本文章来给大家介绍在mysql中unique与primary约束的区别分析,unique与primary是我们在创建mysql时常用的类型了,下面我来给大家介绍介绍. 定义了UNIQUE约束的字段 ... 
- HDU 6148 Valley Numer (数位DP)题解
			思路: 只要把status那里写清楚就没什么难度T^T,当然还要考虑前导零! 代码: #include<cstdio> #include<cstring> #include&l ... 
- BZOJ3884: 上帝与集合的正确用法  拓展欧拉定理
			Description 根据一些书上的记载,上帝的一次失败的创世经历是这样的: 第一天, 上帝创造了一个世界的基本元素,称做“元”. 第二天, 上帝创造了一个新的元素,称作“α”.“α”被定义为“ ... 
- java的Date() 转换符
			本字段下均转自 csdn 阿念1989 本文是学习网络上的文章时的总结,感谢大家无私的分享. System.out.printf()方法可以对日期做处理输出. 对应列表 转换符 类型 举例 c 完整的 ... 
- NOI 8467 鸣人的影分身
			http://noi.openjudge.cn/ch0206/8467/ 描述 在火影忍者的世界里,令敌人捉摸不透是非常关键的.我们的主角漩涡鸣人所拥有的一个招数——多重影分身之术——就是一个很好的例 ... 
- UVa 818 切断圆环链(dfs+二进制枚举)
			https://vjudge.net/problem/UVA-818 题意:有n个圆环,其中有一些已经扣在了一起.现在需要打开尽量少的圆环,使得所有圆环可以组成一条链,例如,有5个圆环,1-2,2-3 ... 
- WiscKey: Separating Keys from Values in SSD-Conscious Storage [读后整理]
			WiscKey: Separating Keys from Values in SSD-Conscious Storage WiscKey是一个基于LSM的KV存储引擎,特点是:针对SSD的顺序和随机 ... 
- Goroutines和Channels(一)
			Go语言中的并发程序可以用两种手段来实现.本章讲解goroutine和channel,其支持“顺序通信进程”(communicating sequential processes)或被简称为CSP.C ... 
- StringBuffer中的sBuffer.delete(0,4);
			只删除第0-3位的字符,第4位是不删的 
- MVC 子对象数据传递
			1.接受参数 public ActionResult Address(User user) { return View(); } 2. User对象类型 public class User { pub ... 
