【运维高级内容--haproxy】

proxies代理配置-defaults

tcp 四层 http七层

haproxy、http默认使用80端口,如需同时启动haproxy、http,为防止端口被占用,需修改http使用的端口:

vim /etc/httpd/conf/httpd.conf

Listen 80 --> Listen 8080                                                  #backup ---sorryserver的端口

#vim /etc/haproxy/haproxy.cfg

#在listen webcluster写入:
    balance uri
    hash-type consistent
    server web1 172.25.254.10:80 check inter 2 fall 3 rise 5 weight 2
    server web2 172.25.254.11:80 check inter 2 fall 3 rise 5 weight 1
#systemctl restart haproxy.service

#在两个webserver写入:

#webserver1
echo 172.25.254.10 - index1.html > /usr/share/nginx/html/index1.html
echo 172.25.254.10 - index2.html > /usr/share/nginx/html/index2.html
echo 172.25.254.10 - index3.html > /usr/share/nginx/html/index3.html
#webserver2
echo 172.25.254.11 - index1.html > /usr/share/nginx/html/index1.html
echo 172.25.254.11 - index2.html > /usr/share/nginx/html/index2.html
echo 172.25.254.11 - index3.html > /usr/share/nginx/html/index3.html


#vim /etc/haproxy/haproxy.cfg

#在listen webcluster写入:
    balance url_param name,userid
    hash-type consistent
    server web1 172.25.254.10:80 check inter 2 fall 3 rise 5 weight 1
    server web2 172.25.254.11:80 check inter 2 fall 3 rise 5 weight 1
#systemctl restart haproxy.service

#vim /etc/haproxy/haproxy.cfg

#在listen webcluster写入:
    balance hdr(User-Agent)
    hash-type consistent
    server web1 172.25.254.10:80 check inter 2 fall 3 rise 5 weight 1
    server web2 172.25.254.11:80 check inter 2 fall 3 rise 5 weight 1
#systemctl restart haproxy.service

测试:

haproxy状态页面监控

启用状态页

#vim /etc/haproxy/haproxy.cfg

listen status
    mode http
    bind *:9999
    stats enable 
    stats refresh 3
    stats uri /status                             #自定义stats page uri
    stats auth yellmiky:yellmiky                  #认证,账号密码均为yellmiky
#systemctl restart haproxy.service

测试:

浏览器访问: 172.25.254.200:9999/status

  • #pid为当前pid号,process为当前进程号,nbproc和nbthread为一共多少进程和每个进程多少个线程 pid = 27134 (process #1, nbproc = 1, nbthread = 1)
  • #启动了多长时间
  • uptime = 0d 0h00m04s
  • #系统资源限制:内存/最大打开文件数/
  • system limits: memmax = unlimited; ulimit-n = 200029
  • #最大socket连接数/单进程最大连接数/最大管道数maxpipes
  • maxsock = 200029; maxconn = 100000; maxpipes = 0
  • #当前连接数/当前管道数/当前连接速率
  • current conns = 2; current pipes = 0/0; conn rate = 2/sec; bit rate = 0.000 kbps
  • #运行的任务/当前空闲率
  • Running tasks: 1/14; idle = 100 %
  • active UP: #在线服务器
  • backup UP: #标记为backup的服务器
  • active UP, going down: #监测未通过正在进入down过程
  • backup UP, going down: #备份服务器正在进入down过程
  • active DOWN, going up: #down的服务器正在进入up过程
  • backup DOWN, going up: #备份服务器正在进入up过程
  • active or backup DOWN: #在线的服务器或者是backup的服务器已经转换成了down状态
  • not checked: #标记为不监测的服务器
  • #active或者backup服务器人为下线的
  • active or backup DOWN for maintenance (MAINT)
  • #active或者backup被人为软下线(人为将weight改成0)
  • active or backup SOFT STOPPED for maintenance
  • session rate(每秒的连接会话信息):
  • Errors(错误统计信息):
  • cur:每秒的当前会话数量 :
  • Req:错误请求量
  • max:每秒新的最大会话数量
  • conn:错误链接量
  • limit:每秒新的会话限制量
  • Resp:错误响应量
  • sessions(会话信息):
  • Warnings(警告统计信息):
  • cur:当前会话量
  • Retr:重新尝试次数
  • max:最大会话量
  • Redis:再次发送次数
  • limit: 限制会话量
  • Total:总共会话量
  • Server(real server信息):
  • LBTot:选中一台服务器所用的总时间
  • Status:后端机的状态,包括UP和DOWN
  • Last:和服务器的持续连接时间
  • LastChk:持续检查后端服务器的时间
  • Wght:权重 Bytes(流量统计):
  • Act:活动链接数量
  • In:网络的字节输入总量
  • Bck:备份的服务器数量
  • Out:网络的字节输出总量
  • Chk:心跳检测时间
  • Dwn:后端服务器连接后都是DOWN的数量
  • Denied(拒绝统计信息):
  • Dwntme:总的downtime时间
  • Req:拒绝请求量 Thrtle:server 状态
  • Resp:拒绝回复量

HAProxy 四层负载

 对mysql实现四层负载:

#vim /etc/haproxy/haproxy.conf
listen dbserver
        bind *:3306
        mode tcp
        balance static-rr
        server db1 172.25.254.10:3306 check inter 2 fall 2 rise 5
        server db2 172.25.254.11:3306 check inter 2 fall 2 rise 5
#systemctl restart haproxy.service

#在后端服务器安装和配置mariadb服务
#webserver1
yum install mariadb-server -y
vim /etc/my.cnf
    [mysq1d]
    server-id=1
systemctl start mariadb
mysql -e "grant all on *.* to miky@'%' identified by 'miky' ;"

#webserver2
yum install mariadb-server -y
vim /etc/my.cnf
    [mysqld]
    server-id=2
systemctl start mariadb
mysql -e "grant all on *.* to miky@'%' identified by 'miky ' ;"

测试: 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值