前提准备
node1:192.168.1.100 haproxy前段调度器
node2、node3是后端真实服务器
node2:192.168.1.101
node3:192.168.1.102
一:先在node2和node3上准备好web服务,并保障可以访问
node2:yum install -y httpd #安装httpd
echo web1 >/var/www/html/index.html #创建一个web页面为web1
systemctl start httpd #启动web服务
iptables -F #清空防火墙
setenforce 0 #关闭selinux
node3:在node2上执行同node1相同的操作。只是将web界面的web1改成web2(在实际应用中node1和node2提供的web服务应该是完全一致的,但是这里为了好辨认轮询效果才进行区分)
yum install -y httpd #安装httpd
echo web2 >/var/www/html/index.html #创建一个web页面为web1
systemctl start httpd #启动web服务
iptables -F #清空防火墙
setenforce 0 #关闭selinux
二:在node1上配置haproxy
yum install -y haproxy 安装HAproxy
vim /etc/haproxy/haproxy.cfg 编辑配置文件
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
user haproxy
group haproxy
pidfile /var/run/haproxy.pid
maxcoun 4000
daemon
defaults
mode http
log global
retries 3
frontend main *:80
use_backend webserver
backend webserver
balance roundrobin
server web1 192.168.1.101:80 check
server web2 192.168.1.102:80 check
listen admin_stats
bind 0.0.0.0:1080
mode http
option httplog
log 127.0.01 local0 err
maxconn 10
stats refresh 30s
stats uri /stats
stats auth admin:admin
stats hide-version
#通过简单轮询到后台node2和node3上,并开启haproxy的web界面监控功能