首页 > 其他分享 >zabbix自定义监控主从状态延迟与创建用户和组及权限管理

zabbix自定义监控主从状态延迟与创建用户和组及权限管理

时间:2022-09-07 22:55:35浏览次数:81  
标签:slave 自定义 etc zabbix master mysql 组及 root

1:zabbix监控主从
部署mysql主从
环境用到两台centos8的操作系统
一台为master一台为slave

[root@localhost ~]# hostnamectl set-hostname master
[root@localhost ~]# bash
[root@master ~]#
[root@localhost ~]# hostnamectl set-hostname slave
[root@localhost ~]# bash
[root@slave ~]#

首先将阿里云的源仓库下载下来

[root@slave ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@slave ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@master ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@master ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

下载mariadb

[root@master ~]# yum -y install mariadb-server mariadb
[root@slave ~]# yum -y install mariadb-server mariadb

初始化数据库

[root@master ~]# systemctl start mariadb.service
[root@master ~]# mysql_secure_installation
Enter current password for root (enter for none):
Set root password? [Y/n]
New password:
Re-enter new password:
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n] n
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]
[root@slave ~]# systemctl start mariadb.service
[root@slave ~]# mysql_secure_installation
Enter current password for root (enter for none):
Set root password? [Y/n]
New password:
Re-enter new password:
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n] n
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]

关闭selinux和防火墙

[root@slave ~]# systemctl stop firewalld.service
sys[root@slave ~]# systemctl disable firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@slave ~]# vim /etc/selinux/config
SELINUX=disabled
[root@slave ~]# setenforce 0
[root@master ~]# systemctl stop firewalld.service
syst[root@master ~]# systemctl disable firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@master ~]# vim /etc/selinux/config
SELINUX=disabled
[root@master ~]# setenforce 0

修改数据库配置文件

[root@master ~]# vim /etc/my.cnf.d/mariadb-server.cnf
log-bin=g
server-id=2000
[root@master ~]# systemctl restart mariadb.service
[root@slave ~]# vim /etc/my.cnf.d/mariadb-server.cnf
log-bin=j
server-id=2001
[root@slave ~]# systemctl restart mariadb.service

进数据库配置主从

[root@master ~]# mysql -uroot -p123456

MariaDB [(none)]> show master status;
+----------+----------+--------------+------------------+
| File     | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+----------+----------+--------------+------------------+
| g.000001 |      320 |              |                  |
+----------+----------+--------------+------------------+
MariaDB [(none)]> create user 'xuanning'@'192.168.226.158' identified by '123456';
MariaDB [(none)]> GRANT REPLICATION SLAVE ON *.* TO 'xuanning'@'192.168.226.158';
MariaDB [(none)]> flush privileges;

[root@slave ~]# mysql -uroot -p123456
MariaDB [(none)]> change master to
    -> master_host='192.168.226.139' ,
    -> master_user = 'xuanning' ,
    -> master_password = '123456' ,
    -> master_log_file = 'g.000001' ,
    -> master_log_pos = 320;
    MariaDB [(none)]> start slave;
    MariaDB [(none)]> show slave status \G
 Slave_IO_Running: Connecting
  Slave_SQL_Running: Yes

主从配置完毕将slave加入到监控平台中
首先下载zabbix的源这里我zabbix服务端有源仓库故直接拷贝过来

[root@slave ~]# scp [email protected]:/etc/yum.repos.d/* /etc/yum.repos.d/

修改/etc/hosts

[root@slave ~]# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.226.139 server
192.168.226.158 agent1
192.168.226.162 master
192.168.226.163 slave

下载zabbix-agent软件包

[root@slave ~]# yum -y install zabbix-agent

修改zabbix-agent配置文件

[root@slave ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.226.139
ServerActive=192.168.226.139
Hostname=slave
[root@slave ~]# systemctl restart zabbix-agent.service

创建主机

在slave上创建脚本脚本用于检测主从状态

[root@slave ~]# mkdir /etc/zabbix/script
[root@slave ~]# cd /etc/zabbix/script/
[root@slave script]# vim mysql.sh
[root@slave script]# cat mysql.sh
#!/bin/bash
USER="root"
PASSWD="123456"
NAME=$1

function IO {
    Slave_IO_Running=`mysql -u $USER -p$PASSWD -e "show slave status\G;" 2> /dev/null |grep Slave_IO_Running |awk '{print $2}'`
    if [ $Slave_IO_Running == "Connecting" ];then
        echo 0
    else
        echo 1
    fi
}

function SQL {
    Slave_SQL_Running=`mysql -u $USER -p$PASSWD -e "show slave status\G;" 2> /dev/null |grep Slave_SQL_Running: |awk '{print $2}'`
if [ $Slave_SQL_Running == "Yes" ];then
echo 0
    else
        echo 1
    fi

}

case $NAME in
   io)
       IO
   ;;
   sql)
       SQL
   ;;
   *)
        echo -e "Usage: $0 [io | sql]"
esac
[root@slave script]# chown -R zabbix.zabbix /etc/zabbix/script/
[root@slave script]# chmod +x mysql.sh

创建自定义键值

[root@slave script]# cd /etc/zabbix/zabbix_agentd.d/
[root@slave zabbix_agentd.d]# vim userparameter_mysql_slave.conf
[root@slave zabbix_agentd.d]# cat userparameter_mysql_slave.conf
UserParameter=mysql.slave[*],/etc/zabbix/script/mysql.sh $1
[root@slave zabbix_agentd.d]# systemctl restart zabbix-agent.service

创建监控项

测试
将主从复制停止

[root@slave ~]# mysql -uroot -p123456
MariaDB [(none)]> stop slave;
Query OK, 0 rows affected (0.001 sec)



将主从复制开启

MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.001 sec)

2:监控主从延迟
编写脚本

[root@slave ~]# cd /etc/zabbix/script/
[root@slave script]# vim mysql_deley.sh
[root@slave script]# cat mysql_deley.sh
#!/bin/bash
delay=$(mysql -uroot -p123456 -e 'show slave status\G' 2> /dev/null | grep 'Seconds_Behind_Master' | awk '{print $2}')
if [ $delay == "NULL" ];then
echo 0
elif [ $delay -ge 0 ] && [ $delay -le 200 ];then
echo 0
else
echo $delay
fi
[root@slave script]# chown zabbix.zabbix mysql_deley.sh
[root@slave script]# chmod +x mysql_deley.sh

自定义键值

[root@slave script]# vim /etc/zabbix/zabbix_agentd.d/userparameter_mysql_slave.c                                                                                onf
[root@slave script]# cat /etc/zabbix/zabbix_agentd.d/userparameter_mysql_slave.c                                                                                onf
UserParameter=mysql.slave[*],/etc/zabbix/script/mysql.sh $1
UserParameter=check_mysql_delay,/bin/bash /etc/zabbix/script/mysql_deley.sh
[root@slave script]# systemctl restart zabbix-agent.service

创建监控项

此处由于环境无法做出延迟故让他等于0一直报警测试

3:zabbix创建用户和组
创建主机群组

创建主机

创建用户组

创建用户
用户的权限有三种
1:用户,默认情况下用户无任何权限,必须明确指定对主机组的任何权限
2:管理员,用户可以访问配置页面
3:超级管理员,用户可以对所以主机拥有所有权限
用户权限

登录

界面没有配置选项,无法进行配置

管理员权限

界面

可以看见能够对主机组内的主机进行配置
超级管理员权限

标签:slave,自定义,etc,zabbix,master,mysql,组及,root
From: https://www.cnblogs.com/soap-bubble/p/16667611.html

相关文章

  • zabbix用户,角色,权限,模板管理
    zabbix用户,角色,权限,模板管理用户组用户角色用户使用刚才创建的用户登录模板组模板模板的监控项可以自己创建也可以从其他模板复制......
  • 4. 新版本的生产者API 带有自定义分区和回调函数的生产者
    1.开启进程[node123]systemctlstopfirewalld[node123]zkServer.shstart[node123]kafka-server-start.sh/opt/app/kafka-0.11.0.0/config/server.properties&[......
  • zabbix自定义监控mysql主从状态和延迟
    zabbix自定义监控mysql主从状态和延迟目录zabbix自定义监控mysql主从状态和延迟zabbix自定义监控mysql主从状态zabbix自定义监控mysql主从延迟zabbix自定义监控mysql主从......
  • docker +zabbix
    基于阿里云服务器安装1、下载镜像1dockerpullmysql:8.023dockerpullzabbix/zabbix-server-mysql:centos-latest45dockerpullzabbix/zabbix-web-nginx-my......
  • CoreDNS实现自定义域名解析
    参考:https://support.huaweicloud.com/usermanual-cce/cce_01_0361.html一、修改CoreDNSHosts配置修改CoreDNS配置文件,将自定义域名添加到hosts中。例如将www.example.......
  • js 实现扁平数组转为树形结构数组及树形结构数组转为扁平数组
    //pid代表属于的父级id//id代表的是自己本身的id,本身的id是多少letflatArr=[{id:1,name:"部门1",pid:0},{id:2,name:"部门2",pid:1}......
  • SpringBoot使用自定义注解+AOP+Redis实现接口限流
    为什么要限流系统在设计的时候,我们会有一个系统的预估容量,长时间超过系统能承受的TPS/QPS阈值,系统有可能会被压垮,最终导致整个服务不可用。为了避免这种情况,我们就需要对......
  • 五分钟实现Zabbix电话短信机器人报警
    Zabbix是现在企业用的比较多的开源监控系统,Zabbix电话短信报警更是运维不可缺少的报警渠道,假如半夜正在睡觉服务器异常了,这时候电话报警就非常必要。Spug推送助手针对......
  • java poi - excel cell 设置自定义颜色
    XSSFCellStylecellStyle=wb.createCellStyle();cellStyle.setFillForegroundColor(newXSSFColor(newColor(195,227,255)));cellStyle.setFillPattern(FillPatter......
  • zabbix自定义监控
    zabbix自定义监控自定义监控进程测试监控httpd,需要在监控端部署httpd,以方便监控``配置监控脚本#在监控端[root@localhost~]#dnf-yinstallhttpd[root@localhost......