Hello World:HAProxy容器节点配置

1. 前言

环境:Ubuntu 16.04 Server
学习Docker容器与容器云 HAProxy容器节点配置汇总:

2. haproxy.cfg配置文件

global
	log 127.0.0.1	local0	# 日志输出配置,所有日志都记录在本机
	maxconn	4096	# 最大连接数
	chroot /usr/local/sbin	# 改变当前工作目录
	daemon	# 以后台形式运行HAProxy
	nbproc	4	# 启动4个HAProxy实例
	pidfile	/usr/local/sbin/haproxy.pid	# pid文件位置

defaults
	log		127.0.0.1	local3	# 日志文件的输出定向
	mode	http	# {tcp|http|health}设定启动实例的协议类型
	option	dontlognull	# 保证HAProxy不记录上级负载均衡发送过来的用于检测状态没有数据的心跳包
	option	redispatch	# 当serverId对应的服务器挂掉后,强制定向到其他健康的服务器
	retries	2	# 重试两次连接失败就认为服务器不可用,主要通过后面的check检查
	maxconn 2000	# 最大连接数
	balance	roundrobin	# balance有两个可用选项:roundrobin和source,其中,roundrobin表示轮询,
						# 而source表示HAProxy不采用轮询的策略,而是把来自某个IP的请求转发给一个固定的IP的后端
	timeout	connect	5000ms	# 连接超时时间
	timeout	client	50000ms	# 客户端连接超时时间
	timeout server	50000ms	# 服务器端连接超时时间
listen redis_proxy
	bind	0.0.0.0:6301
	bind-process	2
	stats	enable
	stats	uri	/haproxy-stats
		server APP1 APP1:8001 check inter 2000 rise 2 fall 5 # 你的均衡节点
		server APP2 APP2:8002 check inter 2000 rise 2 fall 5

3. BUG整理

出现BUG:

'listen' cannot handle unexpected argument '0.0.0.0:6301

解决方案,添加如下语句:

bind	0.0.0.0:6301

出现BUG:

[WARNING] 270/124932 (83) : Proxy 'redis_proxy': 
in multi-process mode, stats will be limited to process assigned to the current request.

解决方案,添加如下语句:

bind-process	2

在访问页面进行访问时出现BUG:

DisallowedHost at /helloworld
Invalid HTTP_HOST header: '192.168.5.128:6301'. 
You may need to add '192.168.5.128' to ALLOWED_HOSTS.

在这里插入图片描述

解决方案:
在APP1和APP2的setting.py文件里,修改ALLOWED_HOSTS = [ ] 字段:

ALLOWED_HOSTS = ['192.168.5.128']

在这里插入图片描述
运行效果:
在这里插入图片描述

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值