zabbix 监控lvs 我想像中比较好弄,但是实际中遇到了权限的问题。记下,供有需要的朋友参考。
一、环境说明
zabbix:2.0.6
ipvsadm:1.24
OS:CentOS 5.4 x86
dip:192.168.100.14
rip:192.168.100.22
rip:192.168.100.24
rip:192.168.100.76
rip:192.168.100.101
二、新建脚本
点击(此处)折叠或打开
[root@lvs-master zabbix]# pwd
/etc/zabbix
[root@lvs-master zabbix]# cat lvs-status.sh
-
!/bin/bash
-
get lvs connection @2013/09/12 by v1
-
author:lizonggang
function AllConn {
sudo /sbin/ipvsadm -L -n |awk '{print 1}END{print sum}'
}
function 101Conn {
sudo /sbin/ipvsadm -L -n | grep 100.101|awk '{print $5}'
}
function 22Conn {
sudo /sbin/ipvsadm -L -n | grep 100.22|awk '{print $5}'
}
function 24Conn {
sudo /sbin/ipvsadm -L -n | grep 100.24|awk '{print $5}'
}
function 76Conn {
sudo /sbin/ipvsadm -L -n | grep 100.76|awk '{print $5}'
}
function AllInConn {
sudo /sbin/ipvsadm -L -n |awk '{print 1}END{print sum}'
}
function 101InConn {
sudo /sbin/ipvsadm -L -n | grep 100.101|awk '{print $6}'
}
function 22InConn {
sudo /sbin/ipvsadm -L -n | grep 100.22|awk '{print $6}'
}
function 24InConn {
sudo /sbin/ipvsadm -L -n | grep 100.24|awk '{print $6}'
}
function 76InConn {
sudo /sbin/ipvsadm -L -n | grep 100.76|awk '{print $6}'
}
-
Run the requested function
$1
**三、修改配置文件
点击(此处)折叠或打开
zabbix agent 添加如下,并重启agent.
[root@lvs-master zabbix]# vim zabbix_agentd.conf
-
ipvsadm Active
UserParameter=lvs.AllConn[*],/etc/zabbix/lvs-status.sh AllConn
UserParameter=lvs.101Conn[*],/etc/zabbix/lvs-status.sh 101Conn
UserParameter=lvs.22Conn,/etc/zabbix/lvs-status.sh 22Conn
UserParameter=lvs.24Conn,/etc/zabbix/lvs-status.sh 24Conn
UserParameter=lvs.76Conn,/etc/zabbix/lvs-status.sh 76Conn
-
ipvsadm InActive
UserParameter=lvs.AllInConn,/etc/zabbix/lvs-status.sh AllInConn
UserParameter=lvs.101InConn,/etc/zabbix/lvs-status.sh 101InConn
UserParameter=lvs.22InConn,/etc/zabbix/lvs-status.sh 22InConn
UserParameter=lvs.24InConn,/etc/zabbix/lvs-status.sh 24InConn
UserParameter=lvs.76InConn,/etc/zabbix/lvs-status.sh 76InConn** [root@lvs-master zabbix]# chmod +x lvs-status.sh
四、排错
由于之前lvs-status.sh 脚本没有加入sudo ,所以看agent日志报如下:
[root@lvs-master zabbix]# tail -f /tmp/zabbix_agentd.log
Can't initialize ipvs: Permission denied (you must be root)
Are you sure that IP Virtual Server is built in the kernel or as module?
但是加入sudo 又报如下:
sudo: sorry, you must have a tty to run sudo
最终解决办法是visudo 修改如下:
点击(此处)折叠或打开
[root@lvs-master ~]# visudo
-
Defaults requiretty
添加
zabbix ALL=(ALL) NOPASSWD:/sbin/ipvsadm
问题是解决了,但是不知道#Defaults requiretty 这样会不会有其它的问题??
五、****zabbix server 测试
点击(此处)折叠或打开
- [root@jumper ~]# zabbix_get -s 192.168.100.14 -p 10050 -k "lvs.AllConn"
- 2326
六、****导入模板(请根据自己的需要,添加/修改/删除)
点击(此处)折叠或打开
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export version="1.0" date="26.12.12" time="12.00">
<hosts>
<host name="LVS Status">
<proxy_hostid>0</proxy_hostid>
<useip>1</useip>
<dns></dns>
<ip>127.0.0.1</ip>
<port>10050</port>
<status>3</status>
<useipmi>0</useipmi>
<ipmi_ip>127.0.0.1</ipmi_ip>
<ipmi_port>623</ipmi_port>
<ipmi_authtype>0</ipmi_authtype>
<ipmi_privilege>2</ipmi_privilege>
<ipmi_username></ipmi_username>
<ipmi_password></ipmi_password>
<groups>
<group>Freetrade</group>
</groups>
<triggers/>
<items>
<item type="7" key="lvs.AllConn" value_type="3">
<description>lvs.AllConn connections</description>
<ipmi_sensor></ipmi_sensor>
<delay>30</delay>
<history>365</history>
<trends>365</trends>
<status>0</status>
<data_type>0</data_type>
<units></units>
<multiplier>0</multiplier>
<delta>0</delta>
<formula>0</formula>
<lastlogsize>0</lastlogsize>
<logtimefmt></logtimefmt>
<delay_flex></delay_flex>
<authtype>0</authtype>
<username></username>
<password></password>
<publickey></publickey>
<privatekey></privatekey>
<params></params>
<trapper_hosts>localhost</trapper_hosts>
<snmp_community></snmp_community>
<snmp_oid></snmp_oid>
<snmp_port>161</snmp_port>
<snmpv3_securityname></snmpv3_securityname>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase></snmpv3_authpassphrase>
<snmpv3_privpassphrase></snmpv3_privpassphrase>
<applications>
<application>LVS</application>
</applications>
</item>
<item type="7" key="lvs.101Conn" value_type="3">
<description>lvs.101Conn connections</description>
<ipmi_sensor></ipmi_sensor>
<delay>30</delay>
<history>365</history>
<trends>365</trends>
<status>0</status>
<data_type>0</data_type>
<units></units>
<multiplier>0</multiplier>
<delta>0</delta>
<formula>0</formula>
<lastlogsize>0</lastlogsize>
<logtimefmt></logtimefmt>
<delay_flex></delay_flex>
<authtype>0</authtype>
<username></username>
<password></password>
<publickey></publickey>
<privatekey></privatekey>
<params></params>
<trapper_hosts>localhost</trapper_hosts>
<snmp_community></snmp_community>
<snmp_oid></snmp_oid>
<snmp_port>161</snmp_port>
<snmpv3_securityname></snmpv3_securityname>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase></snmpv3_authpassphrase>
<snmpv3_privpassphrase></snmpv3_privpassphrase>
<applications>
<application>LVS</application>
</applications>
</item>
<item type="7" key="lvs.22Conn" value_type="3">
<description>lvs.22Conn connections</description>
<ipmi_sensor></ipmi_sensor>
<delay>30</delay>
<history>365</history>
<trends>365</trends>
<status>0</status>
<data_type>0</data_type>
<units></units>
<multiplier>0</multiplier>
<delta>0</delta>
<formula>0</formula>
<lastlogsize>0</lastlogsize>
<logtimefmt></logtimefmt>
<delay_flex></delay_flex>
<authtype>0</authtype>
<username></username>
<password></password>
<publickey></publickey>
<privatekey></privatekey>
<params></params>
<trapper_hosts>localhost</trapper_hosts>
<snmp_community></snmp_community>
<snmp_oid></snmp_oid>
<snmp_port>161</snmp_port>
<snmpv3_securityname></snmpv3_securityname>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase></snmpv3_authpassphrase>
<snmpv3_privpassphrase></snmpv3_privpassphrase>
<applications>
<application>LVS</application>
</applications>
</item>
<item type="7" key="lvs.24Conn" value_type="3">
<description>lvs.24Conn connections</description>
<ipmi_sensor></ipmi_sensor>
<delay>30</delay>
<history>365</history>
<trends>365</trends>
<status>0</status>
<data_type>0</data_type>
<units></units>
<multiplier>0</multiplier>
<delta>0</delta>
<formula>0</formula>
<lastlogsize>0</lastlogsize>
<logtimefmt></logtimefmt>
<delay_flex></delay_flex>
<authtype>0</authtype>
<username></username>
<password></password>
<publickey></publickey>
<privatekey></privatekey>
<params></params>
<trapper_hosts>localhost</trapper_hosts>
<snmp_community></snmp_community>
<snmp_oid></snmp_oid>
<snmp_port>161</snmp_port>
<snmpv3_securityname></snmpv3_securityname>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase></snmpv3_authpassphrase>
<snmpv3_privpassphrase></snmpv3_privpassphrase>
<applications>
<application>LVS</application>
</applications>
</item>
<item type="7" key="lvs.76Conn" value_type="3">
<description>lvs.76Conn connections</description>
<ipmi_sensor></ipmi_sensor>
<delay>30</delay>
<history>365</history>
<trends>365</trends>
<status>0</status>
<data_type>0</data_type>
<units></units>
<multiplier>0</multiplier>
<delta>0</delta>
<formula>0</formula>
<lastlogsize>0</lastlogsize>
<logtimefmt></logtimefmt>
<delay_flex></delay_flex>
<authtype>0</authtype>
<username></username>
<password></password>
<publickey></publickey>
<privatekey></privatekey>
<params></params>
<trapper_hosts>localhost</trapper_hosts>
<snmp_community></snmp_community>
<snmp_oid></snmp_oid>
<snmp_port>161</snmp_port>
<snmpv3_securityname></snmpv3_securityname>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase></snmpv3_authpassphrase>
<snmpv3_privpassphrase></snmpv3_privpassphrase>
<applications>
<application>LVS</application>
</applications>
</item>
<item type="7" key="lvs.AllInConn" value_type="3">
<description>lvs.AllInConn connections</description>
<ipmi_sensor></ipmi_sensor>
<delay>30</delay>
<history>365</history>
<trends>365</trends>
<status>0</status>
<data_type>0</data_type>
<units></units>
<multiplier>0</multiplier>
<delta>0</delta>
<formula>0</formula>
<lastlogsize>0</lastlogsize>
<logtimefmt></logtimefmt>
<delay_flex></delay_flex>
<authtype>0</authtype>
<username></username>
<password></password>
<publickey></publickey>
<privatekey></privatekey>
<params></params>
<trapper_hosts>localhost</trapper_hosts>
<snmp_community></snmp_community>
<snmp_oid></snmp_oid>
<snmp_port>161</snmp_port>
<snmpv3_securityname></snmpv3_securityname>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase></snmpv3_authpassphrase>
<snmpv3_privpassphrase></snmpv3_privpassphrase>
<applications>
<application>LVS</application>
</applications>
</item>
<item type="7" key="lvs.101InConn" value_type="3">
<description>lvs.101InConn connections</description>
<ipmi_sensor></ipmi_sensor>
<delay>30</delay>
<history>365</history>
<trends>365</trends>
<status>0</status>
<data_type>0</data_type>
<units></units>
<multiplier>0</multiplier>
<delta>0</delta>
<formula>0</formula>
<lastlogsize>0</lastlogsize>
<logtimefmt></logtimefmt>
<delay_flex></delay_flex>
<authtype>0</authtype>
<username></username>
<password></password>
<publickey></publickey>
<privatekey></privatekey>
<params></params>
<trapper_hosts>localhost</trapper_hosts>
<snmp_community></snmp_community>
<snmp_oid></snmp_oid>
<snmp_port>161</snmp_port>
<snmpv3_securityname></snmpv3_securityname>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase></snmpv3_authpassphrase>
<snmpv3_privpassphrase></snmpv3_privpassphrase>
<applications>
<application>LVS</application>
</applications>
</item>
<item type="7" key="lvs.22InConn" value_type="3">
<description>lvs.22InConn connections</description>
<ipmi_sensor></ipmi_sensor>
<delay>30</delay>
<history>365</history>
<trends>365</trends>
<status>0</status>
<data_type>0</data_type>
<units></units>
<multiplier>0</multiplier>
<delta>0</delta>
<formula>0</formula>
<lastlogsize>0</lastlogsize>
<logtimefmt></logtimefmt>
<delay_flex></delay_flex>
<authtype>0</authtype>
<username></username>
<password></password>
<publickey></publickey>
<privatekey></privatekey>
<params></params>
<trapper_hosts>localhost</trapper_hosts>
<snmp_community></snmp_community>
<snmp_oid></snmp_oid>
<snmp_port>161</snmp_port>
<snmpv3_securityname></snmpv3_securityname>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase></snmpv3_authpassphrase>
<snmpv3_privpassphrase></snmpv3_privpassphrase>
<applications>
<application>LVS</application>
</applications>
</item>
<item type="7" key="lvs.24InConn" value_type="3">
<description>lvs.24InConn connections</description>
<ipmi_sensor></ipmi_sensor>
<delay>30</delay>
<history>365</history>
<trends>365</trends>
<status>0</status>
<data_type>0</data_type>
<units></units>
<multiplier>0</multiplier>
<delta>0</delta>
<formula>0</formula>
<lastlogsize>0</lastlogsize>
<logtimefmt></logtimefmt>
<delay_flex></delay_flex>
<authtype>0</authtype>
<username></username>
<password></password>
<publickey></publickey>
<privatekey></privatekey>
<params></params>
<trapper_hosts>localhost</trapper_hosts>
<snmp_community></snmp_community>
<snmp_oid></snmp_oid>
<snmp_port>161</snmp_port>
<snmpv3_securityname></snmpv3_securityname>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase></snmpv3_authpassphrase>
<snmpv3_privpassphrase></snmpv3_privpassphrase>
<applications>
<application>LVS</application>
</applications>
</item>
<item type="7" key="lvs.76InConn" value_type="3">
<description>lvs.76InConn connections</description>
<ipmi_sensor></ipmi_sensor>
<delay>30</delay>
<history>365</history>
<trends>365</trends>
<status>0</status>
<data_type>0</data_type>
<units></units>
<multiplier>0</multiplier>
<delta>0</delta>
<formula>0</formula>
<lastlogsize>0</lastlogsize>
<logtimefmt></logtimefmt>
<delay_flex></delay_flex>
<authtype>0</authtype>
<username></username>
<password></password>
<publickey></publickey>
<privatekey></privatekey>
<params></params>
<trapper_hosts>localhost</trapper_hosts>
<snmp_community></snmp_community>
<snmp_oid></snmp_oid>
<snmp_port>161</snmp_port>
<snmpv3_securityname></snmpv3_securityname>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase></snmpv3_authpassphrase>
<snmpv3_privpassphrase></snmpv3_privpassphrase>
<applications>
<application>LVS</application>
</applications>
</item>
</items>
</host>
</hosts>
<dependencies/>
</zabbix_export>
七、****添加图型
web界面添加图型。