JAVA全系列 教程
3762个小节阅读:7092k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
xxxxxxxxxx
yum list | grep haproxy
xxxxxxxxxx
yum -y install haproxy
xxxxxxxxxx
$ vim /etc/haproxy/haproxy.cfg
xxxxxxxxxx
$ haproxy -f /etc/haproxy/haproxy.cfg
HAProxy配置文件主要由全局设定和代理设定两部分组成,包含5个域:global、default、frontend、backend、listen。
xxxxxxxxxx
# 全局配置,定义haproxy进程的工作特性和全局配置
global
log 127.0.0.1 local2
chroot /var/lib/haproxy #chroot运行的路径
pidfile /var/run/haproxy.pid #haproxy pid的存放位置
maxconn 65536 #最大连接数
nbproc 10
ulimit-n 200000
user haproxy #haproxy的运行用户
group haproxy #haproxy的运行用户的所属组
daemon #守护进程的方式在后台工作
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
注意:
全局配置,通常是一些进程级别的配置,与操作系统相关。
xxxxxxxxxx
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http #默认使用的七层协议,也可以是tcp四层协议,如果配置为health,则表示健康检查,返回ok
log global
option tcplog #详细记录tcp日志
option redispatch
option dontlognull #不记录健康检查的日志信息
option forwardfor
retries 3 #重试次数为3次,失败3次以后则表示服务不可用
timeout http-request 5s #http请求超时时间,客户端建立连接5s但不请求数据的时候,关闭客户端连接
timeout queue 10s #等待最大时间,表示等待最大时长为10s
timeout connect 10s #连接超时时间,表示客户端请求转发至服务器所等待的时长为10s
timeout client 30m #客户端超时时间,表示客户端非活跃状态的时间为30min
timeout server 30m #服务器超时时间,表示客户端与服务器建立连接后,等待服务器的超时时间为30min
timeout http-keep-alive 10s #持久连接超时时间,表示保持连接的超时时长为10s
timeout check 10s #心跳检测超时时间,表示健康状态监测时的超时时间为10s
参数:
默认参数配置,主要是涉及的公共配置,在
defaults
中一次性添加。frontend
、backend
、listen
未配置时,都可以默认defaults
中的参数配置。若配置了,会覆盖。
xxxxxxxxxx
frontend test
bind *:8082
default_backend test
option httplog
acl user-core path_beg /test/v1/user/
use_backend user-core_server if user-core
# test
backend test
mode http
balance roundrobin
server node1 10.xxx.xxx.1:7000 check port 7000 inter 5000 rise 5 fall 5
server node2 10.xxx.xxx.2:7000 check port 7000 inter 5000 rise 5 fall 5
# user-core_server
backend user-core_server
mode http
balance roundrobin
server node1 10.xxx.xxx.1:7001 check port 7001 inter 5000 rise 5 fall 5
server node2 10.xxx.xxx.2:7001 check port 7001 inter 5000 rise 5 fall 5 backup
frontend haproxy_statis_front
bind *:8081
mode http
default_backend statis_haproxy
backend statis_haproxy
mode http
balance roundrobin
stats uri /haproxy/stats
stats auth haproxy:zkK_HH@zz
stats refresh 30s
stats show-node
stats show-legends
stats hide-version
参数:
frontend
可以看作是前端接收请求的部分,内部指定后端;backend
可以看作是后端服务接收请求的部分;
xxxxxxxxxx
listen admin_stats
bind *:8080 #监听端口
mode http
option httplog
log global
#统计接口启用开关
stats enable
maxconn 10
#页面刷新时长
stats refresh 30s
#haproxy ui访问后缀
stats uri /haproxy?stats
#认证时的realm,作为提示用的
stats realm haproxy
#认证用户名和密码
stats auth admin:admin
#隐藏HAProxy版本号
stats hide-version
#管理界面只有认证通过后才能在ui上进行管理
stats admin if TRUE
参数:
listen
是`frontend和backend的组合,haproxy的监控ui可以通过这个进行配置。
向配置文件中插入以下配置信息,并保存
xxxxxxxxxx
global
log 127.0.0.1 local0
#log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
#uid 99
#gid 99
daemon
#debug
#quiet
defaults
log global
mode tcp
option abortonclose
option redispatch
retries 3
maxconn 2000
timeout connect 5000
timeout client 50000
timeout server 50000
listen proxy_status
bind :48066
mode tcp
balance roundrobin
server mycat_1 192.168.66.101:8066 check inter 10s
server mycat_2 192.168.66.102:8066 check inter 10s
frontend admin_stats
bind :7777
mode http
stats enable
option httplog
maxconn 10
stats refresh 30s
stats uri /admin
stats auth admin:123123
stats hide-version
stats admin if TRUE
xxxxxxxxxx
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.conf
xxxxxxxxxx
ps -ef|grep haproxy
http://192.168.140.125:7777/admin#在弹出框输入用户名:admin密码:123123
xxxxxxxxxx
mysql -uroot -p123456 -h 192.168.66.101 -P 48066