Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1653421
  • 博文数量: 135
  • 博客积分: 2820
  • 博客等级: 少校
  • 技术积分: 2544
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-16 13:33
文章分类

全部博文(135)

文章存档

2015年(1)

2014年(8)

2013年(16)

2012年(43)

2011年(56)

2010年(11)

分类: LINUX

2013-09-12 16:59:05


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


二、新建脚本 

点击(此处)折叠或打开

  1. [root@lvs-master zabbix]# pwd
  2. /etc/zabbix


  3. [root@lvs-master zabbix]# cat lvs-status.sh
  4. #!/bin/bash
  5. # get lvs connection @2013/09/12 by v1
  6. # author:lizonggang


  7. function AllConn {
  8.         sudo /sbin/ipvsadm -L -n |awk '{print $5}'| awk 'BEGIN{sum=0}{sum+=$1}END{print sum}'
  9. }
  10. function 101Conn {
  11.         sudo /sbin/ipvsadm -L -n | grep 100.101|awk '{print $5}'
  12. }
  13. function 22Conn {
  14.         sudo /sbin/ipvsadm -L -n | grep 100.22|awk '{print $5}'
  15. }
  16. function 24Conn {
  17.         sudo /sbin/ipvsadm -L -n | grep 100.24|awk '{print $5}'
  18. }
  19. function 76Conn {
  20.         sudo /sbin/ipvsadm -L -n | grep 100.76|awk '{print $5}'
  21. }

  22. function AllInConn {
  23.         sudo /sbin/ipvsadm -L -n |awk '{print $6}'| awk 'BEGIN{sum=0}{sum+=$1}END{print sum}'
  24. }
  25. function 101InConn {
  26.         sudo /sbin/ipvsadm -L -n | grep 100.101|awk '{print $6}'
  27. }
  28. function 22InConn {
  29.         sudo /sbin/ipvsadm -L -n | grep 100.22|awk '{print $6}'
  30. }
  31. function 24InConn {
  32.         sudo /sbin/ipvsadm -L -n | grep 100.24|awk '{print $6}'
  33. }
  34. function 76InConn {
  35.         sudo /sbin/ipvsadm -L -n | grep 100.76|awk '{print $6}'
  36. }


  37. # Run the requested function
  38. $1


三、修改配置文件

点击(此处)折叠或打开

  1. zabbix agent 添加如下,并重启agent.
  2. [root@lvs-master zabbix]# vim zabbix_agentd.conf
  3. ### ipvsadm Active
  4. UserParameter=lvs.AllConn[*],/etc/zabbix/lvs-status.sh AllConn
  5. UserParameter=lvs.101Conn[*],/etc/zabbix/lvs-status.sh 101Conn
  6. UserParameter=lvs.22Conn,/etc/zabbix/lvs-status.sh 22Conn
  7. UserParameter=lvs.24Conn,/etc/zabbix/lvs-status.sh 24Conn
  8. UserParameter=lvs.76Conn,/etc/zabbix/lvs-status.sh 76Conn
  9. ### ipvsadm InActive
  10. UserParameter=lvs.AllInConn,/etc/zabbix/lvs-status.sh AllInConn
  11. UserParameter=lvs.101InConn,/etc/zabbix/lvs-status.sh 101InConn
  12. UserParameter=lvs.22InConn,/etc/zabbix/lvs-status.sh 22InConn
  13. UserParameter=lvs.24InConn,/etc/zabbix/lvs-status.sh 24InConn
  14. 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 修改如下:

点击(此处)折叠或打开

  1. [root@lvs-master ~]# visudo
  2. #Defaults requiretty

  3. 添加
  4. zabbix ALL=(ALL) NOPASSWD:/sbin/ipvsadm
问题是解决了,但是不知道#Defaults    requiretty 这样会不会有其它的问题??


五、zabbix server 测试

点击(此处)折叠或打开

  1. [root@jumper ~]# zabbix_get -s 192.168.100.14 -p 10050 -k "lvs.AllConn"
  2. 2326



六、导入模板(请根据自己的需要,添加/修改/删除)

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <zabbix_export version="1.0" date="26.12.12" time="12.00">
  3.   <hosts>
  4.     <host name="LVS Status">
  5.       <proxy_hostid>0</proxy_hostid>
  6.       <useip>1</useip>
  7.       <dns></dns>
  8.       <ip>127.0.0.1</ip>
  9.       <port>10050</port>
  10.       <status>3</status>
  11.       <useipmi>0</useipmi>
  12.       <ipmi_ip>127.0.0.1</ipmi_ip>
  13.       <ipmi_port>623</ipmi_port>
  14.       <ipmi_authtype>0</ipmi_authtype>
  15.       <ipmi_privilege>2</ipmi_privilege>
  16.       <ipmi_username></ipmi_username>
  17.       <ipmi_password></ipmi_password>
  18.       <groups>
  19.         <group>Freetrade</group>
  20.       </groups>
  21.       <triggers/>
  22.       <items>
  23.         <item type="7" key="lvs.AllConn" value_type="3">
  24.           <description>lvs.AllConn connections</description>
  25.           <ipmi_sensor></ipmi_sensor>
  26.           <delay>30</delay>
  27.           <history>365</history>
  28.           <trends>365</trends>
  29.           <status>0</status>
  30.           <data_type>0</data_type>
  31.           <units></units>
  32.           <multiplier>0</multiplier>
  33.           <delta>0</delta>
  34.           <formula>0</formula>
  35.           <lastlogsize>0</lastlogsize>
  36.           <logtimefmt></logtimefmt>
  37.           <delay_flex></delay_flex>
  38.           <authtype>0</authtype>
  39.           <username></username>
  40.           <password></password>
  41.           <publickey></publickey>
  42.           <privatekey></privatekey>
  43.           <params></params>
  44.           <trapper_hosts>localhost</trapper_hosts>
  45.           <snmp_community></snmp_community>
  46.           <snmp_oid></snmp_oid>
  47.           <snmp_port>161</snmp_port>
  48.           <snmpv3_securityname></snmpv3_securityname>
  49.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  50.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  51.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  52.           <applications>
  53.             <application>LVS</application>
  54.           </applications>
  55.         </item>
  56.         <item type="7" key="lvs.101Conn" value_type="3">
  57.           <description>lvs.101Conn connections</description>
  58.           <ipmi_sensor></ipmi_sensor>
  59.           <delay>30</delay>
  60.           <history>365</history>
  61.           <trends>365</trends>
  62.           <status>0</status>
  63.           <data_type>0</data_type>
  64.           <units></units>
  65.           <multiplier>0</multiplier>
  66.           <delta>0</delta>
  67.           <formula>0</formula>
  68.           <lastlogsize>0</lastlogsize>
  69.           <logtimefmt></logtimefmt>
  70.           <delay_flex></delay_flex>
  71.           <authtype>0</authtype>
  72.           <username></username>
  73.           <password></password>
  74.           <publickey></publickey>
  75.           <privatekey></privatekey>
  76.           <params></params>
  77.           <trapper_hosts>localhost</trapper_hosts>
  78.           <snmp_community></snmp_community>
  79.           <snmp_oid></snmp_oid>
  80.           <snmp_port>161</snmp_port>
  81.           <snmpv3_securityname></snmpv3_securityname>
  82.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  83.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  84.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  85.           <applications>
  86.             <application>LVS</application>
  87.           </applications>
  88.         </item>
  89.         <item type="7" key="lvs.22Conn" value_type="3">
  90.           <description>lvs.22Conn connections</description>
  91.           <ipmi_sensor></ipmi_sensor>
  92.           <delay>30</delay>
  93.           <history>365</history>
  94.           <trends>365</trends>
  95.           <status>0</status>
  96.           <data_type>0</data_type>
  97.           <units></units>
  98.           <multiplier>0</multiplier>
  99.           <delta>0</delta>
  100.           <formula>0</formula>
  101.           <lastlogsize>0</lastlogsize>
  102.           <logtimefmt></logtimefmt>
  103.           <delay_flex></delay_flex>
  104.           <authtype>0</authtype>
  105.           <username></username>
  106.           <password></password>
  107.           <publickey></publickey>
  108.           <privatekey></privatekey>
  109.           <params></params>
  110.           <trapper_hosts>localhost</trapper_hosts>
  111.           <snmp_community></snmp_community>
  112.           <snmp_oid></snmp_oid>
  113.           <snmp_port>161</snmp_port>
  114.           <snmpv3_securityname></snmpv3_securityname>
  115.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  116.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  117.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  118.           <applications>
  119.             <application>LVS</application>
  120.           </applications>
  121.         </item>
  122.         <item type="7" key="lvs.24Conn" value_type="3">
  123.           <description>lvs.24Conn connections</description>
  124.           <ipmi_sensor></ipmi_sensor>
  125.           <delay>30</delay>
  126.           <history>365</history>
  127.           <trends>365</trends>
  128.           <status>0</status>
  129.           <data_type>0</data_type>
  130.           <units></units>
  131.           <multiplier>0</multiplier>
  132.           <delta>0</delta>
  133.           <formula>0</formula>
  134.           <lastlogsize>0</lastlogsize>
  135.           <logtimefmt></logtimefmt>
  136.           <delay_flex></delay_flex>
  137.           <authtype>0</authtype>
  138.           <username></username>
  139.           <password></password>
  140.           <publickey></publickey>
  141.           <privatekey></privatekey>
  142.           <params></params>
  143.           <trapper_hosts>localhost</trapper_hosts>
  144.           <snmp_community></snmp_community>
  145.           <snmp_oid></snmp_oid>
  146.           <snmp_port>161</snmp_port>
  147.           <snmpv3_securityname></snmpv3_securityname>
  148.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  149.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  150.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  151.           <applications>
  152.             <application>LVS</application>
  153.           </applications>
  154.         </item>
  155.         <item type="7" key="lvs.76Conn" value_type="3">
  156.           <description>lvs.76Conn connections</description>
  157.           <ipmi_sensor></ipmi_sensor>
  158.           <delay>30</delay>
  159.           <history>365</history>
  160.           <trends>365</trends>
  161.           <status>0</status>
  162.           <data_type>0</data_type>
  163.           <units></units>
  164.           <multiplier>0</multiplier>
  165.           <delta>0</delta>
  166.           <formula>0</formula>
  167.           <lastlogsize>0</lastlogsize>
  168.           <logtimefmt></logtimefmt>
  169.           <delay_flex></delay_flex>
  170.           <authtype>0</authtype>
  171.           <username></username>
  172.           <password></password>
  173.           <publickey></publickey>
  174.           <privatekey></privatekey>
  175.           <params></params>
  176.           <trapper_hosts>localhost</trapper_hosts>
  177.           <snmp_community></snmp_community>
  178.           <snmp_oid></snmp_oid>
  179.           <snmp_port>161</snmp_port>
  180.           <snmpv3_securityname></snmpv3_securityname>
  181.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  182.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  183.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  184.           <applications>
  185.             <application>LVS</application>
  186.           </applications>
  187.         </item>
  188.         <item type="7" key="lvs.AllInConn" value_type="3">
  189.           <description>lvs.AllInConn connections</description>
  190.           <ipmi_sensor></ipmi_sensor>
  191.           <delay>30</delay>
  192.           <history>365</history>
  193.           <trends>365</trends>
  194.           <status>0</status>
  195.           <data_type>0</data_type>
  196.           <units></units>
  197.           <multiplier>0</multiplier>
  198.           <delta>0</delta>
  199.           <formula>0</formula>
  200.           <lastlogsize>0</lastlogsize>
  201.           <logtimefmt></logtimefmt>
  202.           <delay_flex></delay_flex>
  203.           <authtype>0</authtype>
  204.           <username></username>
  205.           <password></password>
  206.           <publickey></publickey>
  207.           <privatekey></privatekey>
  208.           <params></params>
  209.           <trapper_hosts>localhost</trapper_hosts>
  210.           <snmp_community></snmp_community>
  211.           <snmp_oid></snmp_oid>
  212.           <snmp_port>161</snmp_port>
  213.           <snmpv3_securityname></snmpv3_securityname>
  214.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  215.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  216.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  217.           <applications>
  218.             <application>LVS</application>
  219.           </applications>
  220.         </item>
  221.         <item type="7" key="lvs.101InConn" value_type="3">
  222.           <description>lvs.101InConn connections</description>
  223.           <ipmi_sensor></ipmi_sensor>
  224.           <delay>30</delay>
  225.           <history>365</history>
  226.           <trends>365</trends>
  227.           <status>0</status>
  228.           <data_type>0</data_type>
  229.           <units></units>
  230.           <multiplier>0</multiplier>
  231.           <delta>0</delta>
  232.           <formula>0</formula>
  233.           <lastlogsize>0</lastlogsize>
  234.           <logtimefmt></logtimefmt>
  235.           <delay_flex></delay_flex>
  236.           <authtype>0</authtype>
  237.           <username></username>
  238.           <password></password>
  239.           <publickey></publickey>
  240.           <privatekey></privatekey>
  241.           <params></params>
  242.           <trapper_hosts>localhost</trapper_hosts>
  243.           <snmp_community></snmp_community>
  244.           <snmp_oid></snmp_oid>
  245.           <snmp_port>161</snmp_port>
  246.           <snmpv3_securityname></snmpv3_securityname>
  247.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  248.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  249.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  250.           <applications>
  251.             <application>LVS</application>
  252.           </applications>
  253.         </item>
  254.         <item type="7" key="lvs.22InConn" value_type="3">
  255.           <description>lvs.22InConn connections</description>
  256.           <ipmi_sensor></ipmi_sensor>
  257.           <delay>30</delay>
  258.           <history>365</history>
  259.           <trends>365</trends>
  260.           <status>0</status>
  261.           <data_type>0</data_type>
  262.           <units></units>
  263.           <multiplier>0</multiplier>
  264.           <delta>0</delta>
  265.           <formula>0</formula>
  266.           <lastlogsize>0</lastlogsize>
  267.           <logtimefmt></logtimefmt>
  268.           <delay_flex></delay_flex>
  269.           <authtype>0</authtype>
  270.           <username></username>
  271.           <password></password>
  272.           <publickey></publickey>
  273.           <privatekey></privatekey>
  274.           <params></params>
  275.           <trapper_hosts>localhost</trapper_hosts>
  276.           <snmp_community></snmp_community>
  277.           <snmp_oid></snmp_oid>
  278.           <snmp_port>161</snmp_port>
  279.           <snmpv3_securityname></snmpv3_securityname>
  280.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  281.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  282.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  283.           <applications>
  284.             <application>LVS</application>
  285.           </applications>
  286.         </item>
  287.         <item type="7" key="lvs.24InConn" value_type="3">
  288.           <description>lvs.24InConn connections</description>
  289.           <ipmi_sensor></ipmi_sensor>
  290.           <delay>30</delay>
  291.           <history>365</history>
  292.           <trends>365</trends>
  293.           <status>0</status>
  294.           <data_type>0</data_type>
  295.           <units></units>
  296.           <multiplier>0</multiplier>
  297.           <delta>0</delta>
  298.           <formula>0</formula>
  299.           <lastlogsize>0</lastlogsize>
  300.           <logtimefmt></logtimefmt>
  301.           <delay_flex></delay_flex>
  302.           <authtype>0</authtype>
  303.           <username></username>
  304.           <password></password>
  305.           <publickey></publickey>
  306.           <privatekey></privatekey>
  307.           <params></params>
  308.           <trapper_hosts>localhost</trapper_hosts>
  309.           <snmp_community></snmp_community>
  310.           <snmp_oid></snmp_oid>
  311.           <snmp_port>161</snmp_port>
  312.           <snmpv3_securityname></snmpv3_securityname>
  313.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  314.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  315.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  316.           <applications>
  317.             <application>LVS</application>
  318.           </applications>
  319.         </item>
  320.         <item type="7" key="lvs.76InConn" value_type="3">
  321.           <description>lvs.76InConn connections</description>
  322.           <ipmi_sensor></ipmi_sensor>
  323.           <delay>30</delay>
  324.           <history>365</history>
  325.           <trends>365</trends>
  326.           <status>0</status>
  327.           <data_type>0</data_type>
  328.           <units></units>
  329.           <multiplier>0</multiplier>
  330.           <delta>0</delta>
  331.           <formula>0</formula>
  332.           <lastlogsize>0</lastlogsize>
  333.           <logtimefmt></logtimefmt>
  334.           <delay_flex></delay_flex>
  335.           <authtype>0</authtype>
  336.           <username></username>
  337.           <password></password>
  338.           <publickey></publickey>
  339.           <privatekey></privatekey>
  340.           <params></params>
  341.           <trapper_hosts>localhost</trapper_hosts>
  342.           <snmp_community></snmp_community>
  343.           <snmp_oid></snmp_oid>
  344.           <snmp_port>161</snmp_port>
  345.           <snmpv3_securityname></snmpv3_securityname>
  346.           <snmpv3_securitylevel>0</snmpv3_securitylevel>
  347.           <snmpv3_authpassphrase></snmpv3_authpassphrase>
  348.           <snmpv3_privpassphrase></snmpv3_privpassphrase>
  349.           <applications>
  350.             <application>LVS</application>
  351.           </applications>
  352.         </item>
  353.       </items>
  354.     </host>
  355.   </hosts>
  356.   <dependencies/>
  357. </zabbix_export>


七、添加图型

web界面添加图型。











阅读(9388) | 评论(5) | 转发(1) |
0

上一篇:Puppet 安装配置

下一篇:shell 脚本加密 shc

给主人留下些什么吧!~~

zongg2014-08-27 09:11:05

minminmsn:您好,最后lvs没有数据,zabbix_get -s 172.17.2.55 -p 10050  -k "lvs.AllConn"
244.2 这个有数据,不知道是什么原因,lvs模板页参照了改了,还有其他需要注意的吗?比如snmpd配置什么的?谢谢!

得等一小会就有图了。

回复 | 举报

minminmsn2014-08-26 15:50:30

ipvsadm -L -n | sed -n '2,$p' |awk '{print $5}'|awk 'BEGIN{sum=0}{sum+=$1}END{print sum}'
325 去掉行首的lvs版本统计更精确。

minminmsn2014-08-26 12:18:24

您好,最后lvs没有数据,zabbix_get -s 172.17.2.55 -p 10050  -k "lvs.AllConn"
244.2 这个有数据,不知道是什么原因,lvs模板页参照了改了,还有其他需要注意的吗?比如snmpd配置什么的?谢谢!

zongg2013-09-17 08:31:58

missing-cn:是这样的,恭喜你!

谢谢,不会的,还得请教你。

回复 | 举报

missing-cn2013-09-16 21:29:58

是这样的,恭喜你!