[zabbix enterprise-level monitoring]

Table of contents

Zabbix

Zabbix Features

Experimental environment preparation

Server side

agent side

server side

Configure Alibaba Cloud yum source

Start LAMP corresponding service

Prepare java environment

Install zabbix from source code

MariaDB database authorization

Create a zabbix program user and authorize it to prevent permission errors

Modify zabbix configuration file

Configure php and apache

web installation zabbix

Zabbix page optimization

1. Adjust zabbix page to Chinese page

Zabbix monitoring host

Add yourself as a monitored machine


Zabbix

Key point one

  1. Introduction to Zabbix

In the process of enterprise network operation and maintenance, administrators must pay attention to the operating status of each server and network at all times in order to detect problems in time and reduce the occurrence of failures as much as possible. When there are a large number of devices, servers, etc. in the network, in order to obtain monitoring information more conveniently and quickly, some centralized monitoring software is usually used.

If you want to know the running status of the server in real time and solve problems in time when they occur, using monitoring software is a good way. For now, wherever there is a server, a monitoring system is indispensable. There are many existing monitoring system software, but zabbix can flexibly monitor server resources, and combines the advantages of cacti and nagios with more powerful functions to achieve enterprise-level Distributed monitoring, so it is more widely used in the market.

Zabbix is ​​an enterprise-level open source monitoring suite based on a web interface. The underlying architecture (server side and agent side) is written in C language. It is continuously maintained and updated by a foreign team. The software can be freely downloaded and used, and the operation team is charged for providing Technical support is profitable. Many organizations of different sizes in the world rely on Zabbix as their main monitoring platform, especially now that many Internet companies are using it. Provides distributed system monitoring and network monitoring functions, including host performance monitoring, network device performance monitoring, database performance monitoring, multiple alarm methods, detailed reports, chart drawing and other functions. The object of detection can be a Linux or Windows server, or a network device such as a router or a switch. Monitoring and data of remote network servers are provided through SNMP (Simple network protocol), zabbix agent, ping, port monitoring and other methods. Collection and other functions, and provides a notification mechanism so that system administrators can quickly locate and solve various problems in the system. Currently, the latest version of zabbix is ​​zabbix5.0, and the official website is 

Component Description:

1) Zabbix server: The core component responsible for receiving report information sent by the agent. All configuration, statistical data and operational data are organized by it;

2) Database storage: dedicated to storing all configuration information and data collected by zabbix;

3) web interface: GUI interface of zabbix;

4) proxy: an optional component, often used in distributed environments with many monitoring nodes. The proxy server collects some data and forwards it to the server, which can reduce the pressure on the server;

5) Agent: Deployed on the monitored host, it is responsible for collecting local host data such as CPU, memory, database and other data and sending it to the server or proxy;

Monitoring process:

  Agentd needs to be installed on the monitored host. It is responsible for regularly collecting various data and sending it to the zabbix server. The zabbix server stores the data in the database. The zabbix web displays and draws the data on the front end based on the data. Here agentd collects data in two modes: active and passive:

  Active: The agent requests the server to obtain a list of active monitoring items, and actively submits the data that needs to be detected in the monitoring items to the server/proxy.

  Passive: The server requests the agent to obtain the data of the monitoring item, and the agent returns the data.

Client daemon :

This process collects client data such as cpu load, memory, hard disk usage, etc.

zabbix_get

  Zabbix tool, a command used alone, is usually executed on the server or proxy side to obtain remote client information. Usually user troubleshooting. For example, if the client's memory data cannot be obtained on the server side, we can use zabbix_get to obtain the client's content for troubleshooting.

zabbix_sender

  The zabbix tool is used to send data to the server or proxy, and is usually used for long-term inspections. Many checks are very time-consuming and cause zabbix to time out. So we use sender to actively submit data after the script is executed.

zabbix_server

  Zabbix server daemon. The data of zabbix_agentd, zabbix_get, zabbix_sender, zabbix_proxy, and zabbix_java_gateway are ultimately submitted to the server

Note: Of course, not all data is actively submitted to zabbix_server, and some servers take the initiative to retrieve data.

zabbix_proxy

  Zabbix agent daemon. The function is similar to the server, the only difference is that it is just a transfer station, it needs to submit/submit the collected data to the server. Why use a proxy? What does an agent do? Forget it, please continue to pay attention to the operation and maintenance survival time zabbix tutorial series.

zabbix_java_gateway

  A feature introduced after zabbix2.0. As the name suggests: Java gateway, similar to agentd, but only for Java. What needs special attention is that it can only actively obtain data, but cannot passively obtain data. Its data will eventually be sent to the server or proxy.

Key point four

Extension: zabbix monitoring architecture

  在实际监控架构中,zabbix根据网络环境、监控规模等 分了三种架构: server-client 、master-node-client、server-proxy-client三种 。

1、server-client架构

  也是zabbix的最简单的架构,监控机和被监控机之间不经过任何代理 ,直接由zabbix server和zabbix agentd之间进行数据交互。适用于网络比较简单,设备比较少的监控环境 。

2、server-proxy-client架构

  其中proxy是server、client之间沟通的一个桥梁,proxy本身没有前端,而且其本身并不存放数据,只是将agentd发来的数据暂时存放,而后再提交给server 。该架构经常是和master-node-client架构做比较的架构 ,一般适用于跨机房、跨网络的中型网络架构的监控。

3、master-node-client架构

  该架构是zabbix最复杂的监控架构,适用于跨网络、跨机房、设备较多的大型环境 。每个node同时也是一个server端,node下面可以接proxy,也可以直接接client 。node有自已的配置文件和数据库,其要做的是将配置信息和监控数据向master同步,master的故障或损坏对node其下架构的完整性。

重点五

Grafana简介:

  Grafana是一个可视化面板(Dashboard),有着非常漂亮的图表和布局展示,功能齐全的度量仪表盘和图形编辑器,支持Graphite、zabbix、InfluxDB、Prometheus和OpenTSDB作为数据源。以InfluxDB(由go语言编写,是一个开源,分布式,时间序列,事件,可度量和无外部依赖的数据库)作为底层数据库;

  Grafana主要特性:灵活丰富的图形化选项;可以混合多种风格;支持白天和夜间模式;多个数据源。

Zabbix特点


Zabbix是一个高度集成的网络监控解决方案,具备如表所示的特点:

特点

说明

数据采集

可用性和性能检查

支持SNMP(trapping或polling),IPMI,JMX,VMware的监控

自定义检测

按照自定义时间间隔收集所需数据

通过server/proxy和agent来执行监控

灵活的阈值定义

可以定义非常灵活的问题阈值,称为触发器(triggers),从后端数据库调用数值

高度可配置的告警

可以自定义警告升级(escalation),接受者及告警方式

告警信息可以配置并允许使用宏(macro)变量

通过远程命令实行自动化动作(action)

实时绘图

通过内置的绘图方法实现监控数据实时绘图

Web监控能力

Zabbix可以模拟鼠标单击网站并检查其功能性和响应时间

广泛的可视化选项

能够创建自定义图表,可以组合多个项到一个单一的视图中网络拓扑

自定义屏幕和侧边栏作为仪表盘(dashboard)样式显示报告

监视资源的高级视图(商业)

历史数据存储

用数据库来存储数据

配置历史

内置的管理程序

容易配置

添加监控设备作为主机

一旦在数据库中,主机即可被监控

将模版应用到监控监控设备

使用模版

模版中的可以组监控

模版中可以继承其他模版

网络发现

网络设备的自动发现

代理(agent)自动注册

自动发现文件系统,网络接口,SNMP OID

快速的web接口

Web前端采用php编写

按照自定义的方式单击审计日志

Zabbix API

Zabbix API 提供可编程接口面向Zabbix大规模操作,方便第三方软件集成

安全的用户认证

权限系统

某些用户可以受限于某些试图

功能齐全且易于扩展的代理(agent)

部署在监控目标上

Linux和windows上都可以部署

用C语言写的,高性能且内存占用小

二进制守护进程

易移植

通过使用zabbix proxy可以轻松进行远程监控

实验环境准备

Centos7.5:192.168.200.111    server.zabbix.com

Centos7.5:192.168.200.112   agent.zabbix.com

Windows10:192.168.200.2 windows10client

Server端


 [root@localhost ~]# ifconfig ens33 //配置地址如下

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.200.111  netmask 255.255.255.0  broadcast 192.168.200.255

        inet6 fe80::20c:29ff:fe41:e900  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:41:e9:00  txqueuelen 1000  (Ethernet)

        RX packets 894  bytes 100024 (97.6 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 634  bytes 87101 (85.0 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# cat /etc/hostname //编写hostname文件更改主机名

server.zabbix.com

[root@localhost ~]# nslookup www.baidu.com   //测试是否能够上网

Server: 202.106.0.20

Address: 202.106.0.20#53



Non-authoritative answer:

www.baidu.com canonical name = www.a.shifen.com.

Name: www.a.shifen.com

Address: 119.75.216.20

Name: www.a.shifen.com

Address: 119.75.213.61

[root@localhost ~]# hostname server.zabbix.com //更改主机名

[root@localhost ~]# bash //进入新bash环境

[root@server ~]# vim /etc/hosts

[root@server ~]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.200.111 server.zabbix.com

192.168.200.112 agent.zabbix.com

192.168.200.2   windows10

[root@server ~]# scp /etc/hosts 192.168.200.112:/etc/    

The authenticity of host '192.168.200.112 (192.168.200.112)' can't be established.

ECDSA key fingerprint is SHA256:RyIy/xT7fCqWfn1Yr2+VykD2bnJosBrrZQ4H/E62Neg.

ECDSA key fingerprint is MD5:29:eb:f8:06:0d:fb:b3:b7:89:ec:b8:c2:28:89:6d:01.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.200.112' (ECDSA) to the list of known hosts.

[email protected]'s password:

hosts                          100%  250    10.2KB/s   00:00    

[root@server ~]# systemctl stop firewalld.service //关闭firewalld及selinux

[root@server ~]# setenforce 0

setenforce: SELinux is disabled

agent端


[root@localhost ~]# cat /etc/hostname

agent.zabbix.com

[root@localhost ~]# ifconfig ens33

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.200.112  netmask 255.255.255.0  broadcast 192.168.200.255

        inet6 fe80::20c:29ff:feb6:b87b  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:b6:b8:7b  txqueuelen 1000  (Ethernet)

        RX packets 925  bytes 103544 (101.1 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 481  bytes 55752 (54.4 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# hostname agent.zabbix.com

[root@localhost ~]# bash

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

[root@agent ~]# setenforce 0

setenforce: SELinux is disabled

[root@agent ~]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.200.111 server.zabbix.com

192.168.200.112 agent.zabbix.com

192.168.200.101 windows7

[root@agent ~]# ping server.zabbix.com -c 4

PING server.zabbix.com (192.168.200.111) 56(84) bytes of data.

64 bytes from server.zabbix.com (192.168.200.111): icmp_seq=1 ttl=64 time=1.40 ms

64 bytes from server.zabbix.com (192.168.200.111): icmp_seq=2 ttl=64 time=1.10 ms

64 bytes from server.zabbix.com (192.168.200.111): icmp_seq=3 ttl=64 time=1.12 ms

64 bytes from server.zabbix.com (192.168.200.111): icmp_seq=4 ttl=64 time=2.28 ms



--- server.zabbix.com ping statistics ---

4 packets transmitted, 4 received, 0% packet loss, time 3013ms

rtt min/avg/max/mdev = 1.105/1.481/2.289/0.481 ms

server端

配置阿里云yum源


以下实验操作请注意主机名!!!

[root@server ~]# cd /etc/yum.repos.d/

[root@server yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo

[root@server yum.repos.d]# ls

backup  Centos-7.repo  CentOS-Media.repo

[root@server ~]# yum install -y httpd mariadb-server mariadb mariadb-devel php php-mbstring php-mysql php-bcmath php-gd php-xmlrpc php-ldap php-xml libevent libevent-devel net-snmp net-snmp-devel libxml2 libxml2-devel ntpdate curl-devel

//部署lamp环境 提供zabbix访问页面 其中PHP部分选项是为zabbix提供支持

报错如下信息 就是因为要安装mysql-devel

configure: error: MySQL library not found

[root@server yum.repos.d]# ntpdate time.windows.com   //同步时间 清华大学时间服务器

启动LAMP对应服务


[root@server yum.repos.d]# cd

[root@server ~]# systemctl start mariadb

[root@server ~]# systemctl enable mariadb      //设置为开机启动

Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

[root@server ~]# systemctl start httpd

[root@server ~]# systemctl enable httpd

Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

[root@server ~]# mysqladmin -u root password 123123    //为mysql root用户设置密码

准备java环境


[root@server ~]# java -version

openjdk version "1.8.0_161"

OpenJDK Runtime Environment (build 1.8.0_161-b14)

OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)

[root@server ~]# which java

/usr/bin/java

[root@server ~]# rm -rf /usr/bin/java       //删除后重新部署java环境

[root@server ~]# ls

anaconda-ks.cfg            公共  图片  音乐

initial-setup-ks.cfg       模板  文档  桌面

jdk-8u91-linux-x64.tar.gz  视频  下载

[root@server ~]# tar xf jdk-8u91-linux-x64.tar.gz

[root@server ~]# mv jdk1.8.0_91/ /usr/local/java

[root@server ~]# vim /etc/profile

[root@server ~]# tail -2 /etc/profile

export JAVA_HOME=/usr/local/java

export PATH=$PATH:$JAVA_HOME/bin

[root@server ~]# source /etc/profile

[root@server ~]# java -version

java version "1.8.0_91"

Java(TM) SE Runtime Environment (build 1.8.0_91-b14)

Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

[root@server ~]# javac -version

javac 1.8.0_91

[root@server ~]# which java

/usr/local/java/bin/java

源码安装zabbix


[root@server ~]# ls

anaconda-ks.cfg            zabbix-3.4.11.tar.gz  视频  下载

initial-setup-ks.cfg       公共                  图片  音乐

jdk-8u91-linux-x64.tar.gz  模板                  文档  桌面

[root@server ~]# tar xf zabbix-3.4.11.tar.gz -C /usr/src/

[root@server ~]# cd /usr/src/zabbix-3.4.11/

[root@server zabbix-3.4.11]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --enable-java && make -j2 && make install

--prefix=/usr/local/Zabbix      指定安装位置

--enable-server --enable-agent    启用zabbix和agent

详见./configure –help

Mariadb数据库授权


[root@server zabbix-3.4.11]# cd

[root@server ~]# mysql -u root -p123123

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 4

Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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

Query OK, 1 row affected (0.14 sec)

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

Query OK, 0 rows affected (0.07 sec)

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

Query OK, 0 rows affected (0.11 sec)   //此步骤是为zabbix_server启动授权

MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>

Bye

[root@server ~]# cd /usr/src/zabbix-3.4.11/    //导入zabbix需要的mysql数据

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

[root@server zabbix-3.4.11]# mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql

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

登录查看

[root@server ~]# mysql -u root -p123123

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 9

Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use zabbix;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

MariaDB [zabbix]> show tables;

+----------------------------+

| Tables_in_zabbix           |

+----------------------------+

| acknowledges               |

| actions                    |

| alerts                     |

| valuemaps                  |

| widget                     |

| widget_field               |

+----------------------------+

140 rows in set (0.01 sec)

MariaDB [zabbix]> \q

Bye

创建zabbix程序用户并授权防止权限报错


[root@server ~]# useradd -M -s /sbin/nologin zabbix

[root@server ~]# cd /usr/local/

[root@server local]# cd ./zabbix/

[root@server zabbix]# pwd

/usr/local/zabbix

[root@server zabbix]# mkdir logs

[root@server zabbix]# chown -R zabbix:zabbix ../zabbix/

[root@server zabbix]# cp -p etc/zabbix_server.conf{,.bak}

[root@server zabbix]# cp -p etc/zabbix_agentd.conf{,.bak}

修改zabbix配置文件


[root@server zabbix]# cd /usr/local/zabbix/etc/

[root@server etc]# ls

zabbix_agentd.conf      zabbix_server.conf

zabbix_agentd.conf.bak  zabbix_server.conf.bak

zabbix_agentd.conf.d    zabbix_server.conf.d

[root@server etc]# vim zabbix_server.conf

LogFile=/usr/local/zabbix/logs/zabbix_server.log

PidFile=/tmp/zabbix_server.pid

DBHost=192.168.200.111

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix

DBSocket=/var/lib/mysql/mysql.sock
Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf

注释:

LogFile=/usr/local/zabbix/logs/zabbix_server.log     #指定zabbix日志位置

PidFile=/tmp/zabbix_server.pid #指定zabbix pid文件位置

DBHost=192.168.200.111 #指定数据库主机

DBName=zabbix     #指定数据库名为zabbix

DBUser=zabbix                                   #指定用户为zabbix

DBPassword=zabbix #指定密码为zabbix

DBSocket=/var/lib/mysql/mysql.sock #指定mariadb数据库的sock文件

Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf 

[root@server etc]# vim zabbix_agentd.conf

PidFile=/tmp/zabbix_agentd.pid

Server=127.0.0.1,192.168.200.111

ServerActive=192.168.200.111

Hostname=server.zabbix.com                   #指定zabbixserver主机名

LogFile=/usr/local/zabbix/logs/zabbix_agentd.log +
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf

[root@server ~]# ln -s /usr/local/zabbix/sbin/* /usr/local/bin

[root@server ~]# zabbix_server

[root@server ~]# zabbix_agentd

配置php与apache


[root@server ~]# mv /usr/src/zabbix-3.4.11/frontends/php/ /var/www/html/zabbix

[root@server ~]# chown -R apache:apache /var/www/html/zabbix

[root@server ~]# vim /etc/php.ini

878 date.timezone = Asia/Shanghai ##时区

384 max_execution_time = 300 ##单位秒,通过POST、GET以及PUT方式接收数据时间进行限制

394 max_input_time = 300 ##php程序上传文件解析数据时的时间限制

672 post_max_size = 32M ##POST 方式请求数据所允许的最大大小

405 memory_limit = 128M ##设置php程序的内存限制

854 extension=bcmath.so   ##加载zabbix程序需要加载的扩展模块bcmath.so手动添加

[root@server ~]# systemctl restart httpd

[root@server etc]# netstat -anpt | egrep ':10050|:10051|:80'

tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      22546/zabbix_agentd

tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      22651/zabbix_server                  

tcp6       0      0 :::10050                :::*                    LISTEN      22546/zabbix_agentd

tcp6       0      0 :::10051                :::*                    LISTEN      22651/zabbix_server

tcp6       0      0 :::80                   :::*                    LISTEN      2783/httpd

web安装zabbix

访问http://192.168.200.111/zabbix

 

 

 

 

 出现此处便表示zabbix的前端已经搭建成功了  我们看到的zabbix页面为英文的

Zabbix页面优化

1.调整zabbix页面为中文页面

 

 

 

 2.更改admin密码

 

 

 

 

 

3.解决中文乱码问题

[root@server ~]# cd /var/www/html/zabbix/fonts/

[root@server fonts]# ls

DejaVuSans.ttf

[root@server fonts]# mv DejaVuSans.ttf DejaVuSans.ttf.bak

[root@server fonts]# rz

[root@server fonts]# ls

DejaVuSans.ttf.bak  simkai.ttf

[root@server fonts]# mv simkai.ttf DejaVuSans.ttf

[root@server fonts]# ls

DejaVuSans.ttf  DejaVuSans.ttf.bak

[root@server fonts]# ll

总用量 4780

-rw-r--r-- 1 root   root   4135804 9月  22 2017 DejaVuSans.ttf

-rw-r--r-- 1 apache apache  756072 6月  25 16:57 DejaVuSans.ttf.bak

[root@server fonts]# chown -R apache:apache *

[root@server fonts]# ll

总用量 4780

-rw-r--r-- 1 apache apache 4135804 9月  22 2017 DejaVuSans.ttf

-rw-r--r-- 1 apache apache  756072 6月  25 16:57 DejaVuSans.ttf.bak

刷新查看

Zabbix监控主机

添加自身为被监控机

 

 

 

 

 

 等待一会刷新出如下页面

 

Guess you like

Origin blog.csdn.net/2302_77750172/article/details/131848489