一。 zabbix简介
Zabbix 是由Alexei Vladishev创建,目前由Zabbix SIA在持续开发和支持。
Zabbix 是一个企业级的分布式开源监控方案。
Zabbix是一款能够监控各种网络参数以及服务器健康性和完整性的软件。Zabbix使用灵活的通知机制,允许用户为几乎任何事件配置基于邮件的告警。这样可以快速反馈服务器的问题。基于已存储的数据,Zabbix提供了出色的报告和数据可视化功能。这些功能使得Zabbix成为容量规划的理想方案
Zabbix支持主动轮询和被动捕获。Zabbix所有的报告、统计信息和配置参数都可以通过基于Web的前端页面进行访问。基于Web的前端页面可以确保您从任何方面评估您的网络状态和服务器的健康性。适当的配置后,Zabbix可以在IT基础架构监控方面扮演重要的角色。对于只有少量服务器的小型组织和拥有大量服务器的大型公司也同样如此。
Zabbix是免费的。Zabbix是根据GPL通用公共许可证第2版编写和发行的。这意味着它的源代码都是免费发行的,可供公众任意使用。
Zabbix由几个主要的软件组件构成,这些组件的功能如下。
- .Server
.数据库存储
所有配置信息和Zabbix收集到的数据都被存储在数据库中。
- .Web界面
如果使用SQLite,Zabbix Web界面必须要跟Zabbix Server运行在同一台物理机器上。
- Proxy代理服务器
- .Agent监控代理
- .数据流
二 。zabbix安装
安装环境 centos7 zabbix3.4 参考文档 (https://www.zabbix.com/documentation/3.4/zh/manual/installation/install_from_packages)
使用yum环境安装
1》添加zabbix的yum源 (http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/下的 zabbix-release-3.4-1.el7.centos.noarch.rpm ) 安装
[root@bogon ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpm
Retrieving http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-release-3.4-1.el7.centos ################################# [100%]
[root@bogon ~]# rpm -ql zabbix-release-3.4-1.el7.centos.noarch.rpm
package zabbix-release-3.4-1.el7.centos.noarch.rpm is not installed
[root@bogon ~]# rpm -ql zabbix-release
/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
/etc/yum.repos.d/zabbix.repo
/usr/share/doc/zabbix-release-3.4
/usr/share/doc/zabbix-release-3.4/GPL
2》安装zabbix
安装 zabbix-server和前端web界面
yum install -y zabbix-server-mysql zabbix-web-mysql
如果某台机器需要被监控需要安装 zabbix-agent 安装过程:
yum install -y zabbix-agent
查看安装包:[root@bogon ~]# rpm -qa | grep zabbix
zabbix-release-3.4-1.el7.centos.noarch
zabbix-web-mysql-3.4.4-2.el7.noarch
zabbix-web-3.4.4-2.el7.noarch 是php的一些程序页面
zabbix-server-mysql-3.4.4-2.el7.x86_64
查看安装文件[root@bogon ~]# rpm -ql zabbix-server-mysql-3.4.4-2.el7.x86_64
/etc/logrotate.d/zabbix-server 使用了日志轮询日志文件在 /var/log/zabbix/zabbix_server.log
/etc/zabbix/zabbix_server.conf 这是配置文件
/usr/lib/systemd/system/zabbix-server.service
/usr/lib/tmpfiles.d/zabbix-server.conf
/usr/lib/zabbix/alertscripts
/usr/lib/zabbix/externalscripts
/usr/sbin/zabbix_server_mysql
/usr/share/doc/zabbix-server-mysql-3.4.4
/usr/share/doc/zabbix-server-mysql-3.4.4/AUTHORS
/usr/share/doc/zabbix-server-mysql-3.4.4/COPYING
/usr/share/doc/zabbix-server-mysql-3.4.4/ChangeLog
/usr/share/doc/zabbix-server-mysql-3.4.4/NEWS
/usr/share/doc/zabbix-server-mysql-3.4.4/README
/usr/share/doc/zabbix-server-mysql-3.4.4/create.sql.gz
/usr/share/man/man8/zabbix_server.8.gz
/var/log/zabbix
/var/run/zabbix
zabbix使用mysql存储监控数据 必须初始化mysql的数据库信息安装mysql
yum -y install mariadb-server
启动mysql测试是否成功登录(默认mariadb数据库用户名和密码均是root)[root@bogon ~]# service mariadb start
Redirecting to /bin/systemctl start mariadb.service
[root@bogon ~]# mysql -uroot -proot
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.02 sec)
创建zabbix需要的数据库和表结构 参考(https://www.zabbix.com/documentation/3.4/manual/appendix/install/db_scripts)
默认脚本位于源码包 /database目录下 下载源码包(https://www.zabbix.com/download) 传入linux后解压
[root@bogon database]# tar zxvf zabbix-3.4.4.tar.gz
[root@bogon zabbix-3.4.4]# cd database
[root@bogon database]# ll
total 20
drwxr-xr-x 2 a a 55 Nov 9 02:37 ibm_db2
-rw-r--r-- 1 a a 392 Nov 9 02:37 Makefile.am
-rw-r--r-- 1 a a 14974 Nov 9 02:37 Makefile.in
drwxr-xr-x 2 a a 55 Nov 9 02:37 mysql
drwxr-xr-x 2 a a 55 Nov 9 02:37 oracle
drwxr-xr-x 2 a a 55 Nov 9 02:37 postgresql
drwxr-xr-x 2 a a 55 Nov 9 02:37 sqlite3
这个目录可以看到zabbix支持的数据库 我们这里使用mysql 进入mysql目录[root@bogon mysql]# ll
total 4860
-rw-r--r-- 1 a a 2861223 Nov 9 02:37 data.sql
-rw-r--r-- 1 a a 1978341 Nov 9 02:37 images.sql
-rw-r--r-- 1 a a 134738 Nov 9 02:37 schema.sql
创建一个mysql账号用于zabbix程序 同时创建zabbix数据库[root@bogon mysql]# mysql -uroot -proot
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 3
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
Query OK, 0 rows affected (0.00 sec)
依次导入三个脚本到zabbix数据库[root@bogon mysql]# mysql -uzabbix -pzabbix zabbix < schema.sql
[root@bogon mysql]# mysql -uzabbix -pzabbix zabbix < images.sql
[root@bogon mysql]# mysql -uzabbix -pzabbix zabbix < data.sql
如果不想下载源码包 安装包里也有这个脚本名字是create.sql 包含了这三个脚本的sql语句 前提是用户和数据库必须提前创建好 /usr/share/doc/zabbix-server-mysql-3.4.4
zcat create.sql.gz | mysql -uroot -proot zabbix
修改zabbitserver配置文件 配置好数据库信息 (/etc/zabbix/zabbix_server.conf)# vi /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
启动zabbitserver[root@bogon zabbix]# systemctl start zabbix-server
[root@bogon zabbix]# systemctl status zabbix-server
● zabbix-server.service - Zabbix Server
Loaded: loaded (/usr/lib/systemd/system/zabbix-server.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2017-11-28 19:54:31 PST; 5s ago
Process: 3262 ExecStart=/usr/sbin/zabbix_server -c $CONFFILE (code=exited, status=0/SUCCESS)
Main PID: 3264 (zabbix_server)
CGroup: /system.slice/zabbix-server.service
├─3264 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
├─3269 /usr/sbin/zabbix_server: configuration syncer [waiting 60 sec for processes]
├─3270 /usr/sbin/zabbix_server: alerter #1 started
├─3271 /usr/sbin/zabbix_server: alerter #2 started
├─3272 /usr/sbin/zabbix_server: alerter #3 started
├─3273 /usr/sbin/zabbix_server: housekeeper [startup idle for 30 minutes]
├─3274 /usr/sbin/zabbix_server: timer #1 [processed 0 triggers, 0 events in 0.000000 sec, 0 maintenances in 0.000000 sec, idle 29 sec]
├─3275 /usr/sbin/zabbix_server: http poller #1 [got 0 values in 0.002017 sec, idle 5 sec]
├─3276 /usr/sbin/zabbix_server: discoverer #1 [processed 0 rules in 0.001625 sec, idle 60 sec]
├─3277 /usr/sbin/zabbix_server: history syncer #1 [synced 0 items in 0.000002 sec, idle 1 sec]
├─3278 /usr/sbin/zabbix_server: history syncer #2 [synced 0 items in 0.000001 sec, idle 1 sec]
├─3279 /usr/sbin/zabbix_server: history syncer #3 [synced 0 items in 0.000002 sec, idle 1 sec]
├─3280 /usr/sbin/zabbix_server: history syncer #4 [synced 0 items in 0.000002 sec, idle 1 sec]
├─3281 /usr/sbin/zabbix_server: escalator #1 [processed 0 escalations in 0.002437 sec, idle 3 sec]
├─3282 /usr/sbin/zabbix_server: proxy poller #1 [exchanged data with 0 proxies in 0.000005 sec, idle 5 sec]
├─3283 /usr/sbin/zabbix_server: self-monitoring [processed data in 0.000012 sec, idle 1 sec]
├─3291 /usr/sbin/zabbix_server: task manager [processed 0 task(s) in 0.002634 sec, idle 5 sec]
├─3294 /usr/sbin/zabbix_server: poller #1 [got 0 values in 0.000652 sec, idle 5 sec]
├─3295 /usr/sbin/zabbix_server: poller #2 [got 0 values in 0.000269 sec, idle 5 sec]
├─3296 /usr/sbin/zabbix_server: poller #3 [got 0 values in 0.000196 sec, idle 5 sec]
├─3297 /usr/sbin/zabbix_server: poller #4 [got 0 values in 0.001178 sec, idle 5 sec]
├─3298 /usr/sbin/zabbix_server: poller #5 [got 0 values in 0.000204 sec, idle 5 sec]
├─3299 /usr/sbin/zabbix_server: unreachable poller #1 [got 0 values in 0.000200 sec, idle 5 sec]
├─3300 /usr/sbin/zabbix_server: trapper #1 [processed data in 0.000000 sec, waiting for connection]
├─3301 /usr/sbin/zabbix_server: trapper #2 [processed data in 0.000000 sec, waiting for connection]
├─3302 /usr/sbin/zabbix_server: trapper #3 [processed data in 0.000000 sec, waiting for connection]
├─3305 /usr/sbin/zabbix_server: trapper #4 [processed data in 0.000000 sec, waiting for connection]
├─3306 /usr/sbin/zabbix_server: trapper #5 [processed data in 0.000000 sec, waiting for connection]
├─3310 /usr/sbin/zabbix_server: icmp pinger #1 [got 0 values in 0.000316 sec, idle 5 sec]
├─3311 /usr/sbin/zabbix_server: alert manager #1 started
├─3315 /usr/sbin/zabbix_server: preprocessing manager #1 started
├─3316 /usr/sbin/zabbix_server: preprocessing worker #1 started
├─3320 /usr/sbin/zabbix_server: preprocessing worker #2 started
└─3321 /usr/sbin/zabbix_server: preprocessing worker #3 started
Nov 28 19:54:31 bogon systemd[1]: Starting Zabbix Server...
Nov 28 19:54:31 bogon systemd[1]: PID file /run/zabbix/zabbix_server.pid not readable (yet?) after start.
Nov 28 19:54:31 bogon systemd[1]: Started Zabbix Server.
启动前端界面 (zabbix-web自动安装httpd和php服务 只需要启动httd即可访问zabbix)systemctl start httpd
访问 http://192.168.58.152/zabbix 一般提示浏览器过期 跳过就行 到第二步骤说php没有设置timezone
查看系统当前时区(Ameria 时区不对时间会出错)
[root@bogon local]# timedatectl
Local time: Tue 2017-11-28 20:03:02 PST
Universal time: Wed 2017-11-29 04:03:02 UTC
RTC time: Wed 2017-11-29 04:03:02
Time zone: America/Los_Angeles (PST, -0800)
查看系统已经安装的时区(有亚洲)[root@bogon local]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
1) Africa
2) Americas
3) Antarctica
4) Arctic Ocean
5) Asia
6) Atlantic Ocean
7) Australia
8) Europe
9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
设置成 亚洲/上海时区[root@bogon local]# timedatectl set-timezone Asia/Shanghai
安装ntpdate同步时间[root@bogon local]# yum -y install ntpdate
[root@bogon local]# ntpdate time1.aliyun.com
29 Nov 12:28:21 ntpdate[4623]: adjust time server 115.28.122.198 offset -0.018276 sec
Zabbix前端的Apache配置文件位于 /etc/httpd/conf.d/zabbix.conf <IfModule mod_php5.c>
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value always_populate_raw_post_data -1
# php_value date.timezone Europe/Riga
</IfModule>
最后一个#注释打开 修改为 php_value date.timezone Asia/Shanghai
修改后重启 httpd服务 service httpd restart
按照界面安装步骤 再次设置mysql的一些信息 完成后 进入主页面 默认登录用户名和密码是(Admin/zabbix)设置简体中文环境
点击右上角 人形图标 进入设置界面 点击选择Chinese(zh_CN)即可