一、Zabbix 简介
Zabbix 是一个高度集成的网络监控解决方案,可以提供企业级的开源分布式监控解决方案,由一个国外的团队持续维护更新,软件可以自由下载使用,运作团队靠提供收费的技术支持赢利。
- Zabbix 通过 C/S 模式采集数据,通过 B/S 模式在 web 端展示和配置。
- 被监控端:主机通过安装 agent方式采集数据,网络设备通过 SNMP 方式采集数据
- Server 端:通过收集 SNMP 和 agent发送的数据,写入数据库(MySQL,ORACLE 等),再通过 php+apache 在 web 前端展示。
Zabbix 运行条件:
- Server:Zabbix Server 需运 行在 LAMP( Linux+Apache+Mysql+PHP)环 境下(或者LNMP),对硬件要求
- Agent:目前已有的 agent 基本支持市面常见的 OS,包含 Linux、HPUX、Solaris、Sun、windows
- SNMP:支持各类常见的网络设备
Zabbix 主要功能
- 具备常见的商业监控软件所具备的功能(主机的性能监控、网络设备性能监控、数据库 性能监控、FTP等通用协议监控、多种告警方式、详细的报表图表绘制)
- 支持自动发现网络设备和服务器(可以通过配置自动发现服务器规则来实现)
- 扩展性强,server 提供通用接口(api 功能),可以自己开发完善各类监控(根据相关接口编写程序实现)
二、安装部署
主机环境:rhel7.3 selinux and firewalld disabled
| 主机名 | ip | 服务 |
|---|---|---|
| server1 | 172.25.254.1 | zabbix |
| server2 | 172.25.254.2 | nginx |
server1:server端
server2:agent(被监控端)
官方的 Zabbix 发行包适用于 RHEL 7、CentOS 7 和 Oracle Linux 7。在本文中,将使用 RHEL 来指代这三个操作系统。
1.添加 Zabbix 软件 yum 仓库
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# vim zabbix.repo
[zabbix]
name=4.0
baseurl=http://172.25.254.73/zabbix/4.0
gpgcheck=0
2.安装server前端(Zabbix 前端需要额外的基础安装包12个)
安装 Zabbix server(适用于 RHEL7,在 RHEL 6 上弃用)并使用 MySQL 数据库:
[[email protected] yum.repos.d]# yum install zabbix-server-mysql -y
安装 Zabbix 前端(适用于 RHEL 7,在 RHEL 6 上弃用)并使用 MySQL 数据库:
[[email protected] yum.repos.d]# yum install zabbix-web-mysql -y
安装数据库
[[email protected] yum.repos.d]# yum install mariadb-server -y
[[email protected] yum.repos.d]# systemctl start mariadb
[[email protected] yum.repos.d]# mysql_secure_installation
登陆数据库进行授权
[[email protected] yum.repos.d]# mysql -p
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> grant all privileges on zabbix.* to [email protected] identified by 'redhat';
使用 MySQL 来导入 Zabbix server 的初始数据库 schema 和数据,
[[email protected] zabbix-server-mysql-4.0.5]# pwd
/usr/share/doc/zabbix-server-mysql-4.0.5
[[email protected] zabbix-server-mysql-4.0.5]# zcat create.sql.gz
[[email protected] zabbix-server-mysql-4.0.5]# zcat create.sql.gz | mysql -uzabbix -p zabbix
进入数据库查看
[[email protected] ~]# mysql -p
MariaDB [(none)]> use zabbix;
MariaDB [zabbix]> show tables;
为 Zabbix server 配置数据库
编辑 zabbix_server.conf 文件以使用已创建的数据库。例如:
[[email protected] zabbix]# pwd
/etc/zabbix
[[email protected] zabbix]# vim zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=redhat
启动 Zabbix server 进程
[[email protected] ~]# systemctl start zabbix-server
[[email protected] ~]# systemctl enable zabbix-server
可以ps ax查看进程,看是否开启
Zabbix 前端配置
对于 RHEL 7 和更高版本,Zabbix 前端的 Apache 配置文件位于 /etc/httpd/conf.d/zabbix.conf。
虽然已经配置了一些 PHP 参数。但是有必要取消 “date.timezone” 注释,并为其 设置正确的时区 。
[[email protected] conf.d]# pwd
/etc/httpd/conf.d
[[email protected] conf.d]# vim zabbix.conf #修改时区
[[email protected] conf.d]# systemctl start httpd
[[email protected] conf.d]# systemctl enable httpd
浏览器输入172.25.254.1/zabbix(默认Adimn,密码:zabbix)
安装 Agent
[[email protected] ~]# yum install -y zabbix-agent
[[email protected] ~]# netstat -antlp | grep :10050 #此时服务没开
[[email protected] ~]# systemctl start zabbix-agent
二、Agent 主机的添加
1.在被监控端 server2 上安装 zabbix-agent(将server1的yum源发过去)
[[email protected] ~]# yum install zabbix-agent -y
- 手动添加
修改配置文件(不然添加上去的ZBX为灰色)
[[email protected] ~]# vim /etc/zabbix/zabbix_agentd.conf
98 Server=172.25.254.1 #server端(被动)
139 ServerActive=172.25.254.1 #主动
150 Hostname=server2
启动agent
[[email protected] ~]# systemctl enable zabbix-agent
[[email protected] ~]# systemctl start zabbix-agent
[[email protected] ~]# cd /var/log/zabbix/
[[email protected] zabbix]# ls
zabbix_agentd.log
[[email protected] zabbix]# cat zabbix_agentd.log
在浏览器里进行添加
注意:此时ZBX是灰色的,并没有被发现,重启被监控端的agent可以解决
[[email protected] zabbix]# systemctl restart zabbix-agent
[[email protected] zabbix]# cat zabbix_agentd.log
-
自动发现
步骤:
点击监测下的自动发现可以看到发现的主机
点击 配置->主机 可以看到新发现的主机
-
自动注册
先将已经添加的server2删除
步骤:
先将自动发现禁用
重启被监控端的zabbix-agent服务,查看日志,会发现自己注册添加上了
[[email protected] ~]# systemctl restart zabbix-agent
[[email protected] ~]# cd /var/log/zabbix/
[[email protected] zabbix]# ls
zabbix_agentd.log
[[email protected] zabbix]# cat zabbix_agentd.log
点击 配置->主机 可以看到已注册的主机