HAProxy Windows版本的编译及其在CORS中的应用(2)

  ########默认配置############
defaults
mode http #默认的模式mode { tcp|http|health },tcp是4层,http是7层,health只会返回OK
retries 2 #两次连接失败就认为是服务器不可用,也可以通过后面设置
option redispatch #当serverId对应的服务器挂掉后,强制定向到其他健康的服务器
option abortonclose #当服务器负载很高的时候,自动结束掉当前队列处理比较久的链接
maxconn 4096 #默认的最大连接数
timeout connect 5000ms #连接超时
timeout client 30000ms #客户端超时
timeout server 30000ms #服务器超时
#timeout check 2000 #=心跳检测超时
log 127.0.0.1 local0 err #[err warning info debug]


########统计页面配置########
listen admin_stats
bind 0.0.0.0:1080 #监听端口
mode http #http的7层模式
option httplog #采用http日志格式
#log 127.0.0.1 local0 err
maxconn 10
stats refresh 30s #统计页面自动刷新时间
stats uri /stats #统计页面url
stats realm XingCloud\ Haproxy #统计页面密码框上提示文本
stats auth admin:admin #统计页面用户名和密码设置
stats hide-version #隐藏统计页面上HAProxy的版本信息


########test1配置#################
listen test1
bind 0.0.0.0:90
mode tcp
#maxconn 4086
#log 127.0.0.1 local0 debug
server s1 10.18.138.201:80
server s2 10.18.102.190:80
server s3 10.18.102.189:80
server s4 10.18.102.188:80
server s5 10.18.102.187:80
########frontend配置##############


########test2配置#################
listen test2
bind 0.0.0.0:91
mode tcp
#maxconn 4086
#log 127.0.0.1 local0 debug
server s1 10.18.138.130:80 weight 1
server s2 10.18.138.201:8080 weight 6
########frontend配置##############

  4.实例测试

  为了测试运行效果我们使用最简单的配置做一个简单的tcp代理:

##########全局配置#########
global
daemon
nbproc 1
pidfile /var/run/haproxy.pid


########默认配置############
defaults
mode http #默认的模式mode { tcp|http|health },tcp是4层,http是7层,health只会返回OK
retries 2 #两次连接失败就认为是服务器不可用,也可以通过后面设置
option redispatch #当serverId对应的服务器挂掉后,强制定向到其他健康的服务器
option abortonclose #当服务器负载很高的时候,自动结束掉当前队列处理比较久的链接
maxconn 4096 #默认的最大连接数
timeout connect 5000ms #连接超时
timeout client 30000ms #客户端超时
timeout server 30000ms #服务器超时
#timeout check 2000 #=心跳检测超时
log 127.0.0.1 local0 err #[err warning info debug]


########统计页面配置########
listen admin_stats
bind 0.0.0.0:1080 #监听端口
mode http #http的7层模式
option httplog #采用http日志格式
#log 127.0.0.1 local0 err
maxconn 10
stats refresh 30s #统计页面自动刷新时间
stats uri /stats #统计页面url
stats realm XingCloud\ Haproxy #统计页面密码框上提示文本
stats auth admin:admin #统计页面用户名和密码设置
stats hide-version #隐藏统计页面上HAProxy的版本信息


########test1配置#################
listen test1
bind 0.0.0.0:81
mode tcp
#maxconn 4086
#log 127.0.0.1 local0 debug
server s1 192.168.1.200:8000

server s1 192.168.1.201:8001

server s1 192.168.1.202:8002
########frontend配置##############


########test2配置#################
listen test2
bind 0.0.0.0:91
mode tcp
#maxconn 4086
#log 127.0.0.1 local0 debug
server s1 192.168.1.100:9000

server s1 192.168.1.101:9001

server s1 192.168.1.102:9002
########frontend配置##############

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/04dc74bf25f7298ab2258d1cab6c75b7.html