【Zabbix】zabbix_agent安裝指令碼

ringoo_ming發表於2017-12-14

一. install_zabbix_agent_centos5.sh

  1. #!/bin/bash
  2. yum -y install unixODBC-devel unixODBC net-snmp net-snmp-devel OpenIPMI OpenIPM-devel openldap openldap-devel wget curl.x86_64
  3. grep zabbix_agent /etc/services > /dev/null
  4. stat1=$?
  5. if [ $stat1 -ne 0 ];then
  6. cat >> /etc/services <<EOF
  7. zabbix_agent 10050/tcp #Zabbix Agent
  8. zabbix_agent 10050/udp #Zabbix Agent
  9. zabbix_trapper 10051/tcp #Zabbix Trapper
  10. zabbix_trapper 10051/udp #Zabbix Trapper
  11. EOF
  12. fi
  13. cd /opt
  14. if [ -d "zabbix" ];then
  15. /etc/init.d/zabbix_agentd stop
  16. \mv zabbix /tmp
  17. fi
  18. tar zxvf zabbix-2.4.3_centos5.tar.gz
  19. mv /opt/zabbix-2.4.3 /opt/zabbix
  20. cp /opt/zabbix/zabbix_agentd /etc/init.d/
  21. cp /opt/zabbix/iostatcron /etc/cron.d/
  22. chown root:root /etc/cron.d/iostatcron
  23. chown root:root /etc/init.d/zabbix_agentd
  24. chmod a+x /etc/init.d/zabbix_agentd
  25. rpm -ivh /opt/zabbix/python-pika-0.9.5-3.el5.noarch.rpm
  26. id zabbix
  27. stat=$?
  28. if [ "$stat" -ne 0 ];then
  29. useradd zabbix
  30. chown -R zabbix:zabbix /opt/zabbix
  31. else
  32. chown -R zabbix:zabbix /opt/zabbix
  33. fi
  34. chmod a+x /opt/zabbix/sbin/*
  35. chmod a+x /opt/zabbix/bin/*
  36. chmod a+x /opt/zabbix/script/*
  37. cat /var/spool/cron/root | grep "discovery_port.sh" | grep -v grep > /dev/null
  38. stat1=$?
  39. if [ "$stat1" -ne 0 ];then
  40. echo "*/10 * * * * /opt/zabbix/script/discovery_port.sh > /dev/null 2>&1 &" >> /var/spool/cron/root
  41. fi
  42. cat /var/spool/cron/root | grep "discovery_services.py" | grep -v grep > /dev/null
  43. stat2=$?
  44. if [ "$stat2" -ne 0 ];then
  45. echo "*/30 * * * * /usr/bin/nohup /opt/zabbix/script/discovery_services.py > /dev/null 2>&1 &" >> /var/spool/cron/root
  46. fi
  47. cat /var/spool/cron/root | grep "get_java_jstat.py" | grep -v grep > /dev/null
  48. stat_jstat=$?
  49. if [ "$stat_jstat" -ne 0 ];then
  50. echo "*/1 * * * * /usr/bin/nohup /opt/zabbix/script/get_java_jstat.py > /dev/null 2>&1 &" >> /var/spool/cron/root
  51. fi
  52. #set hostname
  53. #ip=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v "172."|grep -v "192"|grep -v inet6|awk '{print $2}'|tr -d "addr:"|he
  54. ad -n 1`
  55. ip=`/sbin/ifconfig -a|grep inet|grep -v inet6|grep -v 127.0.0.1|awk -F\: '{print $2}'|awk '{print $1}'|grep -v "^172"|head -n 1
  56. `
  57. echo $ip
  58. sed -i 's/Hostname=.*/Hostname='${ip}_jgz'/g' /opt/zabbix/etc/zabbix_agentd.conf
  59. grep Hostname /opt/zabbix/etc/zabbix_agentd.conf
  60. /etc/init.d/zabbix_agentd start
  61. grep 'zabbix_agentd' /etc/rc.d/rc.local|grep -v grep > /dev/null
  62. stat3=$?
  63. if [ "$stat3" -ne 0 ];then
  64. echo "/etc/init.d/zabbix_agentd start" >> /etc/rc.d/rc.local
  65. fi

二. install_zabbix_agent_centos6.sh

  1. #!/bin/bash
  2. yum -y install unixODBC-devel unixODBC net-snmp net-snmp-devel OpenIPMI OpenIPM-devel openldap openldap-devel wget curl.x86_64
  3. grep zabbix_agent /etc/services > /dev/null
  4. stat1=$?
  5. if [ $stat1 -ne 0 ];then
  6. cat >> /etc/services <<EOF
  7. zabbix_agent 10050/tcp #Zabbix Agent
  8. zabbix_agent 10050/udp #Zabbix Agent
  9. zabbix_trapper 10051/tcp #Zabbix Trapper
  10. zabbix_trapper 10051/udp #Zabbix Trapper
  11. EOF
  12. fi
  13. cd /opt
  14. if [ -d "zabbix" ];then
  15. /etc/init.d/zabbix_agentd stop
  16. \mv zabbix /tmp
  17. fi
  18. tar zxvf zabbix-2.4.3_centos6.tar.gz
  19. mv /opt/zabbix-2.4.3 /opt/zabbix
  20. cp /opt/zabbix/zabbix_agentd /etc/init.d/
  21. cp /opt/zabbix/iostatcron /etc/cron.d/
  22. chown root:root /etc/cron.d/iostatcron
  23. chown root:root /etc/init.d/zabbix_agentd
  24. chmod a+x /etc/init.d/zabbix_agentd
  25. rpm -ivh /opt/zabbix/python-pika-0.9.5-2.el6.noarch.rpm
  26. id zabbix
  27. stat=$?
  28. if [ "$stat" -ne 0 ];then
  29. useradd zabbix
  30. chown -R zabbix:zabbix /opt/zabbix
  31. else
  32. chown -R zabbix:zabbix /opt/zabbix
  33. fi
  34. chmod a+x /opt/zabbix/sbin/*
  35. chmod a+x /opt/zabbix/bin/*
  36. chmod a+x /opt/zabbix/script/*
  37. cat /var/spool/cron/root | grep "discovery_port.sh" | grep -v grep > /dev/null
  38. stat1=$?
  39. if [ "$stat1" -ne 0 ];then
  40. echo "*/10 * * * * /opt/zabbix/script/discovery_port.sh > /dev/null 2>&1 &" >> /var/spool/cron/root
  41. fi
  42. cat /var/spool/cron/root | grep "discovery_services.py" | grep -v grep > /dev/null
  43. stat2=$?
  44. if [ "$stat2" -ne 0 ];then
  45. echo "*/30 * * * * /usr/bin/nohup /opt/zabbix/script/discovery_services.py > /dev/null 2>&1 &" >> /var/spool/cron/root
  46. fi
  47. cat /var/spool/cron/root | grep "get_java_jstat.py" | grep -v grep > /dev/null
  48. stat_jstat=$?
  49. if [ "$stat_jstat" -ne 0 ];then
  50. echo "*/1 * * * * /usr/bin/nohup /opt/zabbix/script/get_java_jstat.py > /dev/null 2>&1 &" >> /var/spool/cron/root
  51. fi
  52. #ip=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v "172."|grep -v "192"|grep -v inet6|awk '{print $2}'|tr -d "addr:"|he
  53. ad -n 1`
  54. ip=`/sbin/ifconfig -a|grep inet|grep -v inet6|grep -v 127.0.0.1|awk -F\: '{print $2}'|awk '{print $1}'|grep -v "^172"|head -n 1
  55. `
  56. echo $ip
  57. sed -i 's/Hostname=.*/Hostname='${ip}_jgz'/g' /opt/zabbix/etc/zabbix_agentd.conf
  58. grep Hostname /opt/zabbix/etc/zabbix_agentd.conf
  59. /etc/init.d/zabbix_agentd start
  60. grep 'zabbix_agentd' /etc/rc.d/rc.local|grep -v grep > /dev/null
  61. stat3=$?
  62. if [ "$stat3" -ne 0 ];then
  63. echo "/etc/init.d/zabbix_agentd start" >> /etc/rc.d/rc.local
  64. fi

三. install_zabbix_agent_centos7.sh


  1. #!/bin/bash
  2. grep zabbix_agent /etc/services > /dev/null
  3. stat1=$?
  4. if [ $stat1 -ne 0 ];then
  5. cat >> /etc/services <<EOF
  6. zabbix_agent 10050/tcp #Zabbix Agent
  7. zabbix_agent 10050/udp #Zabbix Agent
  8. zabbix_trapper 10051/tcp #Zabbix Trapper
  9. zabbix_trapper 10051/udp #Zabbix Trapper
  10. EOF
  11. fi
  12. cd /opt
  13. if [ -d "zabbix" ];then
  14. /etc/init.d/zabbix_agentd stop
  15. \mv zabbix /tmp
  16. fi
  17. tar zxvf zabbix-2.4.3_centos7.tar.gz
  18. cd /opt/zabbix-2.4.3
  19. ./configure --prefix=/opt/zabbix --enable-agent
  20. make
  21. make install
  22. #mv /opt/zabbix-2.4.3 /opt/zabbix
  23. cp /opt/zabbix-2.4.3/zabbix_agentd /etc/init.d/
  24. cp /opt/zabbix-2.4.3/iostatcron /etc/cron.d/
  25. \cp /opt/zabbix-2.4.3/zabbix_agentd.conf /opt/zabbix/etc/
  26. cp -r /opt/zabbix-2.4.3/script /opt/zabbix/script
  27. mkdir /opt/zabbix/logs
  28. mkdir /opt/zabbix/var
  29. chown root:root /etc/cron.d/iostatcron
  30. chown root:root /etc/init.d/zabbix_agentd
  31. chmod a+x /etc/init.d/zabbix_agentd
  32. rpm -ivh python2-pika-0.10.0-3.el7.noarch.rpm
  33. id zabbix
  34. stat=$?
  35. if [ "$stat" -ne 0 ];then
  36. useradd zabbix
  37. chown -R zabbix:zabbix /opt/zabbix
  38. else
  39. chown -R zabbix:zabbix /opt/zabbix
  40. fi
  41. chmod a+x /opt/zabbix/sbin/*
  42. chmod a+x /opt/zabbix/bin/*
  43. chmod a+x /opt/zabbix/script/*
  44. cat /var/spool/cron/root | grep "discovery_port.sh" | grep -v grep > /dev/null
  45. stat1=$?
  46. if [ "$stat1" -ne 0 ];then
  47. echo "*/10 * * * * /opt/zabbix/script/discovery_port.sh > /dev/null 2>&1 &" >> /var/spool/cron/root
  48. fi
  49. cat /var/spool/cron/root | grep "discovery_services.py" | grep -v grep > /dev/null
  50. stat2=$?
  51. if [ "$stat2" -ne 0 ];then
  52. echo "*/30 * * * * /usr/bin/nohup /opt/zabbix/script/discovery_services.py > /dev/null 2>&1 &" >> /var/spool/cron/root
  53. fi
  54. cat /var/spool/cron/root | grep "get_java_jstat.py" | grep -v grep > /dev/null
  55. stat_jstat=$?
  56. if [ "$stat_jstat" -ne 0 ];then
  57. echo "*/1 * * * * /usr/bin/nohup /opt/zabbix/script/get_java_jstat.py > /dev/null 2>&1 &" >> /var/spool/cron/root
  58. fi
  59. #ip=`/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v "172."|grep -v "192"|grep -v inet6|awk '{print $2}'|tr -d "addr:"|he
  60. ad -n 1`
  61. ip=`/sbin/ifconfig -a|grep inet|grep -v inet6|grep -v 127.0.0.1|awk -F\: '{print $2}'|awk '{print $1}'|grep -v "^172"|head -n 1
  62. `
  63. echo $ip
  64. sed -i 's/Hostname=.*/Hostname='${ip}_jgz'/g' /opt/zabbix/etc/zabbix_agentd.conf
  65. grep Hostname /opt/zabbix/etc/zabbix_agentd.conf
  66. systemctl daemon-reload
  67. /etc/init.d/zabbix_agentd start
  68. grep 'zabbix_agentd' /etc/rc.d/rc.local|grep -v grep > /dev/null
  69. stat3=$?
  70. if [ "$stat3" -ne 0 ];then
  71. echo "/etc/init.d/zabbix_agentd start" >> /etc/rc.d/rc.local
  72. fi



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31442725/viewspace-2148722/,如需轉載,請註明出處,否則將追究法律責任。

相關文章