zabbix监控-上

zabbix监控角度总结


1.监控系统层面

用zabbix自带的默认模板就可以实现

2.监控网站的PV、UV、IP

方法一.

	使用第三方网站进行监控,例如:百度统计   https://tongji.baidu.com
	具体的配置步骤在网站上有介绍
	PS:如果没有经验的话,将第三方统计代码的加入业务代码的操作,可以交给开发来实现,减少操作错误

方法二.

	我们可以使用开源软件自建分析平台,例如:matomo   官网地址:  https://matomo.org/
	具体的安装、配置步骤我会在下面有写

Matomo的安装

背景

我们在这搭建Discuz博客网站实现统计PV、UV、IP

主机:
	10.0.0.142	DIscuz博客网站
	10.0.0.143	Matomo分析平台

安装步骤

1.下载nginx,并进行配置
[root@web ~]# yum install -y nginx
[root@web ~]# cat /etc/nginx/conf.d/discuz.ming.com.conf
server{
	listen 80;
	server_name discuz.ming.com;
	root /discuz;

	location / {
		index index.php index.html index.htm;
	}

	location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

}

2.创建资源目录、上传数据并授权
[root@web ~]# mkdir /html
[root@web ~]# unzip Discuz_X3.4_SC_UTF8_0802.zip 
[root@web ~]# mv upload/* /html
[root@web ~]# chown -R nginx:nginx /html

3. 安装php模块
[root@web ~]# yum install php-fpm php-gd php-mysqli -y
[root@web ~]# vim /etc/php-fpm.d/www.conf 	#修改user和group为nginx用户

4. 安装数据库
[root@web ~]# yum install -y mariadb-server
[root@web ~]# mysql
	create database bbs;
	MariaDB [(none)]> grant all privileges on bbs.* to rel@localhost identified by '123456';
	MariaDB [(none)]> flush privileges;
	
[root@web ~]# mysql_secure_installation 			#输入一次y之后一路回车

5.启动所有服务
[root@web ~]# systemctl start mariadb.service
[root@web ~]# systemctl enable mariadb.service
[root@web ~]# systemctl start php-fpm
[root@web ~]# systemctl enable php-fpm
[root@web ~]# nginx -t
[root@web ~]# systemctl enable nginx
[root@web ~]# systemctl start nginx

##再进行页面配置,至此我们的博客系统搭建完成,下面是我们重要的matomo

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

安装前需知:
1.web所用apache或nginx
2,PHP
	Matomo 3.x 需要 PHP5.5.9或PHP 7.x  
	Matomo 4.x 需要 PHP 7.2.5 +      (PHP 8 仅支持 Matomo 4)
3.数据库
	MySQL 5.5 +, 或者 MariaDB
	默认情况,PHP需要 pdo 和 pdo_mysql ,或mysqli扩展,我们直接安装php72w-mysqlnd
	MySQL需要一个用户名和密码,该用户需要对matomo的库有权限(all privileges)


进行安装:(matomo版本4.0)
1.下载nginx,并进行配置

[root@matomo ~] # yum install -y nginx
[root@matomo ~]# cat /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;


    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        server_name  _;
        root         /html;

        include /etc/nginx/default.d/*.conf;

        location / {
		index index.php index.html index.htm;
        }

	location ~ \.php$ {
            root           /html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }


        
    }


}


[root@matomo ~]# nginx -t
[root@matomo ~]# systemctl start nginx
[root@matomo ~]# systemctl enable nginx

2.php配置源并安装
[root@matomo ~]# yum install epel-release -y
[root@matomo ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[root@matomo ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@matomo ~]# yum install php72w-fpm php72w-mysqlnd php72w-gd php72w-mbstring php72w-xml -y
[root@matomo ~]# vim /etc/php-fpm.d/www.conf 	#修改user和group为nginx用户
[root@matomo ~]# systemctl start php-fpm
[root@matomo ~]# systemctl enable php-fpm

3.创建资源站点目录、上传数据并授权
[root@matomo ~]# mkdir /html
[root@matomo ~]# cd /html
[root@matomo ~]# rz -E    #软件包在我的资源里有,可以去下载
[root@matomo /html]# unzip matomo-latest.zip 
[root@matomo /html]# rm -fr matomo-latest.zip 
[root@matomo /html]# rm -fr How\ to\ install\ Matomo.html 
[root@matomo /html]# mv matomo/* .
[root@matomo /html]# chown -R nginx:nginx .
[root@matomo /html]# systemctl restart php-fpm


4.数据库,用的是DIscuz的Mariadb,新创建个库,和用户,并且授权
	create database matomo;
	MariaDB [(none)]> grant all privileges on matomo.* to matomo@localhost identified by '123456';
	MariaDB [(none)]> flush privileges;

##进行页面的配置,连接数据库的时候,指定远端的10.0.0.142的数据库就可以

3.监控数据库的一系列状态

方法:
1.上传percona-zabbix-templates-1.1.8-1.noarch.rpm,并安装
[root@web ~]# rpm -ivh percona-zabbix-templates-1.1.8-1.noarch.rpm 
warning: percona-zabbix-templates-1.1.8-1.noarch.rpm: Header V4 DSA/SHA1 Signature, key ID cd2efd2a: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:percona-zabbix-templates-1.1.8-1 ################################# [100%]

Scripts are installed to /var/lib/zabbix/percona/scripts
Templates are installed to /var/lib/zabbix/percona/templates

2.将zabbix配置文件放在指定目录下
[root@web ~]# mv /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix/zabbix_agent2.d/
[root@web ~]# systemctl restart zabbix-agent2.service

3.用percona这个我们需要安装php的环境
[root@web ~]# yum install php-cli php-mysqlnd -y 或者php72w-cli php72w-mysqlnd

4.修改连接数据库的账号密码
[root@web ~]# vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php 数据库账号密码

5.在zabbix-server端进行zabbix-get调试取值
[root@zabbix-server ~]# zabbix_get -s 10.0.0.142 -k MySQL.Open-fileszabbix-server

6.导入zabbix的mysql模板,上面的版本太过老旧,导入我上传在CSDN上的资源中的mysql的zabbix_mysql模板


-------------------------------------------------------------------------------------------------------------------------------------------------------------

#由于可能我们数据库非常重要,不可能在数据库服务器上乱装一些php,所以我们会选择远端连接数据库进行监控指标
#选择在web服务器上连接数据库进行监控指标(选择在哪,具体可按照情况来)
	web 	10.0.0.142
	Mysql 	10.0.0.143	(数据库账号,root,密码123456)


1.在web上的操作与上面类似,需要修改一下脚本文件:(修改内容如下)
[root@web ~]# vim /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh 
	HOST=10.0.0.143		#远端数据库的ip地址
	RES=`HOME=~zabbix mysql  -uroot -p123456 -h 10.0.0.143 -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`
	
[root@web ~]#  vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'root';
$mysql_pass = '123456';



2.在zabbix-server端进行zabbix-get调试取值			#在这我们我们是通过142主机取得143数据库上的数据
[root@zabbix-server ~]# zabbix_get -s 10.0.0.142 -k MySQL.Open-fileszabbix-server

3.在zabbix的WEB界面导入zabbix的mysql模板,添加主机

4.snmp监控交换机、路由

#linux、windows
不能安装zabbix-agent的设备,都可以使用snmp监控

snmp协议: simple network manager protocol

OID:监控标准都有一个唯一的id,Object ID

例如:1.3.6.1.2.1.2.2.1.11	接口收到的数据包个数
详情借鉴    https://blog.csdn.net/osmeteor/article/details/19043891?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-12.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-12.control

MIB

存储所有oid信息

snmp协议版本

v1
v2c  	-c commuity (密码,口令)
v3

取值,测试

yum install net-snmp-utils.x86_64 -y
#snmpget 每次只能取一个值
#snmpwalk 范围性的取值		采用这个

[root@zabbix-server ~]# snmpwalk -v 2c -c ming 10.0.0.8 .1.3.6.1.2.1.25.2.2.0		(密码ming,是由服务端设置的)

剩下的zabbix页面添加主机指定snmp添加就可以,记得需指定版本v2c和community

5.zabbix_server自动发现和自动注册

在生产上我们使用自动注册
#自动发现:Server端是主动的一方,当我们的agent端数量非常庞大的时候,我们的Server带来的压力会非常之大
#自动注册:agent端是主动的一方,当新起几千台机器,我们的agentagent主动向zabbix-server索要任务清单,根据清单采集所有监控项,一次性发送给zabbix-server

6.Agent的主动和被动的区别

主动:如果有100个监控项,zabbix-server对agent进行100次取值		
被动:如果有100个监控项,agent主动向zabbix-server索要任务清单,根据清单采集所有监控项,一次性发送给zabbix-server		##生产采取

Agent被动模式的配置文件的配置

WEB:
vim /etc/zabbix/zabbix_agent2.conf
Server=10.0.0.71
ServerActive=10.0.0.71
Hostname=10.0.0.142
HostMetadata=web

DB:
vim /etc/zabbix/zabbix_agent2.conf
Server=10.0.0.71
ServerActive=10.0.0.71
Hostname=10.0.0.51
HostMetadata=db

在这里插入图片描述

7.物理层的监控

物理方面:
	CPU温度、主板温度、功率、电压、风扇转速等

1.云主机不用进行监控

2.物理机可用ipmitool工具监控
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

登高·

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值