负载均衡入门:HAProxy 双 Web 节点集群配置与验证

HAProxy安装

为了更好的快速掌握 HAProxy 的安装和使用,我们以一个案例来进行讲解。首先根据以下要求进行虚拟机的克隆。

编号主机IP软件系统
1lb01192.168.72.100haproxyredhat 9.7
2web1192.168.72.10nginxredhat 9.7
3web2192.168.72.20nginxredhat 9.7

1.1 搭建Web1

1、克隆一台虚拟机,初始化虚拟机(ip ,主机名,关闭防火墙,selinux)

[root@node1 ~]# hostnamectl set-hostname web1&&bash
[root@web1 ~]# systemctl disable firewalld.service 
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".
[root@web1 ~]# setenforce 0
[root@web1 ~]# sed -i "s/SELINUX=enforcing/SELINUX=permissive/" /etc/selinux/config 

下载nginx

[root@web1 ~]# dnf install nginx -y
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.

BaseOS                                                                                      2.7 MB/s | 2.7 kB     00:00    
AppStream                                                                                   3.1 MB/s | 3.2 kB     00:00    
Package nginx-2:1.20.1-22.el9.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

修改欢迎页

[root@web1 ~]# echo "$(hostname) $(hostname -I)" > /usr/share/nginx/html/index.html

[root@web1 ~]# echo "health" > /usr/share/nginx/html/test.html

启动nginx并测试

[root@web1 ~]# systemctl start nginx
[root@web1 ~]# curl localhost
web1 192.168.72.10 
[root@web1 ~]# curl 192.168.72.10 
web1 192.168.72.10 
[root@web1 ~]# 


1.2 搭建Web2

1、克隆一台虚拟机,初始化虚拟机(ip ,主机名,关闭防火墙,selinux)

[root@node1 ~]# hostnamectl set-hostname web2&&bash
[root@web2 ~]# systemctl disable firewalld.service 
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".
[root@web2 ~]# setenforce 0
[root@web2 ~]# sed -i "s/SELINUX=enforcing/SELINUX=permissive/" /etc/selinux/config 

下载nginx

[root@web2 ~]# dnf install nginx -y
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.

BaseOS                                                                                      2.7 MB/s | 2.7 kB     00:00    
AppStream                                                                                   3.1 MB/s | 3.2 kB     00:00    
Package nginx-2:1.20.1-22.el9.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@web2 ~]# 
 

修改欢迎页,创建健康检测页面

[root@web2~]# echo "$(hostname) $(hostname -I)" > /usr/share/nginx/html/index.html

[root@web2 ~]# echo "health" > /usr/share/nginx/html/test.html

启动nginx并测试

[root@web2 ~]# systemctl start nginx
[root@web2~]# curl localhost
web1 192.168.72.20
[root@web2~]# curl 192.168.72.20
web1 192.168.72.20
[root@web2 ~]# 

1.3 搭建HAProxy

1、克隆一台虚拟机,初始化虚拟机(ip ,主机名,关闭防火墙,selinux)

[root@node1 ~]# hostnamectl set-hostname lb1&&bash
[root@lb1 ~]# systemctl disable firewalld.service 
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".
[root@lb1 ~]# setenforce 0
[root@lb1 ~]# sed -i "s/SELINUX=enforcing/SELINUX=permissive/" /etc/selinux/config 

下载haproxy

[root@lb1 ~]# dnf install haproxy -y
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.

BaseOS                                                                                      2.7 MB/s | 2.7 kB     00:00    
AppStream                                                                                   3.1 MB/s | 3.2 kB     00:00    
Dependencies resolved.
============================================================================================================================
 Package                    Architecture              Version                            Repository                    Size
============================================================================================================================
Installing:
 haproxy                    x86_64                    2.4.22-4.el9                       AppStream                    2.2 M

Transaction Summary
============================================================================================================================
Install  1 Package

Total size: 2.2 M
Installed size: 6.6 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                    1/1 
  Running scriptlet: haproxy-2.4.22-4.el9.x86_64                                                                        1/1 
  Installing       : haproxy-2.4.22-4.el9.x86_64                                                                        1/1 
  Running scriptlet: haproxy-2.4.22-4.el9.x86_64                                                                        1/1 
  Verifying        : haproxy-2.4.22-4.el9.x86_64                                                                        1/1 
Installed products updated.

Installed:
  haproxy-2.4.22-4.el9.x86_64                                                                                               

Complete!
 

验证haproxy

[root@lb1 ~]# haproxy -v
HAProxy version 2.4.22-f8e3218 2023/02/14 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2026.
Known bugs: http://www.haproxy.org/bugs/bugs-2.4.22.html
Running on: Linux 5.14.0-570.12.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Apr 4 10:41:31 EDT 2025 x86_64

查看配置文件路径

[root@lb1 ~]# rpm -qc haproxy
/etc/haproxy/haproxy.cfg                # 核心配置文件路径
/etc/logrotate.d/haproxy
/etc/sysconfig/haproxy                # 启动选项所在文件

修改配置文件

[root@lb1 ~]# cp /etc/haproxy/haproxy.cfg{,.bak}
[root@lb1 ~]# vim /etc/haproxy/haproxy.cfg
[root@lb1 ~]# cat /etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   https://www.haproxy.org/download/1.8/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    # to have these messages end up in /var/log/haproxy.log you will
    # need to:
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    stats socket /var/lib/haproxy/stats

    ssl-default-bind-ciphers PROFILE=SYSTEM
    ssl-default-server-ciphers PROFILE=SYSTEM

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
    maxconn                 3000

frontend main
    bind *:80
    default_backend             webcluster

backend webcluster
    balance     roundrobin
    option httpchk GET /test.html
    server      web1 192.168.72.10:80 check inter 2000 rise 2 fall 2 weight 2
    server      web2 192.168.72.20:80 check inter 2000 rise 2 fall 2 weight 2
listen admin_status
    bind *:9129
    stats refresh 30s
    stats uri /admin
    stats auth admin:admin123
    stats hide-version
    stats admin if TRUE

启动haproxy


[root@lb1 ~]# systemctl start haproxy

[root@lb1 ~]# systemctl stop firewalld

打开浏览器访问

http://192.168.72.100:9129/admin

输出后,会弹出输入用户名和密码的窗口,我们输入在配置文件中配置的用户名(admin)和密码(admin123)后就可以登录成功。登录成功后就可以看到如下的界面了。

Read more

OpenCode 免费模型深度评测:四大开源模型场景化对比与选型指南

OpenCode 免费模型深度评测:四大开源模型场景化对比与选型指南

在开源大语言模型(LLM)生态中,OpenCode 凭借其多样化的免费模型矩阵(如 Trinity Large Preview、Big Pickle、MiniMax M2.5 Free、GPT-5 Nano)吸引了开发者与企业的广泛关注。本文将从技术架构、性能表现、适用场景等维度,深度解析这四大模型的差异化优势,并提供选型建议。 1. Trinity Large Preview:超大规模稀疏模型的“创意引擎” 开发者:Arcee AI 核心架构:400B 参数稀疏混合专家(MoE)架构,每 token 仅激活 13B 参数 上下文窗口:512K tokens(约 75 万字) 适用场景:创意写作、

By Ne0inhk
【工创赛2025-智能物流搬运塔吊方案视觉开源(2分15秒)】西安理工大学工程训练中心

【工创赛2025-智能物流搬运塔吊方案视觉开源(2分15秒)】西安理工大学工程训练中心

一、前言         本文也是我的第一篇ZEEKLOG博客,主要内容是记录一下2025年工训赛的参赛过程,讲解一下与louisaerdusai学长一起开发的智能物流视觉方案。主要内容为:实现函数、串口与下位机的通讯和整个实现流程,希望我们的经验能够帮助大家。         本文为视觉算法开源,其他部分开源请移步:【工创赛2025-塔吊结构方案开源(2分15秒)】西安理工大学工程训练中心-ZEEKLOG博客 二、本届视觉设计由来         我在今年校赛阶段参加的是智能救援赛道,由于我们机械设计的过于复杂和一些其他原因,机械结构的反复修改,最终没有尽快实现视觉与机械结构联调,导致我们在校赛就遗憾出局。在校赛遗憾结束后,我有幸加入了学长的队伍,在重新了解了物流搬运的视觉流程后,发现使用Jetson Nano运行OpenCV算法算是更加灵活的选择。但是在省赛是我也发现很多队伍采用的OpenMV方案也可以流畅运行,就我使用这些微型视觉模块的经验来说,我推荐使用MaixCAM pro来实现简单的算法,但是不得不说OpenCV的算法实现是更加通用且灵活的,同时使用OpenCV算

By Ne0inhk
git笔记之默认使用vim以及修改倒数第二次的commit提交信息到远程

git笔记之默认使用vim以及修改倒数第二次的commit提交信息到远程

git笔记之默认使用vim以及修改倒数第二次的commit提交信息到远程 code review! 文章目录 * git笔记之默认使用vim以及修改倒数第二次的commit提交信息到远程 * 一.默认使用vim方法之一:使用 `git config` 命令 * 二.修改倒数第二次的commit提交信息到远程 * 操作步骤 * 第一步:启动交互式变基 (Interactive Rebase) * 第二步:选择要修改的提交 * 第三步:修改提交信息 * 第四步:强制推送到远程 * 总结流程图 * 常见问题:如果在 Rebase 过程中遇到冲突怎么办? 一.默认使用vim方法之一:使用 git config 命令 这是最直接且专门针对 Git 的设置方法。打开的终端(Terminal)或 Git Bash,运行以下命令: git config --global core.editor "

By Ne0inhk

OpenClaw 最新功能大揭秘!2026年最火开源AI Agent迎来史诗级升级,手机变身AI终端不是梦

OpenClaw 最新功能大揭秘!2026年最火开源AI Agent迎来史诗级升级,手机变身AI终端不是梦 大家好,我是Maynor。最近开源社区彻底炸锅了——OpenClaw(前身Clawdbot/Moltbot)又一次刷屏!这个能真正“干活”的本地AI助手,在3月2日刚刚发布v2026.3.1版本,紧接着2月底的v2026.2.26也是里程碑式更新。 从外部密钥管理、线程绑定Agent,到Android深度集成、WebSocket优先传输……OpenClaw正在把“AI常驻员工”从概念变成现实。 今天这篇图文并茂的干货,带你一口气看懂最新功能、安装上手和实战价值!

By Ne0inhk