用 Docker 安装 Smokeping
今天感觉网络有点波动,于是又想搭一个Smokeping。记得它有Docker版本的,可以一把梭,无需头疼各种依赖和报错。很简单,只需8步。
- 2022-10-15 更新了修改resolve.conf的正确方式
1. 安装 Docker Engine
Debian
设置 Docker 软件源
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Add the repository to Apt sources:
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
安装 Docker Engine 组件
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
运行演示程序看是否安装成功
sudo docker run hello-world
CentOS
删除旧组件
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
安装 yum-utils ,设置 Docker 软件源。
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
安装 Docker Engine 组件
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
开启 Docker 服务
sudo systemctl start docker
运行演示程序,看安装是否成功
sudo docker run hello-world
Docker Engine 在其他操作系统,其他安装方式参考官网。
2 安装 Docker-compose
Ubuntu 和 Debian
sudo apt-get update
sudo apt-get install docker-compose-plugin
CentOS
sudo yum update
sudo yum install docker-compose-plugin
$ docker compose version
Docker Compose version v2.21.0
2. 获取镜像,修改镜像,创建docker-compose配置文件
创建目录/usr/local/smokeping
来存放本项目相关文件。
mkdir /usr/local/smokeping
cd /usr/local/smokeping
nano docker-compose.yml
输入以下内容,完成后按Ctrl+X,再按Y,回车。
version: "2.1"
services:
smokeping:
image: ghcr.io/linuxserver/smokeping
container_name: smokeping
hostname: GZ_Telecom
environment:
- PUID=1000
- PGID=1000
- TZ=Asia/Shanghai
volumes:
- ./config:/config
- ./data:/data
ports:
- 50000:80
restart: unless-stopped
network: bridge
位于大陆的服务器需要修改镜像中的resolve.conf文件。所有操作均在/usr/local/smokeping/
目录,步骤:
- 创建自定义resolve.conf
touch resolve.conf && echo "nameserver 223.5.5.5" > resolve.conf
创建一个
Dockerfile
文件用于拉取并修改镜像,
Dockerfile内容如下:FROM linuxserver/smokeping:latest COPY ./resolve.conf /etc/resolve.conf
docker-compose.yml
文件改为以下内容version: "2.1" services: smokeping: build: ./ container_name: smokeping hostname: GZ_Telecom environment: - PUID=1000 - PGID=1000 - TZ=Asia/Shanghai volumes: - ./config:/config - ./data:/data ports: - 50000:80 restart: unless-stopped
- 配置文件存放目录为
/usr/local/smokeping/config
。 - 数据文件存放地址为
/usr/local/smokeping/data
。 - 外部访问端口为
50000
,因为我这台机器有多个服务,80端口留给Nginx。这里先设为50000,再去Nginx里面反代。
3. 试运行
运行docker compose up
。境内服务器应该很慢,多试几次。
没问题就按Ctrl C
退出运行。
[root@gz smokeping]# docker-compose up
Building smokeping
Sending build context to Docker daemon 86.68MB
Step 1/2 : FROM linuxserver/smokeping:latest
latest: Pulling from linuxserver/smokeping
98c52743ac98: Already exists
f5866fce4916: Already exists
b91c15e8ac54: Already exists
f423f9598b47: Pull complete
2bb6ad94a977: Pull complete
d0e3812799bd: Pull complete
Digest: sha256:217bdfeb568854006536e94af0d054a7cd3ee10bfc8af3fbbaea89ce300b3240
Status: Downloaded newer image for linuxserver/smokeping:latest
---> 0cc7559632de
Step 2/2 : COPY ./resolve.conf /etc/resolve.conf
---> f23e29d3ffdf
Successfully built f23e29d3ffdf
Successfully tagged smokeping_smokeping:latest
WARNING: Image for service smokeping was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating smokeping ... done
Attaching to smokeping
smokeping | [custom-init] No custom services found, skipping...
smokeping | s6-rc: info: service s6rc-oneshot-runner: starting
smokeping | s6-rc: info: service s6rc-oneshot-runner successfully started
smokeping | s6-rc: info: service fix-attrs: starting
smokeping | s6-rc: info: service 00-legacy: starting
smokeping | s6-rc: info: service 00-legacy successfully started
smokeping | s6-rc: info: service fix-attrs successfully started
smokeping | s6-rc: info: service legacy-cont-init: starting
smokeping | cont-init: info: running /etc/cont-init.d/01-envfile
smokeping | cont-init: info: /etc/cont-init.d/01-envfile exited 0
smokeping | cont-init: info: running /etc/cont-init.d/10-adduser
smokeping |
smokeping | -------------------------------------
smokeping | _ ()
smokeping | | | ___ _ __
smokeping | | | / __| | | / \
smokeping | | | \__ \ | | | () |
smokeping | |_| |___/ |_| \__/
smokeping |
smokeping |
smokeping | Brought to you by linuxserver.io
smokeping | -------------------------------------
smokeping |
smokeping | To support LSIO projects visit:
smokeping | https://www.linuxserver.io/donate/
smokeping | -------------------------------------
smokeping | GID/UID
smokeping | -------------------------------------
smokeping |
smokeping | User uid: 1000
smokeping | User gid: 1000
smokeping | -------------------------------------
smokeping |
smokeping | cont-init: info: /etc/cont-init.d/10-adduser exited 0
smokeping | cont-init: info: running /etc/cont-init.d/30-config
smokeping | cont-init: info: /etc/cont-init.d/30-config exited 0
smokeping | cont-init: info: running /etc/cont-init.d/99-custom-files
smokeping | [custom-init] No custom files found, skipping...
smokeping | cont-init: info: /etc/cont-init.d/99-custom-files exited 0
smokeping | s6-rc: info: service legacy-cont-init successfully started
smokeping | s6-rc: info: service init-mods: starting
smokeping | s6-rc: info: service init-mods successfully started
smokeping | s6-rc: info: service init-mods-package-install: starting
smokeping | s6-rc: info: service init-mods-package-install successfully started
smokeping | s6-rc: info: service init-mods-end: starting
smokeping | s6-rc: info: service init-mods-end successfully started
smokeping | s6-rc: info: service init-services: starting
smokeping | s6-rc: info: service init-services successfully started
smokeping | s6-rc: info: service legacy-services: starting
smokeping | services-up: info: copying legacy longrun apache (no readiness notification)
smokeping | services-up: info: copying legacy longrun smokeping (no readiness notification)
smokeping | s6-rc: info: service legacy-services successfully started
smokeping | s6-rc: info: service 99-ci-service-check: starting
smokeping | [ls.io-init] done.
smokeping | s6-rc: info: service 99-ci-service-check successfully started
smokeping | ### parsing dig output...OK
smokeping | ### assuming you are using an fping copy reporting in milliseconds
smokeping | Smokeping version 2.007003 successfully launched.
smokeping | Entering multiprocess mode.
smokeping | No targets defined for probe DNS, skipping.
smokeping | No targets defined for probe FPing6, skipping.
smokeping | Child process 145 started for probe FPing.
smokeping | All probe processes started successfully.
smokeping | FPing: probing 22 targets with step 180 s and offset 55 s.
4. 添加要监测的目标
编辑/usr/local/smokeping/config/Targets
文件,按照格式输入要检测的目标。
*** Targets ***
probe = FPing
menu = Top
title = Network Latency Grapher
remark = Welcome to the SmokePing website of WORKS Company. \
Here you will learn all about the latency of our network.
+ US
menu = 美国
title = 在美国的服务器
++ RFCHost
menu = RFCHost(GIA) - LA
title = RFCHost(GIA), 洛杉矶
host = 103.1.1.1
++ GGC
menu = GGC(GIA) - LA
title = GGC(GIA), Los Angels
host = 103.1.1.1
++ 这里填标识符,可以用大小写英文字母、数字、下划线和减号,用正则表达式就是/[-_0-9a-zA-Z]+/
menu = 菜单显示的内容
title = 页面顶部显示的内容
host = 要ping的目标,域名和IP都行
+ EU
menu = 欧洲
title = 在欧洲的服务器
++ Online
menu = Online - NL
title = 就是Online.net的服务器
host = 51.1.1.1
+ eu-ipv6
probe = FPing6
menu = EU IPv6
title = 欧洲的IPv6服务器
++ Online
menu = Online - NL
title = 就是Online.net的服务器
host = 2001:abcd::1
5. 国内服务器需要做的改动
编辑/usr/local/smokeping/config/Probe
文件,将以下DNS里面的lookup改为国内网络能够连接的网址,比如百度。
+ DNS
binary = /usr/bin/dig
lookup = baidu.com
pings = 5
step = 300
6. 启动容器
回到/usr/local/smokeping/
目录,以后台方式启动容器docker-compose up -d
7. 等待10分钟,进入http://服务器IP:50000
查看结果。
不等可以直接打开,只是没有数据而已。
8. 开启反代
server_name,certificate请根据自己实际情况修改。
server{
server_name ping.fly2x.cn;
listen 80;
return 301 https://$host$request_uri;
}
server{
server_name ping.fly2x.cn;
listen 443 ssl http2;
access_log /home/wwwlogs/ping.log combined;
ssl_certificate /etc/ssl/fly2x.cer;
ssl_certificate_key /etc/ssl/fly2x.key;
keepalive_timeout 70;
ssl_session_timeout 24h;
ssl_buffer_size 4k;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_dhparam ssl/dhparam.pem;
ssl_ciphers "ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE";
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/ssl/fly2x.cer;
location / {
proxy_pass http://127.0.0.1:50000;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
9. 常用操作
1. Docker命令
- 进入Docker镜像内部
docker exec -it smokeping /bin/bash
- 重启镜像
docker-compose restart
- 查看日志输出
docker logs smokeping
2. 自定义检测频率
编辑/usr/local/smokeping/config/Database
。
step:多少秒时间ping一轮
pings: 每个节点ping多少下
*** Database ***
step = 180
pings = 20
3. 修改主节点名称
就是图里红框的名称
编辑/usr/local/smokeping/config/General
,添加一个display_name
*** General ***
owner = 王小明
contact = [email protected]
mailhost = mail.fly2x.cn
# NOTE: do not put the Image Cache below cgi-bin
# since all files under cgi-bin will be executed ... this is not
# good for images.
cgiurl = http://localhost/smokeping.cgi
# specify this to get syslog logging
syslogfacility = local0
# each probe is now run in its own process
# disable this to revert to the old behaviour
# concurrentprobes = no
display_name = 广州腾讯云
@include /config/pathnames
10. 遇到的问题
xxx.rrd file not exist
国内服务器需要进入镜像内部,命令见步骤九,修改/etc/resolve.conf
,添加一个国内可用的DNS。nameserver 223.5.5.5
虽然Docker强烈建议大家不要修改镜像里面的文件,而是在docker-compose.yml文件通过定义volumn来修改,但是我试过没用啊,先这么用着吧。等我以后学会了再说。
好了,我学会了。见步骤二。
11. 启用IPv6
来源
编辑 /etc/docker/daemon.json ,加上以下内容。
{
"ipv6": true,
"fixed-cidr-v6": "fd00::/80",
"experimental": true,
"ip6tables": true
}
重启docker enginesudo systemctl restart docker
.
docker-compose.yaml增加一行network_mode: bridge
version: "2.1"
services:
smokeping:
build: ./
container_name: smokeping
hostname: GZ_CT
environment:
- PUID=1000
- PGID=1000
- TZ=Asia/Shanghai
volumes:
- ./config:/config
- ./data:/data
- ./resolve.conf:/etc/resolve.conf
ports:
- 50000:80
restart: unless-stopped
network_mode: bridge
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。