高可用集群下的负载均衡(6):haproxy实现访问不同资源的负载均衡(日志、监控、acl访问控制的配置)
8.7am 2
1.haproxy的日志管理
【1】修改日至配置文件
[root@server2 haproxy]# pwd
/etc/haproxy
[root@server2 haproxy]# vim /etc/rsyslog.conf14 #Provides UDP syslog reception15 $ModLoad imudp #接受haproxy日志16 $UDPServerRun 51472 # Save boot messages also to boot.log73 local7.* /var/log/boot.log74 75 local2.* /var/log/haproxy.log # 添加local2,日志文件位置
[root@server2 haproxy]# systemctl restart rsyslog # 重启
【2】在server2下haproxy的配置文件中添加回环
[root@server2 haproxy]# vim haproxy.cfgbackend appbalance roundrobinserver app1 172.25.18.3:80 checkserver app2 172.25.18.4:80 checkserver buckup 127.0.0.1:8080 backup[root@server2 haproxy]# systemctl restart haproxy
【3】日志配置成功
可查看到日志内容:
[root@server2 haproxy]# vim haproxy.cfg
[root@server2 haproxy]# systemctl restart haproxy
[root@server2 haproxy]# > /var/log/messages
[root@server2 haproxy]# cat /var/log/messages
[root@server2 haproxy]# systemctl restart haproxy.service
[root@server2 haproxy]# cat /var/log/messages
二、haproxy实现不同类型不同调用?
【1】在server2中修改haproxy的配置文件
[root@server2 ~]# vi /etc/haproxy/haproxy.cfg
frontend mainbind *:80acl url_static path_beg -i /static /images /javascript /stylesheets #修改此处acl url_static path_end -i .jpg .gif .png .css .jsuse_backend static if url_staticdefault_backend app
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend staticbalance roundrobinserver static 172.25.14.4:80 check ## server3
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app#balance roundrobinbalance sourceserver app1 172.25.15.3:80 checkserver app2 172.25.15.4:80 check
------------------------------------------------------------------------
[root@server2 haproxy]# systemctl restart haproxy
【2】
[root@server2 haproxy]# vim haproxy.cfg
90 #balance roundrobin91 # balance source92 balance static-rr93 server app1 172.25.15.3:80 check94 server app2 172.25.15.4:80 check[root@server2 haproxy]# systemctl restart haproxy
3. 分别采用源路由算法和权重算法
[root@server2 html]# vi /etc/haproxy/haproxy.cfgfrontend main *:80acl blacklist scr 172.25.15.1block if blacklist
# acl url_static path_beg -i /static images /javascript /stylesheets
# acl url_static path_end -i .jpg .gif .png .css .js# acl read_request method GEF# acl read_request method HEAD# acl write_request method PUT# acl write_request method POST# use_backend static if url_static
# use_backend app if write_requestdefault_backend app[root@server2 haproxy]# systemctl reload haproxy
- 源路由算法
[root@server2 ~]# vim /etc/haproxy/haproxy.cfgbackend app# balance roudrobinbalance source# balance static-rrserver app1 172.25.18.3:80 check server app2 172.25.18.4:80 check [root@server2 ~]# systemctl restart haproxy
- 权重算法
[root@server2 ~]# vim /etc/haproxy/haproxy.cfgbackend appbalance static-rrserver app1 172.25.18.3:80 check weight 1server app2 172.25.18.4:80 check weight 2[root@server2 ~]# systemctl restart haproxy
用server1测试:
4.当server3,server4停用,访问backup备机
[root@server2 haproxy]# vim haproxy.cfg
[root@server2 haproxy]# systemctl reload haproxy
[root@server2 haproxy]# echo "sorry, please try again later" > /var/www/html/index[root@server3 ~]# systemctl stop httpd
[root@server3 ~]# ssh server4 systemctl stop httpd测试:
[root@server1 ~]# curl 172.25.18.2
sorry, please try again later
[root@server1 ~]# curl 172.25.18.2
sorry, please try again later
5.访问限制
【1】将172.25.18.250主机加入黑名单,不能访问server3,server4,当其访问时,会跳转到172.0.0.1:8000端口。
[root@server2 haproxy]# vim haproxy.cfgfrontend main *:80acl blacklist src 172.25.18.250block if blacklisterrorloc 403 http://127.0.0.1:8000[root@server2 haproxy]# systemctl reload haproxy
【2】限制用户访问指定的页面test.html
frontend main *:80acl blacklist src 172.25.18.250# block if blacklist# errorloc 403 http://127.0.0.1:8000acl testfile path /test.htmlhttp-request deny if testfile blacklist# acl url_static path_beg -i /static /images /javascript /stylesheets# acl url_static path_end -i .jpg .gif .png .css .js# use_backend static if url_staticdefault_backend app测试:
[root@server1 ~]# curl 172.25.18.2/test.html
test
[root@server1 ~]# curl 172.25.18.2/test.html
test
【3】访问限制,黑名单用户访问时,重定向到百度
[root@server2 haproxy]# vim haproxy.cfgrontend main *:80acl blacklist src 172.25.18.250# block if blacklist# errorloc 403 http://127.0.0.1:8000# acl testfile path /test.html# http-request deny if testfile blacklistredirect location http://www.baidu.com# acl url_static path_beg -i /static /images /javascript /stylesheets# acl url_static path_end -i .jpg .gif .png .css .js# use_backend static if url_staticdefault_backend app[root@server2 haproxy]# systemctl reload haproxy
6.用haproxy实现动静分离
server3发布静态页面,server4发布php动态页面
root@server3 ~]# mkdir /var/www/html/imgaes
[root@server3 ~]# cd /var/www/html/images
[root@server3 images]# ls
redhat.jpg
[root@server3 images]# systemctl start httpd
[root@server3 images]# ssh server4 systemctl start httpd[root@server4 ~]# vim /var/www/html/index.php
[root@server4 ~]# cat /var/www/html/index.php
<?php
phpinfo()
?>测试:
访问172.25.13.3/images/redhat.jpg
172.25.13.4/index.php
高可用集群下的负载均衡(6):haproxy实现访问不同资源的负载均衡(日志、监控、acl访问控制的配置)相关推荐
- 运维企业专题(11)RHCS高可用集群下MySql数据库与共享磁盘(单点写入、多点写入)的设置
实验环境 主机名 IP 服务 server1 172.25.6.1 ricci,luci, iscsi,mysql-server server2 172.25.6.2 ricci,iscsi,mysq ...
- Hadoop高可用集群下namenode格式化失败问题解决
Hadoop高可用集群下namenode格式化失败问题解决 输入hdfs namenode -format报如下错误 解决方法: 1.在zookeeper目录下执行./bin/zkServer.sh ...
- 高可用集群下的负载均衡(8):pacemaker + corosync + haproxy 实现高可用
实验环境 server1 和 server2 是调度器,server3 和 server4 是服务器 [1]调度器server1 server2 关闭 keepalived 和 httpd,并打开pc ...
- 高可用集群下的负载均衡(7):haproxy + keepalived 实现高可用负载均衡
实验环境 server1 和 server2 是调度器,server3 和 server4 是服务器 一.调度器中进行配置 haproxy+keepalived server1 与server2 均要 ...
- 高可用集群下的负载均衡(5):haproxy的动静分离与读写分离
一.haproxy动静分离 实验环境: server2(haproxy):安装 haproxy server3(静态服务器):在apache的默认发布目录下创建一个 images目录,并放一张图片 s ...
- Keepalived 高可用集群的使用
Keepalived 高可用集群的使用 Keepalived 高可用集群的使用 Keepalived介绍 Keepalived 服务的三个重要功能 Keepalived 高可用故障切换转移原理(重点) ...
- linux系统下对网站实施负载均衡+高可用集群需要考虑的几点
随着linux系统的成熟和广泛普及,linux运维技术越来越受到企业的关注和追捧.在一些中小企业,尤其是牵涉到电子商务和电子广告类的网站,通常会要求作负载均衡和高可用的Linux集群方案. 那么如何实 ...
- LVS+Keepalived-DR模式负载均衡高可用集群
LVS+Keepalived DR模式负载均衡+高可用集群架构图 工作原理: Keepalived采用VRRP热备份协议实现Linux服务器的多机热备功能. VRRP,虚拟路由冗余协议,是针对路由器的 ...
- 负载均衡集群、高可用集群详解,DR、NAT超详细搭建步骤
集群概述 流量相关: PV:PV(page view)即页面浏览量或点击量,是衡量一个网站或网页用户访问量.具体的说,PV值就是所有访问者在24小时(0点到24点)内看了某个网站多少个页面或某 ...
最新文章
- python答辩结束语_Beta答辩总结
- Spring中的JDBC操作
- 计算机初级学哪个公需课,西安职称评审申报你遇到以下问题了吗?
- Django基于JWT实现微信小程序的登录和鉴权
- 云计算和并行计算的关系
- TIMING_03 时序分析原理
- Jmeter 老司机带你一小时学会Jmeter
- [AHOI2009]维护序列
- GStreamer 编写一个简单的MP3播放器
- 河南城镇化争植“智慧”基因
- 四轮定位和四轮动平衡有什么区别?
- shell脚本简单切割字符串
- Kotlin快速入门文档
- “防护左移”赋能开发人员,实时修复代码安全问题
- 5G时代|淘宝直播高画质低延时技术探索
- GPU编程与CG语言之阳春白雪下里巴人.pdf 分享
- sql1428N错误
- 1_01_GLib库入门与实践_GLib库简介
- 2023年西南交通大学马克思主义理论考研上岸前辈备考经验
- 3D游戏引擎入门课程——场景管理