Zabbix监控服务

zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。 zabbix由2部分构成,zabbix server与可选组件zabbix agent。 zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。

环境

系统 IP地址 组件
Centos7 192.168.71.128 LAMP+ zabbix-server-mysq+zabbix-web-mysql
Centos7 192.168.71.129 zabbix-agent

kaiti字符集源码包

kaiti源码包 密码:dzr8

一、监控端配置

1、关闭防火墙

[root@localhost ~]# systemctl stop firewalld.service [root@localhost ~]# systemctl disable firewalld.service [root@localhost ~]# setenforce 0


2、监控端搭建LAMP架构

[root@localhost ~]# yum install httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash -y


3、修改httpd、php配置文件

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf [root@localhost ~]# vim /etc/php.ini


4、开启httpd和mysql服务

[root@localhost ~]# systemctl start httpd.service [root@localhost ~]# systemctl start mariadb.service


5、检查httpd和mysql端口

[root@localhost ~]# netstat -ntap | egrep '(80|3306)' tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2432/mysqld
tcp6 0 0 :::80 :::* LISTEN 2130/httpd


6、对mysql数据库进行基本设定

[root@localhost ~]# mysql_secure_installation

Enter current password for root (enter for none): #第一次配置数据库没有密码,直接回车 Set root password? [Y/n] y #是否设置数据库root密码 New password: #输入密码 Re-enter new password: #再次确认密码 Remove anonymous users? [Y/n] n #是否移除匿名用户 Disallow root login remotely? [Y/n] n #不允许root用户远程登录 Remove test database and access to it? [Y/n] n #是否移除测试数据库database Reload privilege tables now? [Y/n] y #是否现在刷新权限列表


---
**7、进入数据库创建zabbix数据库并授权**
>![](http://i2.51cto.com/images/blog/201810/26/6b12a2c62c722c45e0c34965d9cee422.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)

---

**8、测试php连接数据库**
>[root@localhost ~]# vim /var/www/html/index.php 

<?php $link=mysql_connect('192.168.71.128','zabbix','admin123'); #连接zabbix数据库,密码admin123 if($link) echo "Success!!"; #连接成功返回Success else echo "Fail!!"; #连接失败范围Fail mysql_close(); ?>


	(连接数据库失败问题解决ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES))
	这里是因为有空用户存在,所以需要删除空用户才能连接。
![](http://i2.51cto.com/images/blog/201810/26/1775c2f34eb56f8ac9fd8e0e657c774b.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)

----

**9、网页浏览查看**
>![](http://i2.51cto.com/images/blog/201810/26/2436ccd8bd2512532e5ed2c36674086d.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)

---

**10、安装php相关组件及zabbix**

	[root@localhost ~]# yum install php-bcmath php-mbstring -y
	[root@localhost ~]#  rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm   #安装zabbix的yum源
	[root@localhost ~]# yum install zabbix-server-mysql zabbix-web-mysql -y
	

**11、按照官网设定导入数据库中对应内容**

	[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -p zabbix
	Enter password:     #这里输入zabbix授权用户的密码,如果被拒绝登陆,重新进数据库刷新权限
	

**12、过滤zabbix配置文件中的内容,显示如下:**
>[root@localhost ~]# grep -n '^'[a-Z] /etc/zabbix/zabbix_server.conf
![](http://i2.51cto.com/images/blog/201810/26/de0bf4227c40d3b4587be269990c3c90.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
---

**13、修改时区**
>[root@localhost ~]# vim /etc/httpd/conf.d/zabbix.conf
![](http://i2.51cto.com/images/blog/201810/26/16dad87e0d570f2eac0a40f858b89fbf.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)

---
**14、解决zabbix网页乱码问题**

>[root@localhost ~]# vim /usr/share/zabbix/include/defines.inc.php
	:%s /graphfont/kaiti/g           #使用vi编辑器命令行模式,全局替换

---
**15、复制字符集包到zabbix指定文件中**

>[root@localhost zabbix]# cp STKAITI.TTF  /usr/share/zabbix/fonts/
	[root@localhost zabbix]# ls /usr/share/zabbix/fonts/
	graphfont.ttf  STKAITI.TTF
	
---
**16、开启zabbix服务,重启httpd服务**
>root@localhost zabbix]# systemctl start zabbix-server.service 
[root@localhost zabbix]# systemctl restart httpd.service


---
**17、进入网页安装zabbix**
![](http://i2.51cto.com/images/blog/201810/26/49281b1bd490a5a9b9d9e6062fef3b6d.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
![](http://i2.51cto.com/images/blog/201810/26/2cd589d6fed11c571e141ba2a338ab50.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
![](http://i2.51cto.com/images/blog/201810/26/5f0c68b34e6c33d5dfd86ce188ddeedf.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
![](http://i2.51cto.com/images/blog/201810/26/9d762aaddd891955e84cfd3712ce4ff8.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
![](http://i2.51cto.com/images/blog/201810/26/365ee3add53e812fbe58fcfc154cd869.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
![](http://i2.51cto.com/images/blog/201810/26/79f24f87e67adc5bb8ad46485a1c6086.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
(安装完成后登陆使用默认账户Admin 密码zabbix进行登陆)


### 二、被监控端配置

**1、关闭防火墙**
>[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# systemctl disable firewalld.service
[root@localhost ~]# setenforce 0

---
**2、被监控端安装zabbix代理服务**

	[root@localhost ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm       #安装epel源
	[root@localhost ~]# yum install zabbix-agent -y     #被监控端安装代理服务

---
**3、修改代理端配置文件**
>[root@localhost ~]# grep -n '^'[a-Z] /etc/zabbix/zabbix_agentd.conf![](http://i2.51cto.com/images/blog/201810/26/5b6dedd2d84806b806f7710cee6557c9.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)

---
**4、代理端启动服务**
>[root@localhost ~]# systemctl start zabbix-agent.service 

---
**5、检查端口**

>[root@localhost ~]# netstat -ntap | grep 10050
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      37005/zabbix_agentd 
tcp6       0      0 :::10050                :::*                    LISTEN      37005/zabbix_agentd