zabbix 介绍
- zabbix是一个高度集成的监控解决方案,与Cacti、nagios类似。通过C/S模式采集监控数据,通过B/S模式实现web管理。
- 监控服务器:通过SNMP或Agent采集数据,数据可以写入Mysql,Oracle数据库中,服务器使用LAMP实现web端的管理。
- 被监控主机:被监控主机需要安装agent
- 服务端监听端口为10051,而被监控端即Zabbix——agents代理程序监控10050端口。
zabbix的特点
- zabbix的主要特点:
安装与配置简单,学习成本低
支持多语言(包括中文)
免费开源
自动发现服务器与网络设备
分布式监视以及WEB集中管理功能
可以无agent监视
用户安全认证和柔软的授权方式
通过WEB界面设置或查看监视结果
email等通知功能
Zabbix主要功能:
监控CPU负载、内存使用、磁盘使用、网络状态、端口监视、日志监视、插件开发自定义
zabbix配置文件
zabbix配置文件有两种:
服务器端配置文件(/usr/local/etc/zabbix_server.conf) 客户端配置文件(/usr/local/etc/zabbix_agentd.conf) zabbix代理配置文件(/usr/local/etc/zabbix_proxy.conf)
- 服务器端配置文件zabbix_server.conf常用配置参数:
- 客户端配置文件zabbix_agentd.conf常用配置参数:
部署zabbix
实验环境说明:
- 因为zabbix是用php语言开发的,所以必须先部署lamp架构,或者lnmp架构,使其能够支持运行php网页
zabbix服务端安装
在配置之前,我已近将lamp架构搭建好了,服务都起来了,详细看之前的博文
下面直接开始配置zabbix
- 安装依赖包
[root@localhost ~]# yum -y install net-snmp-devel libevent-devel 安装过程略....
- 下载zabbix
通常去zabbix.com下载源码包,这里我已近上传到/usr/src里面 [root@localhost ~]# cd /usr/src/ [root@localhost src]# ls zabbix-4.0.3.tar.gz
- 解压
[root@localhost src]# tar xf zabbix-4.0.3.tar.gz
- 创建zabbix用户和组
[root@localhost ~]# groupadd -r zabbix [root@localhost ~]# useradd -r -g zabbix -M -s /sbin/nologin zabbix
这里由于我用脚本部署的lamp架构,忘记了mysql密码。所以,先破解mysql密码,详细请看之前的博文
- 配置zabbix数据库
[root@100 ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.7.22 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> alter user 'root'@'localhost' identified by 'scl666'; #重置密码 Query OK, 0 rows affected (0.00 sec) 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.29 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> quit Bye
- 导入数据表
[root@localhost ~]# cd /usr/src/zabbix-4.0.3/database/mysql/ [root@localhost ~]# ls data.sql images.sql Makefile.am Makefile.in schema.sql [root@localhost ~]# mysql -uzabbix -pzabbix123! zabbix < schema.sql mysql: [Warning] Using a password on the command line interface can be insecure. [root@localhost ~]# mysql -uzabbix -pzabbix123! zabbix < images.sql mysql: [Warning] Using a password on the command line interface can be insecure. [root@localhost ~]# mysql -uzabbix -pzabbix123! zabbix < data.sql mysql: [Warning] Using a password on the command line interface can be insecure.
- 编译安装zabbix
[root@localhost ~]# cd /usr/src/zabbix-4.0.3 [root@localhost zabbix-4.0.3]# ./configure --enable-server \ --enable-agent \ --with-mysql \ --with-net-snmp \ --with-libcurl \ --with-libxml2 [root@localhost zabbix-4.0.3]# make install
- 修改服务端配置文件
- 设置数据库信息
[root@100 ~]# ls /usr/local/etc/ zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d [root@100 ~]# vim /usr/local/etc/zabbix_server.conf .... DBPassword=zabbix123! //设置zabbix数据库连接密码
- 启动zabbix_server和zabbix_agentd
[root@localhost ~]# zabbix_server [root@localhost ~]# zabbix_agentd [root@localhost ~]# ss -antl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 *:10050 *:* 客户端口 LISTEN 0 128 *:10051 *:* 服务端口 LISTEN 0 128 127.0.0.1:9000 *:* LISTEN 0 128 :::80 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 80 :::3306 :::*
- zabbix web界面安装前配置
- 修改/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 [root@localhost ~]# cd /usr/src/zabbix-4.0.3 [root@localhost zabbix-4.0.3]# ls aclocal.m4 ChangeLog config.log configure.ac frontends m4 man README AUTHORS compile config.status COPYING include Makefile misc sass bin conf config.sub database INSTALL Makefile.am missing src build config.guess configure depcomp install-sh Makefile.in NEWS [root@localhost zabbix-4.0.3]# mkdir /usr/local/apache/htdocs/zabbix [root@localhost zabbix-4.0.3]# cp -a frontends/php/* /usr/local/apache/htdocs/zabbix/ [root@localhost zabbix-4.0.3]# chown -R apache.apache /usr/local/apache/htdocs
- 配置apache虚拟主机
[root@100 zabbix-4.0.3]# vim /etc/httpd24/httpd.conf - 在末尾添加以下内容 <VirtualHost *:80> DocumentRoot "/usr/local/apache/htdocs/zabbix" ServerName www.xf.com ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1 <Directory "/usr/local/apache/htdocs/zabbix"> Options none AllowOverride none Require all granted </Directory> </VirtualHost>
- 设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php
[root@localhost conf.d]# chmod 777 /usr/local/apache/htdocs/zabbix/conf [root@localhost conf.d]# ll -d /usr/local/apache/htdocs/zabbix/conf drwxrwxrwx 2 apache apache 81 12月 20 2018 /usr/local/apache/htdocs/zabbix/conf
- 重启apache
[root@localhost conf.d]# apachectl -t Syntax OK [root@localhost conf.d]# apachectl stop [root@localhost conf.d]# apachectl start
网页输入ip地址:192.168.170.13(根据自己的apache服务端ip)
zabbix客户端安装
- 准备安装包
[root@localhost ~]# scp zabbix-4.0.3.tar.gz root@192.168.170.14:/usr/src
- 解压安装包
[root@localhost src]# tar xf zabbix-4.0.3.tar.gz [root@localhost src]# ls zabbix-4.0.3 zabbix-4.0.3.tar.gz
- 编译安装
[root@localhost zabbix-4.0.3]# ./configure --enable-agent \ …… [root@localhost zabbix-4.0.3]# make install
- 创建zabbix用户和组
[root@localhost ~]# groupadd -r zabbix [root@localhost ~]# useradd -r -g zabbix -M -s /sbin/nologin zabbix
- 修改配置文件
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf [root@localhost ~]# Server=192.168.170.13 #填写服务端ip ServerActive=192.168.170.13 服务端ip Hostname=14 本机的hostnam (随便写,仅起标识作用,非客户端hostname)
- 重启zabbix-agent服务
[root@localhost ~]# zabbix_agentd `` -去zabbix添加一个主机 ![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/20190826002953977.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjMxMzc0OQ==,size_16,color_FFFFFF,t_70) ![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/20190826003426468.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjMxMzc0OQ==,size_16,color_FFFFFF,t_70) ![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/20190826003630409.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjMxMzc0OQ==,size_16,color_FFFFFF,t_70)