负载均衡入门: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

宏智树AI——ChatGPT学术版驱动,一站式论文写作智能解决方案

宏智树AI——ChatGPT学术版驱动,一站式论文写作智能解决方案

在学术创作日益精细化、规范化的今天,每一位科研学子、研究者都曾面临论文写作的多重困境:大纲难立、文献繁杂、数据难析、格式繁琐,耗费大量时间在机械性工作上,难以聚焦核心研究价值。宏智树AI应运而生,作为一款专为论文写作量身打造的学术写作辅助平台,依托ChatGPT学术版模型驱动,搭载先进AI5.0技术架构,构建起覆盖“大纲生成到定稿答辩”的全流程学术智能解决方案,重新定义学术创作效率与质量边界,让每一份学术成果都能高效落地、彰显专业。 宏智树AI的核心竞争力,源于其深耕学术场景的技术沉淀与功能布局。不同于通用型AI写作工具,平台以ChatGPT学术版为核心驱动,结合AI5.0技术架构的迭代优势,针对学术写作的逻辑特性、规范要求进行千万级学术语料训练,精准适配各学科论文写作范式,实现“智能赋能不越界,专业辅助不缺位”,既保留研究者的核心思考,又高效解决写作中的各类痛点,让学术创作更轻松、更合规、更具深度。 硬核技术底座:ChatGPT学术版+AI5.0,解锁学术智能新高度 技术是学术辅助的核心支撑,宏智树AI以双重技术优势,筑牢学术创作的智能根基。依托ChatGPT学术版模型的强大

2026年医疗AI的可信革命全栈实现(上)

2026年医疗AI的可信革命全栈实现(上)

当AI Agent学会说“我不知道” 主题关键词:Python、向量数据库、医疗AI Agent、贝叶斯网络、NVIDIA 2026 适用对象:医疗信息化团队、算法工程师、医院CIO/CTO、科研与产品团队 核心判断:医疗AI下一阶段的竞争焦点,不是更会“说”,而是更会“量化不确定性、约束错误传播,并在必要时把决定权交还给人类专家”。 执行摘要 本文围绕一个核心命题展开:在2026年的医疗AI部署中,真正稀缺的并不是生成文本的能力,而是系统对“不确定性”的治理能力。大语言模型擅长读懂语言、整合文档、生成解释,却不天然擅长在证据不足时保持克制。贝叶斯网络与贝叶斯增强方法提供的,正是这种“认知刹车”。 工程上,本文给出一套完整实现路径:以Python作为主开发语言,以结构化患者工件作为中间表示,以Milvus/Qdrant/pgvector或FAISS/cuVS承接证据层,以pgmpy/PyMC/NumPyro承接概率推理层,

[特殊字符] CoPaw(阿里龙虾AI)Windows 安装及应用指南

1. 什么是 CoPaw? CoPaw 是阿里云通义实验室推出的个人 AI 智能体,可以在电脑上帮你处理各种任务(如信息整理、定时提醒、文件处理等),并支持接入钉钉、飞书、QQ 等聊天软件,实现 24 小时在线办公助手。 2. 系统要求 * 操作系统:Windows 10 或 Windows 11(64位) * Python:3.9 或更高版本(推荐 3.10) * 内存:建议 4GB 以上(运行时占用约 200~500MB) * 磁盘空间:至少 500MB 可用空间 * 网络:需要能够访问外网(用于调用大模型 API) 3.

这10款AI剪辑神器,彻底颠覆视频创作!

这10款AI剪辑神器,彻底颠覆视频创作!

AI的发展正在逐步向各行各业渗透,特别是软件行业。有人预测,未来几乎所有的应用软件都需要推倒重新写一遍,必须要让软件和AI深度结合。 除了文案类软件、图片处理类软件,视频剪辑软件也开始全面拥抱AI了。今天,就给大家分享10款AI剪辑工具,绝对颠覆你对剪辑的认知,极大地提升你的剪辑效率。 1、剪映(字节跳动旗下软件) 特色:零门槛操作,AI自动字幕、一键成片模板,10分钟产出抖音热门视频;深度适配抖音,内置热门音效、贴纸、BGM库,支持“拍同款”特效同步;多端协同,手机/PC端进度实时同步,适合跨设备创作;用户基数最大(超1亿月活)、功能迭代最快。 场景:个人Vlog、商家促销视频、热点跟拍等。 2、腾讯智影(云端智能创作) 特色:云端协作、浏览器直接操作,支持多人实时编辑;支持AI全链路,文本→配音→数字人播报→视频自动生成,