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

Zabbix Monitoring mysql and alarm (2) final

2025-01-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Zabbix deploys Monitoring Database alarm Service (2) finally

Then zabbix (1) went on to deploy

After configuring for a period of time, check to see if the effect of the monitoring chart has come out.

Zabbix3.0 server already has its own template for mysql, just configure the agent client and add a template to the host on the web side.

Zabbix_agent client operation

(1) first, add permissions to the mysql of the client, that is, the local machine uses the zabbix account to connect to the local mysql.

Mysql > grant all on *. * to zabbix@'localhost' identified by '123456' query OK, 0 rows affected, 1 warning (0.02 sec) mysql > flush privileges;Query OK, 0 rows affected (0.03 sec)

(2) create the. my.cnf connection file under the zabbix_agent service directory

The zabbix installation directory is / usr/local/zabbix

[root@localhost etc] # pwd/usr/local/zabbix/etc [root@localhost etc] # cat .my.cnf [client] user=zabbixpassword=123456

Note:

If the database grant authorization is aimed at localhost, there is no need to add the host parameter in this .my.cnf [as configured above]

But if grant is authorized for a native ip (such as 192.168.31.250), then the host parameter should be added to the .my.cnf file to specify it.

That is, in the .my.cnf file, add:

Host=192.168.0.7

Socket= / usr/local/mysql/mysql.sock

User=zabbix

Password=123456

(3) configure the key file of MySQL

This can be copied from the unzipped package when zabbix3.2 is installed.

Extract the directory when installing from the zabbix_server server

/ root/zabbix-3.2.1/conf/zabbix_agentd/userparameter_mysql.conf is copied to the / usr/local/zabbix/etc/zabbix_agentd.conf.d/ directory on the zabbix_agent client

[root@localhostzabbix] # cd / usr/local/zabbix/etc/zabbix_agentd.conf.d/ [root @ localhostzabbix_agentd.conf.d] # pwd/usr/local/zabbix/etc/zabbix_ agentd.conf.d [root @ localhostzabbix_agentd.conf.d] #, cp,/usr/src/zabbix-3.2.1/conf/zabbix_agentd/userparameter_mysql.conf. / [root@localhostzabbix_agentd.conf.d] # ls userparameter_mysql.conf userparameter_mysql.conf

Then look at the userparameter_mysql.conf file and see the path settings similar to HOME=/var/lib/zabbix, replacing all the paths with / usr/local/zabbix/etc/, the same directory path as the .my.cnf file above.

In addition, pay attention to the mysql command path in the userparameter_mysql.conf file (make the system environment variable of mysql in advance in case the mysql command is not recognized by the system)

As follows:

[root@server1 zabbix_agentd.conf.d] # cat userparameter_mysql.conf

# For all the following commands HOME should be set to the directory that has .my.cnf file with password information.

# Flexible parameter to grab global variables. On the frontend side, use keys like mysql.status[Com _ insert].

# Key syntax is mysql.status [variable].

UserParameter=mysql.status [*], echo "show global status where Variable_name='$1';" | HOME=/usr/local/zabbix/etc/ mysql-N | awk'{print $2}'

# Flexible parameter to determine database or table size. On the frontend side, use keys like mysql.size [zabbix,history,data].

# Key syntax is mysql.size [,].

# Database may be a database name or "all". Default is "all".

# Table may be a table name or "all". Default is "all".

# Type may be "data", "index", "free" or "both". Both is a sum of data and index. Default is "both".

# Database is mandatory if a table is specified. Type may be specified always.

# Returns value in bytes.

# 'sum' on data_length or index_length alone needed when we are getting this information for whole database instead of a single table

UserParameter=mysql.size [*], bash-c 'echo "select sum ($(case" $3 "in both |") echo "data_length+index_length";; data | index) echo "$3_length";; free) echo "data_free" Esac) from information_schema.tables$ ([["$1" = "all" |! "$1]] | | echo" where table_schema=\ "$1\") $([["$2" = "all" | |! "$2]] | | echo" and table_name=\ "$2\"); "| HOME=/usr/local/zabbix/etc/ mysql-N'

UserParameter=mysql.ping,HOME=/usr/local/zabbix/etc/ mysqladmin ping | grep-c alive

UserParameter=mysql.version,mysql-V

(4) check according to the above modification, and then restart zabbix_agent

Then conduct a command line test on the zabbix_server server [192.168.0.7 below is the client's ip]

If the following report is wrong

[root@localhost zabbix] # / usr/local/zabbix/bin/zabbix_get-s 192.168.0.7-p 10050-k "mysql.status [Uptime]"

Sh: mysql: command not found

Solution:

Add an absolute path before the mysql command in userparameter_mysql.conf

[root@localhost /] # / usr/local/zabbix/bin/zabbix_get-s 192.168.0.7-p 10050-k "mysql.status [Uptime]" 169

If there is a number like this string of key, it means that if you configure ok, the server can monitor the mysql data of the client!

Successful, and then add the host corresponding MySQL template in the monitoring interface to ok.

Note: introduction to the zabbix_get command

Parameter description:

-s-- host: specify the client hostname or IP

-p-- port: client port. Default is 10050.

-I-- source-address: specify the source IP and write the ip address of zabbix server, which is generally left blank. If the server has multiple ip, you can specify one.

-k-- key: the key you want to get

Zabbix_get acquires data

Get the load

# zabbix_get-s 192.168.31.250-p 10050-k "system.cpu.load [all,avg15]"

Get hostname

# zabbix_get-s 192.168.31.250-p 10050-k "system.hostname"

(5) Log in to the zabbix monitoring interface, and you can see the built-in mysql monitoring template in "configuration"-"template".

You can add the monitoring template of mysql (included with zabbix) to the corresponding CVM monitoring configuration.

The following is the effect diagram of the mysql monitoring item:

[1] Monitoring the bandwidth of mysql: you can view the number of bytes sent and received by mysql in real time at the front end of zabbix. Where bytes received represents the number of bytes received from all clients and bytes sent represents the number of bytes sent to all clients.

The mysql database has been successfully tested.

Monitor the status of mysql network card

Zabbix3.2.1 mail alarm settings:

The Zabbix monitoring server and client have been deployed, the monitored host has been added, and Zabiix monitoring is running normally.

An email alarm is set on the Zabbix server. When the monitored host goes down or reaches the trigger preset value, it will automatically send an alarm email to the specified mailbox.

Specific operations:

The following operations are performed on the Zabbix monitoring server

Download sendemail software

Then install the two dependent packages, and the command is:

[root@localhost ~] # yum install perl-Net-SSLeay perl-IO-Socket-SSL-y

Extract the software, then copy the sendemail to the / usr/local/bin/ directory, add executable permissions, and then modify the users and groups.

[root@localhost src] # tar zxf sendEmail-v1.56.tar.gz [root@localhost src] # cd sendEmail-v1.56/ [root@localhost sendEmail-v1.56] # cp sendEmail / usr/local/bin/sendEmail [root@localhost sendEmail-v1.56] # chown zabbix:zabbix / usr/local/bin/sendEmail [root@localhost sendEmail-v1.56] # ll / usr/local/bin/sendEmail-rwxr-xr-x. 1 zabbix zabbix 80213 Jan 4 17:52 / usr/local/bin/sendEmail

Go to the / usr/local/zabbix/share/zabbix/alertscripts/ directory and execute # / usr/local/bin/sendEmail-h to view the help of sendEmail

# / usr/local/bin/sendEmail-f xinwang1360@163.com-t xinwang1360@163.com-s smtp.163.com-u "hello"-o message-content-type=html-o message-charset=utf8-xu xinwang1360@163.com-xp password-m "chai xinwang wei wu"

The main options for the command are described:

/ usr/local/bin/sendEmail # command main program

-f xinwang1360@163.com # Sender mailbox

-t xinwang1360@163.com # recipient mailbox

-s smtp.163.com # smtp server for the sender's mailbox

-u "I am the subject of the message" # the title of the message

-o message-content-type=html # format of the message content, html indicates that it is in html format

-o message-charset=utf8 # message content coding

-xu xinwang1360@163.com # user name of the sender's mailbox

-xp password # Sender email password

-m "I am the content of the email" # the specific content of the email

Send successfully to verify the effect is complete.

Then create an alarm script sendmail.sh in this directory

[root@mysqla alertscripts] # vi mail.sh

The following is the content of the script (the coloring part is your mailbox and password,-f and-xu parameters are followed by mailbox,-xp followed by authorization code)

#! / bin/bash

To=$1

Subject=$2

Body=$3

/ usr/local/bin/sendEmail-f xinwang1360@163.com-t xinwang1360@163.com-s smtp.163.com-u "hello"-o message-content-type=html-o message-charset=utf8-xu xinwang1360@163.com-xp password-m "chai xinwang wei wu"

If there are errors in the configuration process, you can effectively and quickly resolve the following

At / usr/local/bin/sendEmail line 1906.

Invalid SSL_version specified at / usr/share/perl5/vendor_perl/IO/Socket/SSL.pm line 415

Note: the first error occurred during the sending mail test

The reason is that the sendemail software is incompatible with the ssl version in perl5. This problem can be solved by modifying the contents of sendemail.

Solution:

The contents of 1906 lines in sendemail, from

If (! IO::Socket::SSL- > start_SSL ($SERVER, SSL_version = > 'SSLv3 TLSv1')) {

Modify to

If (! IO::Socket::SSL- > start_SSL ($SERVER)) {

That is, do not specify the version of SSL and let the program choose for itself.

No matter whether you use 163 email or QQ Mail, you must activate the pop3 service, and the 126/qq mailbox also requires that you must log in using an authorization code to send mail from a third-party client. When using the account password verification, there will be an error in the picture below.

SendEmail [5102]: ERROR = > ERROR = > SMTP-AUTH: Authentication to smtp.126.com:25 failed.

As for the authorization code of the mailbox, just log in to mailbox 126 to set it.

After dealing with the above two problems, you can send an email normally and display a successful prompt as shown below.

After the above email script is configured, you need to add the alarm media on the web side. In the web page management, alarm media type page, click create Media Type on the right.

Go to the creation page, enter the name "email alarm script", select the type script, select the name mail.sh, click the add button, and add three script parameters, namely {ALERT.SENDTO}, {ALERT.SUBJECT}, {ALERT.MESAGE}, for to, subject and body in mail.sh. After adding, click the add button below, and our alarm medium will be created.

After creating the alarm media, we need to associate the alarm media with our users. Click manage, user, and then select our user admin can also create a new user, click the user name to enter the user configuration interface. Click the alarm media, then click add, select the email alarm script we created in the previous step, enter the recipient, select the alarm time and type, and then click add to associate the created alarm media with our users.

What we need to do now is to create a trigger action, that is, if the system fails, trigger this action, and then send an alarm email to our mailbox. Click configure, select actions, and then click create Action on the right.

Write the action name and trigger condition we defined in the name of the action page.

The step is 1-3, that is, from 1 to 3. Once the failure occurs, the Email.sh script is executed to send an alarm email to the zabbix user.

If the failure lasts for 1 hour, it will only be sent 3 times, and the first 3 mailboxes will be sent to zabbix users with an interval of 0 seconds.

If you change it to 1-0, it means there is no limit. Infinite transmission

Set the restore Operation

After you add it, you can see the name of the action we added, as well as the status that the action has been enabled.

Finally, click "report"-> "Action Log" to see the number of times the action was triggered

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

Database

Wechat

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

12
Report