【集群】haproxy负载均衡


前言

本博客内容仅为记录博主思路,仅供参考,一切以自己实践结果为准。


一、haproxy负载均衡

1.0 架构概况

作用 IP地址 安装服务
主负载均衡器 192.168.13.10 haproxy-1.5.19
节点服务器1 192.168.13.20 httpd
节点服务器2 192.168.13.30 httpd
日志收集器 192.168.13.40 ipvsadm/keepalived

1.1 负载均衡调度器

systemctl stop firewalld
setenforce 0
yum install -y pcre-devel bzip2-devel gcc gcc-c++ make
上传压缩包
tar zxvf haproxy-1.5.19.tar.gz
cd haproxy-1.5.19/
make TARGET=linux2628 ARCH=x86_64
make install

mkdir /etc/haproxy
cp examples/haproxy.cfg /etc/haproxy/
vim /etc/haproxy/haproxy.cfg
	4行:log /dev/log    local0
	5行:log /dev/log    local1 notice
	
	8行:#chroot /usr/share/haproxy
	26行以下:全部删除
	26-30行:添加节点服务器信息
		listen  webcluster 0.0.0.0:80
        option httpchk GET /index.html
        balance roundrobin
        server inst1 192.168.13.20:80 check inter 2000 fall 3
        server inst1 192.168.13.30:80 check inter 2000 fall 3

cp /opt/haproxy-1.5.19/examples/haproxy.init /etc/init.d/haproxy
chmod +x /etc/init.d/haproxy
ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
service haproxy start

1.2 节点服务器

systemctl stop firewalld
setenforce 0
yum install httpd -y
echo 'this is web1!' >/var/www/html/index.html
systemctl start httpd

另一台服务器重复操作

二、结语

  • 心态要稳,错了慢慢排
  • 配置文件中的option httpchk GET /index.html这一行,对应着节点服务器最后默认的文件类型,必须对应上,否则返回503

猜你喜欢

转载自blog.csdn.net/H875035681/article/details/125224691