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 ...
随机推荐
- P3952 NOIP2017 时间复杂度
写了两三个小时,麻烦倒是不麻烦,要考虑清楚,想全了 只过了样例提交是不是傻,要自己造数据 数据不大可以用STL 建议自己刚一下,不看代码 #include <iostream> #incl ...
- 【第六章】 springboot + 事务
在实际开发中,其实很少会用到事务,一般情况下事务用的比较多的是在金钱计算方面. mybatis与spring集成后,其事务该怎么做?其实很简单,直接在上一节代码的基础上在相应的方法(通常是servic ...
- UVa 11624 大火蔓延的迷宫
https://vjudge.net/problem/UVA-11624 题意:有一个大火蔓延的迷宫,迷宫中有障碍格,而所有着火的格子都会往四周蔓延.求出到达边界格子时的最短时间. 思路:复杂了一点的 ...
- circRNA研究手册
环状RNA(circRNA)研究技术手册.doc.pdf (转自:汉恒生物)
- phpMyAdmin-Error:The mbstring extension is missing. Please check your PHP configuration.
1.打开php.ini 2.找到 ; extension_dir = "./",把前面的分号去掉.引号里改成extension_dir = "D:php/ext" ...
- Codeforces Beta Round #17 A.素数相关
A. Noldbach problem Nick is interested in prime numbers. Once he read about Goldbach problem. It sta ...
- xss脚本注入后端的防护
1.脚本注入最主要的是不要相信用户输入的任何数据,对数据进行转义 可以使用:org.springframework.web.util.HtmlUtils包中的 HtmlUtils.htmlEscape ...
- 微信小程序发起支付流程
小程序调起支付API 需要参数 邮件中参数 API参数名 详细说明 APPID appid appid是微信小程序后台APP的唯一标识,在小程序后台申请小程序账号后,微信会自动分配对应的appid,用 ...
- 汇编语言调用Linux系统调用read和write
.section .data UserMsg: .ascii "Please input the message:" LenOfUserMsg: .equ lenMsg, LenO ...
- Qt_2D_画图教程
1. ZC: 看点:相同的API,QPainter.QPainterDevice和QPainterEngine这3个类 Qt学习之2D绘图(画刷和画笔) http://blog.csdn.net/lp ...