CentOS 6 zabbix

 

   
   
   
   
  1. #!/bin/bash 
  2. # manoot ChangeLog: 
  3. # ZABBIX INSTALL SCRIPT 
  4. # Ver. 0.6.6 
  5. # If necessary, edit these for your system 
  6. DBUSER='root' 
  7. DBPASS='' 
  8. DBHOST='localhost' 
  9.  
  10. ZBX_VER='1.8.5' 
  11. #ZBX_VER='1.8' 
  12.  
  13. # DO NOT EDIT BELOW THIS LINE 
  14.  
  15. function checkReturn { 
  16.   if [ $1 -ne 0 ]; then 
  17. echo "fail: $2" 
  18.      echo "$3" 
  19.      exit 
  20. else 
  21. echo "pass: $2" 
  22.   fi 
  23. sleep 3 
  24.  
  25. cat << "eof" 
  26.  
  27. === RUN AT YOUR OWN RISK === 
  28.  
  29. DO NOT RUN ON EXISTING INSTALLATIONS, YOU *WILL* LOSE DATA 
  30.  
  31. This script: 
  32.  * Installs Zabbix 1.8.x on CentOS / Red Hat 5 
  33.  * Drops an existing database 
  34.  * Does not install MySQL; to install type "yum install mysql-server" 
  35.  * Assums a vanilla OS install, though it tries to work around it 
  36.  * Does not install zabbix packages, it uses source from zabbix.com 
  37.  
  38. Press Ctrl-C now if you want to exit 
  39.  
  40. Wait 5 seconds... 
  41. eof 
  42. sleep 5 
  43.  
  44. # check selinux 
  45. #if [ "`sestatus |grep status|awk '{ print $3 }'`" == "enabled" ]; then 
  46. #checkReturn 1 "Disable SELinux and then retry" 
  47. #fi 
  48.   
  49. # Start mysql if its on this box 
  50. if [ "`rpm -qa |grep mysql-server`" ]; then 
  51. chkconfig mysqld on 
  52.   service mysqld restart 
  53. fi 
  54.  
  55. # check mysql 
  56. mysql -h${DBHOST} -u${DBUSER} --password=${DBPASS} > /dev/null << eof 
  57. status 
  58. eof 
  59. RETVAL=$? 
  60. checkReturn $RETVAL "basic mysql access" "Install mysql server packages or fix mysql permissions" 
  61.  
  62. rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt 
  63. rpm -Uvh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm 
  64.  
  65. # dependenices for curl: e2fsprogs-devel zlib-devel libgssapi-devel krb5-devel openssl-devel 
  66. yum -y install gcc make patch gcc-c++ gcc-g77 flex bison autoconf automake curl-devel net-snmp-devel \ 
  67. e2fsprogs-devel zlib-devel libgssapi-devel krb5-devel openssl-devel libidn-devel iksemel-devel php-mbstring php-bcmath 
  68.   
  69. RETVAL=$? 
  70. checkReturn $RETVAL "Package install" 
  71.  
  72.  
  73. cd /tmp 
  74. rm -rf zabbix-$ZBX_VER 
  75. rm zabbix-$ZBX_VER.tar.gz 
  76. #wget http://superb-east.dl.sourceforge.net/sourceforge/zabbix/zabbix-$ZBX_VER.tar.gz 
  77. wget http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/$ZBX_VER/zabbix-$ZBX_VER.tar.gz 
  78. RETVAL=$? 
  79. checkReturn $RETVAL "downloading source" "check ZBX_VER variable or mirror might be down" 
  80. tar xzf zabbix-$ZBX_VER.tar.gz 
  81. cd zabbix-$ZBX_VER 
  82.  
  83. ./configure --enable-agent --enable-ipv6 --enable-proxy --enable-server --with-mysql --with-libcurl --with-net-snmp --with-jabber 
  84. RETVAL=$? 
  85. checkReturn $RETVAL "Configure" 
  86. # --with-jabber 
  87. # ipmi 
  88. # ldap 
  89.  
  90.  
  91. make 
  92. RETVAL=$? 
  93. checkReturn $RETVAL "Compile" 
  94.  
  95. make install 
  96. RETVAL=$? 
  97. checkReturn $RETVAL "make install" 
  98.  
  99. echo "DROP DATABASE IF EXISTS zabbix;" | mysql -h${DBHOST} -u${DBUSER} --password=${DBPASS} 
  100.  
  101. echo "CREATE DATABASE zabbix;" 
  102. echo "USE zabbix;" 
  103. cat /tmp/zabbix-$ZBX_VER/create/schema/mysql.sql 
  104. cat /tmp/zabbix-$ZBX_VER/create/data/data.sql 
  105. cat /tmp/zabbix-$ZBX_VER/create/data/p_w_picpaths_mysql.sql 
  106. ) | mysql -h${DBHOST} -u${DBUSER} --password=${DBPASS} 
  107.  
  108.  
  109. #### BEGIN ZABBIX SERVER & AGENT PROCESS INSTALL & START 
  110. adduser -r -d /var/run/zabbix-server -s /sbin/nologin zabbix 
  111. mkdir -p /etc/zabbix/alert.d 
  112. mkdir -p /var/log/zabbix-server 
  113. mkdir -p /var/log/zabbix-agent 
  114. mkdir -p /var/run/zabbix-server 
  115. mkdir -p /var/run/zabbix-agent 
  116. chown zabbix.zabbix /var/run/zabbix* 
  117. chown zabbix.zabbix /var/log/zabbix* 
  118. cp /tmp/zabbix-$ZBX_VER/misc/conf/zabbix_server.conf /etc/zabbix 
  119. cp /tmp/zabbix-$ZBX_VER/misc/conf/zabbix_agentd.conf /etc/zabbix 
  120.  
  121. cp /tmp/zabbix-$ZBX_VER/misc/init.d/redhat/8.0/zabbix_server /etc/init.d 
  122. cp /tmp/zabbix-$ZBX_VER/misc/init.d/redhat/8.0/zabbix_agentd /etc/init.d 
  123.  
  124.  
  125. cd /etc/zabbix 
  126. patch -p0 -l << "eof" 
  127. --- zabbix_server.conf.orig 2009-12-23 10:06:48.000000000 -0800 
  128. +++ zabbix_server.conf 2009-12-23 10:09:45.000000000 -0800 
  129. @@ -35,7 +35,7 @@ 
  130.  # Default: 
  131.  # LogFile
  132.  
  133. -LogFile=/tmp/zabbix_server.log 
  134. +LogFile=/var/log/zabbix-server/zabbix_server.log 
  135.  
  136.  ### Option: LogFileSize 
  137.  # Maximum size of log file in MB. 
  138. @@ -63,6 +63,7 @@ 
  139.  # Mandatory: no 
  140.  # Default: 
  141.  # PidFile=/tmp/zabbix_server.pid 
  142. +PidFile=/var/run/zabbix-server/zabbix_server.pid 
  143.  
  144.  ### Option: DBHost 
  145.  # Database host name. 
  146. @@ -88,7 +89,7 @@ 
  147.  # Default: 
  148.  # DBUser
  149.  
  150. -DBUser=root 
  151. +DBUser=_dbuser_ 
  152.  
  153.  ### Option: DBPassword 
  154.  # Database password. Ignored for SQLite. 
  155. @@ -97,6 +98,7 @@ 
  156.  # Mandatory: no 
  157.  # Default: 
  158.  # DBPassword
  159. +DBPassword=_dbpass_ 
  160.  
  161.  ### Option: DBSocket 
  162.  # Path to MySQL socket. 
  163. @@ -316,6 +318,7 @@ 
  164.  # Mandatory: no 
  165.  # Default: 
  166.  # AlertScriptsPath=/home/zabbix/bin/ 
  167. +AlertScriptsPath=/etc/zabbix/alert.d/ 
  168.  
  169.  ### Option: ExternalScripts 
  170.  # Location of external scripts 
  171. eof 
  172. sed "s/_dbuser_/${DBUSER}/g" /etc/zabbix/zabbix_server.conf > /tmp/mytmp393; mv /tmp/mytmp393 /etc/zabbix/zabbix_server.conf 
  173. sed "s/_dbpass_/${DBPASS}/g" /etc/zabbix/zabbix_server.conf > /tmp/mytmp393; mv /tmp/mytmp393 /etc/zabbix/zabbix_server.conf 
  174.  
  175.  
  176. patch -p0 -l << "eof" 
  177. --- zabbix_agentd.conf.orig 2009-12-23 10:20:25.000000000 -0800 
  178. +++ zabbix_agentd.conf 2009-12-23 10:22:17.000000000 -0800 
  179. @@ -9,6 +9,7 @@ 
  180.  # Mandatory: no 
  181.  # Default: 
  182.  # PidFile=/tmp/zabbix_agentd.pid 
  183. +PidFile=/var/run/zabbix-agent/zabbix_agentd.pid 
  184.  
  185.  ### Option: LogFile 
  186.  # Name of log file. 
  187. @@ -17,8 +18,7 @@ 
  188.  # Mandatory: no 
  189.  # Default: 
  190.  # LogFile
  191. -LogFile=/tmp/zabbix_agentd.log 
  192. +LogFile=/var/log/zabbix-agent/zabbix_agentd.log 
  193.  
  194.  ### Option: LogFileSize 
  195.  # Maximum size of log file in MB. 
  196. @@ -56,6 +56,7 @@ 
  197.  # Mandatory: no 
  198.  # Default: 
  199.  # EnableRemoteCommands=0 
  200. +EnableRemoteCommands=1 
  201.  
  202.  ### Option: LogRemoteCommands 
  203.  # Enable logging of executed shell commands as warnings 
  204. @@ -187,6 +188,7 @@ 
  205.  # Range: 1-30 
  206.  # Default: 
  207.  # Timeout=3 
  208. +Timeout=10 
  209.  
  210.  ### Option: Include 
  211.  # You may include individual files or all files in a directory in the configuration file. 
  212. eof 
  213.  
  214. cd /etc/init.d 
  215. patch -p0 -l << "eof" 
  216. --- zabbix_server.orig 2008-11-13 22:59:49.000000000 -0800 
  217. +++ zabbix_server 2008-11-13 23:53:58.000000000 -0800 
  218. @@ -14,7 +14,7 @@ 
  219.  [ "${NETWORKING}" = "no" ] && exit 0 
  220.   
  221.  RETVAL=0 
  222. -progdir="/usr/local/zabbix/bin/" 
  223. +progdir="/usr/local/sbin/" 
  224.  prog="zabbix_server" 
  225.   
  226.  start() { 
  227. --- zabbix_agentd.orig 2008-11-14 00:15:24.000000000 -0800 
  228. +++ zabbix_agentd 2008-11-14 00:15:32.000000000 -0800 
  229. @@ -14,7 +14,7 @@ 
  230.  [ "${NETWORKING}" = "no" ] && exit 0 
  231.   
  232.  RETVAL=0 
  233. -progdir="/usr/local/zabbix/bin/" 
  234. +progdir="/usr/local/sbin/" 
  235.  prog="zabbix_agentd" 
  236.   
  237.  start() { 
  238. eof 
  239.  
  240.  
  241. chkconfig zabbix_server on 
  242. chkconfig zabbix_agentd on 
  243. chmod +x /etc/init.d/zabbix_server 
  244. chmod +x /etc/init.d/zabbix_agentd 
  245. service zabbix_server restart 
  246. service zabbix_agentd restart 
  247.  
  248. #### END ZABBIX SERVER & AGENT PROCESS INSTALL & START 
  249.  
  250. #### BEGIN WEB 
  251.  
  252. rm -rf /usr/local/share/zabbix 
  253. mkdir -p /usr/local/share/zabbix 
  254. cp -r /tmp/zabbix-$ZBX_VER/frontends/php/* /usr/local/share/zabbix 
  255.  
  256. echo "Alias /zabbix /usr/local/share/zabbix" > /etc/httpd/conf.d/zabbix.conf 
  257. chkconfig httpd on 
  258. service httpd restart 
  259.  
  260. #sed "s/max_execution_time = 30/max_execution_time = 300/g" /etc/php.ini > /tmp/mytmp393; mv /tmp/mytmp393 /etc/php.ini 
  261.  
  262. #touch /usr/local/share/zabbix/conf/zabbix.conf.php 
  263.  
  264.  
  265. cd /usr/local/share/zabbix 
  266. patch -p0 -l << "eof" 
  267. --- include/setup.inc.php.orig 2009-12-23 10:32:58.000000000 -0800 
  268. +++ include/setup.inc.php 2009-12-23 10:34:24.000000000 -0800 
  269. @@ -210,7 +210,7 @@ 
  270.                                         $final_result, 
  271.                                         'PHP max execution time:', 
  272.                                         ini_get('max_execution_time').' sec', 
  273. - ini_get('max_execution_time') >= 300, 
  274. + ini_get('max_execution_time') >= 30, 
  275.                                         '300 sec is a minimal limitation on execution time of PHP scripts')); 
  276.  
  277.                         if(version_compare(phpversion(), '5.1.0', '>=')){ 
  278. @@ -220,7 +220,7 @@ 
  279.                                                 $final_result, 
  280.                                                 'PHP Timezone:', 
  281.                                                 empty($tmezone) ? 'n/a' : $tmezone, 
  282. - !empty($tmezone), 
  283. + empty($tmezone), 
  284.                                                 'Timezone for PHP is not set. Please set "date.timezone" option in php.ini.')); 
  285.                                 unset($tmezone); 
  286.                         } 
  287. --- include/page_header.php.orig 2009-12-23 10:36:53.000000000 -0800 
  288. +++ include/page_header.php 2009-12-23 10:37:55.000000000 -0800 
  289. @@ -444,8 +444,8 @@ 
  290.         if(version_compare(phpversion(), '5.1.0RC1', '>=') && $page['type'] == PAGE_TYPE_HTML){ 
  291.                 $tmezone = ini_get('date.timezone'); 
  292.                 if(empty($tmezone)) { 
  293. - info('Timezone for PHP is not set. Please set "date.timezone" option in php.ini.'); 
  294. - date_default_timezone_set('UTC'); 
  295. + //info('Timezone for PHP is not set. Please set "date.timezone" option in php.ini.'); 
  296. + //date_default_timezone_set('UTC'); 
  297.                 } 
  298.                 unset($tmezone); 
  299.         } 
  300. eof 
  301.  
  302. cat > /usr/local/share/zabbix/conf/zabbix.conf.php << "eof" 
  303. php 
  304. global $DB; 
  305.  
  306. $DB["TYPE"] = "MYSQL"; 
  307. $DB["SERVER"] = "_dbhost_"; 
  308. $DB["PORT"] = "0"; 
  309. $DB["DATABASE"] = "zabbix"; 
  310. $DB["USER"] = "_dbuser_"; 
  311. $DB["PASSWORD"] = "_dbpass_"; 
  312. $ZBX_SERVER = "127.0.0.1"
  313. $ZBX_SERVER_PORT = "10051"
  314.  
  315.  
  316. $IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG
  317. ?> 
  318. eof 
  319.  
  320.  
  321. sed "s/_dbhost_/${DBHOST}/g" /usr/local/share/zabbix/conf/zabbix.conf.php > /tmp/mytmp393; mv /tmp/mytmp393 /usr/local/share/zabbix/conf/zabbix.conf.php 
  322. sed "s/_dbuser_/${DBUSER}/g" /usr/local/share/zabbix/conf/zabbix.conf.php > /tmp/mytmp393; mv /tmp/mytmp393 /usr/local/share/zabbix/conf/zabbix.conf.php 
  323. sed "s/_dbpass_/${DBPASS}/g" /usr/local/share/zabbix/conf/zabbix.conf.php > /tmp/mytmp393; mv /tmp/mytmp393 /usr/local/share/zabbix/conf/zabbix.conf.php 
  324.  
  325. chmod 666 /usr/local/share/zabbix/conf/zabbix.conf.php 
  326.  
  327. sed "s/max_execution_time = 30/max_execution_time = 600/g;s/max_input_time = 60/max_input_time = 600/g;s/memory_limit = 128M/memory_limit = 256M/g;\ 
  328. s/post_max_size = 8M/post_max_size = 32M/g;s/upload_max_filesize = 2M/upload_max_filesize = 16M/g;\s/\;date.timezone =/date.timezone = Asia\/Shanghai/g" /etc/php.ini > /tmp/mytmp393; mv -f /tmp/mytmp393 /etc/php.ini 
  329.  
  330. /etc/init.d/httpd restart    
  331.  
  332. cd 
  333. echo "Load http://localhost/zabbix/" 
  334. echo "username: admin" 
  335. echo "password: zabbix" 
  336.  
  337. cat << "eof" 
  338. ########################## 
  339. vim /etc/php.ini 
  340.     max_execution_time = 600 
  341.     max_input_time = 600 
  342.     memory_limit = 256M 
  343.     post_max_size = 32M 
  344.     upload_max_filesize = 16M 
  345.     date.timezone = "Asia/Shanghai" 
  346.  
  347. /etc/init.d/httpd restart    
  348. ######################### 
  349. eof