背景:本文源起于我所在单位的一个网络运维项目。
网络运行和维护工作中通常会通过进行网络带宽测试判断网络的运行状态。在我开展这个项目之前,我们主要使用两台装有Ixia的计算机进行测试:使用网线将其中一台计算机连接在网络核心交换机上;另一台则连接在需要进行速度测试的位置(一般在网络边缘)。这种工作方式主要有三个问题:
1、测速时需要两名运维人员配合同时开展
2、从机房的运维规章制度要求、运维成本等角度考虑,机房侧的电脑不能长期连接在核心交换上
3、进行测速时,运维人员必须携带装有Ixia的机器到达测速位置;同时Ixia需要一定的使用门槛,非运维人员无法配合开展测速工作。如果短时间内有多个地方需要进行测速,则需要运维人员携带设备连续赶赴多个地点,运维代价过高。
在服务器中部署网络带宽测试工具能很好的解决上述三个问题:
- 采用B/S架构,并设计一套方便易用的UI。使得非技术人员能够配合运维人员,通过浏览器使用测速工具;
- 服务器可以7*24小时运行,开展测速工作时不需要额外的运维人员蹲守在机房中;
- 进行测速时仅需一人(而且不必是技术人员)即可开展。
于是,搭建一套具有Ubuntu+PHP+Ngnix+Docker环境的服务器,并在此基础上部署开源的网络测速工具LibreSpeed正式提上了工作日程。
在正式部署到服务器前,我在两台PC机上进行了尝试:一台是ThinkCentre(i7-8700K,16G,128G+2T),另一台是单位采购的组装机(AMD Ryzen 7 5700G,16G,512G SSD),两台机器均重装为Ubuntu Server 22.04。经测试,两台PC机均能正常运行。测试过程中,我顺手将LibreSpeed的源代码进行了部分修改以适配于我的日常工作,同时也修改了前端页面UI,后文中会陆续提到。
提到这些是因为:在写这篇文章时,我是第三次搭建环境并部署LibreSpeed,也是第一次正式将环境和工具搭建、部署到真正的服务器中——这篇文章正是为了记录这一过程。文章中我会使用之前已经调试好的Docker镜像直接部署,也会简单解释如何新建并设置镜像(但是一定会有遗漏)。
以下是技术部分。
安装Ubuntu Server的过程不在过多描述,无非是下载镜像并刻录到U盘,然后启动服务器进入BIOS设置为从U盘安装介质启动,之后一路回车(当然还是注意下具体的设置内容,根据自己的需求进行调整即可)。
1 配置Ubuntu Server的国内源
Ubuntu Server软件源的位置:/etc/apt/sources.list
(1)对其进行备份:sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
(2)新建软件源文件,并对其进行编辑:sudo nano /etc/apt/sources.list
输入以下内容(华为源):
# deb cdrom:[Ubuntu 22.04.1 LTS _Jammy Jellyfish_ - Release amd64 (20220809.1)]/ jammy main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.huaweicloud.com/repository/ubuntu/ jammy main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.huaweicloud.com/repository/ubuntu/ jammy-updates main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirrors.huaweicloud.com/repository/ubuntu/ jammy universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy universe
deb http://mirrors.huaweicloud.com/repository/ubuntu/ jammy-updates universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://mirrors.huaweicloud.com/repository/ubuntu/ jammy multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse
deb http://mirrors.huaweicloud.com/repository/ubuntu/ jammy-updates multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://mirrors.huaweicloud.com/repository/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse
deb http://mirrors.huaweicloud.com/repository/ubuntu/ jammy-security main restricted
# deb-src http://security.ubuntu.com/ubuntu jammy-security main restricted
deb http://mirrors.huaweicloud.com/repository/ubuntu/ jammy-security universe
# deb-src http://security.ubuntu.com/ubuntu jammy-security universe
deb http://mirrors.huaweicloud.com/repository/ubuntu/ jammy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu jammy-security multiverse
# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.
之后保存+退出,运行命令进行更新操作:sudo apt-get upgrade && apt-get update
2 安装Docker
(1)安装必要的证书、依赖项:
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg lsb-release
(2)从官方Dockers仓库将GPG key添加到系统中:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
(3)将Docker仓库添加到APT源中:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
(4)用新添加的软件仓库中的 Docker 软件包更新软件包数据库,确保从 Docker 仓库而非默认的 Ubuntu 仓库进行安装:
apt-cache policy docker-ce
(5)最后,安装Docker并检查Docker的运行状态:
sudo apt install docker-ce
sudo systemctl status docker
如果已经正确安装了Docker,那么你应该能看到下面或者与之相似的输出结果:
webs@hldservers:~$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2024-04-11 08:15:02 UTC; 37s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 3721 (dockerd)
Tasks: 45
Memory: 32.9M
CPU: 660ms
CGroup: /system.slice/docker.service
└─3721 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock