Mysql安装
下载mysql二进制包
1
2
[root@linux-node1 ~]# cd /usr/local/src
创建mysql用户
1
2
[root@linux-node2 ~]# groupadd mysql
[root@linux-node2 ~]# useradd -r -g mysql -s /bin/false mysql
解压mysql二进制包
1
2
3
4
[root@linux-node2 ~]# cd /usr/local/src
[root@linux-node2 src]# tar zxf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
[root@linux-node2 src]# mv mysql-5.6.30-linux-glibc2.5-x86_64 /usr/local/
[root@linux-node1 ~]# chown -R mysql:mysql /usr/local/mysql-5.6.30-linux-glibc2.5-x86_64
初始化mysql
1
2
3
[root@linux-node1 ~]# ln -s /usr/local/mysql-5.6.30-linux-glibc2.5-x86_64/ /usr/local/mysql
[root@linux-node1 ~]# ln -s /usr/local/mysql/mysql.sock /var/lib/mysql/mysql.sock
[root@linux-node1 ~]# chown -R mysql:mysql /usr/local/mysql
上传压缩包中的my.cnf到/usr/local/mysql目录下
1
2
3
4
[root@linux-node1 ~]# /usr/local/mysql/scripts/mysql_install_db \
–defaults-file=/usr/local/mysql/my.cnf \
–user=mysql –basedir=/usr/local/mysql/ \
–datadir=/usr/local/mysql/data
启动mysql
1
/usr/local/mysql/bin/mysqld –defaults-file=/usr/local/mysql/my.cnf &
连接mysql
1
/usr/local/mysql/bin/mysql -S /usr/local/mysql/mysql.sock
Zabbix安装
请参考官方档:
https://www.zabbix.com/documentation/3.0/manual/installation/install_from_packages#installing_repository_configuration_package
1
2
3
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
yum install zabbix-server-mysql zabbix-web-mysql
yum install zabbix-agent
创建zabbix数据库
1
2
3
/usr/local/mysql/bin/mysql -S /usr/local/mysql/mysql.sock
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql>grant all on zabbix.* to zabbix@’localhost’ identified by ‘zabbix’;
导入zabbix数据源
1
2
配置zabbix-server
1
2
3
4
5
6
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/usr/local/mysql/mysql.sock
启动zabbix-server
1
配置zabbix-agent
1
2
Server=192.168.56.12
启动zabbix-agent
1
systemctl restart zabbix-agent.service
Percona Monitoring Plugin安装
官方参考网址:
https://www.percona.com/doc/percona-monitoring-plugins/1.1/zabbix/index.html#installation-instructions
1
2
yum install percona-zabbix-templates
cp /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agentd.conf.d/userparameter_percona_mysql.conf
创建percona连接数据库配置文件
1
2
3
4
mysqluser=‘zabbix′;
mysql_pass = ‘zabbix’;
修改get_mysql_stats_wrapper.sh
1
sed -i “s#mysql -e#/usr/local/mysql/bin/mysql -S /usr/local/mysql/mysql.sock -e#g” get_mysql_stats_wrapper.sh
重启zabbix_agent
1
测试脚本
1
2
[root@linux-node2 scripts]# /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh gg
970
添加监控
访问:http://192.168.56.12/zabbix
blob.png
导入模版,请使用下面我上传的zbx_export_percona-templates.xml(3.0zabbix自带模版有点坑)
blob.png
zbx_export_percona-templates.xml
添加模版
blob.png
出图Monitoring——Grapha
blob.png