Zabbix-3.4 Introduction and installation configuration

I. Overview

1. Why Zabbix?

Zabbix is ​​an ability to monitor various network parameters and the health and integrity of the server software. Zabbix flexible notification mechanism that allows users to configure the mail-based alerts for virtually any event. This quick feedback server problems. Based on the stored data, Zabbix offers excellent reporting and data visualization capabilities. These features make Zabbix ideal for capacity planning program.

Over a period excerpt in Zabbix official handbook, based on my own experience with, I believe that the above description of some subtle, Zabbix more than the ability to monitor network parameters, server health, it almost can monitor any any index servers, software or application you can think of and configured by flip-flops and other components for these indicators zabbix timely e-mail, SMS and other alerts, and provides a powerful visualization capabilities.

Personally speaking, Zabbix takes only a little effort underlying monitor configuration script, its flexibility and features rolling market the vast majority of commercial or open source monitoring software, and large enough to serve as a company's monitoring framework, for example, to see before 58 of a distributed monitoring product introductions, feelings after reading the basic is this: If this product functionality provided by Zabbix take me on I know I can! In the next few notes that I will one by one example of how to build a complete database monitoring system.

I just copy the effect of drawing a Zabbix can be reached from the official website: (official Chinese example in this case only copy of zabbix interface support)

2. The architecture of about Zabbix

Zabbix has the following components:

Zabbix Server, Zabbix proxy, Zabbix agent, database, Zabbix web interface.

Where the agent is installed with each monitored host client, is responsible for collecting monitoring information. server is responsible for receiving information and monitoring data storage and web page rendering, proxy is an optional installation components can be monitored instead of the server to collect information in order to share the load or serve as a springboard to the server machine, database monitoring information is stored, web page is on display monitoring information, provide the operating functions such as adding a host page, create a user and so on.

熟悉Zabbix的数据流是灵活使用Zabbix的基础,从上述描述可以大致知道Zabbix的数据流,这其中涉及到的一些对象名非常重要,将会贯穿整个Zabbix的配置和使用。

  • 监控项(item)是server上负责接收数据信息的,其结构就是一个指定了返回数据类型的key-value,key名字自定义,对应的value就是获取监控值的脚本命令。

  • 监控项超过某个阈值之后需要告警,为了实现这种告警就需要为监控项创建触发器(trigger),默认的trigger被触发后告警自动显示在仪表板(dashboard)。

  • 默认告警是显示在仪表板(dashboard)的,为了实现短信或邮件告警,就需要创建告警媒介(media types),同时还需要为用户添加告警媒介这样才能将告警发送至用户的邮箱。

  • 为了更好地对监控项进行分类,可以把相似的监控项放在同一个应用集(applications)中。

  • 为了更好的对主机进行分类,可以将功能相同的主机放在同一个host group中。

3.本例的安装环境

CentOS release 6.10 (Final),内核版本2.6.32-754.el6.x86_64。

Zabbix Server IP:10.0.0.200,mysql数据库已经预先安装,版本是5.7.26(有一些向8.0看齐的坑,建议安装5.7.22及以下的版本)。

本例中web服务器使用LAMP环境,因此安装httpd。

Zabbix的安装有多种方式(rpm,容器安装等),本例中使用可以自定义位置和启动项的源码安装方式。

4.本例的主要参考网址

 
二、Zabbix安装配置

1.下载安装包

wget https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.15/zabbix-3.4.15.tar.gz

如果上述地址失效,到https://www.zabbix.com/download寻找相应的zabbix安装包。

2.解压源码tar包,创建zabbix用户(server、agent端都需要创建用户)

groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
tar -zxvf zabbix-3.4.15.tar.gz 

 3.安装依赖包

yum -y install pcre pcre-devel libevent libevent-devel OpenIPMI OpenIPMI-devel libssh2 libssh2-devel net-snmp-devel libcurl libcurl-devel unixODBC-devel libxml2-devel

 4.Server端LAMP架构的安装

4.1 安装php,zabbix服务端程序由php编写,因此需要安装php依赖。

//php解释器版本需要>=5.4版本才可以,本例中安装5.6版本的php。
//首先安装相关的yum源,然后安装php相关的包。
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
yum -y --nogpgcheck install php56w php56w-gd php56w-bcmath php56w-xml php56w-mbstring php56w-ldap php56w-mysql
//如果发现报错也不要慌,一般是你已经安装了其他源里的php,yum list|grep php一下,然后把已安装的非base源里的php全部卸载(先确保没有被其他应用在使用)。
//当然用其他源里的php也可以,只要能保证满足官网的那些php requirements即可。
//如果上述yum源也失效了,那么到网上搜索下其他的php的yum源。

 4.2 安装http,zabbix的web页面展示需要httpd(必须是1.3.12版本及以上)。

yum -y install httpd

4.3 安装mysql(步骤略)

需要注意的是my.cnf文件中一定要添加character_set_server=utf8的选项(或gbk),否则Zabbix无法支持中文界面。此外必须安装mysql时必须安装mysql-devel的包,否则zabbix server可能会安装失败。

5.编译安装Zabbix Server(root用户执行)

./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl
--以上各项含义参考:./configure --help,--enable-server表示安装server,proxy和agent的安装以此类推。
--安装mysql时必须安装mysql-devel否则会编译失败。
make && make install

 6.配置mysql数据库

完成zabbix安装后开始初始化数据库的表结构,zabbix提供了data.sql、images.sql、schema.sql这3个sql脚本来初始化mysql数据库,因为zabbix监控的数据都是要存到这个mysql库以便进行web展示的,以上表模板的位置在解压tar包目录下的database/mysql中。

 mysql> create database zabbix default charset utf8;
 mysql> grant all on zabbix.* to zabbix@localhost identified by 'zabbix';
 mysql> grant all on zabbix.* to zabbix@'%' identified by 'zabbix';
//需要注意的是虽然zabbix 3.4对mysql版本没要求,但是却要求Innodb存储引擎,因此为避免麻烦尽量装5.5以后的mysql版本吧(默认innodb存储引擎)。

 在server端执行全部的脚本:

mysql> source schema.sql
mysql> source images.sql
mysql> source data.sql

 7.编辑server端的配置文件

本例中zabbix的安装位置为/usr/local/zabbix,因此server的conf文件为/usr/local/zabbix/etc/zabbix_server.conf。

关于zabbix_agent.conf和zabbix_agentd.conf,这是agent端使用的配置文件,其中前者用超级服务(xinetd,新一代守护进程机制)的方式来启动,后者是以独立进程的方式来启动的,无论使用哪种方式都可以启动agent。

本例使用zabbix_agentd来启动agent端,配置文件也只需修改zabbix_agentd.conf:

//处理下配置文件中一大堆的注释,看不习惯:
cd /usr/local/zabbix/etc/
mv zabbix_server.conf zabbix_server.conf.bak
mv zabbix_agentd.conf zabbix_agentd.conf.bak
cat zabbix_server.conf.bak |grep -v "^$"|grep -v "^#">zabbix_server.conf
cat zabbix_agentd.conf.bak |grep -v "^$"|grep -v "^#">zabbix_agentd.conf

vi zabbix_server.conf(在本例中只要加个DBPassword=zabbix即可):

LogFile=/tmp/zabbix_server.log
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
Timeout=4
LogSlowQueries=3000

 8.启动zabbix Server

/usr/local/zabbix/sbin/zabbix_server 

 三、启动并配置zabbix web

mkdir /var/www/html/zabbix
cp -ar /root/zabbix-3.4.15/frontends/php/* /var/www/html/zabbix/
--/root/zabbix-3.4.15/是我zabbix解压目录。
service httpd start  --启动httpd

 至此可以通过http://10.0.0.200/zabbix访问zabbix了,10.0.0.200是我Zabbix Server服务器的IP地址。

可以看到有几项php的配置不符合要求,我们改正之:

vi /etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
always_populate_raw_post_data = -1 //这项默认是注释的

 重启httpd服务后刷新,全部通过。

填入数据库的账号密码即可。

根据提示我们下载zabbix.conf.php文件,然后放置到指定位置:/var/www/html/zabbix/conf/

最后的登陆界面如下所示:(默认的账号是admin,密码是zabbix)

四、agent客户端安装配置

前边我们已经在agent节点添加了zabbix用户并下载了zabbix源码安装包,这里只需要传输到server端使用即可:

//在本例中server端也要被监控因此也需要安装agent组件,但其实server在编译安装过程中已经包含了agent的功能,因此实际上在server端直接编辑agent配置文件并启动就可以了。
./configure --prefix=/usr/local/zabbix --enable-agent
 make && make install
cd /usr/local/zabbix/etc/
mv zabbix_agentd.conf zabbix_agentd.conf.bak
cat zabbix_agentd.conf.bak |grep -v "^$"|grep -v "^#">zabbix_agentd.conf

 然后修改/usr/local/zabbix/etc/zabbix_agentd.conf文件:

LogFile=/tmp/zabbix_agentd.log
Server=10.0.0.200
#与server进行active check配置
ServerActive=10.0.0.200:10051
//passive与active模式的区别在于,前者是server端主动来获取数据,后者是客户端主动向server发送数据,因此后者压力更小。
//server端的监听端口是10051,agent端使用的端口是10050。

 

//启动agentd:
/usr/local/zabbix/sbin/zabbix_agentd && ps -ef|grep zabbix_agentd
//关闭agentd:
for p in `ps -ef|grep zabbix_agentd|grep -v grep|awk '{print $2}'`;do kill -9 $p;done && ps -ef|grep zabbix_agentd

 五、web端主机配置

之前已经完成了zabbix server和agent端的基本配置,但想要实现正常的监控还需要在web端添加所有的agent主机信息(本例中有3个,即2个agent服务器和server端的agent)。

我们先在所有agent节点的配置文件中添加:

Hostname=<为agent自定义的主机名(可以与服务器主机名不一样)或者直接写IP>

然后在web界面的配置-->主机中添加所有需要监控的agent主机,这里添加的主机名称必须与agent配置文件中设置的Hostname一致。官网的原文描述如下:

With Zabbix agent running on the host you are configuring, the agent configuration file parameter Hostname must have the same value as the host name entered here. The name in the parameter is needed in the processing of active checks.

DNS名称可以不填,如果要填就要和/etc/hosts文件或DNS服务中的DNS条目一致。

下例添加的agent主机就是zabbix server本身,因为zabbix server本身也要被监控嘛,可以看到使用的端口是10050(agent端口)。

更新后返回主机页面点击状态的按钮使其成为开启状态(或者在添加主机时直接勾选已启用):

至此,zabbix的基本配置已经完毕,以后只需要按需求为主机添加模板或监控项进行监控即可。

Guess you like

Origin www.cnblogs.com/leohahah/p/11165612.html