赞
踩
目录
自动发现,自动注册,被动模式,主动模式(对agent2来说)
在软件系统的高可靠性(也称为可用性,英文描述为HA,High Available)里有个衡量其可靠性的标准——X个9,这个X是代表数字3~5。X个9表示在软件系统1年时间的使用过程中,系统可以正常使用时间与总时间(1年)之比,我们通过下面的计算来感受下X个9在不同级别的可靠性差异。
1个9:(1-90%)*365=36.5天,表示该软件系统在连续运行1年时间里最多可能的业务中断时间是36.5天 2个9:(1-99%)*365=3.65天 , 表示该软件系统在连续运行1年时间里最多可能的业务中断时间是3.65天 3个9:(1-99.9%)*365*24=8.76小时,表示该软件系统在连续运行1年时间里最多可能的业务中断时间是8.76小时。 4个9:(1-99.99%)*365*24=0.876小时=52.6分钟,表示该软件系统在连续运行1年时间里最多可能的业务中断时间是52.6分钟。 5个9:(1-99.999%)*365*24*60=5.26分钟,表示该软件系统在连续运行1年时间里最多可能的业务中断时间是5.26分钟。 6个9:(1-99.9999%)*365*24*60*60=31秒, 示该软件系统在连续运行1年时间里最多可能的业务中断时间是31秒
监控一切需要监控的东西,只要能够想到,能够用命令实现的都能用来监控
一、zabbix简介
1、zabbix是一个基于WEB界面的,并提供分布式系统监视以及网络监视功能的企业级的开源解决方案。 zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供柔软的通知机制以让运维人员能够快速定位。
2、zabbix通过C/S模型来收集数据,通过B/S模型模式在web端展示和进行配置。
被监控端:主机设备通过安装agent收集数据并发送给server端,网络设备通过SNMP收集数据并发送给server端。
server端:通过收集SNMP和agent发送来的数据,将数据写入到后台数据库中(例如:mysql,oracle),在通过web展示出来。
3、运行环境
zabbix server 需要运行在LAMP或者是LNMP的环境下;
agent可以部署在目前常见的OS中,例如linux,windows,HPUX,Solaris,Sun;
SNMP可以支持常见的网络设备。
官方给出了zabbix根据不同环境与平台所需要的硬件需求:
二、zabbix构成
zabbix主要由以下5个组件构成:
1、Server
zabbix server是zabbix的核心组件,server内部存储了所有的配置信息、统计信息和操作信息。zabbix agent会向zabbix server报告可用性、完整性及其他统计信息。
2、web页面
web页面也是zabbix的一部分,通常和zabbix server位于一台物理设备上,但是在特殊情况下也可以分开配置。web页面主要提供了直观的监控信息,以方便运维人员监控管理。
3、数据库
zabbix数据库内存储了配置信息、统计信息等zabbix的相关内容。
4、proxy
zabbix proxy可以根据具体生产环境进行采用或者放弃。如果使用了zabbix proxy,则其会替代zabbix server采集数据信息,可以很好的分担zabbix server的负载。zabbix proxy通常运用与架构过大、zabbix server负载过重,或者是企业设备跨机房、跨网段、zabbix server无法与zabbix agent直接通信的场景。
5、Agent
zabbix agent通常部署在被监控目标上,用于主动监控本地资源和应用程序,并将监控的数据发送给zabbix server。
三、zabbix监控对象
zabbix支持监控各种系统平台,包括Linux和Windows等主流操作系统,也可以借助SNMP或者是SSH协议监控路由交换设备。
zabbix如果部署在服务器上,可以监控其CPU、内存、网络性能等硬件参数,也可以监控具体的服务或者应用程序、服务运行情况及性能。
硬件监控:Zabbix IPMI Interface ,通过IPMI接口进行监控,我们可以通过标准的IPMI硬件接口,监控被监控对象的物理特征,比如电压、温度、风扇状态、电源状态等。
系统监控:Zabbix Agent Interface ,通过专用的代理程序进行监控,与常见的master/agent模型类似,如果被监控对象支持对应的agent,推荐首选这种方式。
Java监控:Zabbix JMX Interface ,通过JMX进行监控,JMX(java management extensions,即java管理扩展),监控JVM虚拟机时,使用这种方法是非常不错的选择。
网络设备监控:Zabbix SNMP Interface ,通过SNMP协议与被监控对象进行通信,SNMP协议的全称为simple network management protocol,被译为简单网络管理协议,通常来说,我们无法在路由器、交换机这种硬件上安装agent,但是这些硬件都支持SNMP协议。
应用服务监控:Zabbix Agent UserParameter
MySQL数据库监控:percona-monitoring-plulgins
URL监控:Zabbix Web 监控
四、zabbix常用术语
zabbix的学习需要掌握一些zabbix的常用术语,zabbix常用术语列举如下:
1、主机(host)
要监控的设备,可以由IP或者是主机名(必须可解析)指定。
2、主机组(host group)
主机的逻辑容器,包含主机和模板,主机组通常在给用户或者是用户组指派监控权限时使用。
3、监控项(item)
一个特定监控指标的相关数据,比如内存的大小、CPU的使用率,甚至是服务的运行状态等等。监控项数据来源于被监控对象,并且每个监控项都由一个key来标识。
4、触发器(trigger)
一个表达式,用于评估监控项的值是否在合理的范围内。当接收的值超出触发器的规定时,就被认为是故障,如果超出后再次符合,就被认为是正常。
5、事件(event)
触发器触发的一个特定事件,或者是zabbix定义的一个自动上线注册主机的事件。
6、动作(action)
指根据配置,zabbix对于触发器触发的特定事件进行处理的具体措施,如执行某个脚本,或者是向管理员邮箱发送邮件等等。
7、报警升级(escalation)
发送警报或者是执行远程命令的自定义方案。
8、媒介(media)
发送通知(告警)的手段,如微信、邮件、钉钉等等。
9、通知(notification)
通过指定的媒介,向用户发送的有关事件的信息。
10、远程命令(remote command)
指运维人员提前写好的命令,可以让被监控主机在触发事件后执行。
11、模板(template)
用于快速定义被监控主机的预设条目集合,通常包括了监控项、触发器、应用等,模板可以直接链接至某个主机。
12、应用(application)
一组监控项的集合。
13、web场景(web scennario)
用于检测web站点可用性的一个或多个HTTP请求。
14、前端(frontend)
zabbix的web接口
安装nginx1.22
#检查软件安装情况
[root@zabbix-proxy ~]# rpm -qa|grep -e mysqld -e mariadb -e php -e nginx -e zabbix
rpm -e `rpm -qa|grep nginx` --nodeps
rm -f /etc/yum.repos.d/*
[root@m03 ~]# cat >/etc/yum.repos.d/nginx.repo<<'EOF' #EOF加单引号可以让$releasever/$basearch/保持不变
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF
[root@m03 ~]# yum install nginx --enablerepo=nginx-stable -y
[root@m03 ~]# mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
[root@m03 ~]# cat >/etc/nginx/conf.d/zbx.oldboylinux.cn.conf<<'EOF' #动态请求转发php的配置
server {
server_name localhost;
listen 80;
root /data/blog;
index index.php index.html;
location ~ \.php$ {
#root /data/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
EOF
[root@m03 ~]# nginx -t
[root@m03 ~]# systemctl start nginx&&systemctl enable nginx
安装php7.2
rpm -e `rpm -qa|grep webtatic` --nodeps
rpm -e `rpm -qa|grep php` --nodeps
curl -s -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
##配置安装源
yum install epel-release -y #此源可以下载webtatic源的rpm包
wget https://mirror.webtatic.com/yum/el7/webtatic-release.rpm --no-check-certificate #下载webtatic-release.rpm包
rpm -Uvh webtatic-release.rpm #安装源-webtatic.repo,webtatic源可以下载新的php软件包
yum install php72w-cli php72w-fpm php72w-gd php72w-mbstring php72w-bcmath php72w-xml php72w-ldap php72w-mysqlnd -y
###rpm -qa |egrep 'nginx|php72w'
###php配置 修改php用户和准备php会话保持目录
[root@m03 ~]# sed -nr '/^(user|group)/p' /etc/php-fpm.d/www.conf #查看配置
user = apache
group = apache
[root@m03 ~]# sed -ri '/^(user|group)/s#apache#nginx#g' /etc/php-fpm.d/www.conf #r选项使用扩展正则表达式
[root@m03 ~]# egrep '^(user|group)' /etc/php-fpm.d/www.conf #egrep=grep -E可以使用扩展正则表达式
user = nginx
group = nginx
[root@m03 ~]# grep 'var/lib/php/session' /etc/php-fpm.d/www.conf
php_value[session.save_path] = /var/lib/php/session
[root@m03 ~]# mkdir -p /var/lib/php/session
[root@m03 ~]# chown nginx.nginx /var/lib/php/session
[root@m03 ~]# php-fpm -t
[19-Oct-2022 05:24:01] NOTICE: configuration file /etc/php-fpm.conf test is successful
[root@oldboy ~]# systemctl start php-fpm.service&&systemctl enable php-fpm.service
[root@oldboy ~]# mkdir /data/blog -p
[root@oldboy ~]# cat>/data/blog/phpinfo.php<<EOF ##测试转发
<?php
phpinfo();
?>
EOF
[root@oldboy ~]# chown -R nginx. /data/blog/
- 安装nginx与php的脚本 #脚本内内联重定向需要对$进行转义,否则重定向的是变量的值,非变量本身.或者'EOF'
- rpm -e `rpm -qa|grep nginx` --nodeps
- rm -f /etc/yum.repos.d/*
- cat>/etc/yum.repos.d/nginx.repo<<EOF
- [nginx-stable]
- name=nginx stable repo
- baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
- gpgcheck=1
- enabled=0
- gpgkey=https://nginx.org/keys/nginx_signing.key
- module_hotfixes=true
- EOF
- yum install nginx --enablerepo=nginx-stable -y
- mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
- cat>/etc/nginx/conf.d/zbx.oldboylinux.cn.conf<<EOF
- server {
- server_name localhost;
- listen 80;
- root /data/blog;
- index index.php index.html;
- location ~ \.php$ {
- #root /data/blog;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
- include fastcgi_params;
- }
- }
- EOF
- nginx -t
- systemctl start nginx&&systemctl enable nginx
-
- rpm -e `rpm -qa|grep webtatic` --nodeps
- rpm -e `rpm -qa|grep php` --nodeps
- curl -s -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
- curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
- yum install epel-release -y
- wget https://mirror.webtatic.com/yum/el7/webtatic-release.rpm --no-check-certificate
- rpm -Uvh webtatic-release.rpm
- yum install php72w-cli php72w-fpm php72w-gd php72w-mbstring php72w-bcmath php72w-xml php72w-ldap php72w-mysqlnd -y
- sed -ri '/^(user|group)/s#apache#nginx#g' /etc/php-fpm.d/www.conf
- egrep '^(user|group)' /etc/php-fpm.d/www.conf
- grep 'var/lib/php/session' /etc/php-fpm.d/www.conf
- mkdir -p /var/lib/php/session
- chown nginx.nginx /var/lib/php/session
- php-fpm -t
- systemctl start php-fpm.service&&systemctl enable php-fpm.service
- mkdir /data/blog -p
- cat>/data/blog/phpinfo.php<<EOF
- <?php
- phpinfo();
- ?>
- EOF
- chown -R nginx. /data/blog/
-
- #EPEL到底是什么,为何经常要安装epel-release软件包
- EPEL (Extra Packages for Enterprise Linux)是基于Fedora的一个项目,为“红帽系”的操作系统提供额
- 外的软件包,适用于RHEL、CentOS和Scientific Linux.
-
- 我们在Centos下使用yum安装时往往找不到rpm的情况,官方的rpm repository提供的rpm包也不够丰富,很多
- 时候需要自己编译很痛苦,而EPEL恰恰可以解决这两方面的问题。EPEL的全称叫 Extra Packages for
- Enterprise Linux 。EPEL是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux
- 等提供高质量软件包的项目。装上了 EPEL之后,就相当于添加了一个第三方源。
安装数据库 ##安装mariadb且使用安全策略
[root@m03 ~]# rpm -e `rpm -qa|grep mysql` --nodeps&&rm -rf /var/lib/mysql/
[root@m03 ~]# yum install -y mariadb-server
[root@m03 ~]# systemctl start mariadb.service&&systemctl enable mariadb
[root@localhost ~]# 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] y
... Success!
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!
#创建zabbix数据库与登录账号
[root@m03 ~]# mysql -uroot -p<<EOF
create database zabbix charset utf8 collate utf8_bin;
grant all on zabbix.* to 'zabbix'@'localhost' identified by '1' ;
EOF
编写数据库连接测试文件:
[root@localhost blog]# cat >/data/blog/mysqli.php<<'EOF'
<?php
//$link_id=mysqli_connect('主机名','用户','密码');
$link_id=mysqli_connect('localhost','zabbix','1') or
mysqli_error();
if($link_id){
echo "mysql successful by oldboy !";
}else{
echo mysqli_error();
}
//这是php单行注释
?>
EOF
#安装zabbix yum源
来源于:清华大学开源软件镜像站 | Tsinghua Open Source Mirror
#zabbix-release.....rpm zabbix yum源的配置文件
[root@localhost yum.repos.d]# ls /etc/yum.repos.d/
CentOS-Base.repo epel.repo nginx.repo webtatic-archive.repo webtatic.repo webtatic-testing.repo
[root@localhost yum.repos.d]# rpm -Uvh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
[root@localhost yum.repos.d]# ls /etc/yum.repos.d/
CentOS-Base.repo epel.repo nginx.repo webtatic-archive.repo webtatic.repo webtatic-testing.repo zabbix.repo
[root@localhost yum.repos.d]# sed -i 's#http://repo.zabbix.com#https://mirrors.tuna.tsinghua.edu.cn/zabbix#g' /etc/yum.repos.d/zabbix.repo #国外源替换为清华源
# 安装 zabbix-server
[root@m03 ~]# yum install -y zabbix-server-mysql zabbix-agent2 #安装server与agent2包
# zabbix 数据库导入数据
[root@m03 ~]# zcat /usr/share/doc/zabbix-server-mysql-5.0.28/create.sql.gz|mysql -uzabbix -p1 zabbix
# zabbix 服务端 配置连接数据库
[root@m03 ~]# vim /etc/zabbix/zabbix_server.conf #修改
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=1
[root@m03 ~]# grep -n '^DB' /etc/zabbix/zabbix_server.conf
92:DBHost=localhost
101:DBName=zabbix
117:DBUser=zabbix
126:DBPassword=1
#修改后 zabbix 服务端开启的功能 (不用修改)
[root@m03 ~]# grep '^[a-Z]' /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=1
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
#启动 zabbix-server
[root@m03 ~]# systemctl start zabbix-server.service&&systemctl enable zabbix-server.service
[root@m03 ~]# [root@m03 ~]# ss -lntup |grep zabbix
zabbix前端页面准备
- ##现有源epel安装的zabbix-web为4.0版本,无法使用
- [root@localhost zabbix]# yum list|grep zabbix
- fping.x86_64 3.16-1.el7 @zabbix-non-supported
- zabbix-agent2.x86_64 5.0.28-1.el7 @zabbix
- zabbix-release.noarch 5.0-1.el7 installed
- zabbix-server-mysql.x86_64 5.0.28-1.el7 @zabbix
- zabbix40.x86_64 4.0.39-1.el7 @epel
- zabbix40-web.noarch 4.0.39-1.el7 @epel
- zabbix40-web-mysql.noarch 4.0.39-1.el7 @epel
- iksemel.x86_64 1.4-2.el7.centos zabbix-non-supported
- iksemel-devel.x86_64 1.4-2.el7.centos zabbix-non-supported
- iksemel-utils.x86_64 1.4-2.el7.centos zabbix-non-supported
- pcp-export-pcp2zabbix.x86_64 4.3.2-13.el7_9 updates
- pcp-export-zabbix-agent.x86_64 4.3.2-13.el7_9 updates
- python-pyzabbix.noarch 0.7.3-2.el7 epel
- python2-zabbix-api-erigones.noarch 1.2.4-3.el7 epel
- python36-zabbix-api-erigones.noarch 1.2.4-3.el7 epel
- uwsgi-stats-pusher-zabbix.x86_64 2.0.18-8.el7 epel
- zabbix-agent.x86_64 5.0.28-1.el7 zabbix
- zabbix-get.x86_64 5.0.28-1.el7 zabbix
- zabbix-java-gateway.x86_64 5.0.28-1.el7 zabbix
- zabbix-js.x86_64 5.0.28-1.el7 zabbix
- zabbix-proxy-mysql.x86_64 5.0.28-1.el7 zabbix
- zabbix-proxy-pgsql.x86_64 5.0.28-1.el7 zabbix
- zabbix-proxy-sqlite3.x86_64 5.0.28-1.el7 zabbix
- zabbix-sender.x86_64 5.0.28-1.el7 zabbix
- zabbix-server-pgsql.x86_64 5.0.28-1.el7 zabbix
- zabbix40-agent.x86_64 4.0.39-1.el7 epel
- zabbix40-dbfiles-mysql.noarch 4.0.39-1.el7 epel
- zabbix40-dbfiles-pgsql.noarch 4.0.39-1.el7 epel
- zabbix40-dbfiles-sqlite3.noarch 4.0.39-1.el7 epel
- zabbix40-proxy.noarch 4.0.39-1.el7 epel
- zabbix40-proxy-mysql.x86_64 4.0.39-1.el7 epel
- zabbix40-proxy-pgsql.x86_64 4.0.39-1.el7 epel
- zabbix40-proxy-sqlite3.x86_64 4.0.39-1.el7 epel
- zabbix40-selinux.noarch 4.0.39-1.el7 epel
- zabbix40-server.noarch 4.0.39-1.el7 epel
- zabbix40-server-mysql.x86_64 4.0.39-1.el7 epel
- zabbix40-server-pgsql.x86_64 4.0.39-1.el7 epel
- zabbix40-web-pgsql.noarch 4.0.39-1.el7 epel
- zabbix50.x86_64 5.0.21-1.el7 epel
- zabbix50-agent.x86_64 5.0.21-1.el7 epel
- zabbix50-dbfiles-mysql.noarch 5.0.21-1.el7 epel
- zabbix50-dbfiles-pgsql.noarch 5.0.21-1.el7 epel
- zabbix50-dbfiles-sqlite3.noarch 5.0.21-1.el7 epel
- zabbix50-proxy.noarch 5.0.21-1.el7 epel
- zabbix50-proxy-mysql.x86_64 5.0.21-1.el7 epel
- zabbix50-proxy-pgsql.x86_64 5.0.21-1.el7 epel
- zabbix50-proxy-sqlite3.x86_64 5.0.21-1.el7 epel
- zabbix50-selinux.noarch 5.0.21-1.el7 epel
- zabbix50-server.noarch 5.0.21-1.el7 epel
- zabbix50-server-mysql.x86_64 5.0.21-1.el7 epel
- zabbix50-server-pgsql.x86_64 5.0.21-1.el7 epel
#web页面安装如下
[root@localhost ~]# rpm -Uvh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/frontend/zabbix-web-5.0.0-1.el7.noarch.rpm
Retrieving https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/frontend/zabbix-web-5.0.0-1.el7.noarch.rpm
error: Failed dependencies:
dejavu-sans-fonts is needed by zabbix-web-5.0.0-1.el7.noarch #需要先安装字体
[root@localhost ~]# yum install dejavu-sans-fonts -y
[root@localhost ~]# rpm -Uvh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/frontend/zabbix-web-5.0.0-1.el7.noarch.rpm
Retrieving https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/frontend/zabbix-web-5.0.0-1.el7.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-web-5.0.0-1.el7 ################################# [100%]
[root@localhost ~]# rpm -ql zabbix-web-5.0.0-1.el7.noarch.rpm
package zabbix-web-5.0.0-1.el7.noarch.rpm is not installed
[root@localhost ~]# rpm -qa|grep zabbix-web
zabbix-web-5.0.0-1.el7.noarch
[root@localhost ~]# rpm -ql zabbix-web-5.0.0-1.el7.noarch#软件包和安装软件的rpm包是二个概念
/usr/share/zabbix/report2.php
/usr/share/zabbix/report4.php
/usr/share/zabbix/robots.txt
.............................................
[root@localhost ~]# cp -r /usr/share/zabbix/ /data/blog/ #zabbix前端页面
安装zabbix(zabbix 前端页面连接数据库与zabbix-server)
#php需要的配置
Minimum required size of PHP post is 16M (configuration option "post_max_size").
Minimum required limit on execution time of PHP scripts is 300 (configuration
option "max_execution_time").
Minimum required limit on input parse time for PHP scripts is 300 (configuration
option "max_input_time").
Time zone for PHP is not set (configuration parameter "date.timezone").
post_max_size 16M
max_execution_time 300
max_input_time 300
date.timezone
[root@m03 ~]# egrep -n '^(max_|date.timezone|post_max)' /etc/php.ini #最后的配置
368:max_execution_time = 300
378:max_input_time = 600
656:post_max_size = 80M
802:max_file_uploads = 20
877:date.timezone = Asia/Shanghai
[root@m03 ~]# systemctl reload php-fpm.service
###########################php databases support报错的解决办法###################
#安装依赖问题,网上很多解决办法是:
yum install -y php-mysql.x86_64
但是我的服务器会报(每台机子配置不同会有差异):
Error: php72w-common conflicts with php-common-5.4.16-48.el7.x86_64
这是因为之前 yum php72w_x86_64 安装的。所以后面这样装就会报错了。
必须用:
yum install -y php72w-mysql
安装成功后重启php和nginx服务即可。
systemctl restart nginx php-fpm
############################################################################
web连接数据库
zabbix页面连接 zabbix服务端
#web端添加zabbix-server主机
温馨提示:主机名称部分要填写客户端主机名或ip,如果是主机名主机名要能解析
此时ZBX为红色,利用agent来监控zabbix-server主机,即运行zabbix-agent2服务,此后变成绿色
[root@zabbix-server ~]# systemctl enable --now zabbix-agent2.service
[root@zabbix-server ~]# grep '^[a-Z]' /etc/zabbix/zabbix_agent2.conf
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=zabbix-server
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
[root@zabbix-server ~]# systemctl list-unit-files|grep zabbix #zabbix-server运行的服务
zabbix-agent2.service enabled
zabbix-server.service enabled
#############################################################################
需要运行zabbix-agent2后问题解决,服务端对本机的监控也是使用的agent2
[root@localhost web]# systemctl start zabbix-agent2.service
#############################################################################
- 重置环境:
- # rpm -qa|grep -E "php|nginx|mysql|mariadb|httpd"
- # rpm -qa|grep -E "php|nginx|mysql|mariadb|httpd"|xargs
- # rpm -qa|grep -E "php|nginx|mysql|mariadb|httpd"|xargs rpm -e --nodeps
- # (find / -user mysql;find / -name mysql)|xargs rm -rf
- # (find / -user apache;find / -name apache)|xargs rm -rf
- # (find / -user php;find / -name php)|xargs rm -rf
- # (find / -name nginx;find / -user nginx)|xargs rm -rf
-
- 卸载zabbix软件
- # rpm -qa |grep zabbix
- # rpm -qa |grep zabbix|xargs
- # rpm -qa |grep zabbix|xargs rpm -e --nodeps
- # (find / -user zabbix;find / -name zabbix)|xargs rm -rf
-
- 关闭Selinux
- # setenforce 0 #临时关闭
- # sed -i '7s#enforcing#disabled#g' /etc/selinux/config #永久关闭,reboot生效
- # getenforce
- Disabled
-
- 关闭防火墙
- # iptables -F
- # systemctl stop firewalld;systemctl stop iptables # systemctl disable --now firewalld;systemctl disable --now iptables
-
- 安装配置nginx
- # cp -r /etc/yum.repos.d/ /etc/yum.repos.d.bak/
- # rm -rf /etc/yum.repos.d/*
- # cat >/etc/yum.repos.d/nginx.repo<<'EOF' #EOF加单引号可以让$releasever/$basearch/保持不变
- [nginx-stable]
- name=nginx stable repo
- baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
- gpgcheck=1
- enabled=0
- gpgkey=https://nginx.org/keys/nginx_signing.key
- module_hotfixes=true
- EOF
- # yum install nginx --enablerepo=nginx-stable -y
- # mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
- # cat >/etc/nginx/conf.d/zbx.oldboylinux.cn.conf<<'EOF' #动态请求转发php的配置
- server {
- server_name localhost;
- listen 80;
- root /data/blog;
- index index.php index.html;
-
- location ~ \.php$ {
- #root /data/blog;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi_params;
- }
- }
- EOF
- # nginx -t
- # systemctl start nginx&&systemctl enable nginx # systemctl enable --now nginx
-
- #############nginx的配置文件
- # rpm -qf `which nginx`
- nginx-1.26.1-2.el7.ngx.x86_64
- # rpm -qc nginx-1.26.1-2.el7.ngx.x86_64
- /etc/logrotate.d/nginx
- /etc/nginx/conf.d/default.conf
- /etc/nginx/fastcgi_params
- /etc/nginx/mime.types
- /etc/nginx/nginx.conf
- /etc/nginx/scgi_params
- /etc/nginx/uwsgi_params
- # grep -Ev '#|^$' /etc/nginx/conf.d/default.conf
- server {
- listen 80;
- server_name localhost;
- location / {
- root /usr/share/nginx/html;
- index index.html index.htm;
- }
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root /usr/share/nginx/html;
- }
- }
-
- 配置基础yum源
- # curl -s -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo #下载源Centos-7.repo
- # curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo #下载源epel-7.repo
- # yum clean all;yum makecache #一定要执行
-
- 安装配置php7.2
- rpm -e `rpm -qa|grep webtatic` --nodeps
- ###配置安装源
- # yum install epel-release -y #此源可以下载webtatic源的rpm包
- # rpm -ql epel-release #epel-release软件包安装了源epel-testing.repo、epel.repo
- /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
- /etc/yum.repos.d/epel-testing.repo
- /etc/yum.repos.d/epel.repo
- /usr/lib/systemd/system-preset/90-epel.preset
- /usr/share/doc/epel-release-7
- /usr/share/doc/epel-release-7/GPL
- # wget https://mirror.webtatic.com/yum/el7/webtatic-release.rpm --no-check-certificate #下载webtatic-release.rpm包
- # rpm -Uvh webtatic-release.rpm #安装源-webtatic.repo,webtatic源可以下载新的php软件包。webtatic-release软件包依赖于epel-release
- # yum install php72w-cli php72w-fpm php72w-gd php72w-mbstring php72w-bcmath php72w-xml php72w-ldap php72w-mysqlnd -y
- # rpm -qa |egrep 'nginx|php72w'
- php72w-common-7.2.34-1.w7.x86_64
- php72w-xml-7.2.34-1.w7.x86_64
- php72w-fpm-7.2.34-1.w7.x86_64
- php72w-mysqlnd-7.2.34-1.w7.x86_64
- php72w-cli-7.2.34-1.w7.x86_64
- nginx-1.26.1-2.el7.ngx.x86_64
- php72w-pdo-7.2.34-1.w7.x86_64
- php72w-ldap-7.2.34-1.w7.x86_64
- php72w-gd-7.2.34-1.w7.x86_64
- php72w-bcmath-7.2.34-1.w7.x86_64
- php72w-mbstring-7.2.34-1.w7.x86_64
- ###php配置 修改php用户和准备php会话保持目录
- # sed -nr '/^(user|group)/p' /etc/php-fpm.d/www.conf #查看配置
- user = apache
- group = apache
- # sed -ri '/^(user|group)/s#apache#nginx#g' /etc/php-fpm.d/www.conf #r选项使用扩展正则表达式
- # egrep '^(user|group)' /etc/php-fpm.d/www.conf #egrep=grep -E可以使用扩展正则表达式
- user = nginx
- group = nginx
- # grep 'var/lib/php/session' /etc/php-fpm.d/www.conf
- php_value[session.save_path] = /var/lib/php/session
- # mkdir -p /var/lib/php/session
- # chown nginx.nginx /var/lib/php/session
- # php-fpm -t
- [19-Oct-2022 05:24:01] NOTICE: configuration file /etc/php-fpm.conf test is successful
- # systemctl start php-fpm.service&&systemctl enable php-fpm.service # systemctl enable --now php-fpm.service
- # mkdir /data/blog -p
- # cat>/data/blog/phpinfo.php<<EOF #测试转发
- <?php
- phpinfo();
- ?>
- EOF
- # chown -R nginx. /data/blog/
-
- 安装数据库
- # yum install -y mariadb-server
- # systemctl start mariadb.service&&systemctl enable mariadb # systemctl enable --now mariadb
- # mysql_secure_installation #数据库初始化
- # mysql -uroot -pxxxxxx -e 'select user,host from mysql.user;'
- +------+-----------+
- | user | host |
- +------+-----------+
- | root | 127.0.0.1 |
- | root | ::1 |
- | root | localhost |
- +------+-----------+
- # mysql -uroot -pxxxxxx<<EOF
- create database zabbix charset utf8 collate utf8_bin;
- grant all on zabbix.* to 'zabbix'@'localhost' identified by '1' ;
- EOF
- # mysql zabbix -uzabbix -p1 -e 'show databases;'
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | zabbix |
- +--------------------+
- # cat >/data/blog/mysqli.php<<'EOF'
- <?php
- //$link_id=mysqli_connect('主机名','用户','密码');
- $link_id=mysqli_connect('localhost','zabbix','1') or
- mysqli_error();
- if($link_id){
- echo "mysql successful by oldboy !";
- }else{
- echo mysqli_error();
- }
- //这是php单行注释
- ?>
- EOF
-
- 安装zabbix
- 1.安装zabbix源 清华源地址:https://mirror.tuna.tsinghua.edu.cn/
- # uname -a #el*:表示发行商的版本,el7表示这个软件包是在rhel7.x/centos7.x下使用
- Linux ansible-server 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
- # rpm -Uvh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
- # ls /etc/yum.repos.d
- CentOS-Base.repo epel.repo.rpmnew nginx.repo webtatic-release.rpm webtatic-testing.repo
- epel.repo epel-testing.repo webtatic-archive.repo webtatic.repo zabbix.repo
- # sed -i 's#http://repo.zabbix.com#https://mirrors.tuna.tsinghua.edu.cn/zabbix#g' /etc/yum.repos.d/zabbix.repo #国外源替换为清华源
- 2.安装zabbix-server
- # yum install -y zabbix-server-mysql
- # zcat /usr/share/doc/zabbix-server-mysql-5.0.42/create.sql.gz|mysql -uzabbix -p1 zabbix #zabbix数据库导入数据
- # sed -i.bak '/DBPassword=/a\DBPassword=1' /etc/zabbix/zabbix_server.conf #配置连接zabbix数据库
- # grep 'DBPassword=' /etc/zabbix/zabbix_server.conf
- # DBPassword=
- DBPassword=1
- # systemctl enable --now zabbix-server.service
- Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
- # systemctl status zabbix-server.service
- ● zabbix-server.service - Zabbix Server
- Loaded: loaded (/usr/lib/systemd/system/zabbix-server.service; enabled; vendor preset: disabled)
- Active: active (running) since Fri 2024-05-31 11:34:56 CST; 5s ago
- Process: 24261 ExecStart=/usr/sbin/zabbix_server -c $CONFFILE (code=exited, status=0/SUCCESS)
- Main PID: 24263 (zabbix_server)
- CGroup: /system.slice/zabbix-server.service
- # systemctl list-unit-files|grep zabbix
- zabbix-server.service enabled
- 3.zabbix前端页面准备
- # rpm -Uvh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/frontend/zabbix-web-5.0.42-1.el7.noarch.rpm
- # cp -R /usr/share/zabbix/ /data/blog/
- # egrep -n '^(max_|date.timezone|post_max)' /etc/php.ini #修改php如下参数,最后的配置
- 368:max_execution_time = 300
- 378:max_input_time = 600
- 656:post_max_size = 80M
- 802:max_file_uploads = 20
- 877:date.timezone = Asia/Shanghai
- # systemctl reload php-fpm.service
- 4.Web访问http://ip/zabbix
- 下载配置文件zabbix.conf.php保存到zabbix-server服务器的/etc/zabbix/web/目录下
- 5.zabbix-server对自己的监控
- # yum install zabbix-agent2 -y
- # systemctl enable --now zabbix-agent2
- 6.安装zabbix-get软件包
- # rpm -Uvh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-get-5.0.42-1.el7.x86_64.rpm
- # rpm -ql zabbix-get
- /usr/bin/zabbix_get
- /usr/share/doc/zabbix-get-5.0.42
- /usr/share/doc/zabbix-get-5.0.42/AUTHORS
- /usr/share/doc/zabbix-get-5.0.42/COPYING
- /usr/share/doc/zabbix-get-5.0.42/ChangeLog
- /usr/share/doc/zabbix-get-5.0.42/NEWS
- /usr/share/doc/zabbix-get-5.0.42/README
- /usr/share/man/man1/zabbix_get.1.gz
- # zabbix_get -s 127.0.0.1 -k 'system.hostname'
- ansible-server
- # zabbix_get -s 192.168.220.125 -p 10050 -k 'system.hostname'
- web01
-
- 被监控主机安装zabbix-agent2
- # cp -R /etc/yum.repos.d/ /etc/yum.repos.d.bak/
- # rm -rf /etc/yum.repos.d/*
- # rpm -Uvh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-agent2-5.0.42-1.el7.x86_64.rpm
- # rpm -qa|grep zabbix
- zabbix-agent2-5.0.42-1.el7.x86_64
- # rpm -ql zabbix-agent2
- /etc/logrotate.d/zabbix-agent2
- /etc/zabbix/zabbix_agent2.conf
- /etc/zabbix/zabbix_agent2.d
- /usr/lib/systemd/system/zabbix-agent2.service
- /usr/lib/tmpfiles.d/zabbix_agent2.conf
- /usr/sbin/zabbix_agent2
- /usr/share/doc/zabbix-agent2-5.0.42
- /usr/share/doc/zabbix-agent2-5.0.42/AUTHORS
- /usr/share/doc/zabbix-agent2-5.0.42/COPYING
- /usr/share/doc/zabbix-agent2-5.0.42/ChangeLog
- /usr/share/doc/zabbix-agent2-5.0.42/NEWS
- /usr/share/doc/zabbix-agent2-5.0.42/README
- /usr/share/man/man8/zabbix_agent2.8.gz
- /var/log/zabbix
- /var/run/zabbix
- # grep '^[a-Z]' /etc/zabbix/zabbix_agent2.conf
- PidFile=/var/run/zabbix/zabbix_agent2.pid
- LogFile=/var/log/zabbix/zabbix_agent2.log
- LogFileSize=0
- Server=192.168.220.108
- ServerActive=127.0.0.1
- Hostname=Zabbix server
- Include=/etc/zabbix/zabbix_agent2.d/*.conf
- ControlSocket=/tmp/agent.sock
- # zabbix_agent2 -p|grep system.hostname
- system.hostname [s|web01]
-
-
- ----------------------------------------------------------------------
- 重启服务
- # systemctl restart nginx php-fpm mariadb zabbix-agent2 zabbix-server.service ##mariadb服务必须在zabbix-server服务之前运行,否则zabbix-server服务可以运行但是10051监听端口无法启用
解决zabbix默认图形乱码问题,修改zabbix字体
安装字体
[root@localhost ~]# yum install wqy-microhei-fonts -y
复制字体 # \cp表示使用原生的cp命令,而不是别名的cp命令
[root@localhost ~]# \cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf
[root@localhost ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
1.Zabbix agent vs agent2
在任何一台服务器上面安装zabbix-agent zabbix-agent2
zabbix agent | zabbix agent2 | |
开发语言 | C语言 | Go语言,和C语言 |
性能 | 独立进程方式运行 | 1个进程多线程技术运行, 减少资源消耗占用较少tcp资源,能够承受更高并发 |
2.Zabbix Agent[2]监控流程
Linux安装与配置客户端,web添加与配置主机
●Linux:在客户端安装zabbix-agent2(rpm)
●LInux:修改配置文件 指定Server为zabbix服务端
●web页面:配置-->主机中==添加主机与关联模板==
●web页面:添加后检测与检查数据
1) 补充:zabbix服务端与客户端配置详解
- #zabbix 服务端 说明
- [root@m03 ~]# rpm -qa |grep zabbix
- zabbix-release-5.0-1.el7.noarch #zabbix yum源软件包
- zabbix-server-mysql-5.0.13-1.el7.x86_64 #server
- zabbix-agent2-5.0.13-1.el7.x86_64 #agent2
- #zabbix服务端
- [root@m03 ~]# rpm -ql zabbix-server-mysql
- /etc/logrotate.d/zabbix-server #日志切割
- /etc/zabbix/zabbix_server.conf #zabbix服务端配置文件
- /usr/lib/systemd/system/zabbix-server.service #systemctl start/stop/restart调用配置文件
- /usr/lib/tmpfiles.d/zabbix-server.conf #备份
- /usr/lib/zabbix/alertscripts #报警使用的脚本 存放处
- /usr/lib/zabbix/externalscripts
- /usr/sbin/zabbix_server_mysql #zabbix 服务端命令
- /usr/share/doc/zabbix-server-mysql-5.0.13/create.sql.gz #zabbix 建表语句
- /usr/share/doc/zabbix-server-mysql-5.0.13/double.sql
- /usr/share/man/man8/zabbix_server.8.gz #帮助文件
- /var/log/zabbix #日志文件
- /var/run/zabbix #pid文件存放
-
- #zabbix_server.conf
- [root@m03 ~]# grep '^[a-Z]' /etc/zabbix/zabbix_server.conf
- LogFile=/var/log/zabbix/zabbix_server.log #日志文件
- LogFileSize=0 #日志文件大小 0不限制大小
- PidFile=/var/run/zabbix/zabbix_server.pid
- SocketDir=/var/run/zabbix
- ##连接数据库部分 zabbix server 连接的数据库
- DBHost=localhost
- DBName=zabbix
- DBUser=zabbix
- DBPassword=123456
- #
- SNMPTrapperFile=/var/log/snmptrap/snmptrap.log #SNMP相关日志
- Timeout=4 #超时时间
- AlertScriptsPath=/usr/lib/zabbix/alertscripts #告警脚本的路径
- ExternalScripts=/usr/lib/zabbix/externalscripts
- LogSlowQueries=3000 #慢查询日志 超过3000毫秒 select
- /show
- StatsAllowedIP=127.0.0.1 #谁可以查看服务端状态
zabbix-server配置文件详细传送门:1 Zabbix server
- #zabbix-客户端配置文件详解
- [root@m03 ~]# grep '^[a-Z]' /etc/zabbix/zabbix_agent2.conf
- PidFile=/var/run/zabbix/zabbix_agent2.pid
- LogFile=/var/log/zabbix/zabbix_agent2.log
- LogFileSize=0
- Server=127.0.0.1 #zabbix 服务端ip地址
- ServerActive=127.0.0.1 #zabbix 客户端主动模式的服务端ip地址
- Hostname=Zabbix server #客户端主机名 暂时不改
- Include=/etc/zabbix/zabbix_agent2.d/*.conf #类似于nginx incloude功能
- ControlSocket=/tmp/agent.sock
-
- 监控客户端
- # 1. 在192.168.220.128主机安装客户端agent2
- [root@localhost ~]# rpm -ivh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-agent2-5.0.0-1.el7.x86_64.rpm
- # 2.修改客户端配置
- [root@web01 ~]# grep ^Server= /etc/zabbix/zabbix_agent2.conf
- Server=192.168.220.118
- # 3. 启动
- [root@web01 ~]# systemctl enable zabbix-agent2.service
- Created symlink from /etc/systemd/system/multi-user.target.wants/zabbixagent2.
- [root@web01 ~]# systemctl start zabbix-agent2.service
- # 4. 检查
- [root@web01 ~]# ss -lntup |grep 10050
- tcp LISTEN 0 128 [::]:10050 [::]:* users:(("zabbix_agent2",pid=1919,fd=6))
- [root@web01 ~]# ps -ef |grep zabbix
- zabbix 1919 1 0 02:23 ? 00:00:06 /usr/sbin/zabbix_agent2 -c /etc/zabbix/zabbix_agent2.conf
- root 2361 1807 0 04:30 pts/0 00:00:00 grep --color=auto zabbix
- [root@web01 ~]# telnet 192.168.220.118 10051
- Trying 192.168.220.118...
- Connected to 192.168.220.118.
- Escape character is '^]'.
- Connection closed by foreign host.
-
- #############################################################################
- zabbix-agent2配置:来源于chaoge视频
- 1.对时
- yum install ntpdate -y
- ntpdate cn.pool.ntp.org #cn.pool.ntp.org是中国NTP服务器
- 2.时区的统一配置
- mv /etc/localtime{,.bak}
- ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
-
- 3.设置开机自启动并现在start,等同于systemctl start 服务名&&systemctl enable 服务名
- systemctl enable --now zabbix-agent2
-
- 查看zabbix-agent2配置文件
- grep -Ev '^#|^$' /etc/zabbix/zabbix-agent2.conf #E使用扩展正则表达式,v匹配的不显示
-
- 查看主机名
- [root@localhost ~]# hostname
- localhost.localdomain
- 设置主机名#hostnamectl set-hostname 主机名
- [root@localhost ~]# hostnamectl set-hostname zbx-agent04
- #############################################################################
- 调试命令
- zabbix_get命令是在server端(192.168.220.118)用来检查agent端(192.168.220.128)的一个命令,在添加完主机或者触发器后,不能正常获得数据,可以用zabbix_get来检查能否采集到agent端数据,以便判断问题症结所在
- agent端(192.168.220.128)
- # rpm -ivh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-agent2-5.0.0-1.el7.x86_64.rpm
- # zabbix_agent2 -p|grep system.hostname ##不启用zabbix-agent2服务即可查看
- system.hostname [s|web02]
- # systemctl start zabbix-agent2 ##启用服务后,server端即可使用zabbix_get命令检查
-
- server端(192.168.220.118)
- # rpm -ivh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-get-5.0.0-1.el7.x86_64.rpm
- # zabbix_get -s 192.168.220.128 -p 10050 -k "system.cpu.load[all,avg1]"
- 0.020000
- You have new mail in /var/spool/mail/root
- # zabbix_get -s '192.168.220.128' -k 'system.hostname'
- web02
-
-
- zabbix创建自定义key
- 被监控主机192.168.220.128修改配置文件
- ##Format: UserParameter=<key>,<shell command>
- [root@localhost ~]# cat /etc/zabbix/zabbix_agent2.d/log_user.conf
- #UserParameter=key,cmd
- #UserParameter=check.ngx,sh /server/scripts/xxx.sh
- UserParameter=log.user,who|wc -l
- [root@localhost ~]# systemctl restart zabbix-agent2.service
- zabbix-agent2(192.168.220.128)客户机上测试 #客户端本地测试键值
- [root@zabbix-agent2 ~]# zabbix_agent2 -t 'log.user'
- log.user [s|3] #s表示类型 文字,3表示结果 键值的结果
- zabbix-server192.168.220.118上测试
- [root@localhost ~]# zabbix_get -s 192.168.220.128 -p 10050 -k log.user
- 3
-
- #自定义带参数key(此处展示一个参数,多参数见自动化运维-全链路全架构无死角监控落地.pdf
- [root@zabbix-server ~]# cat /etc/zabbix/zabbix_agent2.d/Custom_Key_Value.conf #可以将自定义的键值放到一个配置文件中
- UserParameter=log.user,who|wc -l
- UserParameter=log.nginx,echo $[ `ps -ef|grep nginx|grep -v grep|wc -l` - 1 ] #监控nginx是否运行
- UserParameter=login_user_check[*],lastlog|grep -w "$1"|awk '{print $$3}'
- #如果使用自定义键值传参,awk取列的时候要使用$$列。如果没有传参,awk正常使用即可
- [root@zabbix-server ~]# systemctl restart zabbix-agent2.service
- [root@zabbix-server ~]# zabbix_agent2 -t 'log.nginx'
- log.nginx [s|0]
- [root@zabbix-server ~]# zabbix_agent2 -t 'login_user_check[root]'
- login_user_check[root] [s|192.168.220.1]
- [root@zabbix-server ~]# zabbix_get -s '127.0.0.1' -k 'login_user_check[root]'
- 192.168.220.1
主机群组与模板
zabbix添加自定义模板
#给监控项设置标记,方便分类
温馨提示: zbx 5.x 及之前 应用集,zbx 6.x 叫标记。都是用于分类。
#配置监控项名字,填写:键值
信息类型:这里键值结果都是数字,选择数字(无正负即可),如果有小数选择浮点类型,如果是字符,选择字符串。
更新间隔:这里调整为5s秒,生产环境非必须尽量增长间隔比如1m,10m,1h等等。
net.tcp.port[,port] 检查是否能建立 TCP 连接到指定端口。返回 0 - 不能连接;1 - 可以连接
主机群组→模板→应用集→监控项→触发器→图形
测试
主机链接模板
仪表盘检测
如果配置模板内容错误导致主机获取不到数据,可以核对修改模板后从主机删除后重新链接模板
zabbix 5.0配置邮件报警
在配置了监控项之后,一般模板都会自带监控的告警触发器,而目前要配置的是zabbix在这些触发器触发之后需要做的事情,就是要通过邮件通知到相关的人员
1.设置报警媒介类型 ---管理--报警媒介类型--创建媒体类型
网易163邮箱授权码获取
说明:smtp服务器(邮件服务器地址)我这里填写的是163邮件服务器地址,如果你用的是qq 则填写qq的服务器,如下图
测试一下是否能发送告警邮件到邮箱
测试成功后进行下一步:
2.配置用户告警媒介
管理-用户-admin
3.添加报警触发器
配置-动作
#############################################################################
动作可配置项
故障{TRIGGER.STATUS},服务器:{HOSTNAME1}发生: {TRIGGER.NAME}故障!
告警主机:{HOST.NAME}
告警 IP:{HOST.IP}
告警时间:{EVENT.DATE}-{EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息:{TRIGGER.NAME}:{ITEM.VALUE}
事件 ID:{EVENT.ID}
----------------------
恢复{TRIGGER.STATUS},服务器:{HOSTNAME1}: {TRIGGER.NAME}已恢复!
告警主机:{HOSTNAME1}
告警时间:{EVENT.DATE} {EVENT.TIME}
告警等级:{TRIGGER.SEVERITY}
告警信息: {TRIGGER.NAME}
告警项目:{TRIGGER.KEY1}
问题详情:{ITEM.NAME}:{ITEM.VALUE}
当前状态:{TRIGGER.STATUS}:{ITEM.VALUE1}
事件ID:{EVENT.ID}
#############################################################################
动作:邮件的发送
应用服务监控 ##检查端口net.tcp.port[,端口]
[root@localhost ~]# zabbix_get -s '192.168.220.128' -p 10050 -k 'net.tcp.port[,80]' #web服务器监控
0
[root@localhost ~]# zabbix_get -s '192.168.220.128' -p 10050 -k 'net.tcp.port[,10050]'
1
[root@localhost ~]# zabbix_agent2 -t 'net.tcp.port[,10050]'
net.tcp.port[,10050] [s|1]
自动发现(agent2为被动模式):zabbix-server主动去发现所有的客户端,然后将客户端的信息登记在服务端的机器上
准备客户端 192.168.220.130
[root@centos8 ~]# systemctl is-active zabbix-agent2.service #检查服务
active
zabbix服务端 192.168.220.118
[root@localhost ~]# zabbix_get -s '192.168.220.130' -p 10050 -k 'agent.ping' #检查客户端
1 #客户端存活
自动注册(agent2为主动模式):zabbix-agent2主动上报自己的信息,发给zabbix-server
被动模式:对应agent2来说,就是server来找agent2拿数据
主动模式:agent2主动把数据发给server
zabbix-server 192.168.220.108
zabbix-agent2 192.168.220.125
zabbix-agent2 192.168.220.128
配置hosts解析(加速自动发现和添加到主机群组时间) #此处强烈建议在服务端/etc/hosts添加被监控客户端解析,否则Web端添加到监控主机会特别慢!!
zabbix-server服务端/etc/hosts添加(也可以服务端、客户端/etc/hosts同时添加):
# cat >>/etc/hosts<<'EOF'
192.168.220.125 web88888888888888
192.168.220.128 web99999999999999
EOF
zabbix-server端
# zabbix_get -s 192.168.220.125 -p 10050 -k "agent.ping"
zabbix_get [5689]: Get value error: ZBX_TCP_READ() failed: [104] Connection reset by peer
zabbix_get [5689]: Check access restrictions in Zabbix agent configuration ##客户端192.168.220.125的配置文件/etc/zabbix/zabbix_agent2.conf内的Server没有指向zabbix-server(192.168.220.108)
zabbix-agent2客户端(192.168.220.125)
# tail -f zabbix_agent2.log ##配置错误:Server=127.0.0.1
2024/02/02 10:05:45.756163 [101] active check configuration update from [127.0.0.1:10051] started to fail (dial tcp :0->127.0.0.1:10051: connect: connection refused)
2024/02/02 10:31:05.111536 failed to accept an incoming connection: connection from "192.168.220.108" rejected, allowed hosts: "127.0.0.1"
# hostname
web01
修改zabbix-agent2的配置文件
# grep -Ev "^#|^$" /etc/zabbix/zabbix_agent2.conf
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=192.168.220.108 ##zabbix-server的地址(自动发现必配置项)
ServerActive=127.0.0.1 ##自动注册必配置项
Hostname=web22222 ##zabbix-agent2客户端自定义主机名(自动注册用),此选项对自动发现不生效
HostnameItem=system.hostname ##zabbix-agent2客户端默认主机名(自动注册用)
HostMetadataItem=system.uname ##zabbix-agent2客户端主机元数据(自动注册用)
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
# zabbix_agent2 -t "system.uname" ##客户端查看键值,只需安装zabbix-agent2软件包。无需启动zabbix-agent2服务
system.uname [s|Linux web01 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64]
# systemctl restart zabbix-agent2
zabbix-agent2客户端(192.168.220.128)
# hostname
web02
# grep -Ev "^#|^$" /etc/zabbix/zabbix_agent2.conf
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=192.168.220.108
ServerActive=192.168.220.108
Hostname=web33333
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
# systemctl restart zabbix-agent2
zabbix-server服务端
# zabbix_get -s 192.168.220.125 -p 10050 -k "system.uname"
Linux web01 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64
注意:
1.配置文件/etc/zabbix/zabbix_agent2.conf内的选项Hostname与HostnameItem均对自动发现无效
2.自动发现断线状态
/etc/zabbix/zabbix_agent2.conf配置文件说明:
# grep -Ev "^#|^$" /etc/zabbix/zabbix_agent2.conf
PidFile=/var/run/zabbix/zabbix_agent2.pid ##pid存放位置
LogFile=/var/log/zabbix/zabbix_agent2.log ##日志存放位置
LogFileSize=0 ##不限制日志文件大小
Server=192.168.220.108 ##服务端ip,用来自动发现
ServerActive=192.168.220.108 ##服务端ip,用来自动注册
Hostname=web88888888 ##自动注册web端自定义的主机名称
HostnameItem=system.hostname ##自动注册web端的默认主机名称,system.hostname的键值
HostMetadataItem=system.uname ##自动注册的条件:主机元数据
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
Hostname(可以使用zabbix-agent2客户端的主机名也支持自定义主机名。若和HostnameItem选项同时存在则优先级大于HostnameItem,自动注册web端的主机名称必须与此选项匹配)
###选项:主机名
#唯一的、区分大小写的主机名。
#活动检查需要,服务器上Web端自动注册的主机名与此项匹配。
#如果未定义,则从HostnameItem获取值。
HostnameItem(若未定义Hostname选项,则自动注册web端的主机名称匹配zabbix-agent2客户端的主机名)
###选项:主机名项目
#用于生成主机名的项(如果未定义Hostname)。配置文件如果定义了主机名Hostname,则忽略HostnameItem。
#不支持UserParameters或别名。
HostMetadataItem #自动注册如需通过主机元数据进行主机过滤,那么需在客户端配置文件内启用此选项。未启用此选项的主机不匹配任何主机元数据
###选项:HostMetadataItem
#定义主机元数据的可选参数。
#主机元数据用于主机自动注册过程。
说明:zabbix服务端/etc/hosts解析文件内配置的DNS名称不会用于自动注册主机的Web端(配置-主机-)主机名称,但是会加速自动注册过程!
自动注册动作配置
自动注册触发条件的添加
若客户端/etc/zabbix/zabbix_agent2.conf文件内定义了Hostname。无论有没有定义HostnameItem=system.hostname自动注册web端的主机名称都使用Hostname的值
若客户端/etc/zabbix/zabbix_agent2.conf文件内未定义Hostname。无论有没有定义HostnameItem=system.hostname自动注册web端的主机名称都使用对应key(system.hostname)的值
Hostname优先级大于HostnameItem
实例1:客户端/etc/zabbix/zabbix_agent2.conf未定义Hostname选项
# ansible web -i hosts -m shell -a "grep -Ev '^#|^$' /etc/zabbix/zabbix_agent2.conf"
192.168.220.125 | CHANGED | rc=0 >>
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=192.168.220.108
ServerActive=192.168.220.108
HostnameItem=system.hostname
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
192.168.220.128 | CHANGED | rc=0 >>
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=192.168.220.108
ServerActive=192.168.220.108
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
# zabbix_get -s '192.168.220.125' -p 10050 -k 'system.hostname'
web01
# zabbix_get -s '192.168.220.128' -p 10050 -k 'system.hostname'
web02
实例2:客户端/etc/zabbix/zabbix_agent2.conf定义Hostname选项
# ansible web -i hosts -m shell -a "grep -Ev '^#|^$' /etc/zabbix/zabbix_agent2.conf"
192.168.220.125 | CHANGED | rc=0 >>
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=192.168.220.108
ServerActive=192.168.220.108
Hostname=web88888888
HostMetadataItem=system.uname
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
192.168.220.128 | CHANGED | rc=0 >>
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=192.168.220.108
ServerActive=192.168.220.108
HostMetadataItem=system.uname
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
# zabbix_get -s '192.168.220.125' -p 10050 -k 'system.hostname'
web01
# zabbix_get -s '192.168.220.128' -p 10050 -k 'system.hostname'
web02
# ansible web -i hosts -m shell -a "grep -Ev '^#|^$' /etc/zabbix/zabbix_agent2.conf"
192.168.220.125 | CHANGED | rc=0 >>
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=192.168.220.108
ServerActive=192.168.220.108
Hostname=web88888888
HostMetadataItem=system.uname ##元数据的键值
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
192.168.220.128 | CHANGED | rc=0 >>
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=192.168.220.108
ServerActive=192.168.220.108
HostMetadataItem=system.uname
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
# zabbix_get -s '192.168.220.125' -p 10050 -k 'system.uname' ##元数据的键值
Linux web01 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64
# zabbix_get -s '192.168.220.128' -p 10050 -k 'system.uname'
Linux web02 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64
## 服务端日志监控
[root@localhost zabbix]# tail -f /var/log/zabbix/zabbix_server.log
##客户端日志
[root@centos8 ~]# tail -f /var/log/zabbix/zabbix_agent2.log
#分布式监控的作用
1.分担server的集中式压力
agent>proxy>server
2.多机房之间的网络延时问题
#分布式监控配置
主机信息
192.168.220.118 zabbix-server #centos7.9
192.168.220.128 zabbix-proxy #centos7.9
192.168.220.130 zabbix-agent2 #centos8.3
#选择性操作--可以将ip与host的对应关系添加到server端的/etc/hosts加速解析
[root@zabbix-server ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.220.118 zabbix-server #centos7.9
192.168.220.128 zabbix-proxy #centos7.9
192.168.220.130 zabbix-agent2 #centos8.3
zabbix_proxy主机配置 192.168.220.128
#设置主机名
[root@localhost ~]# hostnamectl set-hostname zabbix-proxy
[root@localhost ~]# hostname
zabbix-proxy
[root@zabbix-proxy ~]# rpm -Uvh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm #添加源仓库zabbix.repo
[root@zabbix-proxy ~]# sed -i 's#http://repo.zabbix.com#https://mirrors.tuna.tsinghua.edu.cn/zabbix#g' /etc/yum.repos.d/zabbix.repo #国外源替换为清华源
[root@zabbix-proxy ~]# yum install zabbix-proxy-mysql zabbix-get -y
[root@zabbix-proxy ~]# yum install mariadb-server mariadb -y
[root@zabbix-proxy ~]# systemctl enable --now mariadb
[root@zabbix-proxy ~]# mysql <<'EOF' #创建数据库与用户
create database zabbix_proxy character set utf8 collate utf8_bin;
grant all privileges on zabbix_proxy.* to zabbix_proxy@'localhost' identified by 'zabbix_proxy';
flush privileges;
EOF
#查看zabbix-proxy-mysql软件包的文件
[root@zabbix-proxy ~]# rpm -ql zabbix-proxy-mysql
/etc/logrotate.d/zabbix-proxy
/etc/zabbix/zabbix_proxy.conf
/usr/lib/systemd/system/zabbix-proxy.service
/usr/lib/tmpfiles.d/zabbix-proxy.conf
/usr/lib/zabbix/externalscripts
/usr/sbin/zabbix_proxy_mysql
/usr/share/doc/zabbix-proxy-mysql-5.0.28
/usr/share/doc/zabbix-proxy-mysql-5.0.28/AUTHORS
/usr/share/doc/zabbix-proxy-mysql-5.0.28/COPYING
/usr/share/doc/zabbix-proxy-mysql-5.0.28/ChangeLog
/usr/share/doc/zabbix-proxy-mysql-5.0.28/NEWS
/usr/share/doc/zabbix-proxy-mysql-5.0.28/README
/usr/share/doc/zabbix-proxy-mysql-5.0.28/schema.sql.gz
/usr/share/man/man8/zabbix_proxy.8.gz
/var/log/zabbix
/var/run/zabbix
#导入数据
[root@zabbix-proxy ~]# zcat /usr/share/doc/zabbix-proxy-mysql-5.0.28/schema.sql.gz|mysql zabbix_proxy -uzabbix_proxy -pzabbix_proxy
#修改zabbix_proxy.conf配置文件,注释的地方
[root@zabbix-proxy ~]# grep '^[a-Z]' /etc/zabbix/zabbix_proxy.conf
Server=192.168.220.118 #zabbix-server的ip
Hostname=zabbix-proxy #zabbix-proxy主机名
LogFile=/var/log/zabbix/zabbix_proxy.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_proxy.pid
SocketDir=/var/run/zabbix
DBName=zabbix_proxy #链接的数据库名
DBUser=zabbix_proxy #数据库用户
DBPassword=zabbix_proxy #数据库密码
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
[root@zabbix-proxy log]# systemctl enable --now zabbix-proxy.service #开启服务
[root@zabbix-proxy ~]# tail -f /var/log/zabbix/zabbix_proxy.log #监控日志
2786:20221027:021804.771 Starting Zabbix Proxy (active) [zabbix-proxy]. Zabbix 5.0.28 (revision b2b8e2ce82d).
2786:20221027:021804.771 **** Enabled features ****
2786:20221027:021804.771 SNMP monitoring: YES
2786:20221027:021804.771 IPMI monitoring: YES
2786:20221027:021804.771 Web monitoring: YES
2786:20221027:021804.771 VMware monitoring: YES
2786:20221027:021804.771 ODBC: YES
2786:20221027:021804.772 SSH support: YES
2786:20221027:021804.772 IPv6 support: YES
2786:20221027:021804.772 TLS support: YES
2786:20221027:021804.772 **************************
2786:20221027:021804.772 using configuration file: /etc/zabbix/zabbix_proxy.conf
2786:20221027:021804.777 current database version (mandatory/optional): 05000000/05000007
2786:20221027:021804.778 required mandatory version: 05000000
2786:20221027:021804.786 proxy #0 started [main process]
2791:20221027:021804.786 proxy #1 started [configuration syncer #1]
2791:20221027:021804.800 received configuration data from server at "192.168.220.118", datalen 3662 #提示已连接
#web页面配置
连接后显示
注意:web页面可以看到最近出现时间(只要有时间即可),如果长时间没有出现,可以查看代理日志,如果持续出现not found 情况。可以重启下zabbix-proxy和zabbix-server
zabbix-agent2主机配置 192.168.220.130 #centos8.3
#通过源(本次使用清华源)找到适用于centos8版本zabbix-agent2的rpm包
[root@zabbix-agent2 ~]# rpm -ivh https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/8/x86_64/zabbix-agent2-5.0.0-1.el8.x86_64.rpm
#修改zabbix_agent2.conf配置文件,注释的地方
[root@zabbix-agent2 ~]# grep '^[a-Z]' /etc/zabbix/zabbix_agent2.conf
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=192.168.220.128 #zabbix-proxy主机ip
ServerActive=192.168.220.128 #zabbix-proxy主机ip,用来自动注册的
Hostname=zabbix-agent2 #zabbix-agent2主机对应的hostname
HostnameItem=system.hostname #添加Hostname后此选项可忽略
HostMetadataItem=system.uname #添加Hostname后此选项可忽略
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
DenyKey=system.run[*]
[root@zabbix-agent2 ~]# systemctl enable --now zabbix-agent2 #开启服务
利用zabbix-proxy主机监测zabbix-agent2
[root@zabbix-proxy ~]# zabbix_get -s '192.168.220.130' -p 10050 -k 'agent.ping'
1
故障处理:
[root@zabbix-proxy ~]# tail -f /var/log/zabbix/zabbix_proxy.log
2795:20221027:025141.924 cannot send list of active checks to "192.168.220.130": host [zabbix-agent2] not found
2797:20221027:025345.926 cannot send list of active checks to "192.168.220.130": host [zabbix-agent2] not found
如果长时间提示not found,重启zabbix-proxy主机
[root@zabbix-proxy ~]# systemctl restart zabbix-proxy.service
[root@zabbix-proxy ~]# tail -f /var/log/zabbix/zabbix_proxy.log
2918:20221027:025814.299 enabling Zabbix agent checks on host "zabbix-agent2": host became available
或者
# systemctl restart zabbix-proxy ##代理服务器
# systemctl restart zabbix-agent2 ##zabbix-agent2客户端
#web页面配置
通过代理主机实现客户机的监控
注意:在zabbix-agent2使用zabbix-proxy被zabbix-server端监控的情况下,zabbix-agent2客户端添加自定义监控项并关联模板后需要重启客户端和代理服务器(systemctl restart zabbix-agent2;systemctl restart zabbix-proxy),否则此监控项数据无法正常被zabbix-server服务端获取
- 1.zabbix-server直接监控zabbix-agent2
-
- # tail -f /var/log/zabbix/zabbix_server.log ##zabbix-server主机192.168.220.108
- 2968:20240606:092659.970 server #35 started [trapper #5]
- 2970:20240606:092659.972 server #37 started [alert syncer #1]
- 2968:20240606:093345.982 cannot send list of active checks to "192.168.220.128": host [zabbix-proxy] not found
- 2968:20240606:093546.987 cannot send list of active checks to "192.168.220.128": host [zabbix-proxy] not found ##分析:zabbix-agent2(192.168.220.128)服务已启用(active checks),zabbix的web页面未配置agent主机监控
- 2960:20240606:093619.166 enabling Zabbix agent checks on host "zabbix-proxy": host became available ##zabbix-server的Web端页面已实现zabbix-proxy(192.168.220.128)主机本身(zabbix-agent2)的监控
- 说明:zabbix-agent2主机192.168.220.128被Web监控后
- 若Web页面创建的被代理zabbix-agent2客户端主机名称与配置文件/etc/zabbix/zabbix_agent2.conf的Hostname选项(若未定义Hostname则与system.hostname)一致(zabbix-proxy),那么日志输出
- 2960:20240606:093619.166 enabling Zabbix agent checks on host "zabbix-proxy": host became available
- 若Web页面创建的被代理zabbix-agent2客户端主机名称与配置文件/etc/zabbix/zabbix_agent2.conf的Hostname选项(若未定义Hostname则与system.hostname)不一致(zabbix-proxy),那么日志输出
- 14934:20240606:143854.083 enabling Zabbix agent checks on host "192.168.220.128": host became available
- 14940:20240606:144010.892 cannot send list of active checks to "192.168.220.128": host [zabbix-proxy] not found
- 14938:20240606:144210.896 cannot send list of active checks to "192.168.220.128": host [zabbix-proxy] not found
- 14940:20240606:144411.892 cannot send list of active checks to "192.168.220.128": host [zabbix-proxy] not found
-
-
- # tail -f /var/log/zabbix/zabbix_agent2.log ##zabbix-agent2主机192.168.220.128,同时也是zabbix-proxy
- 2024/06/06 09:33:44.886624 using plugin 'ZabbixStats' providing following interfaces: exporter, configurator
- 2024/06/06 09:33:44.886806 both "Hostname" and "HostnameItem" configuration parameter defined, using "Hostname" ##优先使用Hostname选项
- 2024/06/06 09:33:45.977066 [101] no active checks on server [192.168.220.108:10051]: host [zabbix-proxy] not found ##表示还未被zabbix-server的Web页面监控
- 2024/06/06 09:35:46.983127 [101] no active checks on server [192.168.220.108:10051]: host [zabbix-proxy] not found
- 说明:zabbix-agent2主机192.168.220.128被Web监控后
- 若Web页面创建的被代理zabbix-agent2客户端主机名称与配置文件/etc/zabbix/zabbix_agent2.conf的Hostname选项(若未定义Hostname则与system.hostname)一致(zabbix-proxy),那么日志不输出
- 若Web页面创建的被代理zabbix-agent2客户端主机名称与配置文件/etc/zabbix/zabbix_agent2.conf的Hostname选项(若未定义Hostname则与system.hostname)不一致(zabbix-proxy),那么日志继续输出
- 2024/06/06 14:38:09.891647 [101] no active checks on server [192.168.220.108:10051]: host [zabbix-proxy] not found
- 2024/06/06 14:40:10.891549 [101] no active checks on server [192.168.220.108:10051]: host [zabbix-proxy] not found
- 2024/06/06 14:42:10.894879 [101] no active checks on server [192.168.220.108:10051]: host [zabbix-proxy] not found
- 2024/06/06 14:44:11.891172 [101] no active checks on server [192.168.220.108:10051]: host [zabbix-proxy] not found
- 2024/06/06 14:46:12.892427 [101] no active checks on server [192.168.220.108:10051]: host [zabbix-proxy] not found
- 2024/06/06 14:48:13.893684 [101] no active checks on server [192.168.220.108:10051]: host [zabbix-proxy] not found
-
-
-
-
- 2.zabbix-server通过zabbix-proxy代理监控zabbix-agent2
-
- # tail -f /var/log/zabbix/zabbix_server.log ##zabbix-server主机192.168.220.108
- 2964:20240606:095428.789 cannot parse proxy data from active proxy at "192.168.220.128": proxy "zabbix-proxy" not found
- 2964:20240606:095429.659 cannot parse heartbeat from active proxy at "192.168.220.128": proxy "zabbix-proxy" not found
- 2964:20240606:095429.792 cannot parse proxy data from active proxy at "192.168.220.128": proxy "zabbix-proxy" not found ##代理主机zabbix-proxy(192.168.220.128)未添加到zabbix-server主机的Web页面(管理-)agent代理程序并启用
- 2964:20240606:095432.805 cannot parse proxy data from active proxy at "192.168.220.128": proxy "zabbix-proxy" not found
- 14941:20240606:113845.893 cannot send list of active checks to "192.168.220.128": host [zabbix-proxy] not found ##分析:zabbix-agent2(192.168.220.128)服务已启用(active checks),zabbix的web页面未配置agent主机监控
- 14941:20240606:114046.894 cannot send list of active checks to "192.168.220.128": host [zabbix-proxy] not found
- 14933:20240606:115046.034 enabling Zabbix agent checks on host "zabbix-proxy": host became available ##zabbix-server的Web端页面已实现zabbix-proxy(192.168.220.128)主机本身的监控
-
-
- # tail -f /var/log/zabbix/zabbix_proxy.log ##zabbix-proxy主机192.168.220.128,同时也是zabbix-agent2
- 2228:20240606:095318.188 [Z3001] connection to database 'zabbix_proxy' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) ##数据库未启用
- 2228:20240606:095318.189 database is down: reconnecting in 10 seconds
- 2228:20240606:095328.243 database connection re-established
- 2228:20240606:095328.336 current database version (mandatory/optional): 05000000/05000007
- 2551:20240606:095428.788 cannot send proxy data to server at "192.168.220.108": proxy "zabbix-proxy" not found
- 2546:20240606:095429.657 cannot send heartbeat message to server at "192.168.220.108": proxy "zabbix-proxy" not found
- 2551:20240606:095502.926 cannot send proxy data to server at "192.168.220.108": proxy "zabbix-proxy" not found ##zabbix-server主机的Web页面未添加(管理-)agent代理程序并启用
- 2551:20240606:095503.930 cannot send proxy data to server at "192.168.220.108": proxy "zabbix-proxy" not found
- 2541:20240606:095602.371 cannot send list of active checks to "192.168.220.125": host [zabbix-agent] not found
- 2536:20240606:095806.313 cannot send list of active checks to "192.168.220.125": host [zabbix-agent] not found
- 2536:20240606:100010.310 cannot send list of active checks to "192.168.220.125": host [zabbix-agent] not found ##通过zabbix-proxy(192.168.220.128)代理的zabbix-agent2(192.168.220.125)主机未添加到zabbix-server(192.168.220.108)的Web端监控
- 2727:20240606:101904.287 enabling Zabbix agent checks on host "zabbix-agent": host became available ##自定义Hostname=zabbix-agent主机(zabbix-agent2主机192.168.220.128)已通过zabbix-proxy(192.168.220.128)被zabbix-server(192.168.220.108)实现Web页面监控。若zabbix-proxy和zabbix-agent2配置正确但持续监控不到可重启代理或代理和客户端(systemctl restart zabbix-proxy;systemctl restart zabbix-agent2)
- 说明:zabbix-agent2主机192.168.220.125被Web监控后
- 若Web页面创建的被代理zabbix-agent2客户端主机名称与配置文件/etc/zabbix/zabbix_agent2.conf的Hostname选项(若未定义Hostname则与system.hostname)一致(zabbix-agent),那么日志输出
- 2727:20240606:101904.287 enabling Zabbix agent checks on host "zabbix-agent": host became available
- 若Web页面创建的被代理zabbix-agent2客户端主机名称与配置文件/etc/zabbix/zabbix_agent2.conf的Hostname选项(若未定义Hostname则与system.hostname)不一致(zabbix-agent),那么日志输出
- 4150:20240606:134447.775 enabling Zabbix agent checks on host "192.168.220.125": host became available
- 4126:20240606:134554.761 cannot send list of active checks to "192.168.220.125": host [zabbix-agent] not found
- 4126:20240606:134758.756 cannot send list of active checks to "192.168.220.125": host [zabbix-agent] not found
- # tail -f /var/log/zabbix/zabbix_agent2.log ##zabbix-agent2主机192.168.220.125
- 2024/06/06 11:27:24.751598 [101] active check configuration update from [192.168.220.128:10051] started to fail (Cannot read message: 'read tcp 192.168.220.125:53109->192.168.220.128:10051: i/o timeout') ##通过zabbix-proxy(192.168.220.128)代理的zabbix-agent2(192.168.220.125)主机未添加到zabbix-server(192.168.220.108)的Web端监控
- 2024/06/06 11:29:28.749631 [101] active check configuration update from [192.168.220.128:10051] started to fail (Cannot read message: 'read tcp 192.168.220.125:33715->192.168.220.128:10051: i/o timeout')
- 2024/06/06 11:31:32.747318 [101] active check configuration update from [192.168.220.128:10051] started to fail (Cannot read message: 'read tcp 192.168.220.125:49711->192.168.220.128:10051: i/o timeout')
- 2024/06/06 11:33:36.750639 [101] active check configuration update from [192.168.220.128:10051] started to fail (Cannot read message: 'read tcp 192.168.220.125:42991->192.168.220.128:10051: i/o timeout')
- 说明:zabbix-agent2主机192.168.220.125被Web监控后
- 若Web页面创建的被代理zabbix-agent2客户端主机名称与配置文件/etc/zabbix/zabbix_agent2.conf的Hostname选项(若未定义Hostname则与system.hostname)一致(zabbix-agent),那么日志不输出
- 若Web页面创建的被代理zabbix-agent2客户端主机名称与配置文件/etc/zabbix/zabbix_agent2.conf的Hostname选项(若未定义Hostname则与system.hostname)不一致(zabbix-agent),那么日志继续输出
- 2024/06/06 14:06:27.749477 [101] active check configuration update from [192.168.220.128:10051] started to fail (Cannot read message: 'read tcp 192.168.220.125:56820->192.168.220.128:10051: i/o timeout')
- 2024/06/06 14:08:31.751554 [101] active check configuration update from [192.168.220.128:10051] started to fail (Cannot read message: 'read tcp 192.168.220.125:49103->192.168.220.128:10051: i/o timeout')
192.168.220.108 zabbix-proxy
192.168.220.128 zabbix-server
192.168.220.130 zabbix-agent2
- 192.168.220.128 zabbix-server
- [root@zabbix-server ~]# systemctl list-units|grep zabbix
- zabbix-agent2.service loaded active running Zabbix Agent 2
- zabbix-server.service loaded active running Zabbix Server
- [root@zabbix-server ~]# grep '^[a-Z]' /etc/zabbix/zabbix_server.conf
- LogFile=/var/log/zabbix/zabbix_server.log
- LogFileSize=0
- PidFile=/var/run/zabbix/zabbix_server.pid
- SocketDir=/var/run/zabbix
- DBHost=localhost
- DBName=zabbix
- DBUser=zabbix
- DBPassword=1
- SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
- Timeout=4
- AlertScriptsPath=/usr/lib/zabbix/alertscripts
- ExternalScripts=/usr/lib/zabbix/externalscripts
- LogSlowQueries=3000
- StatsAllowedIP=127.0.0.1
- [root@zabbix-server ~]# grep '^[a-Z]' /etc/zabbix/zabbix_agent2.conf
- PidFile=/var/run/zabbix/zabbix_agent2.pid
- LogFile=/var/log/zabbix/zabbix_agent2.log
- LogFileSize=0
- Server=127.0.0.1
- ServerActive=127.0.0.1
- Hostname=zabbix-server
- Include=/etc/zabbix/zabbix_agent2.d/*.conf
- ControlSocket=/tmp/agent.sock
-
- 192.168.220.108 zabbix-proxy
- [root@zabbix-proxy ~]# systemctl list-units|grep zabbix
- zabbix-agent2.service loaded active running Zabbix Agent 2
- zabbix-proxy.service loaded active running Zabbix Proxy
- [root@zabbix-proxy ~]# grep '^[a-Z]' /etc/zabbix/zabbix_proxy.conf
- Server=192.168.220.128
- Hostname=zabbix-proxy
- LogFile=/var/log/zabbix/zabbix_proxy.log
- LogFileSize=0
- PidFile=/var/run/zabbix/zabbix_proxy.pid
- SocketDir=/var/run/zabbix
- DBHost=localhost
- DBName=zabbix_proxy
- DBUser=zabbix_proxy
- DBPassword=zabbix_proxy
- SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
- Timeout=4
- ExternalScripts=/usr/lib/zabbix/externalscripts
- LogSlowQueries=3000
- StatsAllowedIP=127.0.0.1
- [root@zabbix-proxy ~]# grep '^[a-Z]' /etc/zabbix/zabbix_agent2.conf
- PidFile=/var/run/zabbix/zabbix_agent2.pid
- LogFile=/var/log/zabbix/zabbix_agent2.log
- LogFileSize=0
- Server=192.168.220.128
- ServerActive=192.168.220.128
- Hostname=zabbix-proxy
- HostMetadataItem=system.uname
- Include=/etc/zabbix/zabbix_agent2.d/*.conf
-
- 192.168.220.130 zabbix-agent2
- [root@zabbix-agent2 ~]# systemctl list-units|grep zabbix
- zabbix-agent2.service loaded active running Zabbix Agent 2
- [root@zabbix-agent2 ~]# grep '^[a-Z]' /etc/zabbix/zabbix_agent2.conf
- PidFile=/var/run/zabbix/zabbix_agent2.pid
- LogFile=/var/log/zabbix/zabbix_agent2.log
- LogFileSize=0
- Server=192.168.220.108
- ServerActive=192.168.220.108
- Hostname=zabbix-agent2
- HostMetadataItem=system.uname
- Include=/etc/zabbix/zabbix_agent2.d/*.conf
- ControlSocket=/tmp/agent.sock
- DenyKey=system.run[*]
web页面添加server
添加agent代理程序
等待。。。。
自定义自动注册的主机名称,即修改/etc/zabbix/zabbix_agent2.conf内的hostname即可。现实环境中最好保持/etc/zabbix/zabbix_agent2.conf内的hostname与主机的hostname保持一致
- 192.168.220.108 zabbix-proxy
- [root@zabbix-proxy ~]# grep '^[a-Z]' /etc/zabbix/zabbix_proxy.conf
- Server=192.168.220.128
- Hostname=zabbix-proxy
- LogFile=/var/log/zabbix/zabbix_proxy.log
- LogFileSize=0
- PidFile=/var/run/zabbix/zabbix_proxy.pid
- SocketDir=/var/run/zabbix
- DBHost=localhost
- DBName=zabbix_proxy
- DBUser=zabbix_proxy
- DBPassword=zabbix_proxy
- SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
- Timeout=4
- ExternalScripts=/usr/lib/zabbix/externalscripts
- LogSlowQueries=3000
- StatsAllowedIP=127.0.0.1
- [root@zabbix-proxy ~]# grep '^[a-Z]' /etc/zabbix/zabbix_agent2.conf
- PidFile=/var/run/zabbix/zabbix_agent2.pid
- LogFile=/var/log/zabbix/zabbix_agent2.log
- LogFileSize=0
- Server=192.168.220.128
- ServerActive=192.168.220.128
- Hostname=ceshi ######自定义hostname
- HostMetadataItem=system.uname
- Include=/etc/zabbix/zabbix_agent2.d/*.conf
- ControlSocket=/tmp/agent.sock
-
- 192.168.220.130 zabbix-agent2
- [root@zabbix-agent2 ~]# grep '^[a-Z]' /etc/zabbix/zabbix_agent2.conf
- PidFile=/var/run/zabbix/zabbix_agent2.pid
- LogFile=/var/log/zabbix/zabbix_agent2.log
- LogFileSize=0
- Server=192.168.220.108
- ServerActive=192.168.220.108
- Hostname=zheshiyigeceshi #####自定义hostname
- HostMetadataItem=system.uname
- Include=/etc/zabbix/zabbix_agent2.d/*.conf
- ControlSocket=/tmp/agent.sock
- DenyKey=system.run[*]
通过代理服务器自动注册的总结:
zabbix-server的Web端:管理-agent代理程序
①agent代理程序与/etc/zabbix/zabbix_proxy.conf文件的Hostname选项保持一致,先添加agent代理程序并启用
zabbix-server的Web端:配置-主机内
②zabbix-proxy服务器的监控/etc/zabbix/zabbix_agent2.conf文件内Server和ServerActive指向zabbix-server端的ip,Hostname选项自动注册为Web端的名称
③被zabbix-proxy代理的zabbix-agent2客户器的监控/etc/zabbix/zabbix_agent2.conf文件内Server和ServerActive指向zabbix-proxy代理服务器的ip,Hostname选项自动注册为Web端的名称
参考资料:Zabbix 3.0 从入门到精通(zabbix使用详解) - 惨绿少年 - 博客园
#############################################################################
zabbix-proxy代理主机(192.168.220.125)的监控agent2不可以由proxy代理程序监测,需要直接由zabbix-server监控
[root@zabbix-proxy zabbix]# grep '^[a-Z]' /etc/zabbix/zabbix_agent2.conf
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=192.168.220.108 #192.168.220.108为zabbix-server地址
ServerActive=192.168.220.108
Hostname=zabbix-proxy
HostMetadataItem=system.uname
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
DenyKey=system.run[*]
#############################################################################
无法安装agent 很多前辈的监控软件都可以监控各种设备 都是通过snmp监控
snmp simple network manager protocol 简单网络管理协议
简单网络管理协议(SNMP),由一组网络管理的标准组成,包含一个应用层协议(application layer protocol)、数据库模型(database schema)和一组资源对象。该协议能够支持网络管理系统,用以监测连接到网络上的设备是否有任何引起管理上关注的情况。
yum -y install net-snmp net-snmp-utils
sed -i.ori '57a view systemview included .1' /etc/snmp/snmpd.conf # -i.ori选项:修改文件并创建一个以ori为后缀的备份文件
systemctl start snmpd.service
[root@m01 ~]# snmpwalk -v 2c -c public 127.0.0.1 sysname SNMPv2-MIB::sysName.0 = STRING: m01
说明:
# snmpwalk 类似 zabbix_get
# -v 2c 指定使用snmp协议的版本 snmp分为v1 v2 v3
# -c public 指定暗号
# sysname 类似zabbix的key
添加新的主机,注意使用snmp接口
选择模板,注意使用SNMP的模板
添加完成就能够在主机中看到snmp监控对的主机
##SNMP OID列表 监控需要用到的OID http://www.ttlsa.com/monitor/snmp-oid/ cmdb 资源管理系统
https://www.bilibili.com/video/BV1rb411n7a8/
#自定义脚本与使用
脚本使用总结:
1.创建脚本时注意脚本执行的主机
2.脚本执行在服务器上的前提是服务器必须安装脚本内的执行命令
需要给监控项log.user的键值log.user添加图形
此处为自定义的图形
通过代理主机添加到服务端web的zabbix-agent2客户端在自定义监控项的时候,web端获取键值数据会比较慢(数据-proxy数据库-server数据库),若web长时间获取不到客户端数据可以尝试重启proxy服务
测试键值:
指定ip
区间ip
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。