HAproxy簡單配置

栏目: 服务器 · 发布时间: 8年前

内容简介:HAproxy簡單配置

用途: TCP/HTTP反向代理,四层负载均衡,适合高可用环境。 Linux6.4版本后haproxy已随base仓库收录进来。

主程序:/usr/sbin/haproxy
主配置文件:/etc/haproxy/haproxy.cfg
启动文件:/usr/lib/systemd/system/haproxy.service

安装:yum -y install haproxy调度器实现一个负载均衡,两台客户端安装httpd/nginx和mariadb/mysql(实验环境注意关闭iptables/firewalld和selinux),并建议时间全部同步(chrony服务或直接ntpdate 172.18.0.1/172.16.0.1)

HAproxy簡單配置

配置haproxy配置文件,vim /etc/haproxy/haproxy.cfg (配置之前好习惯把配置文件备份),定义frontend前端和backend后端两个字段

frontend  myweb *:80     (frontend后名字要唯一,绑定的地址和要监听的端口)
default_backend     realserver  

backend realserver  (backend后端服务器名字也要唯一,并要和上面 default_backend定义相同
balance     roundrobin        (调度算法,默认轮询)
server      web1 172.18.250.238:80 check   (负载均衡web1,健康检查)
server      web2 172.18.251.93:80 check      (负载均衡web2,健康检查)

随后启动haproxy服务,可用ss -tnlp查看80端口是否监听,然后访问调度器IP测试轮询后台web页面效果。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Nature of Code

The Nature of Code

Daniel Shiffman / The Nature of Code / 2012-12-13 / GBP 19.95

How can we capture the unpredictable evolutionary and emergent properties of nature in software? How can understanding the mathematical principles behind our physical world help us to create digital w......一起来看看 《The Nature of Code》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具