一.自定义监控进程
1.以httpd服务为例,在agent1中安装httpd
132终端
[root@agent1 ~]# yum -y install httpd
Complete!
[root@agent1 ~]# systemctl restart httpd
[root@agent1 ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@agent1 ~]# ps -ef|grep httpd
root 2931 1 0 14:17 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 2932 2931 0 14:17 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 2933 2931 0 14:17 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 2934 2931 0 14:17 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 2935 2931 0 14:17 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 3665 1425 0 14:19 pts/0 00:00:00 grep --color=auto httpd
[root@agent1 ~]# ps -ef | grep httpd | grep -v grep | wc -l
5
[root@agent1 ~]# ps -ef | grep -v grep | grep -c httpd
5
2.新建脚本存放目录
[root@agent1 ~]# cd /etc/zabbix/
[root@agent1 zabbix]# ls
zabbix_agentd.conf zabbix_agentd.d
[root@agent1 zabbix]# mkdir script
[root@agent1 zabbix]# cd script/
[root@agent1 script]# vim check_httpd.sh
#!/bin/bash
count=$(ps -ef | grep -Ev "grep|$0" | grep -c httpd)
if [ $count -eq 0 ];then
echo '1'
else
echo '0'
fi
[root@agent1 script]# chmod +x check_httpd.sh
[root@agent1 script]# chown -R zabbix.zabbix /etc/zabbix/script/
[root@agent1 script]# ll
total 4
-rwxr-xr-x 1 zabbix zabbix 117 Sep 6 14:30 check_httpd.sh
测试脚本--0是httpd服务开启,1为关闭
[root@agent1 script]# ./check_httpd.sh
0
[root@agent1 script]# systemctl stop httpd
[root@agent1 script]# ./check_httpd.sh
1
[root@agent1 script]# systemctl restart httpd
[root@agent1 script]# ./check_httpd.sh
0
3.修改zabbix_agentd.conf文件
[root@agent1 script]# vim /etc/zabbix/zabbix_agentd.conf
UserParameter=loginusers,who | wc -l
UserParameter=check_httpd,/bin/bash /etc/zabbix/script/check_httpd.sh
重启服务
[root@agent1 script]# systemctl restart zabbix-agent.service
4.zabbix server端进行测试脚本
[root@server ~]# zabbix_get -s 192.168.46.132 -k check_httpd
0
5.zabbix web平台配置
?
?
?
6.配置触发器?
?
?
?
?
7.测试–关闭httpd服务,测试告警信息
此时关掉服务查看
[root@agent1 script]# systemctl stop httpd
到163邮箱查看是否接收到警告邮件
?此时启动服务(修复问题)查看
?修复好了之后也会在163邮箱里收到问题已修复的邮件
二.自定义监控日志
下载log.py来协助我们进行测试,以httpd服务为例
1将log.py上传到/etc/zabbix/script/目录下,然后给执行权限,修改所有者和所属组为zabbix
log.py? 作用:检查日志文件中是否有指定的关键字? 第一个参数为日志文件名(必须有,相对路径、绝对路径均可)? 第二个参数为seek position文件的路径(可选项,若不设置则默认为/tmp/logseek文件。相对路径、绝对路径均可)? 第三个参数为搜索关键字,默认为 Error
?
[root@agent1 ~]# cd /etc/zabbix/script/
[root@agent1 script]# ls
check_httpd.sh log.py
[root@agent1 script]# chown zabbix.zabbix log.py
[root@agent1 script]# chmod +x log.py
[root@agent1 script]# ll
total 8
-rwxr-xr-x 1 zabbix zabbix 117 Sep 6 14:30 check_httpd.sh
-rwxr-xr-x 1 zabbix zabbix 1854 Sep 6 15:23 log.py
2.httpd服务的日志文件在/var/log/httpd/目录下,首先我们需要给这个目录设置一个ACL权限,让zabbix用户有权限去访问该目录
[root@agent1 script]# setfacl -m u:zabbix:r-x /var/log/httpd/
3.下载python3来执行log.py脚本
[root@agent1 script]# yum -y install python3
Complete!
4.修改zabbix_agentd.conf文件,并重启服务
[root@agent1 script]# vim /etc/zabbix/zabbix_agentd.conf
UserParameter=loginusers,who | wc -l
UserParameter=check_httpd,/bin/bash /etc/zabbix/script/check_httpd.sh
UserParameter=check_logs[*],/usr/bin/python3 /etc/zabbix/script/log.py $1 $2 $3
重启服务
[root@agent1 script]# systemctl restart zabbix-agent.service
5、测试脚本
0为没有Error日志信息,1为有Error日志信息
[root@agent1 script]# python3 log.py /var/log/httpd/error_log
0
[root@agent1 script]# echo "Error" >> /var/log/httpd/error_log
[root@agent1 script]# python3 log.py /var/log/httpd/error_log
1
[root@agent1 script]# vim /var/log/httpd/error_log
Error(最后一行删掉)
测试完成后将写入的Error内容删除,而且因文件/tmp/logseek属于root账户,在web端写入写不进去,所以删除。
[root@agent1 script]# cd /tmp
[root@agent1 tmp]# ls
ks-script-6beai4br
logseek
systemd-private-1df51c7a13fd4ddbbb04356a0976b812-httpd.service-JcIKKw
vmware-root_895-3979642976
vmware-root_917-4022308724
vmware-root_925-3988621690
vmware-root_931-3988621659
[root@agent1 tmp]# rm -rf logseek
6.配置监控项
?
?7.创建触发器
?
?
?
?
8.测试,echo Error >> /var/log/httpd/error_log?
[root@agent1 tmp]# echo "Error" >> /var/log/httpd/error_log
zabbix网页查看报警信息
?163邮箱查看警告邮件
?恢复操作
[root@agent1 tmp]# vim /var/log/httpd/error_log
Error 删除Error(在最后一行)
网页查看报警信息为不存在
此时163邮箱也会发问题已恢复的邮件
三.Zabbix监控mysql主从
1.部署mysql主从,使用mariadb进行操作
另外再加2台虚拟机,命名分别为master和slave,在server端hosts配置文件里进行添加
[root@server ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.46.129 server.example.com server
192.168.46.132 agent1.example.com agent1
192.168.46.133 master.example.com master
192.168.46.134 slave.example.com slave
2.将server、agent1、master、slave主机的/etc/hosts文件全部设置
为
132终端agent1
[root@agent1 ~]# scp root@192.168.46.129:/etc/hosts /etc/hosts
root@192.168.46.129's password:
hosts 100% 320 257.6KB/s 00:00
[root@agent1 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.46.129 server.example.com server
192.168.46.132 agent1.example.com agent1
192.168.46.133 master.example.com master
192.168.46.134 slave.example.com slave
133终端master
[root@master ~]# scp root@192.168.46.129:/etc/hosts /etc/hosts
The authenticity of host '192.168.46.129 (192.168.46.129)' can't be established.
ECDSA key fingerprint is SHA256:Du+5ve7y+/kK9kBqXL7U3jKuAeyxogDYJ4TrgXtdfM0.
Are you sure you want to continue connecting (yes/no/[fingerprint])? y
Please type 'yes', 'no' or the fingerprint: yes
Warning: Permanently added '192.168.46.129' (ECDSA) to the list of known hosts.
root@192.168.46.129's password:
hosts 100% 320 202.3KB/s 00:00
134终端slave
[root@slave ~]# scp root@192.168.46.129:/etc/hosts /etc/hosts
The authenticity of host '192.168.46.129 (192.168.46.129)' can't be established.
ECDSA key fingerprint is SHA256:Du+5ve7y+/kK9kBqXL7U3jKuAeyxogDYJ4TrgXtdfM0.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.46.129' (ECDSA) to the list of known hosts.
root@192.168.46.129's password:
hosts 100% 320 122.3KB/s 00:00
3.master和slave为centos7的操作系统,将centos7的安装源下载下
来,然后两台主机都安装mariadb mariadb-server
133终端
[root@master yum.repos.d]# rm -rf *
[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2495 100 2495 0 0 12794 0 --:--:-- --:--:-- --:--:-- 12794
[root@master yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@master yum.repos.d]# cd
[root@master ~]# yum -y install mariadb-server mariadb
Complete!
[root@master ~]# systemctl restart mariadb
[root@master ~]# systemctl enable mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
134终端
[root@slave yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2495 100 2495 0 0 14505 0 --:--:-- --:--:-- --:--:-- 14505
[root@slave yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@slave yum.repos.d]# cd
[root@slave ~]# yum -y install mariadb-server mariadb
Complete!
[root@slave ~]# systemctl restart mariadb
[root@slave ~]# systemctl enable mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
4.两台主机都初始化mysql数据库
133终端master
[root@master ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
#########################################################################
134终端slave
[root@slave ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
5.修改数据库配置文件,然后两台主机都重启mariadb服务
133终端master
[root@master ~]# vim /etc/my.cnf.d/mariadb-server.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log_bin=mysql-bin
server_id=20
[root@master ~]# systemctl restart mariadb
134终端slave
[root@slave ~]# vim /etc/my.cnf.d/mariadb-server.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log_bin=mysql-bin
server_id=30
[root@slave ~]# systemctl restart mariadb
6.进入数据库配置主从
133终端master
[root@master ~]# mysql -uroot -predhat
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.28-MariaDB-log MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by "redhat";
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> grant replication slave on *.* to 'user'@'slave' identified by 'redhat';
Query OK, 0 rows affected (0.000 sec)
134终端slave
[root@slave ~]# mysql -uroot -predhat
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.28-MariaDB-log MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant all privileges on *.* to root@'%' identified by "redhat";
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> change master to master_host='master',master_user='user',master_password='redhat';
Query OK, 0 rows affected (0.004 sec)
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> show slave status\G
Slave_IO_Running: Connecting
Slave_SQL_Running: Yes (进来看到这两个值就是连接的OK的)
7.在slave主机中安装zabbix-agent软件包,将slave添加到zabbix web监控平台中,将server主机的zabbix.repo复制过来,然后将yum源中的8改成7,接着安装zabbix-agent(我这边用的8的源)
在133和134终端安装eple源
阿里云的epel源之前就安装好了,所以就省略过程...
[root@slave ~]# cd /etc/yum.repos.d/
[root@slave yum.repos.d]# ls
CentOS-Base.repo epel.repo epel-testing.repo
epel-modular.repo epel-testing-modular.repo
[root@slave yum.repos.d]# scp root@192.168.46.129:/etc/yum.repos.d/zabbix.repo .
root@192.168.46.129's password:
zabbix.repo 100% 386 217.5KB/s 00:00
[root@slave yum.repos.d]# ls
CentOS-Base.repo epel.repo epel-testing.repo
epel-modular.repo epel-testing-modular.repo zabbix.repo
[root@slave yum.repos.d]# yum -y install zabbix-agent
Complete!
8.修改 /etc/zabbix/zabbix_agentd.conf,重启服务
[root@slave yum.repos.d]# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.46.129 修改为129的(服务端)的IP地址
ServerActive=192.168.46.129 修改为129的(服务端)的IP地址
Hostname=slave (修改为自己的主机名)
[root@slave yum.repos.d]# systemctl restart zabbix-agent.service
[root@slave yum.repos.d]# systemctl enable zabbix-agent.service
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-agent.service → /usr/lib/systemd/system/zabbix-agent.service.
关闭防火墙
134终端slave
[root@slave yum.repos.d]# systemctl stop firewalld
[root@slave yum.repos.d]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@slave yum.repos.d]# vim /etc/selinux/config
SELINUX=disabled
[root@slave yum.repos.d]# setenforce 0
[root@slave yum.repos.d]# systemctl restart mariadb
133终端master
[root@master ~]# systemctl stop firewalld
[root@master ~]# systemctl disable firewalld
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@slave yum.repos.d]# setenforce 0
[root@master ~]# systemctl restart mariadb
9.进入zabbix web监控平台,添加主机
?
?
?
?
?10.在slave主机上配置脚本
[root@slave yum.repos.d]# cd /etc/zabbix/
[root@slave zabbix]# mkdir script
[root@slave zabbix]# ls
script zabbix_agentd.conf zabbix_agentd.d
[root@slave zabbix]# cd script/
[root@slave script]# ls
[root@slave script]# vim mysql_status.sh (mysql_status.sh脚本的名称可自定义)
#!/bin/bash
USER="root"
PASSWD="redhat"
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]# chmod +x mysql_status.sh
[root@slave script]# chown -R zabbix.zabbix /etc/zabbix/script/
[root@slave script]# ll
total 4
-rwxr-xr-x. 1 zabbix zabbix 634 Sep 7 14:37 mysql_status.sh
11.编写一个自配置文件,里面指定上面编写的脚本的路径,然后重启服务
[root@slave script]# cd /etc/zabbix/
[root@slave zabbix]# ls
script zabbix_agentd.conf zabbix_agentd.d
[root@slave zabbix]# cd zabbix_agentd.d
[root@slave zabbix_agentd.d]# ls
[root@slave zabbix_agentd.d]# vim userparameter_mysql_slave.conf
UserParameter=mysql.slave[*],/etc/zabbix/script/mysql_slave_status.sh $1
[root@slave zabbix_agentd.d]# systemctl restart zabbix-agent.service
[root@slave zabbix_agentd.d]# chown zabbix.zabbix userparameter_mysql_slave.conf
[root@slave zabbix_agentd.d]# systemctl restart zabbix-agent.service
12.去zabbix server验证状态,使用zabbix_get命令验证,需要先下载zabbix-get软件包
129端口server
[root@server ~]# yum -y install zabbix-get
Complete!
#验证的结果如果是0,为正常,如果为1,则异常
[root@server ~]# zabbix_get -s 192.168.46.134 -k mysql.slave[io]
0
[root@server ~]# zabbix_get -s 192.168.46.134 -k mysql.slave[sql]
0
13.在zabbix web平台配置
新建监控项(两个监控项)
?
?
?
?
?
?
?
?
?
?
?
?
?
模拟故障-测试?
134终端slave
[root@slave script]# mysql -uroot -predhat
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 75
Server version: 10.3.28-MariaDB-log MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> stop slave; (给它停掉 制造问题)
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> show slave status \G;
Slave_IO_Running: No
Slave_SQL_Running: No 此时这里全部显示No
状态发生了变化,去zabbix网页看看触发器有没有触发报警
?
?
?
?
134终端slave
修复问题查看
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> show slave status \G;
Slave_IO_Running: Connecting
Slave_SQL_Running: Yes 此时之前这两行全都是No的,也恢复了正常
接下来在zabbix网页查看报警信息有没有消失
?
?
?
?创建图形
?
?
?
?
?
?
14.zabbix监控主从延迟
1.配置库脚本
134终端slave
[root@slave ~]# cd /etc/zabbix/script/
[root@slave script]# ls
mysql_status.sh
[root@slave script]# vim mysql_delay.sh
#!/bin/bash
delay=$(mysql -uroot -predhat -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 1
fi
[root@slave script]# chmod +x mysql_delay.sh
[root@slave script]# chown zabbix.zabbix mysql_delay.sh
[root@slave script]# ll
total 8
-rwxr-xr-x 1 zabbix zabbix 257 Sep 7 17:26 mysql_delay.sh
-rwxr-xr-x 1 zabbix zabbix 634 Sep 7 16:04 mysql_status.sh
2.配置agentd文件,并重启服务
134终端slave
[root@slave script]# cd ..
[root@slave zabbix]# ls
script zabbix_agentd.conf zabbix_agentd.d
[root@slave zabbix]# cd zabbix_agentd.d/
[root@slave zabbix_agentd.d]# ls
userparameter_mysql_slave.conf
[root@slave zabbix_agentd.d]# vim userparameter_mysql_slave.conf
UserParameter=mysql.slave[*],/etc/zabbix/script/mysql_status.sh $1
UserParameter=check_mysql_delay,/bin/bash /etc/zabbix/script/mysql_delay.sh
[root@slave zabbix_agentd.d]# systemctl restart zabbix-agent.service
3.zabbix server主机进行脚本测试
129终端server
[root@server zabbix]# zabbix_get -s 192.168.46.134 -k check_mysql_delay
0
值为0:正常
测试mysql_delay.sh脚本
[root@slave zabbix_agentd.d]# cd /etc/zabbix/script/
[root@slave script]# ./mysql_delay.sh
0
4.在zabbix web平台操作
添加监控项
?
?
?
?
?
?
?
?
?四.创建主机组
1、创建主机–以master主机为例
master:
[root@master yum.repos.d]# scp root@192.168.46.134:/etc/yum.repos.d/* .
The authenticity of host '192.168.46.134 (192.168.46.134)' can't be established.
ECDSA key fingerprint is SHA256:oraa0iv66USiDvLhe1ll4kBvl9TAe3nneA4BuY1Yfv0.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.46.134' (ECDSA) to the list of known hosts.
root@192.168.46.134's password:
CentOS-Base.repo 100% 1653 1.2MB/s 00:00
epel-modular.repo 100% 1389 2.9MB/s 00:00
epel.repo 100% 1326 1.9MB/s 00:00
epel-testing-modular.repo 100% 1488 2.7MB/s 00:00
epel-testing.repo 100% 1425 3.1MB/s 00:00
zabbix.repo 100% 386 704.8KB/s 00:00
[root@master yum.repos.d]# ls
CentOS-Base.repo epel.repo epel-testing.repo
epel-modular.repo epel-testing-modular.repo zabbix.repo
[root@master yum.repos.d]# yum -y install zabbix-agent
Complete!
[root@master yum.repos.d]# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.46.129 改成129服务端IP地址
ServerActive=192.168.46.129 改成129服务端IP地址
Hostname=master 改成自己的主机名
[root@master yum.repos.d]# systemctl restart zabbix-agent.service
[root@master yum.repos.d]# systemctl enable zabbix-agent.service
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-agent.service → /usr/lib/systemd/system/zabbix-agent.service.
2.在zabbix web平台创建主机组
?
?3.创建主机
?
?
?????????
?
?五.创建用户组
?
?
?
六.创建用户?
?
?
?
?
?
?
?
用Admin用户登录zabbix web平台,修改lpz用户属性为管理员(从用户改为超级管理员)
?
?
?
?
|