您的位置:首页 > 移动开发

监控方式实战之zabbix-snmp-jmx-trapper

2017-03-01 14:28 816 查看

SNMP配置手册

http://blog.sina.com.cn/s/blog_4b90b10f01014is1.html

TRAP是当满足某些条件了就是触发出一条信息,这条信息可以是通知,也可以是警报,比如说管理员登录进来后让系统发一条信息,管理员A在9点15的时候登录了服务器,或是做数据整理时在做到50%的时候发送一条信息出来。
这些信息你看完可能就看完了,但是你再需要他们回头查询的话就很费事,这时就帮上忙了,你可以指定说TRAP发信息时全都指到一个的服务器里,你每次查看信息也可以到服务里看就行了。这样历史LOG也不会丢。


snmp的日志等级分为7个等级
0 或 ! —— LOG_EMERG
1 或 a —— LOG_ALERT
2 或 c —— LOG_CRIT
3 或 e —— LOG_ERR
4 或 w —— LOG_WARNING
5 或 n —— LOG_NOTICE
6 或 i —— LOG_INFO
7 或 d —— LOG_DEBUG
既然已经知道了日志等级了,接下来就直接修改配置文件吧。
vi /etc/sysconfig/snmpd.options
加入以下一行配置,然后保存退出。
OPTIONS="-LS3d -Lf /dev/null -p /var/run/snmpd.pid -a"


OPTIONS="-LS 0-4 d -Lf /dev/null -p /var/run/snmpd.pid -a"

snmp 监听端口修改

最简单的实现如下:
/usr/sbin/snmpd tcp:端口或/usr/sbin/snmpd udp:端口

或vi /etc/rc.d/init.d/snmpd
修改前 OPTIONS="-Lsd -Lf /dev/null -p /var/run/snmpd.pid -a"
修改后 OPTIONS=" tcp:9999 -Lsd -Lf /dev/null -p /var/run/snmpd.pid -a"
/etc/rc.d/init.d/snmpd start就行了。

SNMP监控 :

4.1 LINUX服务器

4.1.1 准备工作

linux安装系统盘或下载的软件包net-snmp-5.4.3.tar.gz

4.1.2 安装方法

安装SNMP相关软件包:net-snmp-5.4.3.tar.gz安装SNMP软件:# tar -zxvf /winshare/net-snmp-5.4.3.tar.gz# cd ./ net-snmp-5.4.3#./configure –prefix=/usr/local/snmp//配置指定安装目录安装过程中,询问信息可直接回车,默认即可。# make# make install

4.1.3 配置SNMP文件

安装完成后,执行:# /usr/local/bin/snmpconfI can create the following types ofconfiguration files for you.Select the file type you wish tocreate:(you can create more than one as yourun this program) 1: snmpd.conf 2: snmptrapd.conf 3: snmp.confOther options: quitSelect File: 1在出现菜单中,选择1The configuration information whichcan be put into snmpd.conf is dividedinto sections. Select aconfiguration section for snmpd.confthat you wish to create: 1: MonitorVarious Aspects of the Running Host 2: AgentOperating Mode 3: Extending the Agent 4: AccessControl Setup 5: TrapDestinations 6: SystemInformation SetupOther options: finishedSelect section: 4在出现菜单中,选择4Section: Access ControlSetupDescription: This section defineswho is allowed to talk to your running snmpagent.Select from: 1: aSNMPv3 read-write user 2: aSNMPv3 read-only user 3: aSNMPv1/SNMPv2c read-only access community name 4: aSNMPv1/SNMPv2c read-write access community nameOther options: finished,listSelect section: 3在出现菜单中,选择3,配置v1和v2c版本的只读community字。Configuring: rocommunityDescription: a SNMPv1/SNMPv2cread-only access community name arguments: community [default|hostname|network/bits] [oid]The community name to add read-onlyaccess for: public提示输入只读community字,这里输入public。The hostname or network address toaccept this community name from [RETURN for all]: 提示通过此community字访问设备的网段及主机地址,这里可以直接输入回车确认,表示全部。The OID that this community should berestricted to [RETURN for no-restriction]:提示可以访问的OID范围,这里直接回车确认,表示全部OID。Finished Output:community public配置后返回菜单,输入finished,退到上一级菜单,在顶级菜单输入quit,提示配置文件建立成功:I can create the following types ofconfiguration files for you.Select the file type you wish tocreate:(you can create more than one as yourun this program) 1: snmpd.conf 2: snmptrapd.conf 3: snmp.confOther options: quitSelect File: quitThe following files werecreated: snmpd.conf

4.1.4 启动SNMP服务

# /usr/local/sbin/snmpd -c/usr/bin/snmpd.conf

4.1.5 验证SNMP服务

# ps –ef|grep snmproot 6827 1 0 02:38? 00:00:00 /usr/local/sbin/snmpd -c /usr/bin/snmpd.confroot 6829 21311 76 02:38 pts/2 00:00:00 grep snmp客户端可以使用SolarWinds Engineers Edition,检测liunx系统的各项参数。

1.1 交换机

1.3 中兴交换机

使用以下配置命令前,均需要执行以下步骤:1.登陆交换机。(可以使用串口线直接连接,如果交换机配置有管理IP并且允许telnet登陆,则也可以通过telnet进行登陆。)2.输入enable命令进入特权模式。3.输入config terminal进行配置模式。使用完配置命令后,均需要执行以下步骤进行保存:1.输入end命令退出配置模式。2.write保存配置文件。

1.3.1 SNMP配置

1. 配置snmp的只读communitysnmp-server community public view test rosnmp-server view DefaultView system includedsnmp-server view AllView internet includedsnmp-server view test zxr10IPAddrTableincludedsnmp-server view test zte includedsnmp-server view test mib-2 included

1.3.2 TRAP配置

1.配置交换机允许发送trapsnmp-server enable trap2.配置交换机接收trap的主机snmp-server host 192.168.2.74 trap version 2cpublic 指定交换机SNMPTrap的接收者为192.168.2.74,发送Trap时采用public作为字串

1.3.3 Syslog配置

1.打开交换机的syslog功能syslog on2. 直接配置相应的syslog发送到的接收主机,192.168.2.74为该主机的ip地址。syslog server 192.168.2.743.选择发送warning以上级别的log信息。syslog level warnings

IPMI:

建议: 使用自定义 item, 本地执行 ipmitool 命令来获取文件

Java gateway

1, 安装 yum install -y zabbix-java-gateway java-1.8.0
2, 配置 vim /etc/zabbix/zabbix_java_gateway.conf
3, 启动 systemctl start zabbix-java-gateway.service

4, 端口 进程

5, vim /etc/zabbix/zabbix-server/zabix.conf
6, 重启 zabbix-server

mv apache-tomcat-8.0.36 /usr/local/
ln -s /usr/local/apache-tomcat-8.0.36 /usr/local/tomcat

JMX 三种类型: 1, 无密码认证 2, 用户名密码 3, SSL

开启JMX 远程监控:

vim /usr/local/tomcat/bin/catalina.sh

CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8888
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false

Djava.rmi.server.hostname=192.168.1.1"

手动检测监控状态:

zabbix_get -s 192.168.56.12 -k

开启Nginx 监控

编写脚本来进行数据采集

设置用户自定义参数

重启zabbix-agent

5. 添加item
6. 创建图形
7. 创建触发器
8. 创建模板

1, 脚本
2, 上传到 /etc/zabbix/zabbix_agentd.conf

自定义告警脚本:

1, 放在 cd /usr/lib/zabbix/alertscripts
2, 要支持三个参数

3,

短信通道

监控Mysql : 使用percona plugin

yum install percona-zabbix-templates php php-mysql

http://www.percona.com

1, 监控主机多, 性能跟不上, 延迟大
2, 多机房 防火墙

Zabbix 轻松解决。 Nagios 不太好解决
针对Agent来说

1, 主动模式 active

2, 被动模式

当监控主机超过300+ , 建议使用主动模式。

开启主动模式:
/etc/zabbix/zabbix_agent.conf

Zabbix-server -> zabbix proxy -> zabbix agent

vim /etc/zabbix/zabbix_proxy.conf

grep '^[a-Z]' /etc/zabbix/zabbix_proxy.conf

Server=192.168.1.1
Hostname=zabbix-proxy
LogFile=/var/log/zabbix/zabbix_proxy.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_proxy.pid
DBHost=localhost
DBName=zabbix_proxy
DBUser=zabbix_proxy
DBPassword=zabbix_proxy
SNMPTrapperFile=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000

systemctl start zabbix-proxy

centos 7 补全: yum -y install bash-completion
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  实战 zabbix