zabbix详细介绍及其自动动态发现
zabbix3.2.1
第1章 安装
1.1 查看系统环境
[root@centos7-2 ~]#
[root@centos7-2 ~]# hostname -I
10.0.0.10 172.16.1.10
[root@centos7-2 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@centos7-2 ~]# uname -r
3.10.0-327.el7.x86_64
[root@centos7-2 ~]# uname -m
x86_64
[root@centos7-2 ~]#
1.2 部署
rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
# 安装zabbix,httpd,php
yum install -y zabbix-server-mysql zabbix-web-mysql
# 安装mariadb
yum -y install mariadb-server
systemctl start mariadb.service
# 创建数据库,权限
mysql
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
exit
# 导入数据库sql文件
zcat /usr/share/doc/zabbix-server-mysql-3.2.11/create.sql.gz|mysql -uzabbix -pzabbix zabbix
# 配置zabbix Server连接mysql
sed -i.ori '115a DBPassword=zabbix' /etc/zabbix/zabbix_server.conf
# 修改apache-php配置时区
sed -i.ori '18a php_value date.timezone Asia/Shanghai' /etc/httpd/conf.d/zabbix.conf
#启动并加入开机自启动
systemctl start zabbix-server
systemctl start httpd
systemctl enable zabbix-server.service httpd.service mariadb.service
# 只能在服务端操作,-s执行相应客户端IP 用来获取agent的相关信息
yum install zabbix-get -y
zabbix_get -s 172.16.1.11 -p 10050 -k "system.cpu.load[all,avg1]"
==================================================================
第2章 客户端
#配置 rpm
rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
#暗转zabbix-agent
yum install zabbix-agent -y
#修改zabbix-server的ip
sed -i.ori 's#Server=127.0.0.1#Server=172.16.1.10#' /etc/zabbix/zabbix_agentd.conf
#开机启动&自启动
systemctl start zabbix-agent.service
systemctl enable zabbix-agent
#编写自定义监控脚本
echo "UserParameter=nginx_status,who |wc -l" > /etc/zabbix/zabbix_agentd.d/userparameter_nginx.statu.conf
systemctl restart zabbix-agent.service
服务端测试命令
zabbix_get -s 172.16.1.11 -p 10050 -k "nginx_status"
2
第3章 配置zabbix_web
这里暂时选用一下zabbix3.4的配置界面。



此处没用使用ip地址,是因为数据库中只是授权localhost。
第4章 配置自动发现
4.1 配置模板
4.1.1 创建模板


4.1.2 创建应用集


4.1.3 创建监控项


4.1.4 创建触发器



4.1.5 图形界面显示


4.1.6 创建自动发现规则



4.1.7 自动发现关联模板




第5章 自动发现规则实现动态监控端口
5.1 脚本内容
#JSON格式的脚本
[root@zabbix-agent2 ~]# cat /etc/zabbix/script/discovery.sh
#!/bin/bash
portarray=(`netstat -tnlp|egrep -i "$1"|awk {'print $4'}|awk -F':' '{if ($NF~/^[0-9]*$/) print $NF}'|sort|uniq`)
#namearray=(`netstat -tnlp|egrep -i "$1"|awk {'print $7'}|awk -F'/' '{if ($NF != "Address") print $NF}'|uniq`)
length=${#portarray[@]}
printf "{\n"
printf '\t'"\"data\":["
for ((i=0;i<$length;i++))
do
printf '\n\t\t{'
printf "\"{#TCP_PORT}\":\"${portarray[$i]}\"}"
# printf "\"{#TCP_NAME}\":\"${namearray[$i]}\"}"
if [ $i -lt $[$length-1] ];then
printf ','
fi
done
printf "\n\t]\n"
printf "}\n"
#脚本给与 执行权限
[root@zabbix-agent2 ~]# chmod +x /etc/zabbix/script/discovery.sh
使用netstat命令输出端口号;-tnlp=Tcp协议+不显示别名+listen状态+显示程序名称;$1~$9表示输出的第几个参数;awk {'print $4'}表示输出第4个参数(如0.0.0.0:80);awk -F':' '{if ($NF~/^[0-9]*$/) print $NF}表示截取冒号后面的值,且只能是0~9的数字;|sort|uniq表示排序和去重。
脚本中注释掉的两行是用来监控服务的,只需替换掉其上的一行就是个扫描服务的脚本了。
5.2 测试脚本
[root@zabbix-agent2 ~]# sh /etc/zabbix/script/discovery.sh
{
"data":[
{"{#TCP_PORT}":"10050"},
{"{#TCP_PORT}":"111"},
{"{#TCP_PORT}":"20048"},
{"{#TCP_PORT}":"2049"},
{"{#TCP_PORT}":"22"},
{"{#TCP_PORT}":"41406"},
{"{#TCP_PORT}":"44522"},
{"{#TCP_PORT}":"58850"},
{"{#TCP_PORT}":"60859"}
]
}
5.3 脚本的key
[root@zabbix-agent2 ~]# cat /etc/zabbix/zabbix_agentd.d/userparameter_port.conf
UserParameter=listenport,/etc/zabbix/script/discovery.sh "$1"
5.4 重启agent
[root@zabbix-agent2 ~]# systemctl restart zabbix-agent.service
5.5 服务端测试
[root@zabbx-server ~]# zabbix_get -s 172.16.1.12 -p 10050 -k "listenport"
{
"data":[
{"{#TCP_PORT}":"10050"},
{"{#TCP_PORT}":"111"},
{"{#TCP_PORT}":"20048"},
{"{#TCP_PORT}":"2049"},
{"{#TCP_PORT}":"22"},
{"{#TCP_PORT}":"41406"},
{"{#TCP_PORT}":"44522"},
{"{#TCP_PORT}":"58850"},
{"{#TCP_PORT}":"60859"}
]
}
5.6 web界面配置
5.6.1 加模板


5.6.2 自动发现规则


5.6.3 创建监控项原型


5.6.4 创建触发器



5.6.5 添加图形


zabbix详细介绍及其自动动态发现的更多相关文章
- 日志模块详细介绍 hashlib模块 动态加盐
目录 一:hashlib模块 二:logging 一:hashlib模块 加密: 将明文数据通过一系列算法变成密文数据(目的就是为了数据的安全) 能够做文件一系列校验 python的hashlib提供 ...
- Android manifest之manifest标签详细介绍
AndroidManifest详细介绍 本文主要对AndroidManifest.xml文件中各个标签进行说明.索引如下: 概要PART--01 manifest标签PART--02 安全机制和per ...
- ubuntu文件目录详细介绍
/bin 二进制可执行命令 /dev 设备文件(硬盘/光驱等) /etc 系统管理和配置文件 /etc/rc.d 启动的配置文件和脚本 /home 用户主目录,下面会有以登录用户名作为文件夹名的各文件 ...
- Linux各目录及每个目录的详细介绍(转载)
[常见目录说明] 目录 /bin 存放二进制可执行文件(ls,cat,mkdir等),常用命令一般都在这里. /etc 存放系统管理和配置文件 /home 存放所有用户文件的根目录,是用户主目录的基点 ...
- 03-Linux各目录及每个目录的详细介绍
Linux各目录及每个目录的详细介绍 [常见目录说明] 目录 /bin 存放二进制可执行文件(ls,cat,mkdir等),常用命令一般都在这里. /etc 存放系统管理和配置文件 /home 存放所 ...
- 详细介绍Redis的几种数据结构以及使用注意事项(转)
原文:详细介绍Redis的几种数据结构以及使用注意事项 1. Overview 1.1 资料 <The Little Redis Book>,最好的入门小册子,可以先于一切文档之前看,免费 ...
- SpringMVC之六:Controller详细介绍
一.简介 在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层处理之后封装成一个Model ,然后再把该Mo ...
- kvm详细介绍
KVM详解,太详细太深入了,经典 2016-07-18 19:56:38 分类: 虚拟化 原文地址:KVM详解,太详细太深入了,经典 作者:zzjlzx KVM 介绍(1):简介及安装 http:// ...
- Linux 目录详细介绍
[常见目录说明] 目录 /bin 存放二进制可执行文件(ls,cat,mkdir等),常用命令一般都在这里. /etc 存放系统管理和配置文件 /home 存放所有用户文件的根目录,是用户主目录的基点 ...
随机推荐
- 解决Codeforces访问慢的本地方案
参考: http://m.blog.csdn.net/blog/Xiangamp/42245923#
- bzoj 4991 [Usaco2017 Feb]Why Did the Cow Cross the Road III(cdq分治,树状数组)
题目描述 Farmer John is continuing to ponder the issue of cows crossing the road through his farm, intro ...
- mysql 之 Workbench的使用
mysql 之 Workbench的使用 (1)简介 MySQL Workbench是一款专为MySQL设计的ER/数据库建模工具.它是著名的数据库设计工具DBDesigner4的继任者.你可以用My ...
- baidu 和 es 使用
http://www.cnblogs.com/kangoroo/p/8047586.html
- Balanced Binary Tree (二叉树DFS)
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- Ubuntu16.04安装deb文件时提示:此软件来自第三方且可能包含非自由组件
解决方式: 1.在Ubuntu软件中心安装GDebi. 2.安装好之后,选择这个要安装的deb文件右键,打开方式选择GDebi,然后输入管理员密码等待安装,期间如果不行需要重试几次. 3.另外的方法, ...
- mysql导入大型sql文件时注意事项
原文:http://blog.csdn.net/k21325/article/details/70808563 大型sql文件,需要在my.ini(windows)或者my.cnf(Linux)中设置 ...
- yarn之安装依赖包
安装依赖关系 yarn install用于安装项目的所有依赖项.依赖关系从您的项目package.json文件中检索,并存储在yarn.lock文件中. 开发包时,安装依赖关系最常见的是在 您刚刚检出 ...
- Unity3D研究之多语言用中文做KEY
做多语言的时候用中文做KEY绝对是有100%的优点,假设用英文表示那么代码里面给文字赋值的地方全都是英文.写的代码多了以后维护起来就没有人能看懂了,或者看起来非常费劲. 对PoolManager ...
- Android架构的简单探讨(一)
在CSDN上看到这样一篇译文,虽然最终的解决方案要按照自己特定的项目去设计,但该文还是引起了很多自己的共鸣,原文猛戳这里. 这是他提出的基于Messaging的MVC框架: 其中包含的设计思想在于:哪 ...