安装环境:两台虚拟主机 安装步骤: 首先 做mysql主从(详解下面链接) https://blog.csdn.net/RoninLJH/article/details/106753020
。
[root@localhost ~]# systemctl stop firewalld [root@localhost ~]# setenforce 0 [root@localhost ~]# ntpdate pool.ntp.org配置yum源
[root@localhost ~]# vim /etc/yum.repos.d/zabbix.repo [zabbix] name=Zabbix Official Repository - $basearch baseurl=http://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/$basearch/ enabled=1 gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 [zabbix-debuginfo] name=Zabbix Official Repository debuginfo - $basearch baseurl=http://mirrors.aliyun.com/zabbix/zabbix/4.4/rhel/7/$basearch/debuginfo/ enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591 gpgcheck=0 [zabbix-non-supported] name=Zabbix Official Repository non-supported - $basearch baseurl=http://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearch/ enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX gpgcheck=0安装zabbix、httpd
[root@localhost ~]# yum -y install zabbix-server-mysql zabbix-web-mysql httpd登录mysql、创建zabbix数据库,并授权
[root@localhost ~]# mysql MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; MariaDB [(none)]> grant all on zabbix.* to zabbix@'localhost' identified by 'zabbix'; MariaDB [(none)]> flush privileges;导入数据库数据
[root@localhost ~]# zcat /usr/share/doc/zabbix-server-mysql-4.4.10/create.sql.gz | mysql -uzabbix -pzabbix zabbix修改zabbix配置文件
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf DBPassword=zabbix修改时间戳
[root@localhost ~]# vim /etc/php.ini date.timezone =Asia/Shanghai启动httpd、zabbix
[root@localhost ~]# systemctl enable httpd zabbix-server [root@localhost ~]# systemctl start httpd zabbix-server [root@localhost ~]# netstat -anpt |egrep "80|10051"
**
**
上传语言包
[root@localhost ~]# cd /usr/share/zabbix/assets/fonts/ [root@localhost fonts]# rm -rf graphfont.ttf [root@localhost fonts]# mv simkai.ttf graphfont.ttf安装zabbix监控端(注意:需要配置yum源,同server端一样)
[root@localhost ~]# yum -y install zabbix-agent修改配置文件
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf Server=192.168.33.137 ServerActive=192.168.33.173开启zabbix
[root@localhost ~]# systemctl enable zabbix-agent [root@localhost ~]# systemctl start zabbix-agent设置k(需要在从库里授权一个用户)
MariaDB [(none)]> grant all on *.* to ljh@'localhost' identified by 'ljh'; [root@localhost ~]# mkdir /etc/zabbix/scripts [root@localhost ~]# vim /etc/zabbix/scripts/check_mysql.sh ---------------------------------- #!/bin/bash case $1 in #mysql主从是否正常 slave_yes) mysql -uljh -pljh-e "show slave status \G;" | grep "Yes" |wc -l ;; #mysql是否存活 slave_status) netstat -anpt |grep mysqld |wc -l ;; #mysql吞吐量 发送 Bytes_sent) mysqladmin -uljh -pljh extended-status |grep Bytes_sent |awk '{print $4}' ;; #mysql吞吐量 接收 Bytes_received) mysqladmin -uljh -pljh extended-status |grep Bytes_received |awk '{print $4}' ;; #表大小 tb_size) mysql -uljh -pljh -e "select data_length from information_schema.tables where table_schema='mysql' and table_name='db';" | sed -n '2p' ;; #库大小 db_size) mysql -uljh -pljh -e "select sum(data_length) as xx from information_schema.tables where table_schema='mysql'" |sed '1d' ;; #每秒请求数 qps) mysqladmin status | awk '{print $6/$2}' ;; #事务数 tps) commit=`mysqladmin extended-status |grep Com_commit |awk '{print $4}'` rollback=`mysqladmin extended-status |grep -w Com_rollback |awk '{print $4}'` uptime=`mysqladmin status | awk '{print $2}'` t=`expr $commit + $rollback` echo `expr $t / $uptime` ;; esac ----------------------------------- [root@localhost ~]# chmod +x /etc/zabbix/scripts/check_mysql.sh [root@localhost ~]# vim /etc/zabbix/zabbix_agentd.d/mysql.conf ----------------------------- UserParameter=mysql_status[*],/etc/zabbix/scripts/check_mysql.sh $1 ------------------------------ [root@localhost ~]# systemctl restart zabbix-agent [root@localhost ~]# chmod +s /bin/netstat注意:监控的主机ip为节点ip 查看 添加触发器 测试触发器报警
[root@localhost ~]# systemctl stop mariadb [root@localhost ~]# systemctl start mariadb**
**