首页 > 数据库 > 其他综合 >

数据库监控(Zabbix)

2019-02-27

数据库监控(Zabbix)

[root@wallet04 ~]# rpm -ivh epel-release-6-8.noarch.rpm

[root@wallet04 ~]# rpm -ivh https://mirror.webtatic.com/yum/el6/latest.rpm

[root@wallet04 ~]# yum install -y httpd php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-devel.x86_64 \

php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-bcmath.x86_64 php56w-xml.x86_64 \

php56w-mysqlnd.x86_64 php56w-pdo.x86_64

[root@wallet04 ~]# vi /etc/httpd/conf/httpd.conf

ServerName 192.168.1.204:80

[root@wallet04 ~]# vi /etc/php.ini

date.timezone = Asia/Shanghai

max_execution_time = 300

max_input_time = 300

post_max_size = 32M

memory_limit = 128M

mbstring.func_overload = off

always_populate_raw_post_data = -1

[root@wallet04 ~]# service httpd start

[root@wallet04 ~]# rpm -ivh http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

[root@wallet04 ~]# yum install -y mysql-community-server

[root@wallet04 ~]# service mysqld start

[root@wallet04 ~]# /usr/bin/mysql_secure_installation

[root@wallet04 ~]# mysql -uroot -pabcd.1234

mysql> create database zabbix default character set utf8;

Query OK, 1 row affected (0.05 sec)

mysql> grant all on zabbix.* to 'zabbix'@'localhost' identified by 'zabbix';

Query OK, 0 rows affected (0.10 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.01 sec)

[root@wallet04 ~]# yum install -y net-snmp net-snmp-utils net-snmp-devel

[root@wallet04 ~]# tar zxvf zabbix-3.0.16.tar.gz

[root@wallet04 ~]# cd zabbix-3.0.16

[root@wallet04 zabbix-3.0.16]# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2

[root@wallet04 zabbix-3.0.16]# make install

[root@wallet04 zabbix-3.0.16]# mysql -uroot -p zabbix < database/mysql/schema.sql

[root@wallet04 zabbix-3.0.16]# mysql -uroot -p zabbix < database/mysql/images.sql

[root@wallet04 zabbix-3.0.16]# mysql -uroot -p zabbix < database/mysql/data.sql

[root@wallet04 zabbix-3.0.16]# cp misc/init.d/fedora/core/zabbix_* /etc/init.d/

[root@wallet04 zabbix-3.0.16]# cp -r frontends/php /var/www/html/zabbix

[root@wallet04 ~]# vi /usr/local/etc/zabbix_server.conf

DBHost=localhost

DBName=zabbix

DBUser=zabbix

DBPassword=zabbix

[root@wallet04 ~]# service zabbix_server start

Starting zabbix_server: [ OK ]

[root@wallet04 ~]# netstat -tupln |grep zabbix_server

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

[root@wallet04 ~]# service zabbix_agentd start

Starting zabbix_agentd: [ OK ]

[root@wallet04 ~]# netstat -tupln |grep zabbix_agentd

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

[root@wallet01 ~]# yum install -y golang

[root@wallet01 ~]# go version

go version go1.11.2 linux/amd64

[root@wallet01 ~]# export GOPATH=/home/go

[root@wallet01 ~]# go get -u github.com/go-sql-driver/mysql

[root@wallet01 ~]# git clone https://github.com/actiontech/actiontech_zabbix_mysql_monitor.git

Initialized empty Git repository in /root/actiontech_zabbix_mysql_monitor/.git/

remote: Enumerating objects: 193, done.

remote: Total 193 (delta 0), reused 0 (delta 0), pack-reused 193

Receiving objects: 100% (193/193), 10.78 MiB | 185 KiB/s, done.

Resolving deltas: 100% (115/115), done.

[root@wallet01 ~]# cd actiontech_zabbix_mysql_monitor

[root@wallet01 actiontech_zabbix_mysql_monitor]# chmod a+x *.sh

[root@wallet01 actiontech_zabbix_mysql_monitor]# ./build.sh

[root@wallet01 actiontech_zabbix_mysql_monitor]# ls -l

total 7296

-rwxr-xr-x 1 root root 5972403 Jan 10 16:25 actiontech_mysql_monitor

-rw-r--r-- 1 root root 50120 Aug 8 15:12 actiontech_mysql_monitor.go

-rw-r--r-- 1 root root 20065 Aug 8 15:12 actiontech_mysql_monitor_test.go

-rw-r--r-- 1 root root 673006 Aug 8 15:12 actiontech_zbx_3.0_template_mysql_server.xml

-rw-r--r-- 1 root root 690284 Aug 8 15:12 actiontech_zbx_3.4_template_mysql_server.xml

-rwxr-xr-x 1 root root 122 Aug 8 15:12 build.sh

-rwxr-xr-x 1 root root 450 Aug 8 15:12 install.sh

-rw-r--r-- 1 root root 11358 Aug 8 15:12 LICENSE

-rw-r--r-- 1 root root 25165 Aug 8 15:12 README.md

-rw-r--r-- 1 root root 283 Aug 8 15:12 userparameter_actiontech_mysql.conf

[root@wallet01 actiontech_zabbix_mysql_monitor]# mkdir -p /var/lib/zabbix/actiontech/scripts

[root@wallet01 actiontech_zabbix_mysql_monitor]# cp actiontech_mysql_monitor /var/lib/zabbix/actiontech/scripts/

[root@wallet01 actiontech_zabbix_mysql_monitor]# cp userparameter_actiontech_mysql.conf /usr/local/etc/zabbix_agentd.conf.d/

[root@wallet01 ~]# cd /var/lib/zabbix/actiontech/scripts

[root@wallet01 scripts]# vi mysql.sh

#!/bin/bash

sudo /var/lib/zabbix/actiontech/scripts/actiontech_mysql_monitor --host=localhost --port=$1 --user=root --pass=abcd.1234 --items=$2 | awk &#39;{print $3}&#39;

[root@wallet01 scripts]# chmod a+x mysql.sh

[root@wallet01 scripts]# ./mysql.sh 3306 Aborted_clients

46

[root@wallet01 ~]# vim /etc/sudoers

Defaults:zabbix !requiretty

zabbix ALL=(ALL) NOPASSWD: ALL

[root@wallet01 ~]# su - zabbix

[zabbix@wallet01 ~]$ cd /var/lib/zabbix/actiontech/scripts

[zabbix@wallet01 scripts]$ ./mysql.sh 3306 Aborted_clients

46

[root@wallet01 ~]# cd /usr/local/etc/zabbix_agentd.conf.d

[root@wallet01 zabbix_agentd.conf.d]# vi userparameter_actiontech_mysql.conf

UserParameter=MySQL.[*],/var/lib/zabbix/actiontech/scripts/mysql.sh $1 $2

UserParameter=MySQL.port_discovery,/var/lib/zabbix/actiontech/scripts/actiontech_mysql_monitor --discovery_port true

[root@wallet01 ~]# vi /usr/local/etc/zabbix_agentd.conf

Server=192.168.1.204

Hostname=wallet01

Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf

[root@wallet01 ~]# /etc/init.d/zabbix_agentd restart

[root@zabbix ~]# zabbix_get -s 192.168.1.201 -k MySQL.[3306,Aborted_clients]

46

[root@wallet01 ~]# tar zxvf fpmmm-1.0.1.tar.gz -C /usr/local

[root@wallet01 ~]# cd /usr/local/fpmmm-1.0.1/tpl/

[root@wallet01 tpl]# cp fpmmm.conf.template /etc/fpmmm.conf

[root@wallet01 ~]# vi /etc/fpmmm.conf

# Information for MySQL connections:

Username = fpmmm

Password = fpmmm

MysqlHost = localhost

MysqlPort = 3306

# Zabbix Server IP address

ZabbixServer = 192.168.1.204

[wallet01] # This MUST match Hostname in Zabbix!

Type = mysqld

MysqlPort = 3306

Modules = mysql innodb

PidFile = /var/run/mysqld/mysqld.pid

[root@wallet01 ~]# mysql -uroot -pabcd.1234

mysql> grant process on *.* to &#39;fpmmm&#39;@&#39;localhost&#39; identified by &#39;fpmmm&#39;;

mysql> grant replication client on *.* to &#39;fpmmm&#39;@&#39;localhost&#39;;

mysql> grant replication slave on *.* to &#39;fpmmm&#39;@&#39;localhost&#39;;

mysql> grant select on mysql.user to &#39;fpmmm&#39;@&#39;localhost&#39;;

mysql> flush privileges;

[root@wallet01 ~]# yum install php-cli php-process php-mysqli php-posix

[root@wallet01 ~]# cat << _EOF >/etc/php.d/fpmmm.ini

variables_order = "EGPCS"

date.timezone = &#39;Asia/Shanghai&#39;

_EOF

[root@wallet01 ~]# useradd zabbix

[root@wallet01 ~]# tar zxvf zabbix-3.0.20.tar.gz

[root@wallet01 ~]# cd zabbix-3.0.20/

[root@wallet01 zabbix-3.0.20]# ./configure --enable-agent

[root@wallet01 zabbix-3.0.20]# make install

[root@wallet01 ~]# ln -s /usr/local/bin/zabbix_sender /usr/bin/zabbix_sender

[root@wallet01 ~]# /usr/local/fpmmm-1.0.1/bin/fpmmm --config=/etc/fpmmm.conf

1

[root@wallet01 ~]# cat /var/log/fpmmm/fpmmm.log

[root@wallet01 ~]# crontab -e

* * * * * /usr/local/fpmmm-1.0.1/bin/fpmmm --config=/etc/fpmmm.conf

[root@wallet01 ~]# crontab -l

* * * * * /usr/local/fpmmm-1.0.1/bin/fpmmm --config=/etc/fpmmm.conf

相关文章
最新文章
热点推荐