Smartping搭建

环境:ubuntu20.04

概览:

  • 二进制安装
  • docker容器安装
  • ansible`安装

Smartping源码包下载地址:
https://github.com/gy-games/smartping/releases/download/v0.5.0/smartping-v0.5.0.tar.gz

一. 二进制安装

0. 全文smartping配置文件config-base.json留存

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
{
"Ver": "0.8.0",
"Port": 8899,
"Name": "本机",
"Addr": "127.0.0.1",
"Mode": {
"Endpoint": "",
"LastSuccTime": "",
"Status": "true",
"Type": "local"
},
"Base": {
"Archive": 10,
"Refresh": 1,
"Timeout": 5
},
"Topology": {
"Tline": "1",
"Tsound": "/alert.mp3",
"Tsymbolsize": "70"
},
"Alert": {
"EmailHost": "",
"RevcEmailList": "",
"SendEmailAccount": "",
"SendEmailPassword": ""
},
"Network": {
"1.2.3.4": {
"Name": "OtherSP",
"Addr": "1.2.3.4",
"Smartping": true,
"Ping": [
"114.114.114.114",
"127.0.0.1",
"8.8.4.4"
],
"Topology": [
{
"Addr": "127.0.0.1",
"Name": "本机",
"Thdavgdelay": "200",
"Thdchecksec": "900",
"Thdloss": "30",
"Thdoccnum": "3"
},
{
"Addr": "114.114.114.114",
"Name": "114DNS",
"Thdavgdelay": "200",
"Thdchecksec": "900",
"Thdloss": "30",
"Thdoccnum": "3"
},
{
"Addr": "8.8.4.4",
"Name": "GoogleDNS",
"Thdavgdelay": "200",
"Thdchecksec": "900",
"Thdloss": "30",
"Thdoccnum": "3"
},
{
"Addr": "1.2.3.4",
"Name": "OtherSP",
"Thdavgdelay": "200",
"Thdchecksec": "900",
"Thdloss": "30",
"Thdoccnum": "3"
}
]
},
"114.114.114.114": {
"Name": "114DNS",
"Addr": "114.114.114.114",
"Smartping": false,
"Ping": [],
"Topology": []
},
"123.125.114.144": {
"Name": "百度",
"Addr": "123.125.114.144",
"Smartping": false,
"Ping": [],
"Topology": []
},
"127.0.0.1": {
"Name": "本机",
"Addr": "127.0.0.1",
"Smartping": true,
"Ping": [
"1.2.3.4",
"114.114.114.114",
"123.125.114.144",
"127.0.0.1",
"69.171.229.28",
"8.8.4.4"
],
"Topology": [
{
"Addr": "1.2.3.4",
"Name": "OtherSP",
"Thdavgdelay": "200",
"Thdchecksec": "900",
"Thdloss": "30",
"Thdoccnum": "3"
},
{
"Addr": "114.114.114.114",
"Name": "114DNS",
"Thdavgdelay": "200",
"Thdchecksec": "900",
"Thdloss": "30",
"Thdoccnum": "3"
},
{
"Addr": "8.8.4.4",
"Name": "GoogleDNS",
"Thdavgdelay": "200",
"Thdchecksec": "900",
"Thdloss": "10",
"Thdoccnum": "3"
},
{
"Addr": "69.171.229.28",
"Name": "Facebook",
"Thdavgdelay": "200",
"Thdchecksec": "900",
"Thdloss": "30",
"Thdoccnum": "3"
},
{
"Addr": "123.125.114.144",
"Name": "百度",
"Thdavgdelay": "200",
"Thdchecksec": "900",
"Thdloss": "30",
"Thdoccnum": "3"
}
]
},
"69.171.229.28": {
"Name": "Facebook",
"Addr": "69.171.229.28",
"Smartping": false,
"Ping": [],
"Topology": []
},
"8.8.4.4": {
"Name": "GoogleDNS",
"Addr": "8.8.4.4",
"Smartping": false,
"Ping": [],
"Topology": []
}
},
"Chinamap": {
"上海": {
"cmcc": [
"117.184.42.114"
],
"ctcc": [
"180.163.15.160"
],
"cucc": [
"223.167.104.117"
]
},
"北京": {
"cmcc": [
"111.13.217.125"
],
"ctcc": [
"120.92.180.135"
],
"cucc": [
"111.207.189.5"
]
},
"广东": {
"cmcc": [
"120.236.14.140"
],
"ctcc": [
"218.17.216.171"
],
"cucc": [
"58.252.2.194"
]
},
"浙江": {
"cmcc": [
"183.246.69.139"
],
"ctcc": [
"115.236.169.86"
],
"cucc": [
"60.12.214.156"
]
}
},
"Toollimit": 0,
"Authiplist": "",
"Password": "smartping"
}

1.下载源码包后将源码包解压到opt目录解压命名为samrtping

1
2
3
4
# 下载
wget -P /opt https://github.com/gy-games/smartping/releases/download/v0.5.0/smartping-v0.5.0.tar.gz
# 解压
mkdir -p /opt/smartping && tar -xvf smartping-v0.5.0.tar.gz -C /opt/smartping

2.启动服务

1
2
3
4
5
# 启动smartping
cd /opt/smartping && ./control start|stop|restart
# 成功
root@zznn:/opt/smartping# ss -ntulp |grep smartping
tcp LISTEN 0 128 *:8899

服务配置文件config-base.json

浏览器访问:http://localhost:8899

3.扩展建立system托管方式启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
vim /etc/systemd/system/smartping.service

cat <<EOF >/etc/systemd/system/smartping.service

[Unit]
Description="smartping"
After=network.target

[Service]
Type=simple
ExecStart=/opt/smartping/bin/smartping > /opt/smartping/bin/smartping.log &
WorkingDirectory=/opt/smartping/bin/
Restart=always

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable smartping
systemctl restart smartping
systemctl status smartping

NOTE:smartping启动方式有两种在两个不同路径均能启动

  1. 直接全路径启动:/opt/smartping/bin/smartping 此种启动方式建立托管文件成功
  2. 常规启动:/opt/smartping/control此种启动方式建立托管文件时不成功原因还不清楚 smartping改变端口+密码直接修改配置文件文件:/opt/smartping/conf/config-base.json

二. docker方式部署

1. Dockerfile文件

1
2
3
4
5
6
FROM centos:7
WORKDIR /smartping
ADD smartping-v0.8.0.tar.gz /smartping/
RUN chmod +x control
EXPOSE 8899
CMD ["/smartping/bin/smartping"]

构建镜像命令

参数:
-f 指定文件目录
-t 命名空间

1
2
3
4
5
6
7
8
# 执行构建
docker build -f /home/gegewu/mydocker/Dockerfile -t centos/smartping-1 .
# 运行容器
docker run -d -p 8888:8899 --privileged=true --name smartping-v1 -v /home/gegewu/mydocker/smartping/config-base.json:/smartping/conf/config-base.json:rw centos/smartping-v1
# 进入容器
docker exec it +ID sh
# 查看容器
docker container ls --all

2.使用docker-compose编排构建

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
version: "3.0"

services:
smartping:
build:
context: .
dockerfile: Dockerfile
restart: always
container_name: smartping-v2
hostname: smartping-v2
ports:
- 8880:8899
volumes:
- /home/gegewu/mydocker/smartping/config-base.json:/smartping/conf/config-base.json
command: /smartping/bin/smartping

3.创建:docker-compose build

创建详情:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 使用docker-compose编排构建
root@gegewu1:/home/gegewu/mydocker# docker-compose build
Building smartping
Step 1/6 : FROM centos:7
---> eeb6ee3f44bd
Step 2/6 : WORKDIR /smartping
---> Using cache
---> 306c910e14ec
Step 3/6 : ADD smartping-v0.8.0.tar.gz /smartping/
---> 4c8ec23fae8a
Step 4/6 : RUN chmod +x control
---> Running in f25dbcc33838
Removing intermediate container f25dbcc33838
---> 6e2a10675449
Step 5/6 : EXPOSE 8899
---> Running in eaac019fb75d
Removing intermediate container eaac019fb75d
---> b7de58724d80
Step 6/6 : CMD ["/smartping/bin/smartping"]
---> Running in c9a6967f19b8
Removing intermediate container c9a6967f19b8
---> d6ab26b8bc6a
Successfully built d6ab26b8bc6a
Successfully tagged mydocker_smartping:latest
# 运行:docker-compose up -d
# 运行详情:
root@gegewu1:/home/gegewu/mydocker# docker-compose up -d
Creating network "mydocker_default" with the default driver
Creating smartping-v2 ... done

4. 扩展:将此容器push到阿里云私有镜像仓库 使用docker-compose编排部署

docker-compose文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
version: "3.0"
services:
smartping_0.8:
image: registry.cn-hangzhou.aliyuncs.com/zznn/mycentos:smartping_gegewu_v1.0
restart: unless-stopped
container_name: smartping_0.8
hostname: smartping_0.8
environment:
TZ: Asia/Shanghai
ports:
- 8899:8899
volumes:
- ./config-base.json:/smartping/conf/config-base.json
command: /smartping/bin/smartping
networks:
- smartping_0.8
networks:
smartping_0.8:
driver: bridge

执行部署: docker-compose up -d 效果如下:

image-20230809190623765

三. 采用ansible自动构建

1. playbook文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ansible 搭建smartping
#1. 将文件传输到远端机器
#2. 文件为:smartping-v0.8.0.tar.gz anaconda-ks.cfg
- hosts: 10.0.0.128
vars:
web_server: httpd
linux_dir: /home/gegewu/smartping

tasks:

- name: file
file: path="{{ linux_dir }}" state=directory owner=gegewu group=gegewu mode=777 recurse=yes

- name: unarchive
unarchive: src=./smartping-v0.8.0.zip dest="{{ linux_dir }}" mode=0777

- name: copy
copy: src=./anaconda-ks.cfg dest="{{ linux_dir }}" mode=0777

- name: 8899
firewalld:
zone: public
permanent: yes
immediate: yes
port: 8899/tcp
state: enabled

- name: start
shell: /"{{ linux_dir }}/control start"

- name: service
service: name=firewalld state=started enabled=yes

- name: web
shell: echo "浏览器访问本机ip:8899"
register: web_ip

- name: debug
debug:
msg: "{{ web_ip }}"

2. 部署节点执行构建 (host文件自行定义)

1
2
3
4
# 检查语法有没有错误
ansible-playbook -i hosts --syntax smartping.yml
# 执行
ansible-playbook -i hosts smartping.yml

上述方式构建完成效果:

image-20230809190648801