haproxy 重新配7.5虚拟机
server1
yum install -y haproxy
rpm -qpl 包 查看安装生成的文件
vim /etc/haproxy/haproxy.cfg 配置文件
安装好会生成用户haproxy
vim /etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
#main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main
bind *:80
default_backend webserver
#---------------------------------------------------------------------
#static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend webserver
balance roundrobin
server web1 172.25.18.2:80 check
server web2 172.25.18.3:80 check
轮询机制
server2 3
yum install -y httpd
写发布文件
systemctl start httpd
主机
curl 172.25.18.1
日志
server1
vim /etc/rsyslog.conf
local7.* /var/log/boot.log
下面添加
local2.* /var/log/haprox.log
systemctl restart rsyslog.service
ll /var/log/haproxy.log查看
vim /etc/haproxy/haproxy.cfg
添加
stats uri /admin/stats
monitor-uri /monitoruri
systemctl restart haproxy.service
测试
主机
浏览器
172.25.18.1/admin/stats
172.25.18.1/monitoruri显示 200 ok 就是正确
server1
添加用户和密码
vim /etc/haproxy/haproxy.cfg
stats admin:westos
重启服务
主机
浏览器
172.25.18.1/admin/stats
server1
stats refresh 5s 每过5s刷新
禁止黑名单
frontend下面
bind *:80下面添加
acl blacklist src 172.25.18.250
http-request deny if blacklist
errorloc 403 http://172.25.18.1:8080/index.html
将错误返回到本机的8080端口
systemctl restart haproxy
server1
yum install -y httpd
写发布文件
vim /etc/httpd/conf/httpd.conf 修改端口因为80被haproxy占用
Listen 8080
systemctl start httpd
主机访问
172.25.18.1
动静请求分离
vim /etc/haproxy/haproxy.conf
errorloc 下面
use_backend dynamic if {path_end .php }
default_backend static
backend dynamic
ba不动
删除web2
backend static
ba照搬
web2配置
注释掉黑名单
systemctl restart haproxy
server2 3
yum install -y php
写php发布文件
server2 <?
phpinfo()
?>
server3 server3
systemctl restart httpd
主机测试
172.25.18.1/index.php
172.25.18.1
读写操作
acl read method HEAD
acl read method GET
acl write method POST
acl write method PUT
注释掉 use_backend dynamic if {path_end .php }
use_backend dynamic if write
use_backend static if read
systemctl restart haproxy
systemctl restart httpd
找upload放在server2 /var/www/html下
删除原来的发布文件php
将upload里面的文件移出来
mv upload/*
chmod 777 upload
vim upload_file.php
修改文件2000000
scp -r index.php upload upl_f server3:/var/www/html 跟server2一样的操作
测试
主机
172.25.18.1/index.php
上传图片测试
可以写入名字区分