zabbix服务
1. zabbix介绍
zabbix([`zæbiks])是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
zabbix由2部分构成,zabbix server与可选组件zabbix agent。
zabbix server可以通过SNMP,zabbix agent,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。
2. zabbix特点
zabbix的主要特点:
- 安装与配置简单,学习成本低
- 支持多语言(包括中文)
- 免费开源
- 自动发现服务器与网络设备
- 分布式监视以及WEB集中管理功能
- 可以无agent监视
- 用户安全认证和柔软的授权方式
- 通过WEB界面设置或查看监视结果
- email等通知功能
Zabbix主要功能:
- CPU负荷
- 内存使用
- 磁盘使用
- 网络状况
- 端口监视
- 日志监视
3.zabbix配置文件
zabbix配置文件有两种:
- 服务器端配置文件(/usr/local/etc/zabbix_server.conf)
- 客户端配置文件(/usr/local/etc/zabbix_agentd.conf)
- zabbix代理配置文件(/usr/local/etc/zabbix_proxy.conf)
服务器端配置文件zabbix_server.conf常用配置参数:
参数 | 作用 |
---|---|
LogFile | 设置服务端日志文件存放路径 |
ListenIP | 设置服务端监听IP |
ListenPort | 设置服务端监听的端口号 |
PidFile | 设置服务端进程号文件存放路径 |
DBHost | 指定zabbix的数据库服务器IP |
DBName | 指定zabbix使用的数据库库名 |
DBUser | 指定zabbix数据库登录用户 |
DBPassword | 指定zabbix数据库登录密码 |
DBPort | 指定zabbix数据库端口号 |
User | 设置zabbix以什么用户的身份运行 |
AlertScriptsPath | 设置告警脚本存放路径 |
ExternalScripts | 外部脚本存放路径 |
客户端配置文件zabbix_agentd.conf常用配置参数:
参数 | 作用 |
---|---|
Server | 指定zabbix服务器的IP或域名 |
ServerActive | 指定zabbix服务器的IP或域名 |
Hostname | 指定本机的主机名,此项必须与web界面配置项一致 |
UnsafeUserParameters | 是否启用自定义监控项,可选值为1或0 |
UserParameter | 指定自定义监控脚本参数 |
LogFile | 设置客户端日志文件存放路径 |
4.部署zabbix
4.1 zabbix服务端安装
//安装依赖包
yum -y install net-snmp-devel libevent-devel
//下载zabbix
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
apr-1.6.5 apr-util-1.6.1 debug httpd-2.4.37.tar.bz2 php-7.2.8 zabbix-4.0.4.tar.gz
apr-1.6.5.tar.bz2 apr-util-1.6.1.tar.bz2 httpd-2.4.37 kernels php-7.2.8.tar.xz
//解压
[root@localhost src]# tar -xf zabbix-4.0.4.tar.gz
[root@localhost src]# ls
apr-1.6.5 apr-util-1.6.1 debug httpd-2.4.37.tar.bz2 php-7.2.8 zabbix-4.0.4
apr-1.6.5.tar.bz2 apr-util-1.6.1.tar.bz2 httpd-2.4.37 kernels php-7.2.8.tar.xz zabbix-4.0.4.tar.gz
//创建zabbix用户和组
[root@localhost ~]# groupadd -r zabbix
[root@localhost ~]# useradd -r -M -s /sbin/nologin -g zabbix zabbix
//配置zabbix数据库
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.23-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on zabbix.* to zabbix@localhost identified by 'zabbix123!';
Query OK, 0 rows affected, 2 warnings (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
[root@localhost ~]# cd /usr/src/zabbix-4.0.4/database/mysql/
[root@localhost mysql]# ls
data.sql images.sql Makefile.am Makefile.in schema.sql
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
//编译安装zabbix
[root@localhost ~]# cd /usr/src/zabbix-4.0.4
[root@localhost zabbix-4.0.4]# ./configure --enable-server \
> --enable-agent \
> --with-mysql \
> --with-net-snmp \
> --with-libcurl \
> --with-libxml2
[root@localhost zabbix-4.0.4]# make install
4.2 zabbix服务端配置
[root@localhost ~]# ls /usr/local/etc/
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d
//修改服务端配置文件
//设置数据库信息
[root@localhost ~]# vim /usr/local/etc/zabbix_server.conf
# Comment this line if no password is used.
#
# Mandatory: no
# Default:
DBPassword=zabbix123! //设置zabbix数据库连接密码
### Option: DBSocket
# Path to MySQL socket.
#
//启动zabbix_server和zabbix_agentd
root@localhost ~]# zabbix_server
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
[root@localhost ~]# zabbix_agentd
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
[root@localhost ~]#
4.3 zabbix服务端web界面安装与配置
4.3.1 zabbix web界面安装前配置
//修改/etc/php.ini的配置并重启php-fpm
[root@localhost ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@localhost ~]# cd /usr/src/zabbix-4.0.4
[root@localhost zabbix-4.0.4]# ls
aclocal.m4 build conf config.status configure.ac depcomp INSTALL Makefile man NEWS src
AUTHORS ChangeLog config.guess config.sub COPYING frontends install-sh Makefile.am misc README
bin compile config.log configure database include m4 Makefile.in missing sass
[root@localhost zabbix-4.0.4]# mkdir /usr/local/apache/htdocs/zabbix
[root@localhost zabbix-4.0.4]# \cp -a frontends/php/* /usr/local/apache/htdocs/zabbix/
[root@localhost zabbix-4.0.4]# chown -R apache.apache /usr/local/apache/htdocs/zabbix
//配置apache虚拟主机
[root@localhost ~]# vim /etc/httpd24/httpd.conf
[root@localhost ~]# tail -11 /etc/httpd24/httpd.conf
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/zabbix"
ServerName zabbix.zml.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
<Directory "/usr/local/apache/htdocs/zabbix">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
//设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php
[root@localhost ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf
[root@localhost ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwsrwx. 2 apache apache 81 2月 4 17:57 /usr/local/apache/htdocs/zabbix/conf
//重启apache
[root@localhost ~]# apachectl -t //检测Apache的语法错误
Syntax OK
[root@localhost ~]# apachectl stop
[root@localhost ~]# apachectl start
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
[root@localhost ~]#
4.3.4 安装zabbix web界面
- 修改hosts文件,添加域名与IP的映射
- 在浏览器上访问域名或者IP
- 恢复zabbix/conf目录的权限为755
修改hosts文件
在浏览器上访问IP进行安装:
选择默认
在Database host这里添加数据库的IP地址
恢复zabbix/conf目录的权限为755:
[root@localhost ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf
[root@localhost ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxr-sr-x. 2 apache apache 104 2月 22 16:08 /usr/local/apache/htdocs/zabbix/conf
5. 登录zabbix
zabbix默认登录用户名和密码:
用户名 | 密码 |
---|---|
Admin | zabbix |
6. zabbix客户端配置
//安装依赖包
[root@localhost ~]# yum -y install net-snmp-devel libevent-devel
//下载zabbix
//解压
[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug kernels zabbix-4.0.4.tar.gz
[root@localhost src]# tar -xf zabbix-4.0.4.tar.gz
[root@localhost src]# ls
debug kernels zabbix-4.0.4 zabbix-4.0.4.tar.gz
/创建zabbix用户和组
[root@localhost ~]# groupadd -r zabbix
[root@localhost ~]# useradd -M -r -s /sbin/nologin -g zabbix zabbix
//编译安装zabbix
[root@localhost ~]# cd /usr/src/zabbix-4.0.4
[root@localhost zabbix-4.0.4]# ./configure --enable-agent
[root@localhost zabbix-4.0.4]# make install
//修改客户端配置文件
[root@localhost ~]# cd /usr/local/etc/
[root@localhost etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d
[root@localhost etc]# sed -i '/Server=127.0.0.1/s/127.0.0.1/192.168.233.132/g' zabbix_agentd.conf
[root@localhost etc]# sed -i '/ServerActive=127.0.0.1/s/127.0.0.1/192.168.233.132/g' zabbix_agentd.conf
[root@localhost etc]# sed -i '/Hostname=Zabbix server/s/Zabbix server/agent1/g' zabbix_agentd.conf
//启动服务
[root@localhost ~]# zabbix_agentd
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
7. 解决zabbix服务监控的中文乱码问题
在浏览器上打开zabbix的时候,如果用中文访问,就会出现以下中文乱码的情况
所以,我们要解决中文乱码的问题
- 在windows界面将C:\windows\fonts\简体楷体复制出来
- 把这个字体文件放到/usr/local/apache/htdocs/zabbix/fonts/下,并且设置fonts目录的属主和属组都是apache,让apache用户对simkai.tt有读的权限
[root@localhost ~]# cd /usr/local/apache/htdocs/zabbix/fonts/
[root@localhost fonts]# ls
DejaVuSans.ttf simkai.ttf
[root@localhost fonts]# ll
总用量 12252
-rw-r--r--. 1 apache apache 756072 2月 4 17:57 DejaVuSans.ttf
-rw-r--r--. 1 root apache 11785184 2月 23 10:26 simkai.ttf
- 修改/usr/loacl/apache/htdocs/zabbix/include/下面的defines.inc.php
[root@localhost ~]# cd /usr/local/apache/htdocs/zabbix/include/
[root@localhost include]# ls
actions.inc.php events.inc.php items.inc.php regexp.inc.php
audit.inc.php forms.inc.php js.inc.php schema.inc.php
blocks.inc.php func.inc.php locales.inc.php screens.inc.php
classes gettextwrapper.inc.php maintenances.inc.php services.inc.php
config.inc.php graphs.inc.php maps.inc.php sounds.inc.php
correlation.inc.php hostgroups.inc.php media.inc.php translateDefines.inc.php
db.inc.php hosts.inc.php menu.inc.php triggers.inc.php
debug.inc.php html.inc.php page_footer.php users.inc.php
defines.inc.php httptest.inc.php page_header.php validate.inc.php
discovery.inc.php ident.inc.php perm.inc.php valuemap.inc.php
draw.inc.php images.inc.php profiles.inc.php views
[root@localhost include]# vim defines.inc.php
define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans'); // font file name //把这里的DejaVuSans改成simkai.ttf
define('ZBX_FONT_NAME', 'DejaVuSans'); //把这里的DejaVuSans改成simkai.ttf
8. zabbix主机和主机组的添加
8.1 添加主机组
- 点击右上角的添加主机群组
- 添加一个名叫zabbix_agent的主机组
8.2 添加主机(要被监控的agent)
- 点击主机
- 点击右上角的创建主机,然后点击添加就可以了
9. zabbix模板使用
- 点击主机
- 点击agent1主机,然后在点击模板
- 在链接指示器哪里点击选择,选择Tenmplate OS Linux,然后点击添加和更新
- 点击监控项
- 点击触发器
- 检测zabbix主机的状态可用性
注:这里为绿色,没有问题,如果是红色,则重启服务,若是没有颜色,则实验失败,要关闭防火墙和 selinux。
10. 添加监控项
root@localhost ~]# touch /opt/zml
[root@localhost ~]# cd /opt/
[root@localhost opt]# chown zabbix.zabbix zml
[root@localhost opt]# ll
总用量 0
-rw-r--r--. 1 zabbix zabbix 0 2月 25 19:17 zml
[root@localhost opt]# cd
11. 触发器
测试
[root@localhost ~]# echo "123" >> /opt/zml
12. 监控服务进程
[root@localhost ~]# mkdir /scripts
[root@localhost ~]# cd /scripts/
[root@localhost scripts]# vim process.sh
[root@localhost scripts]# cat process.sh
#!/bin/bash
a=$(ps -ef|egrep -v "grep|$0"|grep $1|wc -l)
if [ $a -eq 0 ];then
echo 1
else
echo 0
fi
[root@localhost scripts]# chmod 755 process.sh
[root@localhost scripts]# cd ..
[root@localhost /]# chown -R zabbix.zabbix scripts/
[root@localhost ~]# sed -i '/# UnsafeUserParameters=0/s/#//g' /usr/local/etc/zabbix_agentd.conf
[root@localhost ~]# sed -i '/ UnsafeUserParameters=0/s/0/1/g' /usr/local/etc/zabbix_agentd.conf
[root@localhost ~]# echo "UserParameter=check_ftp,/scripts/process.sh vsftpd" >> /usr/local/etc/zabbix_agentd.conf
[root@localhost ~]# pkill zabbix
[root@localhost ~]# zabbix_agentd
添加监控项
添加触发器
手动监控
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
[root@localhost ~]# zabbix_get -s 192.168.233.129 -k check_ftp
1
测试
[root@localhost ~]# systemctl stop vsftpd
[root@localhost ~]# systemctl start vsftpd
13. 监控日志
[root@localhost ~]# cd /scripts/
[root@localhost scripts]# ls
log.py process.sh
[root@localhost scripts]# chown zabbix.zabbix log.py
[root@localhost scripts]# ll
总用量 8
-rw-r--r--. 1 zabbix zabbix 1854 2月 25 19:45 log.py
-rwxr-xr-x. 1 zabbix zabbix 102 2月 25 19:32 process.sh
[root@localhost ~]# echo "UserParameter=check_log_apache,python /scripts/log.py /etc/httpd/logs/error_log" >> /usr/local/etc/zabbix_agentd.conf
[root@localhost ~]# pkill zabbix
[root@localhost ~]# zabbix_agentd
[root@localhost ~]# cd /etc/httpd/logs/
[root@localhost logs]# ll -d
drwx------. 2 root root 41 2月 25 19:49 .
[root@localhost logs]# cd ..
[root@localhost httpd]# chmod 755 logs/
[root@localhost httpd]# cd logs/
[root@localhost logs]# ll -d
drwxr-xr-x. 2 root root 41 2月 25 19:49 .
[root@localhost logs]#
添加监控项
添加触发器
手动监控
[root@localhost ~]# zabbix_get -s 192.168.233.129 -k check_log_apache
0
[root@localhost ~]# echo "Error" >> /etc/httpd/logs/error_log
[root@localhost ~]# zabbix_get -s 192.168.233.129 -k check_log_apache
1
14. 邮件警告
- 关闭postfix服务
在Centos/Linux7之前在做邮件警告的时候,需要关掉两个服务,一个是postfix,还有一个是sendmail,而Centos/Linux7只需要关掉一个postfix服务,端口是25
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 32 :::21 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
[root@localhost ~]#systemctl stop postfix
[root@localhost ~]# systemctl disable postfix
Removed symlink /etc/systemd/system/multi-user.target.wants/postfix.service.
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 32 :::21 :::*
LISTEN 0 128 :::22 :::*
- 安装mailx,在Linux7的版本是12.5,而不是旧版本,所以不需要编译安装
[root@localhost ~]# yum -y install mailx
//修改配置文件,在/etc/mail.rc的文件最后添加内容
[root@localhost ~]# vim /etc/mail.rc
[root@localhost ~]# tail -5 /etc/mail.rc
set from=2010187443@qq.com //发件人的地址
set smtp=smtp.qq.com //邮箱服务器的地址
set smtp-auth-user=2010187443@qq.com //发件人邮箱地址
set smtp-auth-password buwoevqikhiybegg //smtp允许第三方登录的授权码,也可以输入邮箱的登录密码
set smtp-auth=login
通过mail命令手动测试发送邮件
[root@localhost ~]# echo "hello"|mail -s "招呼" 3243722021@qq.com
- 在zabbix上配置
点击Adminstration下的Media types ,然后点击Create media type,创建一个名叫mail_scripts的报警媒介
使用哪个用户来这种媒介告警,这里使用Admin用户来使用这个媒介,因为这个用户已经在一个用户组了,所以不需要添加用户组和用户
点击Adminstration下的Users ,然后点击Admin用户
然后在点击Users下面的Media,然后添加
添加动作,点击Configure下面的Actions,然后点击Create action
- 创建脚本,在alertscripts告警目录创建脚本
[root@localhost ~]# mkdir /usr/loacl/etc/alertscripts
[root@localhost ~]# cd /usr/loacl/etc/alertscripts
[root@localhost alertscripts]# vim mail.sh
[root@localhost alertscripts]# cat mail.sh
#!/bin/bash
SENDTO=$1
SUBJECT=$2
MESSAGE=$3
echo $3 |mail -s $2 $1
[root@localhost alertscripts]# chmod 755 mail.sh
[root@localhost alertscripts]# ll
总用量 4
-rwxr-xr-x. 1 zabbix zabbix 67 2月 26 16:25 mail.sh
[root@localhost alertscripts]# cd ..
[root@localhost etc]# chown -R zabbix.zabbix alertscripts/
[root@localhost etc]# ll alertscripts/
总用量 4
-rw-r--r--. 1 zabbix zabbix 67 2月 26 16:25 mail.sh
[root@localhost ~]# cd /usr/local/etc
[root@localhost etc]# [root@localhost etc]# vim zabbix_server.conf
······
# Mandatory: no
# Default:
# AlertScriptsPath=${datadir}/zabbix/alertscripts
AlertScriptsPath=/usr/local/etc/alertscripts
### Option: ExternalScripts
# Full path to location of external scripts.
······
[root@localhost etc]# zabbix_server
[root@localhost etc]# zabbix_agentd
- 手动测试脚本发送邮件
[root@localhost ~]# su - zabbix -s /bin/bash
上一次登录:二 2月 26 16:43:45 CST 2019pts/1 上
su: 警告:无法更改到 /home/zabbix 目录: 没有那个文件或目录
-bash-4.2$ /usr/local/etc/alertscripts/mail.sh 3243722021@qq.com biaotou hello
- 手动触发警告,查收邮件
[root@localhost ~]# systemctl stop vsftpd
15. 监控MySQL主从
- 监测MySQL主从问题
//创建脚本,在scripts创建mysql.sh脚本
[root@localhost scripts]# vim mysql.sh
[root@localhost scripts]# cat mysql.sh
#!/bin/bash
a=$(mysql -e "show slave status\G;" |grep "Slave_IO_Running"|awk -F':' '{print $NF}')
b=$(mysql -e "show slave status\G;" |grep "Slave_SQL_Running:"|awk -F':' '{print $NF}')
if [ $a == Yes -a $b == Yes ];then
echo 0
else
echo 1
fi
[root@localhost ~]# chown -R zabbix.zabbix /scripts/
[root@localhost ~]# chmod -R 775 /scripts/
//修改配置文件
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
[root@localhost ~]# tail -1 /usr/local/etc/zabbix_agentd.conf
UserParameter=check_mysql,/scripts/mysql.sh
//重启服务
[root@localhost ~]# pkill zabbix
[root@localhost ~]# zabbix_agentd
//手动监控
[root@localhost ~]# zabbix_get -s 192.168.233.128 -k check_mysql
0
//停止slave服务
mysql> stop slave;
Query OK, 0 rows affected (0.04 sec)
[root@localhost ~]# zabbix_get -s 192.168.233.128 -k check_mysql
1
- 添加监控项
- 添加触发器
- 手动触发警告,查收邮件
[root@localhost ~]# mysql
- 解决问题
mysql> start slave;
Query OK, 0 rows affected (0.04 sec)
- 监测MySQL延迟
//创建脚本,在scripts创建mysql1.sh脚本
[root@localhost ~]# vim /scripts/mysql1.sh
[root@localhost ~]# cat /scripts/mysql1.sh
#!/bin/bash
a=$(mysql -e "show slave status\G"|grep "Read_Master_Log_Pos"|awk '{print $NF}')
b=$(mysql -e "show slave status\G"|grep "Exec_Master_Log_Pos"|awk '{print $NF}')
c=$[$a-$b]
case $c in
0)
echo 0
;;
*)
echo 1
;;
esac
[root@localhost ~]# chown -R zabbix.zabbix /scripts/
[root@localhost ~]# chmod -R 775 /scripts/
//修改配置文件
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
[root@localhost ~]# tail -1 /usr/local/etc/zabbix_agentd.conf
UserParameter=check_mysql_relay,/scripts/mysql1.sh
//重启服务
[root@localhost ~]# pkill zabbix
[root@localhost ~]# zabbix_agentd
- 添加监控项
- 添加触发器
- 故意修改脚本文件。让其输出值为1