Zabbix监控系统部署及添加被控节点

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Zabbix监控系统部署及添加被控节点相关的知识,希望对你有一定的参考价值。

zabbix

zabbix是由 Alexei Vladishev开发的一种网络监视、管理系统,基于 Server-Client架构。可用于监视各种网络服务、服务器和网络机器等状态。

使用各种 Database-end 如 mysql, PostgreSQL, SQLite, Oracle 或 IBM DB2 储存资料。Server 端基于 C语言、Web 管理端frontend则是基于php所制作的。Zabbix可以使用多种方式监视。可以只使用 Simple Check 不需要安装 Client 端,亦可基于 SMTP 或 HTTP ... 各种协定做死活监视。

在客户端如 UNIX, Windows 中安装 Zabbix Agent 之后,可监视 CPU Load、网络使用状况、硬盘容量等各种状态。而就算没有安装 Agent 在监视对象中,Zabbix 也可以经由 SNMP、TCP、ICMP、利用 IPMI、SSH、telnet 对目标进行监视。

另外,Zabbix 包含 XMPP 等各种 Item 警示功能。

zabbix官网: https://www.zabbix.com

zabbix主要由二个部分构成 zabbix server和 zabbix agent;
zabbix proxy是用来管理其他的agent,作为代理使用。

系统环境:

主机名 操作系统 IP地址 服务名
zabbix centos7.4 192.168.96.70 zabbix2.2.23
www centos7.4 192.168.96.71 zabbix-agent
客户端 windows 10 192.168.96.2 网页浏览器

百度网盘 密码:x1uy

一、安装LAMP环境

1.安装lamp相关软件包

yum install -y httpd mariadb-server mariadb php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash php-bcmath php-mbstring

2.关闭防火墙及selinux

systemctl stop firewalld.service
setenforce 0

3.编辑httpd.conf

vim /etc/httpd/conf/httpd.conf

#设置域名
ServerName www.yun.com:80

#修改监听地址
Listen 192.168.96.70:80
#Listen 80

#添加主页类型index.php
DirectoryIndex index.html index.php

4.设置php配置中的时区

vim /etc/php.ini

#PRC:中国时区
date.timezone = PRC

技术分享图片

5.启动httpd、mariadb服务

systemctl enable httpd.service
systemctl start httpd.service
systemctl enable mariadb.service
systemctl start mariadb.service

6.检查服务信息

netstat -ntap | egrep ‘(80|3306)‘

技术分享图片

7.添加php测试页

vim /var/www/html/index.php

<?php
    phpinfo();
?>

8.客户端访问php测试页

http://192.168.96.70/index.php

技术分享图片

9.初始化mysql数据库

mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we‘ll need the current
password for the root user.  If you‘ve just installed MariaDB, and
you haven‘t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): // 回车键
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:    //设置新密码
Re-enter new password:      //确认密码
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] n     //是否移除anonymous用户
 ... skipping.

Normally, root should only be allowed to connect from ‘localhost‘.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n       //是否允许root用户远程登录
 ... skipping.

By default, MariaDB comes with a database named ‘test‘ that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n    //是否移除test数据库
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y    //重新加载数据表
 ... Success!

Cleaning up...

All done!  If you‘ve completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

10.登录mysql,创建zabbix数据库及创建zabbix用户并设置密码

mysql -u root -p

mysql> create database zabbix character set utf8 collate utf8_bin;

mysql> grant all privileges on zabbix.* to [email protected]‘%‘ identified by ‘123123‘;

mysql>flush privileges;

11.创建mysql数据库的测试网页文件

vim /var/www/html/mysql.php

<?php
$link=mysql_connect(‘192.168.96.70‘,‘zabbix‘,‘123123‘);
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
mysql_close();
?>

12.客户端访问mysql.php网页,显示success则访问mysql正常,fail则访问失败,请检查mysql.php中连接地址、用户名、密码是否正确,若还是有问题请检查mysql.user表用户名称是否有空而导致的错误,以下为解决方法

> select user,host from mysql.user;   

#用户名称为空占用导致本地无法登录远程可登录
+--------+-----------+
| user   | host      |
+--------+-----------+
| zabbix | %         |
| root   | 127.0.0.1 |
| root   | ::1       |
|        | localhost |
| root   | localhost |
|        | zabbix    |
| root   | zabbix    |
+--------+-----------+

> drop user ‘‘@localhost;

> drop user ‘‘@zabbix;

> flush privileges;

技术分享图片

技术分享图片

二、部署zabbix Server

1.下载zabbix官方yum源文件

rpm -i https://repo.zabbix.com/zabbix/2.2/rhel/7/x86_64/zabbix-release-2.2-1.el7.noarch.rpm

2.安装zabbix服务端及被控端软件包

yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y

3.导入zabbix数据库(必须安装此顺序导入,不然会报错)

cd /usr/share/doc/zabbix-server-mysql-2.2.23/create/

mysql -uzabbix -p  zabbix < schema.sql
mysql -uzabbix -p  zabbix < images.sql
mysql -uzabbix -p  zabbix < data.sql

4.编辑zabbix_service.conf配置,结果如下

egrep -n ‘^‘[a-Z] /etc/zabbix/zabbix_server.conf

39:LogFile=/var/log/zabbix/zabbix_server.log
50:LogFileSize=0
72:PidFile=/var/run/zabbix/zabbix_server.pid
91:DBName=zabbix
107:DBUser=zabbix
115:DBPassword=123123
124:DBSocket=/var/lib/mysql/mysql.sock
288:SNMPTrapperFile=/var/log/snmptt/snmptt.log
426:Timeout=3
468:AlertScriptsPath=/usr/lib/zabbix/alertscripts
478:ExternalScripts=/usr/lib/zabbix/externalscripts
512:LogSlowQueries=3000

5.编辑zabbix配置文件,指定时区

vim /etc/httpd/conf.d/zabbix.conf

php_value date.timezone Asia/Shanghai

技术分享图片

6.修正zabbix-web图表中文乱码

vim /usr/share/zabbix/include/defines.inc.php

#替换全文中所有graphfot为kaiti
:%s/graphfont/kaiti/g

技术分享图片

7.复制字体文件至zabbix/fonts/目录下

cp kaiti.ttf /usr/share/zabbix/fonts/

8.启动zabbix-server服务

systemctl enable zabbix-server
systemctl start zabbix-server

9.检查是否已监听10051端口

netstat -anpt | grep zabbix

技术分享图片

10.重启httpd服务

systemctl restart httpd.service

11.客户端访问(用户名:Admin 密码:zabbix),进入zabbix的安装界面

http://192.168.96.70/zabbix/

技术分享图片

技术分享图片

技术分享图片

技术分享图片

技术分享图片

技术分享图片

技术分享图片

技术分享图片

三、设置中文环境

1. Profile ---->User -----> Languages 中设置chinese(zh_cn)

技术分享图片

2. 网页界面已经显示为中文了

技术分享图片

四、添加被控服务器

服务器:zabbix

zabbix之前已经安装好了zabbix—agent软件包,这里就不用再安装,直接进行设置

1.编辑zabbix_agentd.conf配置,结果如下

egrep -n ‘^‘[a-Z] /etc/zabbix/zabbix_agentd.conf

13:PidFile=/var/run/zabbix/zabbix_agentd.pid
23:LogFile=/var/log/zabbix/zabbix_agentd.log
34:LogFileSize=0
85:Server=192.168.96.70
126:ServerActive=192.168.96.70
137:Hostname=zabbix
246:Include=/etc/zabbix/zabbix_agentd.d/

2.启动zabbix-agent服务

systemctl enable zabbix-agent.service
systemctl restart zabbix-agent.service

3.检查是否已监听10050端口

netstat -anpt | grep zabbix

技术分享图片

服务器:www

1.关闭防火墙及selinux

systemctl stop firewalld
setenforce 0

2.下载安装yum源文件

rpm -i https://repo.zabbix.com/zabbix/2.2/rhel/7/x86_64/zabbix-release-2.2-1.el7.noarch.rpm

3.安装zabbix-agent软件包

yum install -y zabbix-agent httpd

4.编辑zabbix_agentd.conf配置,结果如下

egrep -n ‘^‘[a-Z] /etc/zabbix/zabbix_agentd.conf

13:PidFile=/var/run/zabbix/zabbix_agentd.pid
23:LogFile=/var/log/zabbix/zabbix_agentd.log
34:LogFileSize=0
85:Server=192.168.96.70
126:ServerActive=192.168.96.70
137:Hostname=www
246:Include=/etc/zabbix/zabbix_agentd.d/

5.启动zabbix-agent服务

systemctl enable zabbix-agent.service
systemctl restart zabbix-agent.service
systemctl enable httpd.service
systemctl start httpd.service

6.检查是否已监听10050端口

netstat -anpt | grep zabbix_agent

技术分享图片

五、添加被控主机:

1. 配置-主机-创建主机:

技术分享图片

2.添加主机信息

技术分享图片

3.成功添加2台被控主机

技术分享图片

以上是关于Zabbix监控系统部署及添加被控节点的主要内容,如果未能解决你的问题,请参考以下文章

Zabbix实战之部署篇Zabbix使用SNMP监控Linux系统

centos6安装配置zabbix3被控端

自动化运维-ansible------playbook及实战案例

zabbix-proxy及ELK

Zabbix监控系统部署(源码)

zabbix-agent安装及添加配置nginx,mysql及系统的监控