Zabbix企业级高级应用-数据库主从监控

发布时间:2023年12月19日

客户端开启自定义key值
vim /etc/zabbix/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=nginx_status[*],/etc/zabbix/nginx-status.sh $1

nginx配置文件的修改
yum install -y epel-release
yum install -y nginx
vim /etc/nginx/nginx.conf
location /nginx_status {
stub_status on;
access_log off;
allow 192.168.0.0/16;
allow 127.0.0.1;
deny all;
}

测试是否能够获取到nginx状态
curl http://127.0.0.1/nginx_status

添加监控脚本
vim /etc/zabbix/nginx-status.sh
#/bin/bash
NGINX_PORT=80
NGINX_COMMAND=KaTeX parse error: Expected '}', got 'EOF' at end of input: …p://127.0.0.1:"NGINX_PORT"/nginx_status/" |awk '/Active/ {print KaTeX parse error: Expected 'EOF', got '}' at position 3: NF}?' } nginx_readi…NGINX_PORT"/nginx_status/" |awk '/Reading/ {print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}?' } nginx_writi…NGINX_PORT"/nginx_status/" |awk '/Writing/ {print KaTeX parse error: Expected 'EOF', got '}' at position 2: 4}?' } nginx_waiti…NGINX_PORT"/nginx_status/" |awk '/Waiting/ {print KaTeX parse error: Expected 'EOF', got '}' at position 2: 6}?' } nginx_accep…NGINX_PORT"/nginx_status/" |awk 'NR3 {print KaTeX parse error: Expected 'EOF', got '}' at position 2: 1}?' } nginx_handl…NGINX_PORT"/nginx_status/" |awk 'NR3 {print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}?' } nginx_reque…NGINX_PORT"/nginx_status/" |awk ‘NR==3 {print $3}’
}
case $NGINX_COMMAND in
active)
nginx_active;
;;
reading)
nginx_reading;
;;
writing)
nginx_writing;
;;
waiting)
nginx_waiting;
;;
accepts)
nginx_accepts;
;;
handled)
nginx_handled;
;;
requests)
nginx_requests;
;;
*)
echo $“USAGE:$0 {active|reading|writing|waiting|accepts|handled|requests}”
esac

chmod +x /etc/zabbix/nginx-status.sh
zabbix_get -s nginx的ip -k nginx_status
zabbix_get -s nginx的ip -k nginx_status[accepts]

Zabbix web端添加监控

数据库的主从复制
主从版本一致:
master:
select version();
slave:
select version();

Mysql数据库安装方式

1)官网下载
mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar

2)解压并创建mysql yum仓库

mkdir /mysql57 && tar xf mysql-5.7.29-1.el7.x86_64.rpm-bundle.tar -C /mysql57 && createrepo /mysql57

3)yum仓库配置

vim /etc/yum.repos.d/CentOS-Base.repo
//添加如下5行

[mysql57]

name=mysql57

enabled=1

gpgcheck=0

baseurl=file:///mysql57

4)刷新yum并安装mysql-server

yum clean all

yum install -y mysql-server

5)启动并更改默认管理密码

systemctl start mysqld

grep “password” /var/log/mysqld.log //mysql5.7版本数据库默认密码存放在日志文件中

mysqladmin -uroot -p password “ABCabc-123” //使用默认密码改密码

配置传统复制的单主复制

1)编辑master1服务器的配置文件,配置server-id,开启二进制日志文件功能

vim /etc/my.cnf

[mysqld]

server-id = 100

log_bin = mysql-bin

systemctl restart mysqld

2)创建具有复制权限的用户

grant replication slave on . to ‘repluser’@‘192.168.180.%’ identified by ‘ABCabc-123’;

flush privileges;

show master status\G;

3)编辑mslave服务器配置文件,指定server-id

vim /etc/my.cnf

[mysqld]

server-id = 110

systemctl restart mysqld
4)链接master服务器

mysql -uroot -pABCabc-123

change master to
master_host=“192.168.180.200”,
master_user=“repluser”,
master_password=“ABCabc-123”,
master_port=3306,
master_log_file=“mysql-bin.000001”,
master_log_pos=605; \日志偏移量根据实际情况进行调整

5)启动从服务器
start slave;

6)查看从服务器状态
show slave status\G;

在SQL SLAVE上安装agent
rpm -Uvh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
yum install -y zabbix-agent

vim /etc/zabbix/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=mysql.slave[*],/etc/zabbix/mysql-slave.sh

vim /etc/zabbix/mysql-slave.sh
#!/bin/bash
/usr/bin/mysql -uroot -pabc-123 -e ‘show slave status\G’ |grep -E “Slave_IO_Running|Slave_SQL_Running”|awk ‘{print $2}’|grep -c Yes

文章来源:https://blog.csdn.net/drrui520/article/details/135014132
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。