Just came David MySQL monitoring time is very easy to encounter problems and most of the problems appear in the MySQL configuration above, see I do the following hope to you some help, haha don't talk about good study now start
1. Create a MySQL user
[[email protected]]# Groupadd MySQL
[Email protected]]# Mkdir-pv/data/mysql
[Email protected]]# useradd-r-G mysql-d/data/mysql/-s/sbin/nologin MySQL
2. Get the MySQL Package
[Email protected] y]# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49.tar.gz
3. Installing dependent Packages
[Email protected]]# yum-y install cmake gcc* ncurses-devel
4. SOURCE Installation MySQL
[[email protected]] #tar zxvf/data/pkg/mysql-5.6.10.tar.gz
[Email protected]]# CD mysql-5.5.49
[Email protected] mysql-5.5.49]# Cmake-dcmake_install_prefix=/usr/local/mysql-ddefault_charset=utf8-denabled_ Local_infile=1-dmysql_datadir=/data/mysql-dwith_extra_charsets=all-dwith_readline=1-dwith_innobase_storage_ Engine=1-dmysql_tcp_port=3306-ddefault_collation=utf8_general_ci
[[email protected] mysql-5.5.49]# make-j 4 && make install
[Email protected] mysql-5.5.49]# chown-r mysql.mysql/usr/local/mysql
[Email protected] mysql-5.5.49]# cd/usr/local/mysql/support-files/
5. Copy the MySQL configuration file
[email protected] support-files]# CP my-medium.cnf/data/mysql/my.cnf
[email protected] support-files]# CP mysql.server/etc/init.d/mysqld
[Email protected] support-files]# chmod +x/etc/init.d/mysqld
6. Initialize MySQL
[Email protected] support-files]# cd/usr/local/mysql/scripts
[Email protected] scripts]#/mysql_install_db--user=mysql--basedir=/usr/local/mysql/--datadir=/data/mysql/
7. Modify the MySQL Data directory
[Email protected]]# CD/&& MORE/ETC/MY.CNF
[Mysqld]
Datadir=/data/mysql
Socket=/var/lib/mysql/mysql.sock
User=mysql
# Disabling Symbolic-links is recommended to prevent assorted security risks
Symbolic-links=0
[Mysqld_safe]
Log-error=/var/log/mysqld.log
Pid-file=/var/run/mysqld/mysqld.pid
[Email protected]]# mkdir-pv/var/lib/mysql/&& ln-s/tmp/mysql.sock/var/lib/mysql/
8. Start MySQL
[Email protected]]# ln-s/usr/local/mysql/bin/mysql/usr/bin/
[Email protected]]# ln-s/usr/local/mysql/bin/mysqladmin/usr/bin/
[[Email protected]]# service mysqld start
[Email protected]]# mysqladmin-uroot password "123456"
9. Log in to the database to create a Zabbix library
[Email protected]]# mysql-p123456
Mysql> CREATE DATABASE Zabbix default CharSet UTF8;
Mysql> grant all privileges in zabbix.* to [email protected] ' localhost ' identified by ' Zabbix ';
mysql> flush Privileges;
mysql> show databases;
Mysql> quit
Write a new MySQL configuration file because we will again use userparameter_mysql.conf in this default template for MySQL
[Email protected] scripts]# MORE/USR/LOCAL/ZABBIX/ETC/.MY.CNF
#zabbix_agent
[MySQL]
Host=localhost
User=zabbix
Password=zabbix
Socket=/tmp/mysql.sock
[Mysqladmin]
Host=localhost
User=zabbix
Password=zabbix
Socket=/tmp/mysql.sock
[[email protected] scripts] #chmod 655/usr/local/zabbix/etc/.my.cnf
Here's how to configure the configuration file used to. my.cnf in the default template
[Email protected] scripts]# more/usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_mysql.conf
Then restart Zabbix_agentd
[Email protected] scripts]# service Zabbix_agentd restart
The rest of you. To add a template
Zabbix monitoring Nginx
On the Zabbix agentd client, check to see if Nginx has loaded the –with-http_stub_status_module. Because the Zabbix monitor Nginx is based on Nginx's stub status module, the data provided by the status module is captured. If not previously opened, now want to enable the Stubstatus module, when compiling nginx to add parameters –with-http_stub_status_module
Check if With-http_stub_status_module is installed
[Email protected] scripts]#/usr/local/nginx/sbin/nginx-v
Nginx version:nginx/1.9.15
Built by GCC 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
Built with OpenSSL 1.0.1e-fips 2013
TLS SNI Support Enabled
Configure arguments:--prefix=/usr/local/nginx--user=nginx--group=nginx--with-http_ssl_module--with-http_v2_ Module--with-http_stub_status_module--with-pcre
In zabbix.conf configuration Stub_status_module
Start Nginx
Service Nginx Restart
Test with Curl.
[Email protected] zabbix_agentd.conf.d]# Curl Http://47.93.232.219/nginx-status
Active Connections:2
Server accepts handled requests
367 367 8631
reading:0 writing:1 waiting:1
Status page The meaning of each data:
Active connections– the number of active connections currently being processed by Nginx.
Serveraccepts handled requests-processed a total of 233,851 connections, successfully created 233,851 handshakes (proving that there was no failure in the middle), processed 687,942 requests in total (averaging 2.94 data requests per handshake) )。
Reading-nginx the number of Header messages read to the client.
Writing-nginx the number of Header information returned to the client.
waiting-Open keep-alive, this value is equal to active– (reading + writing), meaning that Nginx has processed the host connection waiting for the next request instruction.
Zabbix-agent Configuration
There are 3 steps, the first is to write a script to get nginx information, then add the key information in the configuration, and then restart the agent service.
① Write Nginx monitoring script, remember the path, the following configuration needs to be used, pay attention to the script permissions issues, agent running user to be able to execute.
Mkidr-p/usr/local/zabbix/scripts/
Cd/usr/local/zabbix/scripts
VI nginx-check.sh
#!/bin/bash
##################################
# Zabbix Monitoring Script
#
# Nginx:
#-Anything available via Nginx stub-status module
#
##################################
# Contact:
# [Email protected]
# Zabbix Requested parameter
Zbx_req_data= "$"
Zbx_req_data_url= "$"
# Nginx Defaults
Nginx_status_default_url= "Http://bbs.jzq.pub/nginx-status" # (write the domain name of the website here)
Wget_bin= "/usr/bin/wget"
#
# Error Handling:
#-Need to being displayable in Zabbix (avoid not_supported)
#-Items need to is of type "float" (allow negative + float)
#
error_no_access_file= "-0.9900"
error_no_access= "-0.9901"
error_wrong_param= "-0.9902"
Error_data= " -0.9903" # either can not Connect/bad Host/bad port
# Handle host and Port if Non-default
if [!-Z "$ZBX _req_data_url"]; Then
Url= "$ZBX _req_data_url"
Else
Url= "$NGINX _status_default_url"
Fi
# Save the Nginx stats in a variable for future parsing
nginx_stats=$ ($WGET _bin-q $URL-O-2>/dev/null)
# Error during retrieve
If [$?-ne 0-o-Z "$NGINX _stats"]; Then
Echo $ERROR _data
Exit 1
Fi
#
# Extract data from Nginx stats
#
Case $ZBX _req_data in
Active_connections) echo "$NGINX _stats" | head-1 | cut-f3-d ';
Accepted_connections) echo "$NGINX _stats" | Grep-ev ' [a-za-z] ' | Cut-f2-d ';
Handled_connections) echo "$NGINX _stats" | Grep-ev ' [a-za-z] ' | cut-f3-d ';
handled_requests) echo "$NGINX _stats" | Grep-ev ' [a-za-z] ' | Cut-f4-d ';
Reading) echo "$NGINX _stats" | Tail-1 | Cut-f2-d ';
Writing) echo "$NGINX _stats" | Tail-1 | Cut-f4-d ';
Waiting) echo "$NGINX _stats" | Tail-1 | Cut-f6-d ';
*) echo $ERROR _wrong_param; Exit 1;;
Esac
Exit 0
chmod o+x/usr/local/zabbix/scripts/nginx-check.sh
The agent's configuration file/etc/zabbix/zabbix_agentd.conf defines the other key's include directory include=/etc/zabbix/zabbix_agentd.d/, if not this configuration please add it yourself. Next, create a new file nginx-params.conf in the/etc/zabbix/zabbix_agentd.d/directory, which reads as follows
[Email protected] zabbix_agentd.conf.d]# more/usr/local/zabbix/etc/zabbix_agentd.conf.d/nginx-params.conf
Userparameter=nginx[*],/usr/local/zabbix/scripts/nginx-check.sh "$"
/etc/init.d/zabbix-agent restart
Import nginx template file below
Zabbix Monitoring Mysql,nginx