Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Case practice of Zabbix Monitoring production in small and medium-sized Enterprises

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Introduction of Zabbix monitoring

1. Overview of Zabbix's functions

1.1 what is zabbix

Zabbix is an enterprise-class, open source, distributed monitoring suite.

Zabbix can monitor networks and services. Zabbix can implement Wechat by using flexible alarm mechanism

Automatic alarm of text messages and emails. Zabbix uses the stored monitoring data to provide monitoring reports and achieve graphical display.

1.2 zabbix featur

Zabbix is a highly integrated network monitoring suite that provides the following features through a single package

Data collection

Allows flexible customization of fault thresholds, called trigger in Zabbix, and stored in the back-end database

Advanced alarm configuration

Real-time drawing of monitoring data through built-in drawing engine

Extended graphical display

The data is stored in the database

Historical data is configurable

Built-in data cleaning mechanism

Simple configuration

Group monitoring can be added to the template

Templates allow inheritance

Network automatic discovery

The web front end is written in php.

Access is accessible

You can do whatever you want.

Audit log

Zabbix API

Secure authority authentication

Users can limit the list of allowed maintenance

Full-featured, easy to expand agent

C development, high performance, low memory consumption

Transplant easily

1.3 Zabbix Featur

Monitoring topology diagram description:

(1) automatic alarm mechanism can be realized through Wechat, SMS and email.

(2) you can configure it through the Web page and monitor the status to view it.

(3) the equipment of printer, router and switch can be monitored by SNMP protocol.

Items that can be monitored for the host include:

CPU:CPU load, CPU utilization

Memory: memory utilization, interchangeable memory / virtual memory utilization

Network: network transmission, network failure, packet loss

Disk: disk utilization, disk Ibank O

Service: process monitoring, interface service, TCP port connection, response time, DNS monitoring, NTP monitoring

Log: log monitoring, text log, event log

File: file monitorin

Other: performance counters (Windows systems only)

Custom alarm mechanism:

If the fault is not resolved within 10 minutes, you can notify the system administrator by text message or email

If the fault is not resolved in 15 minutes, you can notify the operation and maintenance personnel by text message or email.

If the fault is not resolved within 30 minutes, you can notify the manager by text message or email.

You can use the proxy proxy server

The agent Zabbix server collects the monitored monitoring data and sends it to the server.

2. Zabbix program architecture

The architecture diagram is as follows:

2.1 description of each component of Zabbix:

Zabbix Server

Zabbix Server is the core component, which is used to obtain agent survival and monitoring data.

All configuration, statistics and operation data are accessed to database through Server.

Zabbix database

All Zabbix data is stored in the database

Web GUI

For easier barrier-free access to Zabbix, the web interface is provided

This interface, as part of Zabbix Server, usually runs on the same host as server

Note: if SQLite is used as the database, the web interface and Zabbix Server must be running on the same host

Proxy

Zabbix Proxy can replace Zabbix Server for performance and availability data collection.

Proxy is an optional component for Zabbix deployment. If you want to share a single Zabbix Server load, it is recommended to use proxy

Agent

Zabbix agents is deployed on the target monitor and monitors local resources and applications, reporting collected data to Zabbix Server

Monitoring process:

Monitor the data flow through zabbix and take corresponding measures.

First create a host, and then create an item to collect data

Create a trigger (trigger) through item

Create an action (action) through a trigger (trigger)

2.2 Zabbix component structure diagram:

2.3 Zabbix related terms:

Related nouns explain:

Host (host)

A network device you want to monitor (need to know IP/DNS)

Host group (host group)

A logical host group that contains hosts and templates

If the host and the template are in the same host, the template cannot be link to another. Host groups are usually used to create access rights to different user groups

Monitoring item (item)

The data you want to collect from the mainframe

Trigger (trigger)

A logical expression used to express that the data obtained from the monitoring item reaches the preset fault threshold

When the received monitoring value reaches the preset threshold

Then the state of the trigger is changed from 'OK' to' Problem',. When the monitoring value received is lower than the threshold, the state is maintained / changed to 'OK'.

Event (event)

An event such as a trigger status change or an automatic discovery (discovery) / agent automatic registration

Action (action)

The default process when an event occurs

An action (action) includes an action (operations, such as sending an alarm) and a condition (when the specified operation is completed)

Alarm upgrade (escalation)

A custom operation execution process in an action, a queue for sending alarms / executing remote commands

Media (media)

The channel that sends the alarm

Alarm (notification)

Send event messages through media channels

Remote command (remote command)

A default command that executes automatically when the monitoring host reaches certain conditions (condition)

Template (template)

A set of monitoring items, triggers, drawings, panels (screen), applications, low-level auto-discovery rules, etc.

And entity templates that can be applied by other hosts can improve the speed of host deployment monitoring tasks.

It is also very easy to mass updates to monitoring tasks. The template is linked by the host (link)

Application (application)

Monitoring item logic group

Web Scheme (scenario)

One or more http requests to check the availability of a web site

Front end (frontend)

Web interface provided by Zabbix

Zabbix API

Zabbix API allows you to create and update through JSON RPC protocol

Get Zabbix objects (such as hosts, monitoring items, drawings, etc.) and complete custom tasks

Zabbix server

Zabbix Software Center process

Used to connect Zabbix proxy and agent to complete monitoring, evaluation triggers, sending alarms and central data storage

Zabbix agent

Processes deployed on monitoring hosts to monitor local resources and applications

Zabbix proxy

The process of completing data collection instead of Zabbix server, usually used to reduce the load on the central Zabbix Server

Node (node)

A complete set of Zabbix server configurations, usually located in a distributed system, used to monitor the area

2.4 introduction to Zabbix workflow:

Server

Zabbix server is the core process of Zabbix software.

Server uses polling and trapping to collect data to determine whether the threshold is reached, and then uses the trigger to send an alarm to the user.

Server can also perform remote network service detection through simple service check (simple service check).

Server is not only a database for storing all configuration, statistics and operation data, but also a fault alarm service.

Zabbix server can be divided into three parts according to different functions: Zabbix server, Web GUI and Database

Since all the configuration information of Zabbix is saved in the database, server and web GUI can operate directly.

For example, when a new monitoring item is created through the Web interface (or API), it inserts the created data into the database

In about a minute, Zabbix server will query the monitoring item data table.

And save the list of monitoring items of the query in your own cache (cache)

That's why changes made through the Zabbix front end will take effect in about two minutes.

Zabbix server runs as a daemon process

Zabbix server is required to run under a non-root account by default.

If Zabbix server and agent are running on the same host

It is recommended to run under different users, because once running under the same user

Agent will have access to server's configuration file

And can easily obtain Zabbix Admin-level users, such as database password

Agent

Zabbix agent is deployed on the monitored host to monitor local resources and applications (such as hard drives, memory, processors, etc.)

Zabbix agent collects local host operation information and sends the data to Zabbix server for processing

Once an exception occurs (such as the hard disk is full or the service process is interrupted), Zabbix server will automatically respond and give an alarm.

Zabbix agent uses local system calls to collect statistics, so it is very efficient

Passive (passive) and active (active) checks

Zabbix agent provides passive and active search methods.

In passive inspection mode, agent replies to data requests, and Zabbix server or proxy asks for agent data

Such as CPU load, and then Zabbix agent sends back the result to server

The process of active inspection will be relatively complex.

Agent must first request Zabbix server for a list of monitoring items, and then send the corresponding value to server

To choose whether to check passively or actively, you need to choose from the type of monitoring item.

'Zabbix agent' or 'Zabbix agent (active)'

Zabbix agent runs on the monitored host and can be run by daemon

Zabbix agent is generally required to run under a non-root account

If you start Zabbix agent under your 'root' account, it will automatically select

Create 'zabbix' users' in the operating system unless you modify the 'AllowRoot' parameter' in the agent configuration file

Agent proxy

The Zabbix agent (proxy) is usually used instead of server to collect monitoring information and send data to Zabbix server

The collected data is first stored in the cache of the proxy host and then transferred to Zabbix server

Proxy is optional, but it can effectively reduce the load of a single Zabbix server in a distributed environment.

Through the agent to collect monitoring data, server can effectively reduce the consumption of CPU and disk Icano.

Zabbix agent can perform the centralized monitoring of remote area, branch office and network without local administrator.

The Zabbix agent uses a separate database

Note:

Zabbix proxy database can use SQLite, MySQL, PostgreSQL

If there are limitations and risks when Oracle or IBM DB2 automatically discover rules at a low level

Zabbix proxy runs as a daemon.

Zabbix proxy is generally required to run under a non-root account

If you run under the 'root' account

It will automatically select 'zabbix' users that were previously established in the operating system, but cannot be configured at compile time or in the configuration file

II. Project planning framework

2.1 Host grouping

Exchanger

Nginx

Tomcat

Mysql

2.2 Monitoring object identification

Monitoring the switch using SNMP

Use IPMI to monitor server hardware

Monitor the server using Agent

Use JMX to monitor java

Monitor Nginx statu

Monitoring Mysql

Monitor Web statu

Third, Zabbix monitoring practice 3.1 SNMP monitoring network equipment 3.1.1 switch start SNMP

Experience: monitoring directly with IPMI often fails to get data, and the item that comes with the template is not suitable for a real server.

Recommendation: use custom item and locally execute ipmitool command to monitor and obtain data, which can be used to monitor the fan speed of the server.

3.3 add system Monitoring

Use zabbix agent to monitor, briefly

3.4.Add application monitoring 3.4.1 JAVA application

Use JXM mode + java_gateway agent monitoring

Java_gateway can run on any server and is a separate service

1) install zabbix-java-gateway

[root@linux-node1 ~] # vim / etc/zannox/zabbix_java_gateway

3) start zabbix_java_gateway and check the port and process

[root@linux-node2 ~] # vim / usr/local/tomcat/bin/catalina.sh

CATALINA_OPTS= "$CATALINA_OPTS-Dcom.sun.management.jmxremote

-Dcom.sun.management.jmxremote.port=8888

-Dcom.sun.management.jmxremote.ssl=false

-Dcom.sun.management.jmxremote.authenticate=false

-Djava.rmi.server.hostname=192.168.56.12 "

[root@linux-node2 ~] # / usr/local/tomcat/bin/shutdown.sh

[root@linux-node2 ~] # / usr/local/tomcat/bin/startup.sh

6) add tomcat to the host on zabbix-server

And connect the Template-JMX-Generic template, select JMX interfaces

3.4.2 Nginx application

1) enable nginx monitoring

Add a location to the nginx configuration file to allow only local access

[root@linux-node1 ~] # vim redis-memcached-nginx-tcp.sh

#! / bin/bash

# # #

# $Name: zabbix_linux_plugins.sh

# $Version: v1.0

# $Function: zabbix plugins

# $Description: Monitor Linux Service Status

# # #

Tcp_status_fun () {

TCP_STAT=$1

# netstat-n | awk'/ ^ tcp/ {+ + state [$NF]} END {for (key in state) print key,state [key]}'> / tmp/netstat.tmp

Ss-ant | awk'NR > 1 {+ + s [$1]} END {for (k in s) print KJS [k]}'> / tmp/netstat.tmp

TCP_STAT_VALUE=$ (grep "$TCP_STAT" / tmp/netstat.tmp | cut-d'- f2)

If [- z $TCP_STAT_VALUE]; then

TCP_STAT_VALUE=0

Fi

Echo $TCP_STAT_VALUE

}

Nginx_status_fun () {

NGINX_PORT=$1

NGINX_COMMAND=$2

Nginx_active () {

/ usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" 2 > / dev/null | grep 'Active' | awk' {print $NF}'

}

Nginx_reading () {

/ usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" 2 > / dev/null | grep 'Reading' | awk' {print $2}'

}

Nginx_writing () {

/ usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" 2 > / dev/null | grep 'Writing' | awk' {print $4}'

}

Nginx_waiting () {

/ usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" 2 > / dev/null | grep 'Waiting' | awk' {print $6}'

}

Nginx_accepts () {

/ usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" 2 > / dev/null | awk NR==3 | awk'{print $1}'

}

Nginx_handled () {

/ usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" 2 > / dev/null | awk NR==3 | awk'{print $2}'

}

Nginx_requests () {

/ usr/bin/curl "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" 2 > / dev/null | awk NR==3 | awk'{print $3}'

}

Case $NGINX_COMMAND in

Active)

Nginx_active

Reading)

Nginx_reading

Writing)

Nginx_writing

Waiting)

Nginx_waiting

Accepts)

Nginx_accepts

Handled)

Nginx_handled

Requests)

Nginx_requests

Esac

}

Memcached_status_fun () {

M_PORT=$1

M_COMMAND=$2

Echo-e "stats\\ nquit" | nc 127.0.0.1 "$M_PORT" | grep "STAT $M_COMMAND" | awk'{print $3}'

}

Redis_status_fun () {

R_PORT=$1

R_COMMAND=$2

(echo-en "INFO\\ r\ n"; sleep 1;) | nc 127.0.0.1 "$R_PORT" > / tmp/redis_ "$R_PORT" .tmp

REDIS_STAT_VALUE=$ (grep "$R_COMMAND": "/ tmp/redis_" $R_PORT ".tmp | cut-d':'- f2)

Echo $REDIS_STAT_VALUE

}

Main () {

Case $1 in

Tcp_status)

Tcp_status_fun $2

Nginx_status)

Nginx_status_fun $2 $3

Memcached_status) memcached_status_fun $2 $3

Redis_status) redis_status_fun $2 $3

*)

Echo $"Usage: $0 {tcp_status key | memcached_status key | redis_status key | nginx_status key}"

Esac

}

Main $1 $2 $3

[root@linux-node1 ~] # chmod + x redis-memcached-nginx-tcp.sh

Whether it is normal after adding the test script

[root@linux-node1 ~] # vim redis-memcached-nginx-tcp.conf

UserParameter=linux_ status [\ *], / etc/zabbix/zabbix_agetd.d/redis-memcached-nginx-tcp.sh "$1"$2"$3"

4) add zabbix-agent configuration and pass zabbix-server test

Modify agent configuration

[root@linux-node1 ~] # zabbix_get-s 192.168.11.11-k linux_ status [Nginx _ status,8080,active]

twelve

5) add template, add item, and add different item for multiple clones

6) create a graphic

Slightly

7) create a trigger

Slightly

8) create a generic template

Slightly

3.4.3 use the percona monitoring plug-in to monitor Mysql applications

To learn percona, please move to percona-mysql. This principle is that php connects to the mysql database, and the shell script obtains the data. The deployment begins below.

1) install the template on the agent side

[root@linux-node1 ~] # yum install percona-zabbix-templates

2) create a configuration file for zabbix-agent

[root@linux-node1 ~] # mkdir-p / etc/zabbix_agentd.conf.d/ [root @ linux-node1 ~] # cp / var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf / etc/zabbix_agentd.conf.d/userparameter_percona_mysql.conf

3) modify agent configuration and restart

[root@linux-node1 ~] # Include=/etc/zabbix/zabbix_agentd.d/\ * .conf [root@linux-node1 ~] # service zabbix-agent restart

4) configure connection Mysql

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report