128.2. haproxy.cfg

默认配置文件

$ cat /etc/haproxy/haproxy.cfg
# this config needs haproxy-1.1.28 or haproxy-1.2.1

global
	log 127.0.0.1	local0
	log 127.0.0.1	local1 notice
	#log loghost	local0 info
	maxconn 4096
	#chroot /usr/share/haproxy
	user haproxy
	group haproxy
	daemon
	#debug
	#quiet

defaults
	log	global
	mode	http
	option	httplog
	option	dontlognull
	retries	3
	option redispatch
	maxconn	2000
	contimeout	5000
	clitimeout	50000
	srvtimeout	50000

listen	appli1-rewrite 0.0.0.0:10001
	cookie	SERVERID rewrite
	balance	roundrobin
	server	app1_1 192.168.34.23:8080 cookie app1inst1 check inter 2000 rise 2 fall 5
	server	app1_2 192.168.34.32:8080 cookie app1inst2 check inter 2000 rise 2 fall 5
	server	app1_3 192.168.34.27:8080 cookie app1inst3 check inter 2000 rise 2 fall 5
	server	app1_4 192.168.34.42:8080 cookie app1inst4 check inter 2000 rise 2 fall 5

listen	appli2-insert 0.0.0.0:10002
	option	httpchk
	balance	roundrobin
	cookie	SERVERID insert indirect nocache
	server	inst1 192.168.114.56:80 cookie server01 check inter 2000 fall 3
	server	inst2 192.168.114.56:81 cookie server02 check inter 2000 fall 3
	capture cookie vgnvisitor= len 32

	option	httpclose		# disable keep-alive
	rspidel ^Set-cookie:\ IP=	# do not let this cookie tell our internal IP address

listen	appli3-relais 0.0.0.0:10003
	dispatch 192.168.135.17:80

listen	appli4-backup 0.0.0.0:10004
	option	httpchk /index.html
	option	persist
	balance	roundrobin
	server	inst1 192.168.114.56:80 check inter 2000 fall 3
	server	inst2 192.168.114.56:81 check inter 2000 fall 3 backup

listen	ssl-relay 0.0.0.0:8443
	option	ssl-hello-chk
	balance	source
	server	inst1 192.168.110.56:443 check inter 2000 fall 3
	server	inst2 192.168.110.57:443 check inter 2000 fall 3
	server	back1 192.168.120.58:443 backup

listen	appli5-backup 0.0.0.0:10005
	option	httpchk *
	balance	roundrobin
	cookie	SERVERID insert indirect nocache
	server	inst1 192.168.114.56:80 cookie server01 check inter 2000 fall 3
	server	inst2 192.168.114.56:81 cookie server02 check inter 2000 fall 3
	server	inst3 192.168.114.57:80 backup check inter 2000 fall 3
	capture cookie ASPSESSION len 32
	srvtimeout	20000

	option	httpclose		# disable keep-alive
	option  checkcache		# block response if set-cookie & cacheable

	rspidel ^Set-cookie:\ IP=	# do not let this cookie tell our internal IP address

	#errorloc	502	http://192.168.114.58/error502.html
	#errorfile	503	/etc/haproxy/errors/503.http
	errorfile	400	/etc/haproxy/errors/400.http
	errorfile	403	/etc/haproxy/errors/403.http
	errorfile	408	/etc/haproxy/errors/408.http
	errorfile	500	/etc/haproxy/errors/500.http
	errorfile	502	/etc/haproxy/errors/502.http
	errorfile	503	/etc/haproxy/errors/503.http
	errorfile	504	/etc/haproxy/errors/504.http

128.2.1. stats

listen stats :8000
        mode http
        transparent
        stats uri /haproxy-stats
        stats realm Haproxy \ statistic
        stats auth neo:chen
		stats hide-version

listen  admin_status
        mode  http
        bind 202.76.124.110:8899
        option httplog
        stats enable
        stats refresh 10s
        stats hide-version
        stats realm Haproxy\ Statistics
        stats uri  /admin-status
        stats auth  admin:password
        stats admin if TRUE

128.2.2. listen 方式

listen tomcat-app *:80
	maxconn 2000
	balance source
	option  httpclose               # disable keep-alive
	option  forwardfor
	server  app1 202.13.69.16:8080 check
	server  app2 103.13.40.66:8080 check
			

128.2.3. frontend/backend 方式

frontend  tomcat-app *:8080
    default_backend	tomcat-app
backend tomcat-app
    balance source
    server  app1 202.13.69.16:8080 check
    server  app2 103.11.40.66:8080 check
			

128.2.4. option

128.2.4.1. httpclose

option  httpclose               # disable keep-alive
				

128.2.4.2. forwardfor

forwardfor 实例

listen web :80
	mode http
	balance roundrobin
	option httpclose
	option forwardfor
	server web1 192.168.1.1:80 check weight 1 minconn 1 maxconn 3 check inter 40000
	server web2 192.168.1.2:80 check weight 1 minconn 1 maxconn 3 check inter 40000

128.2.4.3. httpchk

option httpchk
option httpchk <uri>
option httpchk <method> <uri>
option httpchk <method> <uri> <version>
ex:

option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www

option httpchk GET /robots.txt
option httpchk GET /index.html
option httpchk *

option httpchk GET /robots.txt # 指的是 GET /robots.txt HTTP/1.0
option httpchk # 指的是 OPTIONS / HTTP/1.0
option httpchk * # 指的是 OPTIONS * HTTP/1.0

128.2.5. balance

常用负载均衡算法

roundrobin	轮循
leastconn	最小连接数
source		源IP会话保持
			

128.2.6. server

server xxxxx xxx.xxx.xxx.xxx:xxx check port 80 inter 1500 rise 3 fall 3 weight 1
			

port 端口检查

inter 是检测心跳频率

rise 3次检查正确,认为服务器可用

fall 3次失败认为服务器不可用

weight 代表权重

原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

时间: 2024-10-19 02:23:07

128.2. haproxy.cfg的相关文章

第 128 章 HAProxy - fast and reliable load balancing reverse proxy

128.1. Installing 128.1.1. Ubuntu $ apt-cache search haproxy haproxy - fast and reliable load balancing reverse proxy sudo apt-get install haproxy 启用HAProxy $ sudo vim /etc/default/haproxy # Set ENABLED to 1 if you want the init script to start hapro

Haproxy+Keepalived集群实例配置

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://koumm.blog.51cto.com/703525/1733880 环境说明: 操作系统: Redhat 6.5 x64,本文采用rpm方式安装haproxy,keepalived.    如果采用原码安装:可以参考基础CentOS5.9 Haproxy+Keepalived+Jboss集群实施架构一例     app1: 192.168.0.24     app1: 192

使用HAproxy为阿里中间件做负载均衡。

背景:    最近为一传统行业客户部署阿里中间件的过程中,需要使用负载均衡技术,最初计划使用LVS的DR模式,但考虑到使用LVS DR+keepalived模式 配置较为复杂,服务器数量较多,需要在后端服务器上做VIP绑定和ARP抑制操作,后期维护困难,还有windows系统,而且用户对Linux系统不熟悉.后来准备使用LVS的NAT模式,因为NAT模式不需要对后端服务器做修改,可是NAT模式对网络结构有要求,我们不能改变用户的网络结构.于是使用了HAproxy的反向代理功能.与keepaliv

linux中实现Web服务器负载均衡(HAProxy+Keepalived)

  说明: 操作系统:CentOS 5.X 64位 Web服务器:192.168.21.127.192.168.21.128 站点:bbs.111cn.net和sns.111cn.net部署在两台Web服务器上 实现目的: 增加两台服务器(主主模式),通过HAProxy+Keepalived实现Web服务器负载均衡 架构规划: HAProxy服务器:192.168.21.129.192.168.21.130 虚拟服务器(VIP):192.168.21.253.192.168.21.254 部署完

128.3. Example 配置实例

128.3.1. HTTP 配置实例 cd /etc/haproxy/ cp haproxy.cfg haproxy.cfg.old # cat /etc/haproxy/haproxy.cfg #--------------------------------------------------------------------- # Example configuration for a possible web application. See the # full configurat

Shell编程实现Haproxy负载均衡集群的启动和关闭管理

#!/bin/bash #-------------------------Haproxy Server Management Shell script------------------------------------------------ #Authors are from JC #time:2012-10-10 #QQ:408822635 #from  the region Beijng.China. #-------------------------Haproxy Server

centos 6.3下haproxy和apache的配置过程

一.什么是haproxy HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可 靠的一种解决方案.HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要会话保持或七层处理. HAProxy运行在当前的硬件上,完全可以支持数以万计的并发连接.并且它的运行模式使得它可以很简单安全 的整合进您当前的架构中, 同时可以保护你的web服务器不被暴露到网络上. 二.安装haproxy 系统环境:centos6.3 apache: httpd

全面讲解在Linux系统中安装和配置HAProxy的过程

  一.Haproxy概念 Haproxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.Haproxy特别适用于那些负载特大的web站点,这些站点通常又需要会保持或七层处理.Haproxy运行在当前的硬件上,完全可以支持数以万计的并发连接.并且它的运行模式使得它可以很简单安全的整合进您当前的架构中,同时可以保护你的web服务器不被暴露到网络上. 二.安装Haproxy 代码如下: [root@node3 app]# tar zxvf

CentOS7+MySQL/MariaDB+Galera+HAProxy+Keepalived构建高可用数据库集群

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://dgd2010.blog.51cto.com/1539422/1603972 方案优势: Galera能够实现MySQL/MariaDB数据库的主主复制和多主复制等模式,这些复制模式都是同步进行的,同步时间非常短 每一个节点都可以同时写入和读取,当某一节点发生故障时,可自动从集群中自动剔除 HAProxy能提供负载均衡和故障判断等功能解决服务器系统存在的单点故障 Keepaliv