准备环境
三台服务员 一台做haproxy 代理
12.18.130.138 做nginx 页面发布服务器
12.18.130.139 做nginx 页面发布服务器
12.18.130.137 做haproxy 代理
一、nginx 1 部署配置haproxy代理页面(rs1)
1、部署web服务
# yum -y install nginx
1.1 修改nginx1 12.18.130.139 配置文件配置页面
# vim /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name _;
location / {
root /wed/xxy;
index index.html index.htm;
}
}
1.2 创建发布目录
# mkdir -pv /wed/xxy
1.3 写发布目录内容
# vim /wed/xxy/index.html
1.4 重启nginx
# systemctl restart nginx
二、在nginx2上部署haproxy代理页面 (rs2)
1、部署web服务
# yum -y install nginx
1.1 修改nginx1 12.18.130.138 配置文件配置页面
# vim /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name _;
location / {
root /wed/xxy;
index index.html index.htm;
}
}
1.2 创建发布目录
# mkdir -pv /wed/xxy
1.3 写发布目录内容
# vim /wed/xxy/index.html
1.4 重启nginx
# systemctl restart nginx
三、配置haproxy 代理服务器
12.18.130.137 做haproxy 代理
1、安装haproxy
# yum install haproxy -y
2、修改配置haproxy
# cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak
# vim /etc/haproxy/haproxy.cfg
# cat /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
listen stats
bind *:1314
stats enable
stats refresh 30s
stats hide-version
stats uri /stats
stats realm Haproxy\ stats
stats auth kunkun:year2.5
stats admin if TRUE
frontend web
mode http
bind *:80
default_backend httpservers
backend httpservers
balance roundrobin
server http1 12.18.130.139:80 maxconn 2000 weight 1 check inter 1s rise 2 fall 2
server http2 12.18.130.140:80 maxconn 2000 weight 1 check inter 1s rise 2 fall 2
3、重启haproxy
# systemctl start haproxy
四、客户端访问 地址
12.18.130.137