1.Linux监控平台介绍

       一个成熟的企业必须要有监控平台,流行的开源监控软件有:Cacti、Nagios、Zabbix、smokeping、open-falcon等。

     
 前三款软件都可以监控服务器的基础指标,比如CPU、内存、磁盘、网络等,其中Cacti更擅长监控网络流量,很多IDC机房的网络设备流量用cacti来监控,因为它成图专业。Cacti、Nagios以及Zabbix都是C/S架构,需要安装一个服务器,然后还需要在被监控的机器上安装客户端。这三款软件都需要有PHP环境的支持,其中Nagios不需要数据库,Cacti和Zabbix都需要MySQL的支持,用来存储数据。Nagios在许多年前很受欢迎,但现在不如Zabbix了,因为Zabbix可以存储数据,很方便地画图,并且支持查询历史数据。Zabbix还有一个特性,它可以非常方便地自定义监控项目。

     
 Cacti、smokeping偏向于基础监控,成图非常漂亮。open-falcon为小米公司开发,开源后受到诸多大公司和运维工程师的追捧,适合大企业,滴滴、360、新浪微博、京东等大公司在使用这款监控软件,值得深入研究。

2.Zabbix监控介绍

     
 Zabbix是C/S架构,基于C++开发,分为服务端(server)和客户端(client),监控中心支持web界面配置和管理。理论上,在硬件和网络条件允许的情况下,单个server节点可以支持上万台客户端。Zabbix的最新版本3.4,官方文档地址为:
https://www.zabbix.com/manuals <https://www.zabbix.com/manuals>。

Zabbix整个体系架构如下:

1)zabbix-server

zabbix-server监控中心,是整个监控体系中最核心的组件,它负责接收客户端发送的报告信息,所有配置、统计数据及操作数据都由它组织。

2)数据存储

所有的收集信息存储在这里。

3)web界面

web界面即GUI,这是Zabbix监控简单易用的原因之一,因为可以在Web界面中配置、管理各个客户端,需要有PHP支撑。

4)zabbix-proxy

zabbix-proxy为可选组件,用于监控节点非常多的分布式环境中,它可以代理zabbix-server的功能,减轻zabbix-server的压力。

5)zabbix-agent

zabbix-agent为客户端软件,用于采集各监控项目的数据,并把采集的数据传输给zabbix-proxy或zabbix-server。

流程图如下:



Zabbix监控原理:

Agent安装在被监控的主机上,Agent负责定期收集客户端本地各项数据,并发送至Zabbix Server端,Zabbix
Server收到数据,将数据存储到数据库中,用户基于Zabbix
WEB可以看到数据在前端展现图像。当Zabbix监控某个具体的项目,改项目会设置一个触发器阈值,当被监控的指标超过该触发器设>定的阈值,会进行一些必要的动作,动作包括:发送信息(邮件、微信、短信)、发送命令(SHELL
命令、Reboot、Restart、Install等)。

3.安装Zabbix

Zabbix的官方下载地址为:https://www.zabbix.com/download
<https://www.zabbix.com/download>,在安装时需要先安装Zabbix的yum扩展源,然后利用yum安装。

3.1 服务器安装zabbix
[root@yuioplvlinux-128 ~]# wget
repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
--2018-07-08 17:27:00--
http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
正在解析主机 repo.zabbix.com (repo.zabbix.com)... 162.243.159.138 正在连接
repo.zabbix.com (repo.zabbix.com)|162.243.159.138|:80... 已连接。 已发出 HTTP
请求,正在等待回应... 200 OK 长度:13392 (13K) [application/x-redhat-package-manager]
正在保存至: “zabbix-release-3.2-1.el7.noarch.rpm”
100%[===========================================================================================>]
13,392 --.-K/s 用时 0s 2018-07-08 17:27:01 (183 MB/s) - 已保存
“zabbix-release-3.2-1.el7.noarch.rpm” [13392/13392]) [root@yuioplvlinux-128 ~]#
rpm -ivh zabbix-release-3.2-1.el7.noarch.rpm
警告:zabbix-release-3.2-1.el7.noarch.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID
a14fe591: NOKEY 准备中... ################################# [100%] 正在升级/安装...
1:zabbix-release-3.2-1.el7 ################################# [100%]
使用命令“yum install -y zabbix-agent zabbix-get zabbix-server-mysql zabbix-web
zabbix-web-mysql”安装

安装完成后,查看mysql服务是否启动;
[root@yuioplvlinux-128 ~]# ps aux |grep mysql root 935 0.0 0.1 115432 1572 ? S
15:43 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe
--datadir=/usr/local/mysql/data/mysql
--pid-file=/usr/local/mysql/data/mysql/yuioplvlinux-128.pid mysql 1106 0.2 45.0
1324420 453700 ? Sl 15:43 0:23 /usr/local/mysql/bin/mysqld
--basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/mysql
--plugin-dir=/usr/local/mysql/lib/plugin --user=mysql
--log-error=yuioplvlinux-128.err
--pid-file=/usr/local/mysql/data/mysql/yuioplvlinux-128.pid root 1888 0.0 0.0
112720 968 pts/1 R+ 17:56 0:00 grep --color=auto mysql
编辑/etc/my.cnf,新增一行,配置编码格式,保存后重启mysql服务。
character_set_server = utf8
配置mysql:
[root@yuioplvlinux-128 ~]# mysql -uroot -p123456 Warning: Using a password on
the command line interface can be insecure. Welcome to the MySQL monitor.
Commands end with ; or \g. Your MySQL connection id is 3 Server version:
5.6.40-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or
its affiliates. All rights reserved. Oracle is a registered trademark of Oracle
Corporation and/or its affiliates. Other names may be trademarks of their
respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the
current input statement. mysql> create database zabbix character set utf8;
#创建Zabbix库,字符集为UTF-8 Query OK, 1 row affected (0.09 sec) mysql> grant all on
zabbix.* to 'zabbix'@'127.0.0.1' identified by 'yu-zabbix'; Query OK, 0 rows
affected (0.00 sec)
导入Zabbix相关的数据;
[root@yuioplvlinux-128 ~]# cd /usr/share/doc/zabbix-server-mysql-3.2.11/
[root@yuioplvlinux-128 zabbix-server-mysql-3.2.11]# ls AUTHORS ChangeLog
COPYING create.sql.gz NEWS README [root@yuioplvlinux-128
zabbix-server-mysql-3.2.11]# gzip -d create.sql.gz [root@yuioplvlinux-128
zabbix-server-mysql-3.2.11]# ls AUTHORS ChangeLog COPYING create.sql NEWS
README [root@yuioplvlinux-128 zabbix-server-mysql-3.2.11]# mysql -uroot
-p123456 zabbix < create.sql #导入mysql Warning: Using a password on the command
line interface can be insecure.
 

编辑/etc/zabbix/zabbix_server.conf配置文件;
DBHost=127.0.0.1 #在DBName=zabbix上面增加 DBPassword=yu-zabbix #在DBuser下面增加
启动Zabbix服务;
[root@yuioplvlinux-128 ~]# systemctl start zabbix-server
[root@yuioplvlinux-128 ~]# ps aux |grep zabbix zabbix 2432 1.1 0.4 254852 4184
? S 19:19 0:01 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf zabbix
2435 0.0 0.3 254860 3136 ? S 19:19 0:00 /usr/sbin/zabbix_server: configuration
syncer [synced configuration in 0.021904 sec, idle 60 sec] zabbix 2436 0.0 0.2
254852 2892 ? S 19:19 0:00 /usr/sbin/zabbix_server: db watchdog [synced alerts
config in 0.002751 sec, idle 60 sec] zabbix 2437 0.1 0.5 361792 5264 ? S 19:19
0:00 /usr/sbin/zabbix_server: poller #1 [got 0 values in 0.000008 sec, idle 5
sec] zabbix 2438 0.1 0.5 361792 5264 ? S 19:19 0:00 /usr/sbin/zabbix_server:
poller #2 [got 0 values in 0.000009 sec, idle 5 sec] zabbix 2439 0.1 0.5 361792
5264 ? S 19:19 0:00 /usr/sbin/zabbix_server: poller #3 [got 0 values in
0.000008 sec, idle 5 sec] zabbix 2440 0.2 0.5 361792 5264 ? S 19:19 0:00
/usr/sbin/zabbix_server: poller #4 [got 0 values in 0.000009 sec, idle 5 sec]
zabbix 2441 0.0 0.5 361792 5264 ? S 19:19 0:00 /usr/sbin/zabbix_server: poller
#5 [got 0 values in 0.000016 sec, idle 5 sec] zabbix 2442 0.1 0.5 361792 5264 ?
S 19:19 0:00 /usr/sbin/zabbix_server: unreachable poller #1 [got 0 values in
0.000008 sec, idle 5 sec] zabbix 2443 0.0 0.3 254852 3624 ? S 19:19 0:00
/usr/sbin/zabbix_server: trapper #1 [processed data in 0.000000 sec, waiting
for connection] zabbix 2444 0.0 0.3 254852 3624 ? S 19:19 0:00
/usr/sbin/zabbix_server: trapper #2 [processed data in 0.000000 sec, waiting
for connection] zabbix 2445 0.0 0.3 254852 3624 ? S 19:19 0:00
/usr/sbin/zabbix_server: trapper #3 [processed data in 0.000000 sec, waiting
for connection] zabbix 2446 0.0 0.3 254852 3624 ? S 19:19 0:00
/usr/sbin/zabbix_server: trapper #4 [processed data in 0.000000 sec, waiting
for connection] zabbix 2447 0.0 0.3 254852 3624 ? S 19:19 0:00
/usr/sbin/zabbix_server: trapper #5 [processed data in 0.000000 sec, waiting
for connection] zabbix 2448 0.0 0.2 257428 2688 ? S 19:19 0:00
/usr/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000009 sec, idle 5
sec] zabbix 2449 0.0 0.2 254852 2876 ? S 19:19 0:00 /usr/sbin/zabbix_server:
alerter [sent alerts: 0 success, 0 fail in 0.001124 sec, idle 30 sec] zabbix
2450 0.0 0.2 254852 2512 ? S 19:19 0:00 /usr/sbin/zabbix_server: housekeeper
[startup idle for 30 minutes] zabbix 2451 0.0 0.2 254932 2996 ? S 19:19 0:00
/usr/sbin/zabbix_server: timer #1 [processed 0 triggers, 0 events in 0.000031
sec, 0 maintenances in 0.000000 sec, idle 30 sec] zabbix 2452 0.0 0.2 254852
2892 ? S 19:19 0:00 /usr/sbin/zabbix_server: http poller #1 [got 0 values in
0.000859 sec, idle 5 sec] zabbix 2453 0.1 0.5 359320 5252 ? S 19:19 0:00
/usr/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.002845 sec, idle
60 sec] zabbix 2454 0.0 0.2 254852 2888 ? S 19:19 0:00 /usr/sbin/zabbix_server:
history syncer #1 [synced 0 items in 0.000001 sec, idle 1 sec] zabbix 2455 0.0
0.2 254852 2888 ? S 19:19 0:00 /usr/sbin/zabbix_server: history syncer #2
[synced 0 items in 0.000001 sec, idle 1 sec] zabbix 2456 0.0 0.2 254852 2888 ?
S 19:19 0:00 /usr/sbin/zabbix_server: history syncer #3 [synced 0 items in
0.000002 sec, idle 1 sec] zabbix 2457 0.0 0.2 254852 2888 ? S 19:19 0:00
/usr/sbin/zabbix_server: history syncer #4 [synced 0 items in 0.000001 sec,
idle 1 sec] zabbix 2458 0.0 0.3 254852 3828 ? S 19:19 0:00
/usr/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.001104 sec,
idle 3 sec] zabbix 2464 0.0 0.3 254852 3832 ? S 19:19 0:00
/usr/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in
0.000007 sec, idle 5 sec] zabbix 2468 0.0 0.2 254852 2656 ? S 19:19 0:00
/usr/sbin/zabbix_server: self-monitoring [processed data in 0.000007 sec, idle
1 sec] zabbix 2473 0.2 0.2 254852 2876 ? S 19:19 0:00 /usr/sbin/zabbix_server:
task manager [processed 0 task(s) in 0.000445 sec, idle 5 sec] root 2491 0.0
0.0 112720 968 pts/0 R+ 19:21 0:00 grep --color=auto zabbix
[root@yuioplvlinux-128 ~]# netstat -lntp Active Internet connections (only
servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program
name tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 2432/zabbix_server tcp 0 0
0.0.0.0:22 0.0.0.0:* LISTEN 895/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
1174/master tcp6 0 0 :::10051 :::* LISTEN 2432/zabbix_server tcp6 0 0 :::3306
:::* LISTEN 1106/mysqld tcp6 0 0 :::22 :::* LISTEN 895/sshd tcp6 0 0 ::1:25
:::* LISTEN 1174/master
启动httpd服务,需要注意的是:启动之前,确保80端口没有被占用。
[root@yuioplvlinux-128 ~]# systemctl start httpd [root@yuioplvlinux-128 ~]#
systemctl enable zabbix-server Created symlink from
/etc/systemd/system/multi-user.target.wants/zabbix-server.service to
/usr/lib/systemd/system/zabbix-server.service. [root@yuioplvlinux-128 ~]#
systemctl enable httpd Created symlink from
/etc/systemd/system/multi-user.target.wants/httpd.service to
/usr/lib/systemd/system/httpd.service.
在浏览器中输入地址:http://192.168.30.128/zabbix,打开的页面如下:

 



点击下一步,可以看到一个Fail,这是因为没有配置时区;



编辑/etc/php.ini,新增一行;
date.timezone = Asia/Shanghai
重启httpd服务后,刷新页面;



输入数据库地址和密码;



Host和Port为默认的,需要做了更改,在这修改即可;



配置成功页面如下:



登录账户默认是:Admin,密码是:zabbix;



登录的页面如下:



修改默认密码;



输入密码并确认,将语言选择为简体中文;





刷新后页面如下:



3.2 客户端安装zabbix

客户端下载zabbix的yum源后,使用命令“yum install -y zabbix-agent”安装;

安装完成后,编辑/etc/zabbix/zabbix_agentd.conf配置文件;
Server=127.0.0.1修改为Server=192.168.30.128 #定义服务端的ip(被动模式)
ServerActive=127.0.0.1修改为ServerActive=192.168.30.128 #定义服务端的ip(主动模式)
Hostname=Zabbix server修改为Hostname=linux-130 #这是自定义的主机名,需要在web界面下设置同样的主机名
启动zabbix服务;
[root@yuioplvlinux-130 ~]# systemctl start zabbix-agent [root@yuioplvlinux-130
~]# ps aux |grep zabbix zabbix 2000 0.0 0.1 80752 1272 ? S 05:01 0:00
/usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf zabbix 2001 0.0 0.1
80752 1316 ? S 05:01 0:00 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix 2002 0.0 0.1 80752 1836 ? S 05:01 0:00 /usr/sbin/zabbix_agentd: listener
#1 [waiting for connection] zabbix 2003 0.0 0.1 80752 1836 ? S 05:01 0:00
/usr/sbin/zabbix_agentd: listener #2 [waiting for connection] zabbix 2004 0.0
0.1 80752 1836 ? S 05:01 0:00 /usr/sbin/zabbix_agentd: listener #3 [waiting for
connection] zabbix 2005 0.0 0.2 80884 2224 ? S 05:01 0:00
/usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec] root 2007 0.0 0.0 112720
968 pts/0 R+ 05:01 0:00 grep --color=auto zabbix [root@yuioplvlinux-130 ~]#
netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q
Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:10050
0.0.0.0:* LISTEN 2000/zabbix_agentd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
749/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1000/master tcp6 0 0 :::10050
:::* LISTEN 2000/zabbix_agentd tcp6 0 0 :::3306 :::* LISTEN 931/mysqld tcp6 0 0
:::22 :::* LISTEN 749/sshd tcp6 0 0 ::1:25 :::* LISTEN 1000/master
3.3 忘记Admin密码

忘记Admin密码,可以登录服务器的数据库进行更改,操作如下:
[root@yuioplvlinux-128 ~]# mysql -uroot -p123456 Warning: Using a password on
the command line interface can be insecure. Welcome to the MySQL monitor.
Commands end with ; or \g. Your MySQL connection id is 209 Server version:
5.6.40-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or
its affiliates. All rights reserved. Oracle is a registered trademark of Oracle
Corporation and/or its affiliates. Other names may be trademarks of their
respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the
current input statement. mysql> use zabbix; #切换至zabbix库 Reading table
information for completion of table and column names You can turn off this
feature to get a quicker startup with -A Database changed mysql> desc users;
+----------------+---------------------+------+-----+---------+-------+ | Field
| Type | Null | Key | Default | Extra |
+----------------+---------------------+------+-----+---------+-------+ |
userid | bigint(20) unsigned | NO | PRI | NULL | | | alias | varchar(100) | NO
| UNI | | | | name | varchar(100) | NO | | | | | surname | varchar(100) | NO |
| | | | passwd | char(32) | NO | | | | | url | varchar(255) | NO | | | | |
autologin | int(11) | NO | | 0 | | | autologout | int(11) | NO | | 900 | | |
lang | varchar(5) | NO | | en_GB | | | refresh | int(11) | NO | | 30 | | | type
| int(11) | NO | | 1 | | | theme | varchar(128) | NO | | default | | |
attempt_failed | int(11) | NO | | 0 | | | attempt_ip | varchar(39) | NO | | | |
| attempt_clock | int(11) | NO | | 0 | | | rows_per_page | int(11) | NO | | 50
| | +----------------+---------------------+------+-----+---------+-------+ 16
rows in set (0.04 sec) mysql> update users set passwd=md5('yu-linux') where
alias= 'Admin'; #将密码修改为yu-linux Query OK, 1 row affected (0.07 sec) Rows
matched: 1 Changed: 1 Warnings: 0
 

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信