文章目录
1. zabbix介绍
Zabbix 由 Alexei Vladishev 创建,目前由其成立的公司—— Zabbix SIA 积极的持续开发更新维护, 并为用户提供技术支持服务。
Zabbix 是一个企业级分布式开源监控解决方案。
Zabbix 软件能够监控众多网络参数和服务器的健康度、完整性。Zabbix 使用灵活的告警机制,允许用户为几乎任何事件配置基于邮件的告警。这样用户可以快速响应服务器问题。Zabbix 基于存储的数据提供出色的报表和数据可视化功能。这些功能使得 Zabbix 成为容量规划的理想选择。
Zabbix 支持主动轮询(polling)和被动捕获(trapping)。Zabbix所有的报表、统计数据和配置参数都可以通过基于 Web 的前端页面进行访问。基于 Web 的前端页面确保您可以在任何地方访问您监控的网络状态和服务器健康状况。适当的配置后,Zabbix 可以在监控 IT 基础设施方面发挥重要作用。无论是对于有少量服务器的小型组织,还是拥有大量服务器的大企业而言,同样适用。
Zabbix 是免费的。Zabbix 是根据 GPL 通用公共许可证的第二版编写和发布的。这意味着产品源代码是免费发布的,可供公共使用。
2. Zabbix 特点和功能
zabbix的主要特点:
- 安装与配置简单,学习成本低
- 支持多语言(包括中文)
- 免费开源
- 自动发现服务器与网络设备
- 分布式监视以及WEB集中管理功能
- 可以无agent监视
- 用户安全认证和柔软的授权方式
- 通过WEB界面设置或查看监视结果
- email等通知功能
Zabbix主要功能:
- CPU负荷
- 内存使用
- 磁盘使用
- 网络状况
- 端口监视
- 日志监视
3. zabbix监控指标
系统:
- 内存使用率
- cpu使用率
- 磁盘使用率
- 监控文件是否被修改
网络:
- 流量
- 路由器
- 交换机
- 防火墙
业务:
- 进程
- 日志
硬件:
- 电源
- 温度
4. zabbix配置文件
zabbix配置文件有两种:
- 服务器端配置文件(/usr/local/etc/zabbix_server.conf)
- 客户端配置文件(/usr/local/etc/zabbix_agentd.conf)
- zabbix代理配置文件(/usr/local/etc/zabbix_proxy.conf)
服务器端配置文件zabbix_server.conf常用配置参数:
参数 | 作用 |
---|---|
LogFile | 设置服务端日志文件存放路径 |
ListenIP | 设置服务端监听IP |
ListenPort | 设置服务端监听的端口号 |
PidFile | 设置服务端进程号文件存放路径 |
DBHost | 指定zabbix的数据库服务器IP |
DBName | 指定zabbix使用的数据库库名 |
DBUser | 指定zabbix数据库登录用户 |
DBPassword | 指定zabbix数据库登录密码 |
DBPort | 指定zabbix数据库端口号 |
User | 设置zabbix以什么用户的身份运行 |
AlertScriptsPath | 设置告警脚本存放路径 |
ExternalScripts | 外部脚本存放路径 |
客户端配置文件zabbix_agentd.conf常用配置参数:
参数 | 作用 |
---|---|
Server | 指定zabbix服务器的IP或域名 |
ServerActive | 指定zabbix服务器的IP或域名 |
Hostname | 指定本机的主机名,此项必须与web界面配置项一致 |
UnsafeUserParameters | 是否启用自定义监控项,可选值为{1 |
UserParameter | 指定自定义监控脚本参数 |
LogFile | 设置客户端日志文件存放路径 |
5. 部署zabbix
环境说明:
环境 | IP | 要安装的应用 |
---|---|---|
服务器 | 192.168.50.138 | lamp架构 zabbix server zabbix agent |
客户端 | 192.168.50.132 | zabbix agent |
因为zabbix是用php语言开发的,所以必须先部署lamp架构,使其能够支持运行php网页
5.1 zabbix服务端安装
安装依赖包
[root@localhost ]# yum -y install net-snmp-devel libevent-devel
下载zabbix,并解压
wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-5.2.0.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg lamp zabbix-5.2.0.tar.gz
[root@localhost ~]# tar xf zabbix-5.2.0.tar.gz
创建用户和组
[root@localhost zabbix-5.2.0]# useradd -r -M -s /sbin/nologin zabbix
[root@localhost zabbix-5.2.0]# id zabbix
uid=991(zabbix) gid=989(zabbix) groups=989(zabbix)
创建zabbix数据库
[root@localhost ~]# mysql -uroot -p123
mysql: [Warning] Using a password on the command line interface
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.31 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All righ
Oracle is a registered trademark of Oracle Corporation and/or it
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current in
mysql> create database zabbix character set utf8 collate utf8_bin; 创建一个数据库
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123!'; 授权,给密码
Query OK, 0 rows affected, 2 warnings (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> quit
Bye
[root@localhost ~]# cd zabbix-5.2.0
[root@localhost zabbix-5.2.0]# ls
[root@localhost zabbix-5.2.0]# cd database/
[root@localhost database]# cd mysql/
[root@localhost mysql]# pwd
/root/zabbix-5.2.0/database/mysql
[root@localhost mysql]# ls
data.sql images.sql Makefile.in
double.sql Makefile.am schema.sql
[root@localhost mysql]# mysql -uzabbix -p'zabbix123!' zabbix < schema.sql 按顺序来配
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -p'zabbix123!' zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -p'zabbix123!' zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uroot -p123
mysql: [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 7
Server version: 5.7.31 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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>
mysql> use 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> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
| conditions |
| config |
| config_autoreg_tls |
| corr_condition |
| corr_condition_group |
| corr_condition_tag |
| corr_condition_tagpair |
| corr_condition_tagvalue |
| corr_operation |
| correlation |
| dashboard |
| dashboard_user |
| dashboard_usrgrp |
| dbversion |
| dchecks |
| dhosts |
| drules |
| dservices |
| escalations |
| event_recovery |
| event_suppress |
| event_tag |
| events |
| expressions |
| functions |
| globalmacro |
| globalvars |
| graph_discovery |
| graph_theme |
| graphs |
| graphs_items |
| group_discovery |
| group_prototype |
| history |
| history_log |
| history_str |
| history_text |
| history_uint |
| host_discovery |
| host_inventory |
| host_tag |
| hostmacro |
| hosts |
| hosts_groups |
| hosts_templates |
| housekeeper |
| hstgrp |
| httpstep |
| httpstep_field |
| httpstepitem |
| httptest |
| httptest_field |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
| interface_discovery |
| interface_snmp |
| item_application_prototype |
| item_condition |
| item_discovery |
| item_parameter |
| item_preproc |
| item_rtdata |
| items |
| items_applications |
| lld_macro_path |
| lld_override |
| lld_override_condition |
| lld_override_opdiscover |
| lld_override_operation |
| lld_override_ophistory |
| lld_override_opinventory |
| lld_override_opperiod |
| lld_override_opseverity |
| lld_override_opstatus |
| lld_override_optag |
| lld_override_optemplate |
| lld_override_optrends |
| maintenance_tag |
| maintenances |
| maintenances_groups |
| maintenances_hosts |
| maintenances_windows |
| mappings |
| media |
| media_type |
| media_type_message |
| media_type_param |
| module |
| opcommand |
| opcommand_grp |
| opcommand_hst |
| opconditions |
| operations |
| opgroup |
| opinventory |
| opmessage |
| opmessage_grp |
| opmessage_usr |
| optemplate |
| problem |
| problem_tag |
| profiles |
| proxy_autoreg_host |
| proxy_dhistory |
| proxy_history |
| regexps |
| rights |
| role |
| role_rule |
| screen_user |
| screen_usrgrp |
| screens |
| screens_items |
| scripts |
| service_alarms |
| services |
| services_links |
| services_times |
| sessions |
| slides |
| slideshow_user |
| slideshow_usrgrp |
| slideshows |
| sysmap_element_trigger |
| sysmap_element_url |
| sysmap_shape |
| sysmap_url |
| sysmap_user |
| sysmap_usrgrp |
| sysmaps |
| sysmaps_elements |
| sysmaps_link_triggers |
| sysmaps_links |
| tag_filter |
| task |
| task_acknowledge |
| task_check_now |
| task_close_problem |
| task_data |
| task_remote_command |
| task_remote_command_result |
| task_result |
| timeperiods |
| trends |
| trends_uint |
| trigger_depends |
| trigger_discovery |
| trigger_queue |
| trigger_tag |
| triggers |
| users |
| users_groups |
| usrgrp |
| valuemaps |
| widget |
| widget_field |
+----------------------------+
170 rows in set (0.00 sec)
编译安装zabbix
[root@localhost zabbix-5.2.0]# ./configure --enable-server \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2
[root@localhost zabbix-5.2.0]# make install
5.2 zabbix服务端配置
设置zabbix数据库连接密码
[root@localhost ~]# cd zabbix-5.2.0
[root@localhost zabbix-5.2.0]# cd /usr/local/etc/
[root@localhost etc]# ls
zabbix_agentd.conf zabbix_server.conf
zabbix_agentd.conf.d zabbix_server.conf.d
[root@localhost etc]# vim zabbix_server.conf
DBPassword=zabbix123! 取消注释,并填写密码
启动zabbix_server和zabbix_agentd
[root@localhost etc]# zabbix_server
[root@localhost etc]# zabbix_agentd
[root@localhost etc]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
5.3 zabbix服务端web界面安装与配置
5.3.1 zabbix web界面安装前配置
创建目录,修改权限
[root@localhost zabbix-5.2.0]# mkdir /usr/local/apache/htdocs/zabbix
[root@localhost zabbix-5.2.0]# cp -a ui/* /usr/local/apache/htdocs/zabbix/
[root@localhost ~]#
[root@localhost ~]# chown -R apache.apache /usr/local/apache/htdocs/
[root@localhost ~]# ll /usr/local/apache/htdocs/
total 12
-rw-r--r--. 1 apache apache 45 Jun 12 2007 index.html
-rw-r--r--. 1 apache apache 23 Nov 3 18:55 index.php
drwxr-xr-x. 12 apache apache 4096 Nov 3 20:14 zabbix
配置apache虚拟主机
[root@localhost ~]# vim /etc/httpd24/extra/vhosts.conf
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/zabbix"
ServerName zabbix.example.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix
<Directory "/usr/local/apache/htdocs/zabbix>
Require all granted
</Directory>
</VirtualHost>
- 此时访问网页这步会报错
修改/etc/php.ini的配置并重启php-fpm
[root@localhost ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
- 此时会恢复正常
- 此时告知没有权限
设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php
[root@localhost ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf
[root@localhost ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwxrwx. 3 apache apache 94 Oct 26 23:44 /usr/local/apache/htdocs/zabbix/conf
5.3.2 安装zabbix web界面
- 修改/etc/hosts文件,添加域名与IP的映射
- 在浏览器上访问域名,本文设置的域名为zabbix.wangqing.com,你需要修改成你自己的域名
➜ ~ sudo vim /etc/hosts
Password:
➜ ~ cat /etc/hosts
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
172.16.12.128 zabbix.wangqing.com
- 恢复zabbix/conf目录的权限为755:
[root@localhost ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf
[root@localhost ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxr-xr-x. 3 apache apache 117 Nov 3 20:40 /usr/local/apache/htdocs/zabbix/conf
5.4 客户端安装
1. 安装依赖包和编译器
[root@150 ~]# yum -y install net-snmp-devel libevent-devel make gcc gcc-c++ pcre*
2. 在官网下载包并解压缩
[root@150 ~]# tar xf zabbix-5.2.0.tar.gz
3. 创建zabbix用户
[root@150 ~]# useradd -r -M -s /sbin/nologin zabbix
4. 源码编译
[root@150 ~]# cd zabbix-5.2.0
[root@150 zabbix-5.2.0]# ./configure --enable-agent
[root@150 zabbix-5.2.0]# make install
5. 编辑配置文件
[root@150 etc]# pwd
/usr/local/etc
[root@150 etc]# vim zabbix_agentd.conf
Server=192.168.230.128 #改成服务端IP地址 被动模式
ServerActive=192.168.230.128 #改成服务端IP地址 主动模式
Hostname=test1 #改成标识本机的代号,用于添加主机
6. 开启服务
[root@150 etc]# zabbix_agentd
[root@150 etc]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@150 etc]#
5.5 登录zabbix
zabbix默认登录用户名和密码:
用户名 | 密码 |
---|---|
Admin | zabbix |