企业实战--Haproxy(使用Haproxy实现读写分离)

1.配置haproxy服务器

在server1:

[root@server1 html]# vim /etc/haproxy/haproxy.cfg 

 61 # main frontend which proxys to the backends
 62 #---------------------------------------------------------------------
 63 frontend  westos *:80
 64     acl url_static       path_beg       -i /images
 65     acl url_static       path_end       -i .jpg .gif .png
 66     acl read method GET
 67     acl read method HEAD                #两个read write 只用一个就行
 68     acl write method PUT
 69     acl write method POST
 70     #acl westos.org hdr_beg(host)       -i westos.org
 71     #acl 172.25.63.1 hdr_beg(host)      -i 172.25.63.1 
 72     #errorloc 403 http://172.25.63.1:8000
 73     use_backend app          if write                   #如果是写的话就是动态页面
 74     default_backend             static                  #默认为静态页面
 75 #     redirect code 301 location http://www.westos.org if westos.org              #以westos.org访问就自动重定向到www.we    stos.org
 76 #    redirect code 301 location http://www.westos.org if 172.25.63.1             #以172.25.63.1访问就自动重定向到www.w    estos.org

2.配置后端服务器

在server2和server3做同样的操作:

[root@server2 ~]# yum install php -y
[root@server2 ~]# cd /var/www/html/
[root@server2 html]# ls
index.html  index.php  upload_file.php	upload			#放入测试脚本以及文件目录

[root@server2 html]# vim upload_file.php 
  5 && ($_FILES["file"]["size"] < 2000000))

[root@server2 html]# chmod 777 upload_file.php 
[root@server2 html]# systemctl restart httpd

3.测试

server1重启haproxy后:

[root@server1 html]# systemctl restart haproxy

在客户端浏览器输入 172.25.63.1/index.php 进行写测试:

在这里插入图片描述在这里插入图片描述在客户端浏览器输入 172.25.63.1/images 进行读测试:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值