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

Llama-3.2-3B效果实测:Ollama部署对比Qwen2-1.5B在摘要任务中的BLEU提升

Llama-3.2-3B效果实测:Ollama部署对比Qwen2-1.5B在摘要任务中的BLEU提升 1. 为什么这次实测值得你花三分钟看完 你是不是也遇到过这样的问题:手头有个长文档要压缩成一段精炼摘要,但试了几个开源小模型,要么漏掉关键信息,要么生成内容啰嗦重复,甚至把原文意思都改了?我最近也卡在这个环节很久——直到把Llama-3.2-3B和Qwen2-1.5B放在同一套Ollama环境里,用完全相同的测试集、提示词和评估方式跑了一轮摘要任务。 结果很意外:Llama-3.2-3B的BLEU-4分数比Qwen2-1.5B高出6.8分(从32.1到38.9),而且生成内容更紧凑、事实一致性更强。这不是理论值,是我在本地MacBook Pro M2上实打实跑出来的数据。整套流程不需要GPU,不装Docker,不用写一行训练代码,只靠Ollama一条命令就能启动服务。 这篇文章不讲参数、不聊架构,就带你走一遍:怎么用Ollama快速拉起两个模型、怎么设计公平的摘要测试、怎么用Python脚本自动算BLEU、以及最关键的——哪些场景下Llama-3.2-3B真的比Qwen2-1

FLUX.1-dev创意工作流:从Midjourney迁移指南+Prompt工程适配最佳实践

FLUX.1-dev创意工作流:从Midjourney迁移指南+Prompt工程适配最佳实践 如果你是从Midjourney转向本地部署的创作者,或者正在寻找一个画质顶尖、永不崩溃的AI绘图方案,那么这篇文章就是为你准备的。 Midjourney以其出色的艺术表现力,成为了许多人的AI绘图启蒙工具。但你是否也遇到过这些问题:生成次数有限制、排队等待时间长、无法深度定制生成参数、或者对生成内容的隐私性有顾虑?当你的创作需求从“玩一玩”升级到“生产力”时,一个稳定、私密、可控的本地化方案就显得尤为重要。 今天,我们将深入探讨如何将你的创意工作流,从Midjourney平滑迁移到FLUX.1-dev旗舰版。这不仅仅是一个工具替换,更是一次创作能力的全面升级。我们将重点解决两个核心问题:如何快速上手这个强大的本地系统,以及如何将你熟悉的Midjourney Prompt技巧,完美适配到FLUX模型上,让你无缝衔接,甚至获得更惊艳的成果。 1. 为什么选择FLUX.1-dev作为你的下一站? 在深入迁移细节之前,我们先来了解一下这个“新家”到底强在哪里。你拿到的这个FLUX.1-de

虚拟世界的AI魔法:AIGC引领元宇宙创作革命

虚拟世界的AI魔法:AIGC引领元宇宙创作革命

云边有个稻草人-ZEEKLOG博客——个人主页 热门文章_云边有个稻草人的博客-ZEEKLOG博客——本篇文章所属专栏 ~ 欢迎订阅~ 目录 1. 引言 2. 元宇宙与虚拟世界概述 2.1 什么是元宇宙? 2.2 虚拟世界的构建 3. AIGC在元宇宙中的应用 3.1 AIGC生成虚拟世界环境 3.2 AIGC生成虚拟角色与NPC 3.3 AIGC创造虚拟物品与资产 4. AIGC在虚拟世界与元宇宙的技术实现 4.1 生成式对抗网络(GANs)在元宇宙中的应用 4.2 自然语言处理(NLP)与虚拟角色的对话生成 4.3 计算机视觉与物理引擎 5. 持续创新:AIGC与元宇宙的未来趋势 5.1 个人化与定制化体验 5.

【AIGC】大模型面试高频考点19:常见的17种RAG方案

【AIGC】大模型面试高频考点19:常见的17种RAG方案

RAG技术全景解析:从基础分块到自适应多模态检索 * 一、基础分块与语义优化 * 1. Simple RAG(简单切块) * 2. Semantic Chunking(语义切块) * 3. Context Enriched Retrieval(上下文增强检索) * 4. Contextual Chunk Headers(上下文标题) * 二、检索优化与重排序 * 1. Document Augmentation(文档增强) * 2. Query Transformation(查询转换) * 3. Reranker(重排序) * 4. RSE(Re-ranking with Semantic Expansion) * 三、智能路由与自反思机制 * 1. Feedback Loop(反馈闭环) * 2. Adaptive RAG(