Chinaunix首页 | 论坛 | 博客
  • 博客访问: 355362
  • 博文数量: 34
  • 博客积分: 251
  • 博客等级: 二等列兵
  • 技术积分: 419
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-21 15:50
文章分类

全部博文(34)

文章存档

2017年(5)

2016年(19)

2012年(10)

我的朋友

分类: 系统运维

2016-05-20 01:52:22

基于文章http://blog.chinaunix.net/uid-26168435-id-5728816.html,写了1个简单的脚本来简化zabbix_agnetd的部署。
脚本运行注意事项:
1. script与zabbix-3.0.1.tar.gz放置在同一个目录运行;
2. 由于zabbix安装文件的名字未采用变量,script中已写死,虽然可变更,但需要同步修改脚其中对应的地方;
3. script涉及到变更运行目录,所以请使用"source" 或 ". "运行script,如: "source xx.sh"或". ./xx.sh";
4. script运行基于centos6.x,请注意与centos7.x的命令区别,这里主要是centos7.x默认没有iptables,需要提前准备好iptables的环境。
点击(此处)折叠或打开
  1. #!/bin/bash
  2. # Program:
  3. # Automatic install zabbix_agentd-3.0.1 in centos-6.x-x86_64 by the scripts.
  4. # Usage:
  5. # It relate to chage directory, please use source or . to execute this scripts, the others methods will fail.
  6. # History:
  7. # 2016/05/10 v0.1
  8. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
  9. export PATH
  10. # Check if user is root.
  11. if [ $(id -u) != "0" ]; then
  12. echo "Error: You must be root to run this script, please use root to install zabbix_agentd!"
  13. exit 1
  14. fi
  15. # Function: check the zabbix_server ip address which has be inputed.
  16. checkip() {
  17. echo $1 | egrep -q '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' > /dev/null
  18. if [ $? -ne 0 ]; then
  19. echo "Error: Please input correct format IP address!"
  20. exit 1
  21. fi
  22. ipaddr=$1
  23. ip1=`echo $ipaddr | awk -F. '{print $1}'`
  24. ip2=`echo $ipaddr | awk -F. '{print $2}'`
  25. ip3=`echo $ipaddr | awk -F. '{print $3}'`
  26. ip4=`echo $ipaddr | awk -F. '{print $4}'`
  27. for num in $ip1 $ip2 $ip3 $ip4; do
  28. if [ $num -ge 255 ] || [ $num -lt 0 ]; then
  29. echo "Error: Please input correct format IP address!"
  30. exit 1
  31. fi
  32. done
  33. return 0
  34. }
  35. # Input zabbix_server's ip address.
  36. read -p "Please input zabbix_server's ip address[ie: 192.168.1.1]: " zabbixserverip
  37. checkip $zabbixserverip
  38. echo "OK! Your zabbix_server is ${zabbixserverip}!"
  39. # Set iptables rules, zabbix server will detect agentd by tcp 10050, and zabbix_agentd will send trapper to server by tcp 10051.
  40. iptables -I INPUT -s $zabbixserverip -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT
  41. iptables -I OUTPUT -d $zabbixserverip -p tcp -m state --state NEW -m tcp --dport 10051 -j ACCEPT
  42. service iptables save
  43. # Check selinux.
  44. if [ $(getenforce) = "Enforcing" ]; then
  45. sed -i 's|SELINUX=enforcing|SELINUX=disabled|g' /etc/selinux/config ; sed -i 's|SELINUXTYPE=targeted|#SELINUXTYPE=targeted|g' /etc/selinux/config && setenforce 0
  46. fi
  47. # Create zabbix group and user.
  48. groupadd zabbix
  49. useradd -g zabbix -s /sbin/nologin zabbix
  50. # Install zabbix_agentd
  51. cur_dir=$(pwd)
  52. tar -zxvf $cur_dir/zabbix-3.0.1.tar.gz -C /usr/local/src/
  53. cd /usr/local/src/zabbix-3.0.1
  54. ./configure --prefix=/usr/local/zabbix --enable-agent && make && make install
  55. cd ~
  56. # Add soft link to zabbix_agentd execute file.
  57. ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
  58. ln -s /usr/local/zabbix/bin/* /usr/local/bin/
  59. # Modify zabbix_agentd config file.
  60. sed -i "s|Server=127.0.0.1|Server=${zabbixserverip}|g" /usr/local/zabbix/etc/zabbix_agentd.conf
  61. sed -i '262s|# Include=/usr/local/etc/zabbix_agentd.conf.d/|Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/|g' /usr/local/zabbix/etc/zabbix_agentd.conf
  62. sed -i 's|# UnsafeUserParameters=0|UnsafeUserParameters=1|g' /usr/local/zabbix/etc/zabbix_agentd.conf
  63. # Set zabbix_agentd automatic start scripts.
  64. cp /usr/local/src/zabbix-3.0.1/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd
  65. chown zabbix:zabbix /etc/rc.d/init.d/zabbix_agentd
  66. chmod +x /etc/rc.d/init.d/zabbix_agentd
  67. sed -i 's|BASEDIR=/usr/local|BASEDIR=/usr/local/zabbix|g' /etc/rc.d/init.d/zabbix_agentd
  68. chkconfig --level 35 zabbix_agentd on
  69. # Start zabbix_agentd service.
  70. service zabbix_agentd start
  71. # Check zabbix_agentd service.
  72. if [ $(netstat -tnlp | grep zabbix_agentd | awk '{print $7}' | awk -F/ '{print $2}') = "zabbix_agentd" ]; then
  73. echo -e "\033[32m [INFO]Zabbix_agentd has installed and started! \033[0m"
  74. else
  75. echo -e "\033[31m [ERROR]Zabbix_agentd has not started! \033[0m"
  76. fi
  77. # Clean install package.
  78. rm -rf /usr/local/src/zabbix-3.0.1

阅读(3958) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~