During this period of time, the server status is monitored.SNMPProtocol.SNMPInstallation configuration andPythonExtensionSNMPRecord it for later reference.
I. Installation SNMP 1 , Linux Install Net-snmp
Environment:Centos 6.3 _ 64
1.1PassYumSearchSNMPComplete name
Yum search SNMP
1.2InstallNet-snmp
Yum install net-snmp-y
Installed successfully. Version:5.5:
1.3Change configuration file
File Path:/Etc/snmp/snmpd. conf
Modify the following key points based on the default configuration file:
Note:
41The default value does not need to be changed.PublicThe key is to use it later.
47Rows and48Row isSNMPProtocol version.
57Rows and64Row useAllOpen the permission (note that this is onlyDemo)
1.4StartSNMPService
/Etc/init. d/snmpd start
Or
Service snmpd start
Configure boot start:
Chkconfig snmpd on
1.5VerifySNMP
Snmpwalk-V 1-C public ipaddr. 1
Appendix:
If the service cannot run properly after it is started, first check the Firewall Status:/Etc/init. d/iptables status
Perform the following operations as needed:
Temporarily disable the Firewall:/Etc/init. d/iptables stop
Permanently disable the Firewall:Chkconfig -- level 35 iptables off
Set161Port and162Port setting through Firewall:
VI/etc/sysconfig/iptables
Add the following content:
-A input-M state -- state new-m udp-p udp -- dport 161-J accept
-A input-M state -- state new-m udp-p udp -- dport 162-J accept
:
RestartIptablesService:
Service iptables restart
Or
/Etc/init. d/iptables restart
2 , Windows Install Net-snmp
URL:Http://sourceforge.net/projects/net-snmp/files/
Download path:Http://hivelocity.dl.sourceforge.net/project/net-snmp/net-snmp%20binaries/5.5.1-binaries/net-snmp-5.5.1-1.x86.exe
There are more detailed tutorials on the Internet, so I will not go into details here,
For details, refer to here:Http://www.cnblogs.com/VRS_technology/archive/2010/08/12/1798191.html
Key point: in the path (software installation path)\ Etc \ SNMP \, Add a fileSnmpd. conf(My approach isLinuxUnderSnmpd. confFile directlyCopy).
Ii. Use Python Extension SNMP
InSnmpd. confThe file containsBashExample of extension ,:
My version is5.5I don't know why, although the configuration file is usedExecBut I found thatExtend.
BashConfiguration:
Extend. 1.3.6.1.4.1.23456.51 shelltest2/bin/sh/tmp/test1.sh
PythonConfiguration:
Extend. 1.3.6.1.4.1.23456.52 pythontest/usr/bin/Python/tmp/test1.py
Test1.shThe content is as follows:
#! /Bin/ShEcho "123"Exit22
Test1.pyThe content is as follows:
#! /Usr/bin/PythonPrint "Just a test"
RestartSnmpdService:
Service snmpd restart
SnmpwalkAccess:
Snmpwalk-V 1-C public localhost. 1.3.6.1.4.1.23456.50.4.1
Snmpwalk-V 1-C public localhost. 1.3.6.1.4.1.23456.51.4.1
Snmpwalk-V 1-C public localhost. 1.3.6.1.4.1.23456.52.4.1
Execution result
We can see thatExtendBoth configurations are successfully executed.
If the following error occurs, disableSELinux:
String: "/usr/bin/Python: Can't open file '/tmp/test1.py': [errno 13] Permission denied"
Appendix:
ViewSELinuxStatus:Getenforce
Temporarily closeSELinux(No need to restart ):Setenforce 0
Permanently closeSELinux(Restart required ):
VI/etc/SELinux/config
SetSELinux = enforcingChangeSELinux = Disable,:
3. Implement Custom Service Status Monitoring
This is actually something in the second part. It is listed separately to introduce a cross-platform server status monitoring.PythonModule:Psutil
PsutilIs used to obtain information about running processes and systemsCPUAnd memory usage (supportedLinux, OS X, and FreeBSDAndWindowsSystem ).
URL:Https://github.com/elventear/psutil
PythonCode(Getcpuusage. py):
#! /Usr/bin/PythonImportPsutilPrintPsutil. cpu_percent ()
Snmpd. confConfiguration:
Extend. 1.3.6.1.4.1.23456.60 getcpuusage/usr/bin/Python/tmp/getcpuusage. py