温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Centos7.2下搭建Zabbix3.2(简)

发布时间:2020-04-03 01:26:47 来源:网络 阅读:1940 作者:Bella小旭 栏目:数据库

一、简介   

    zabbix(音同 zbix)是一个基于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地址主要软件
Zabbix ServerCentos7.2192.168.1.103zabbix-3.2.4、httpd、mariadb、php等。
Zabbix AgentCentos7.2192.168.1.105zabbix-3.2.4
Zabbix AgentWindows Server 2008 R2192.168.1.106


三、搭建Zabbix Server并添加主机


1、安装Zabbix Server


安装所需软件包

[root@bogon ~]# yum -y install gcc* make php php-gd php-mysql php-bcmath php-mbstring php-xml curl curl-devel net-snmp   net-snmp-devel perl-DBI httpd mariadb* mysql-devel libxml2-devel curl-devel unixODBC-devel net-snmp-devel OpenIPMI-devel vim


创建zabbix用户

[root@bogon zabbix-3.2.4]# useradd zabbix


关闭防火墙(由于本次是实验环境为了调试方便所以关闭防火墙,生产环境中一定要打开防火墙,并配置相关规则)

[root@bogon zabbix-3.2.4]# systemctl stop firewalld.service


[root@bogon ~]# tar xf zabbix-3.2.4.tar.gz 

[root@bogon ~]# cd zabbix-3.2.4

[root@bogon zabbix-3.2.4]# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-unixodbc

[root@bogon zabbix-3.2.4]# make install


启动数据库

[root@bogon zabbix-3.2.4]# systemctl start mariadb.service


给数据库设置密码(本次试验中是新安装的数据库,所以将密码设置为linux.com123)

[root@bogon zabbix-3.2.4]# mysqladmin -u root -p password linux.com123

Enter password:                     ←直接敲回车即可(新安装的数据库默认是没有密码的)

[root@bogon zabbix-3.2.4]# mysql -u root -p

Enter password:                     ←输入刚刚设置的密码


创建新用户,用户名为“zabbix”密码“zabbix”,并将zabbix数据库授权给zabbix用户

MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;

MariaDB [(none)]> insert into mysql.user(Host,User,Password) values('localhost','zabbix',password('zabbix'));

MariaDB [(none)]> flush privileges;


MariaDB [(none)]> grant all on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix' with grant option;


MariaDB [(none)]> flush privileges; 

MariaDB [(none)]> quit


导入Sql语句

[root@bogon zabbix-3.2.4]# mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql 

[root@bogon zabbix-3.2.4]# mysql -uzabbix -pzabbix zabbix < database/mysql/p_w_picpaths.sql 

[root@bogon zabbix-3.2.4]# mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql 


在/etc/php.ini中添加或修改如下内容

[root@bogon zabbix-3.2.4]# vim /etc/php.ini

878    date.timezone= Asia/Shanghai

384    max_execution_time = 300

672    post_max_size = 32M

407    memory_limit = 128M

1707  mbstring.func_overload = 1


将httpd、mariadb添加到系统启动

[root@bogon ~]# systemctl enable httpd.service

[root@bogon ~]# systemctl enable mariadb.service


[root@bogon zabbix-3.2.4]#cp misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server

[root@bogon zabbix-3.2.4]#cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd


[root@bogon zabbix-3.2.4]# chkconfig --add zabbix_server

[root@bogon zabbix-3.2.4]# chkconfig zabbix_server on


[root@bogon zabbix-3.2.4]# chkconfig --add zabbix_agentd

[root@bogon zabbix-3.2.4]# chkconfig zabbix_agentd on

[root@bogon zabbix-3.2.4]# cp -r ./frontends/php/ /var/www/html/zabbix

[root@bogon zabbix-3.2.4]# chown -R apache.apache /var/www/html/zabbix


启动httpd服务

[root@bogon ~]# systemctl start httpd.service


Zabbix Agent配置(被监控端)

[root@bogon ~]# yum -y install gcc* make vim

[root@bogon ~]# setenforce 0

[root@bogon ~]# vim /etc/sysconfig/selinux 

[root@bogon ~]# systemctl stop firewalld.service

[root@bogon ~]# setenforce 0

[root@bogon ~]# vim /etc/sysconfig/selinux 

[root@bogon ~]# systemctl stop firewalld.service


编译安装Zabbix Agent

[root@bogon zabbix-3.2.4]# ./configure --enable-agent

[root@bogon zabbix-3.2.4]# make install


[root@bogon zabbix-3.2.4]#cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd

[root@bogon zabbix-3.2.4]# chkconfig --add zabbix_agentd

[root@bogon zabbix-3.2.4]# chkconfig zabbix_agentd on

[root@bogon zabbix-3.2.4]# chkconfig --list zabbix_agentd 

[root@bogon zabbix-3.2.4]# useradd zabbix


更改如下三项

[root@bogon zabbix-3.2.4]# vim /usr/local/etc/zabbix_agentd.conf

Server=192.168.1.104

ServerActive=192.168.1.104

Hostname=Linux                ←需要和下文Web中添加的主机名一致

[root@bogon ~]# systemctl start zabbix_agentd.service


Web端配置

通过浏览器访问“http://192.168.0.104/zabbix”


点击“next step”(如果出现红色选项需要在/etc/php.ini中将相应的值修改为与required相等)



Centos7.2下搭建Zabbix3.2(简)


输入数据库名、用户名以及密码

Centos7.2下搭建Zabbix3.2(简)


输入主机名

Centos7.2下搭建Zabbix3.2(简)


确认信息是否正确

Centos7.2下搭建Zabbix3.2(简)



zabbix对网页目录权限不足,所以需要我们手动下载配置文件,并放到网页中提示的位置(1、点击Download the configuration file。 2、将该文件存放到“/var/www/html/zabbix/conf/zabbix.conf.php”)

Centos7.2下搭建Zabbix3.2(简)


刷新网页发现已经找到该配置文件

Centos7.2下搭建Zabbix3.2(简)






默认用户名“Admin”、密码“zabbix”

Centos7.2下搭建Zabbix3.2(简)


进入到zabbix首页面发现zabbix服务显示没有启动,但通过shell查看服务的状态发现服务已经启动

[root@bogon ~]# systemctl status zabbix_server.service

● zabbix_server.service - SYSV: Starts and stops Zabbix Server using chkconfig

   Loaded: loaded (/etc/rc.d/init.d/zabbix_server; bad; vendor preset: disabled)

   Active: active (running) since 三 2017-03-15 09:20:20 CST; 30min ago


这是由于selinux机制限制所造成的,关闭selinux机制即可

[root@bogon ~]# setenforce 0


将SELINUX项更改为disabled

[root@bogon ~]# vim /etc/sysconfig/selinux

SELINUX=disabled


Centos7.2下搭建Zabbix3.2(简)


刷新页面即可

Centos7.2下搭建Zabbix3.2(简)


点击“configuration → Host groups”并点击右上角的“create host group”创建一个新的host group


Centos7.2下搭建Zabbix3.2(简)


数据新建host group的名称,并选择需要用到的模板(添加到该组的主机默认会使用添加该模板)

Centos7.2下搭建Zabbix3.2(简)


2、添加主机

点击“configuration→hosts”然后点击右上角的create host新建主机

输入主机名、选择主机组、填写被监控主机的IP地址

Centos7.2下搭建Zabbix3.2(简)



点击templates并添加相应模板Centos7.2下搭建Zabbix3.2(简)


等待Availability中的ZBX变为绿色即表示可以与被监控主机正常通信

Centos7.2下搭建Zabbix3.2(简)









点击“Monitoring→graphs在右上角选择主机后即可查看被监控主机的数据

Centos7.2下搭建Zabbix3.2(简)


添加网卡监控项目

进入到“configuration→templates→选择需要添加网卡监控的模板→itmes”本次笔者选择的是Template OS Linux模板添加网卡监控

Centos7.2下搭建Zabbix3.2(简)


添加网卡监控需要添加两个Item(因为网卡流量是一进一出)

添加In方向item

1、在Name中填写In方向的名字本次实验使用的是“Incoming network traffic on Networkinterfacecard”

2、type中选择“Zabbix_agent”

3、key中输入“Net_incoming”

4、Type of information中选择“Numeric(float)”

5、Units选择Bps

6、其他按照下图中更改即可


Centos7.2下搭建Zabbix3.2(简)


添加Out方向item

1、在Name中填写In方向的名字本次实验使用的是“Net_Outgoing network traffic on Networkinterfacecard”

2、type中选择“Zabbix_agent”

3、key中输入“Net_Outgoing”

4、Type of information中选择“Numeric(float)”

5、Units选择Bps

6、其他按照下图中更改即可

Centos7.2下搭建Zabbix3.2(简)


添加完In、Out方向的item之后需要回到“configuration→templates→选择需要添加网卡监控的模板→graphs”

Centos7.2下搭建Zabbix3.2(简)


点击右上角的"Create graph"并在items中添加刚刚添加的两个item

Centos7.2下搭建Zabbix3.2(简)


在“monitoring→graphs”中查看

Centos7.2下搭建Zabbix3.2(简)


添加Windows监控

在官网下载Zabbix Agent windows版http://www.zabbix.com/downloadCentos7.2下搭建Zabbix3.2(简)


将文件解压放到windows的c盘下

Centos7.2下搭建Zabbix3.2(简)


编辑conf/zabbix_agentd.win.conf(建议使用notepad++编辑)

修改如下项:(和linux上类似)

Hostname=WindowsServer2008R2

ServerActive=192.168.1.104

Server=192.168.1.104


打开cmd,输入如下信息(将zabbix_agent添加到服务中)

c:\bin\win64\zabbix_agentd.exe -c c:\conf\zabbix_agentd.win.conf -i


启动服务

c:\bin\win64\zabbix_agentd.exe -c c:\conf\zabbix_agentd.win.conf -s


使用netstat -an | find "10050"查看端口是否启用

Centos7.2下搭建Zabbix3.2(简)


打开服务控制台也可以看到

Centos7.2下搭建Zabbix3.2(简)


在Zabbix Server web界面中添加主机

进入到“configuration→hosts”点击“create host”输入主机名、主机IP等信息

Centos7.2下搭建Zabbix3.2(简)


点击templates选择windows模板

Centos7.2下搭建Zabbix3.2(简)


添加完成

Centos7.2下搭建Zabbix3.2(简)


点击“monitoring→graph”并在右上角选择刚刚添加的windows主机查看图像

Centos7.2下搭建Zabbix3.2(简)


3、添加邮件报警

[root@bogon ~]# yum -y install mailx


添加如下几行

[root@bogon ~]# vim /etc/mail.rc

set from=1861097xxxx@163.com                ←发送邮件的邮箱地址

set smtp=smtp.163.com

set smtp-auth-user=1861097xxxx@163.com        ←同上,发送邮件的邮箱地址

set smtp-auth-password=lx3768150                ←笔者使用的是163的邮箱,需要使用授权码登录

set smtp-auth=login

[root@bogon ~]# systemctl start mailx.service


发送邮件测试

[root@bogon ~]# echo "zabbix test" | mail -s "zabbix" 1247718627@qq.com


编写发送脚本

[root@bogon ~]#vim /usr/local/share/zabbix/alertscripts/sendmail.sh

#!/bin/sh

#

#echo "$3" | mail -s "$2" $1

echo "$3" | sed s/'\r'//g | mail -s "$2" $1

 

[root@bogon ~]# chmod +x /usr/local/share/zabbix/alertscripts/sendmail.sh


接下来需要在Web中配置报警


打开“Administrator→media type →create media type”

Centos7.2下搭建Zabbix3.2(简)


打开“Administrator→user”点击admin,选择“media”并点击“add”

Centos7.2下搭建Zabbix3.2(简)


点击update更新

Centos7.2下搭建Zabbix3.2(简)


关闭Windows Server 2008 R2邮箱收到报警信息

Centos7.2下搭建Zabbix3.2(简)


问题汇总:

将zabbix更改为中文之后图像乱码

Centos7.2下搭建Zabbix3.2(简)


解决方法:

这个问题是由于zabbix的web端没有中文字库,我们最需要把中文字库加上即可。

1、选择C:\Windows\Fonts\选择一种中文字库例如“简体字”。点击右键复制

Centos7.2下搭建Zabbix3.2(简)


将字体上传到“Zabbix Server”的zabbix自体库中

Centos7.2下搭建Zabbix3.2(简)



将刚刚上传的文件名改为小写

[root@bogon fonts]# mv SIMFANG.TTF simfang.ttf


在如下两行中将默认的“DejaVuSans”更改为刚刚上传的“simfang”

[root@bogon ~]# vim /var/www/html/zabbix/include/defines.inc.php

//define('ZBX_FONT_NAME', 'DejaVuSans');

define('ZBX_FONT_NAME', 'simfang');


//define('ZBX_GRAPH_FONT_NAME',         'DejaVuSans');

define('ZBX_GRAPH_FONT_NAME',           'simfang');


刷新网页

Centos7.2下搭建Zabbix3.2(简)


相关资料:

百度知道zabbix

zabbix中文乱码

《Zabbix监控深度实践》


      笔者最近刚刚开始使用Zabbix,还不是特别的熟悉,如有哪里写错或者忘写的地方还请大家指出,谢谢!




向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI