准备两台服务器,实例的操作系统为:Centos7.8
两台服务器的防火墙必需关闭,并且能互相访问
主-master:192.168.1.1
从-slave:192.168.1.2
一、master搭建
#安装wget和vim
yum install -y wget vim
#安装elep
yum install epel-release -y
#安装依赖
yum install rrdtool perl-rrdtool perl-core openssl-devel fping curl gcc-c++ make wqy-zenhei-fonts.noarch supervisor curl -y
#安装fping
cd
wget https://fping.org/dist/fping-4.2.tar.gz
tar -zxvf fping-4.2.tar.gz
cd fping-4.2
./configure --prefix=/usr/local/fping
make && make install
#安装 httpd
yum install -y httpd
#下载 安装smokeping
cd
wget --no-check-certificate https://oss.oetiker.ch/smokeping/pub/smokeping-2.8.2.tar.gz
tar -xzvf smokeping-2.8.2.tar.gz
cd smokeping-2.8.2
./configure --prefix=/usr/local/smokeping
/usr/bin/gmake install
#配置smokeping
cd /usr/local/smokeping
mkdir var htdocs/{data,cache,var}
chown apache.apache -R /usr/local/smokeping
touch /var/log/smokeping.log
chown apache.apache /var/log/smokeping.log
cd /usr/local/smokeping/htdocs/
cp smokeping.fcgi.dist smokeping.fcgi
echo swbooo:123456 > /usr/local/smokeping/etc/smokeping_secrets.dist
chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist
#复制默认配置文件
cp /usr/local/smokeping/etc/config.dist /usr/local/smokeping/etc/config
#修改smokeping的配置文件config
vi /usr/local/smokeping/etc/config # 找到对应参数修改
cgiurl = http://192.168.1.1/smokeping.cgi #自己的IP
imgcache = /usr/local/smokeping/htdocs/cache
datadir = /usr/local/smokeping/htdocs/data
piddir = /usr/local/smokeping/htdocs/var
binary = /usr/local/fping/sbin/fping
#Slave 节点设置
*** Slaves ***
secrets=/usr/local/smokeping/etc/smokeping_secrets.dist
+swbooo
display_name=swbooo
color=0000ff
#监控节点设置
*** Targets ***
probe = FPing
menu = Top
title = Network Latency Grapher
remark = Welcome to the SmokePing website of xxx Company. \
Here you will learn all about the latency of our network.
+ Test
menu= test
title = test
++ google-dns
menu = google-dns
title = google-dns
alerts = google-dns
slaves = swbooo
host = 8.8.8.8
#主master 执行debug运行,测试没有报错即可
/usr/local/smokeping/bin/smokeping --debug
#添加smokeping为服务
cat > /usr/lib/systemd/system/smokeping.service<<EOF
[Unit]
Description=Latency Logging and Graphing System
After=syslog.target network.target
[Service]
#ExecStart=/usr/sbin/smokeping --nodaemon # 2.6 yum install
ExecStart=/usr/local/smokeping/bin/smokeping --nodaemon --config=/usr/local/smokeping/etc/config --logfile=/var/log/smokeping.log # 2.7 src install
ExecReload=/bin/kill -HUP $MAINPID
StandardError=syslog
[Install]
WantedBy=multi-user.target
EOF
#配置httpd,/etc/httpd/conf/httpd.conf 中 DocumentRoot "/var/www/html" 后添加内容,如下:
Alias /smokeping "/usr/local/smokeping/htdocs/"
<Directory "/usr/local/smokeping">
AllowOverride None
Options All
AddHandler cgi-script .fcgi .cgi
AllowOverride AuthConfig
require all granted
Order deny,Allow
Allow from 10.0.0.0/8 #允许访问的IP段,可自行设置,必需允许Slave节点的IP访问
Allow from 192.168.0.0/16
deny from all
AuthName "Welcome to Access Smokeping monitor system!!"
AuthType Basic
AuthUserFile /usr/local/smokeping/htdocs/htpasswd
Require valid-user
DirectoryIndex smokeping.fcgi
</Directory>
#生成网页basic 验证密码,可以不设置
htpasswd -c /usr/local/smokeping/htdocs/htpasswd admin #设置用户admin的密码,网页登录的密码
htpasswd -D /usr/local/smokeping/htdocs/htpasswd admin #删除用户admin的密码
#设置中文,/usr/local/smokeping/etc/basepage.html.dist 的 head 内添加
<META charset="utf-8" />
#访问测试
systemctl start smokeping
systemctl start httpd
#启动 smokeping 和 apache,然后访问 http://自己的IP/smokeping
二、从节点配置
#安装wget和vim
yum install -y wget vim
#安装elep
yum install epel-release -y
#安装依赖
yum install rrdtool perl-rrdtool perl-core openssl-devel fping curl gcc-c++ make wqy-zenhei-fonts.noarch supervisor curl -y
#安装fping
cd
wget https://fping.org/dist/fping-4.2.tar.gz
tar -zxvf fping-4.2.tar.gz
cd fping-4.2
./configure --prefix=/usr/local/fping
make && make install
#下载 安装smokeping
cd
wget --no-check-certificate https://oss.oetiker.ch/smokeping/pub/smokeping-2.8.2.tar.gz
tar -xzvf smokeping-2.8.2.tar.gz
cd smokeping-2.8.2
./configure --prefix=/usr/local/smokeping
/usr/bin/gmake install
#配置smokeping
cd /usr/local/smokeping
mkdir var htdocs/{data,cache,var}
chown apache.apache -R /usr/local/smokeping
touch /var/log/smokeping.log
chown apache.apache /var/log/smokeping.log
cd /usr/local/smokeping/htdocs/
cp smokeping.fcgi.dist smokeping.fcgi
chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist
#复制默认配置文件
cp /usr/local/smokeping/etc/config.dist /usr/local/smokeping/etc/config
#修改smokeping的配置文件config
vi /usr/local/smokeping/etc/config # 找到对应参数修改
imgcache = /usr/local/smokeping/htdocs/cache
datadir = /usr/local/smokeping/htdocs/data
piddir = /usr/local/smokeping/htdocs/var
binary = /usr/local/fping/sbin/fping
#设置slave密码
echo 123456 > /usr/local/smokeping/etc/smokeping_secrets.dist
#启动smkeping
/usr/local/smokeping/bin/smokeping --master-url=http://192.168.1.1/smokeping/ --cache-dir=/usr/local/smokeping/htdocs/cache --shared-secret=/usr/local/smokeping/etc/smokeping_secrets.dist --slave-name=swbooo --logfile=/usr/local/smokeping/htdocs/slave.log
一、–master-url这个参数最好理解吧,后面只需要填写你的主服务器公网IP即可。
二、–cache-dir缓存文件存储的路径,不多解释
三、–shared-secret密钥文件的绝对路径。
四、–slave-name对接主服务器上的从服务器名字,这里一定要修改成你们自己的,我这里是swbooo
五、–logfile日志文件保存路径。
#暂停smokeping
kill -9 `ps -ef |grep "smokeping"|grep -v "grep"|grep -v "smokeping.sh"|grep -v "perl"|awk '{print $2}'|xargs` 2>/dev/null
#如果从节点连接成功 但是没有数据
查看master节点 /usr/local/smokeping/htdocs/data
这个目录存放了监控数据 用户名和权限必需得是Apache
chown -R apache.apache /usr/local/smokeping/htdocs/data/Test