且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

zabbix1.8和2.0版本通用的安装脚本

更新时间:2022-09-19 22:13:00

用zabbix监控服务器2年多了,早就写好了服务器端的安装部署脚本,现在拿出来和大家分享一下。zabbix1.8和2.0版本通用的安装脚本,默认的为1.8.9的版本,大家要是想安装2.0以上的版本,只用替换zabbix的安装包即可,其他的不变。安装所用到的软件包在:http://down.51cto.com/data/556418这个位置,大家可以下载,也可以根据脚本中用到的软件自行去下载。安装之后打开浏览器:http://192.168.8.11/zabbix进行zabbix的初始化,基本就是检测运行环境之类的,点击下一步即可完成,如果有错误的话他会提示,按照提示修改配置即可。脚本如下:

 


  1. #/bin/sh 
  2. mkdir -p /home/soft 
  3. unzip zabbix.zip -d /home/soft/ 
  4.  
  5. cd /home/soft/ 
  6. tar -zxf libpng-1.2.16.tar.gz 
  7. cd libpng-1.2.16
  8. ./configure --prefix=/usr/local --enable-shared 
  9. make && make install 
  10.  
  11. cd /home/soft/ 
  12. tar -zxf libiconv-1.11.tar.gz 
  13. cd libiconv-1.11
  14. ./configure --prefix=/usr/local --enable-shared --enable-static 
  15. make && make install 
  16.  
  17. cd /home/soft/ 
  18. tar -zxf jpegsrc.v6b.tar.gz 
  19. cd jpeg-6b
  20. ./configure --enable-static --enable-shared --prefix=/usr/local 
  21. make && make install 
  22.  
  23. cd /home/soft/ 
  24. tar -zxf freetype-2.3.1.tar.gz 
  25. cd freetype-2.3.1
  26. ./configure --prefix=/usr/local --enable-shared 
  27. make && make install 
  28.  
  29. cd /home/soft/ 
  30. tar -zxf curl-7.17.1.tar.gz 
  31. cd curl-7.17.1
  32. ./configure --prefix=/usr/local --enable-shared 
  33. make && make install 
  34.  
  35. cd /home/soft/ 
  36. tar -zxf gd-2.0.34.tar.gz 
  37. cd gd-2.0.34
  38. ./configure --prefix=/usr/local --enable-shared --with-png=/usr/local --with-freetype=/usr/local --with-libiconv-prefix=/usr/local --with-jpeg=/usr/local 
  39. make && make install 
  40.  
  41. cd /home/soft/ 
  42. tar -zxf httpd-2.2.21.tar.gz 
  43. cd httpd-2.2.21
  44. ./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-deflate --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-ssl --with-ssl=/usr/include/openssl --enable-mods-shared=all 
  45. make && make install 
  46. groupadd apache 
  47. useradd -g apache apache 
  48. cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd 
  49. chmod 755 /etc/rc.d/init.d/httpd 
  50. echo '# chkconfig: 2345 85 15' >> /etc/rc.d/init.d/httpd 
  51. mv /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak 
  52. cp /home/soft/httpd.conf /usr/local/apache/conf/httpd.conf 
  53. echo '# description: httpd is a World Wide Web Server' >> /etc/rc.d/init.d/httpd 
  54. chkconfig --add httpd 
  55. chkconfig httpd on 
  56. echo "127.0.0.1 `hostname`">>/etc/hosts 
  57. service httpd restart 
  58.  
  59.  
  60. cd /home/soft/ 
  61. groupadd mysql 
  62. useradd -g mysql mysql 
  63. mv /home/mysql /data1/ 
  64. ln -s /data1/mysql /home/mysql 
  65. tar -zxf mysql-5.1.59-linux-i686-glibc23.tar.gz -C /usr/local/ 
  66. mv /usr/local/mysql-5.1.59-linux-i686-glibc23/ /usr/local/mysql/ 
  67. mkdir -p /usr/local/mysql/etc/ 
  68. chown -R mysql.mysql /usr/local/mysql 
  69. cd /usr/local/mysql/ 
  70. ./scripts/mysql_install_db --no-defaults 
  71. cd /home/soft/ 
  72. cp -rp /usr/local/mysql/data/mysql /data1/mysql/data/ 
  73. chown -R mysql.mysql /data1/mysql 
  74. mkdir -p /usr/lib/mysql/ 
  75. ln -s /usr/local/mysql/lib/* /usr/lib/mysql/ 
  76. ln -s /usr/local/mysql/bin/* /usr/bin/ 
  77. echo "/usr/local/mysql/lib" >> /etc/ld.so.conf 
  78. ldconfig 
  79. cp /home/soft/mysqld /etc/init.d/ 
  80. chmod +x /etc/init.d/mysqld 
  81. chkconfig --add mysqld 
  82. chkconfig --level 345 mysqld on 
  83. service mysqld start 
  84. mysqladmin -uroot password zabbix 
  85. mysql -pzabbix -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'zabbix';update mysql.user set password=password('zabbix') where user='root';flush privileges;" 
  86. #mysql -pzabbix -e "UPDATE zabbix.items SET history=7;" 
  87. #这条语句在安装结束后导入监控模板后手动执行,用于修改监控数据保存天数的修改。 
  88.  
  89. #如果需要用snmp来监控的话,需要加上snmp软件,自己指定yum源进行安装 
  90. #echo "baseurl=ftp://10.14.23.235/snmp">> /etc/yum.repos.d/as.repo 
  91. #yum install net-snmp-devel -y 
  92.  
  93. cd /home/soft/ 
  94. tar -zxf php-5.2.17.tar.gz 
  95. ln -s  /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2 
  96. ln -s /usr/local/lib/libcurl.so.4 /usr/lib/libcurl.so.4 
  97. cd /home/soft/php-5.2.17/; 
  98. ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs --with-ttf --with-freetype-dir=/usr/local --with-iconv-dir=/usr/local --with-curl=/usr/local --with-zlib --with-gettext --with-libxml-dir=/usr/local --with-gd=/usr/local --with-png-dir --enable-mbstring --enable-exif --enable-force-cgi-redirect --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-calendar --enable-gd-native-ttf --enable-gd-jis-conv --disable-debug --disable-path-info-check --enable-soap --silent --enable-sockets --with-openssl --enable-bcmath --with-gettext --with-jpeg-dir=/usr/local 
  99. #用到snmp的话加上 --with-snmp 
  100. #--enable-bcmath --with-gettext还有GD的 注意这几个参数一定要加上,特别是zabbix2.0以上版本需要 
  101. make && make install 
  102. mkdir -p /usr/local/php/etc 
  103. cp /home/soft/php.ini /usr/local/php/etc/ 
  104.  
  105. cd /home/soft/ 
  106. tar -zxf zabbix-1.8.9.tar.gz 
  107. cd zabbix-1.8.9 
  108. ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-libcurl && make && make install 
  109. #用到snmp的话加上--with-net-snmp 用到代理的话加上 --enable-proxy  
  110. mkdir -p /etc/zabbix 
  111. cp /home/soft/zabbix_* /etc/zabbix/ 
  112. #110行和111行在2.0以上的版本中不需要,因为zabbix默认安装的配置文件在/usr/local/zabbix/etc/下面,只需修改相关数据库连接信息即可
  113. cd /home/soft/ 
  114. groupadd zabbix 
  115. useradd zabbix -g zabbix 
  116. mysql -uroot -pzabbix -e "create database zabbix character set utf8;" 
  117. cd /home/soft/zabbix-1.8.9
  118. mysql -uroot -pzabbix zabbix < create/schema/mysql.sql 
  119. mysql -uroot -pzabbix zabbix < create/data/data.sql 
  120. mysql -uroot -pzabbix zabbix < create/data/images_mysql.sql 
  121. #zabbix2.0以上版本导入数据库时有先后顺序,并且数据库文件的名字也有变化,请按照一下顺序来导入 
  122. #mysql -uroot -pzabbix zabbix < create/schema/schema.sql 
  123. #mysql -uroot -pzabbix zabbix < create/data/images.sql 
  124. #mysql -uroot -pzabbix zabbix < create/data/data.sql 
  125.  
  126. cp -r /home/soft/zabbix-1.8.9/frontends/php /usr/local/apache/htdocs/zabbix 
  127. cp /home/soft/zabbix-server /etc/init.d/zabbix-server 
  128. cp /home/soft/zabbix-agentd /etc/init.d/zabbix-agentd 
  129. chmod +x /etc/init.d/zabbix* 
  130. chkconfig --add zabbix-agentd  
  131. chkconfig --add zabbix-server 
  132. chkconfig --level 345 zabbix-server on 
  133. chkconfig --level 345 zabbix-agentd  on 
  134. cp /home/soft/simhei.ttf /usr/local/apache/htdocs/zabbix/fonts/ 
  135. sed -i 's/DejaVuSans/simhei/g' /usr/local/apache/htdocs/zabbix/include/defines.inc.php 
  136. #在页面选择中文时用这个字体替换掉之前的字体,这样可以汉化图标中的中文。 
  137.  
  138. echo "zabbix-agent    10050/tcp  #Zabbix Agent">>/etc/services 
  139. echo "zabbix-agent    10050/udp  #Zabbix Agent">>/etc/services 
  140. echo "zabbix-trapper  10051/tcp  #Zabbix Trapper">>/etc/services 
  141. echo "zabbix-trapper  10051/udp  #Zabbix Trapper">>/etc/services  

zabbix客户端的安装比较简单:

1:linux系统

下载zabbix软件包,解压zabbix软件包:

cd /home/soft/zabbix-1.8.11/ ./configure --prefix=/usr/local/zabbix --enable-agent && make && make install

http://down.51cto.com/data/556418这个位置有他的配置文件和服务文件的模板,是我修改过的,可以直接使用。

/usr/sbin/groupadd zabbix

/usr/sbin/useradd zabbix -g zabbix

/sbin/chkconfig --add zabbix-agentd

/sbin/chkconfig --level 345 zabbix-agentd  on

echo "zabbix-agent    10050/tcp  #Zabbix Agent">>/etc/services

echo "zabbix-agent    10050/udp  #Zabbix Agent">>/etc/services

/etc/init.d/zabbix-agentd restart

2:windows端的安装:

 下载zabbix的windows软件包,解压zabbix软件包,windows端的配置文件和linux一样,执行下面的安装zabbix为服务:
C:\zabbix\zabbix_agentd.exe -c C:\zabbix\zabbix_agentd.conf -i
net start "Zabbix Agent"
@pause
 



本文转自 lover00751CTO博客,原文链接:http://blog.51cto.com/wangwei007/1033847,如需转载请自行联系原作者