Skip to Content
基于 Node.js 的分布式系统
book

基于 Node.js 的分布式系统

by Thomas Hunter
May 2025
Intermediate to advanced
390 pages
4h 55m
Chinese
O'Reilly Media, Inc.
Content preview from 基于 Node.js 的分布式系统

附录 A. 安装 HAProxy

HAProxy 是一种反向代理,,用于在请求传送到应用程序代码之前拦截请求。本书中使用它来卸载一些本不应由 Node.js 进程处理的任务。

如果你使用 Linux,你有几个选择。第一个选择是尝试使用发行版的软件安装程序直接安装haproxy 。这可能很简单 sudo apt install haproxy.不过,这样安装的 HAProxy 版本可能太旧。如果您的发行版提供的 HAProxy 版本早于v2(您可以在安装后运行 haproxy -v来检查,那么你就需要用另一种方法来安装。

Linux从源代码构建

第一种方法是从http://haproxy.org网站下载官方源代码包。然后,解压缩内容,编译应用程序,并执行安装。此方法还将安装man 网页,其中将提供有用的文档。运行这些命令下载并编译 HAProxy:

$ sudo apt install libssl-dev # Debian / Ubuntu
$ curl -O http://www.haproxy.org/download/2.1/src/haproxy-2.1.8.tar.gz
$ tar -xf haproxy-2.1.8.tar.gz
$ cd haproxy-2.1.8
$ make -j4 TARGET=linux-glibc USE_ZLIB=yes USE_OPENSSL=yes
$ sudo make install

如果在编译过程中出现错误,则可能需要使用发行版的软件包管理器来安装丢失的软件包。

Linux:安装预编译二进制文件

不过,如果你想避免编译软件的过程,可以选择下载预编译的二进制文件。我无法找到官方版本,所以这里有一个我在本地编译并上传到网络服务器的版本。运行以下命令下载、解压缩并安装预编译二进制文件:

$ curl -O https://thomashunter.name/pkg/haproxy-2.1.8-linux.tar.gz
$ tar -xf haproxy-2.1.8-linux.tar.gz
$ ./haproxy -v # test
$ sudo mv ./haproxy /usr/bin/haproxy
$ sudo chown root:root /usr/bin/haproxy

macOS:通过 Homebrew 安装

如果你使用 macOS,我强烈建议你安装Homebrew(如果你还没有安装)。Homebrew 通常会提供最新版本的软件,并包含现代版本的 HAProxy。使用 Homebrew,运行以下命令即可安装 HAProxy:

$ brew install haproxy@2.1.8
$ haproxy -v # test
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Distributed Systems with Node.js

Distributed Systems with Node.js

Thomas Hunter
TypeScript Cookbook

TypeScript Cookbook

Stefan Baumgartner
AWS 烹饪书

AWS 烹饪书

John Culkin, Mike Zazon

Publisher Resources

ISBN: 9798341659308