#!/bin/bash
#zabbix one-click Install # Database user name dbuser= ' root ' #数据库用户密码DBPASS = ' root ' #本地地址DBHOST = ' localhost ' #zabbix download version zbx_ver= ' 2.4.3 ' # # #检查返回值 function Checkreturn {if [$1-ne 0]; then echo "Fail: $" echo "$" exit Else Echo "pass: $" fi SL Eep 3}## #安装的前提条件 # # #只个版本只可在centos或redhat 6.0 Install # # #前提需要先安装mysql cat << "EOF" = = = run at YOUR OWN RISK ===do not run on EXISTING installations, you *will* lose Datathis script: * Installs Zabbix 2.2.x in centos/red Hat 6 * Drops an EXISTING Database * Does not install MySQL; To install type ' yum install mysql-server ' * assums a vanilla OS install, though it tries to work around it * Does not INS Tall Zabbix packages, it uses source from zabbix.com * Disables firewall * Disables selinuxeof#### #前提条 pieces read-p ' Type ' Go ' To continue: ' Respif ["$RESP"! = "Go"]; Then echo "Sorry to hear It" exitelse echo "Lets does this ..." fi# check selinux## #检查防火墙是否关闭if ["' Sestatus |grep status|a WK ' {print $} ' "= =" Enabled "; Then #checkReturn 1 "Disable SELinuxAnd then retry "Setenforce 0 sed" s/selinux=enforcing/selinux=disabled/g "/etc/selinux/config >/tmp/mytmp093; Mv/tmp/mytmp093/etc/selinux/configfi#disable firewall# #关闭防火墙chkconfig iptables off/etc/init.d/iptables Stop # # # # Check if MySQL shuts down if ["' Rpm-qa |grep mysql-server '"]; Then chkconfig mysqld on service mysqld restartfi# check mysqlmysql-h${dbhost}-u${dbuser}--password=${dbpass} >/d Ev/null << eofstatuseofretval=$?checkreturn $RETVAL "basic mysql access" Install mysql server packages or fix MySQL Permissions "if [! "' Rpm-qa|grep fping '"; Then if ["' uname-m '" = = "x86_64"]; Then RPM-UHV http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm elif ["' Uname-m "= =" i686 "]; Then RPM-UHV http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm fifiyum-y Install GCC mysql-devel curl-devel httpd php php-mysql php-bcmath php-gd php-xml php-mbstring net-snmp-devel fping e2fsprogs-deve L zlib-Devel libgssapi-devel krb5-devel openssl-devel wget libssh2-devel openldap-devel libxml2-devel make patchRETVAL=$? Checkreturn $RETVAL "Package Install" chmod 4755/usr/sbin/fpingcd/tmprm-rf/etc/zabbixrm-rf zabbix-$ZBX _verrm zabbix-$ ZBX_VER.tar.gzwget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/$ZBX _ver/zabbix-$ZBX _ Ver.tar.gzretval=$?checkreturn $RETVAL "Downloading source" "Check zbx_ver variable or mirror might is down" tar xzf Zabbix -$ZBX _ver.tar.gzcd zabbix-$ZBX _ver./configure--enable-agent--enable-ipv6--enable-proxy--enable-server-- With-mysql--with-libcurl--with-net-snmp--with-ssh2--with-ldap--with-libxml2--sysconfdir=/etc/zabbixRETVAL=$? Checkreturn $RETVAL "Configure" Makeretval=$?checkreturn $RETVAL "Compile" Make Installretval=$?checkreturn $RETVAL " Make install "echo" DROP DATABASE IF EXISTS Zabbix; "| Mysql-h${dbhost}-u${dbuser}--password=${dbpass} (echo "CREATE DATABASE Zabbix;") echo "Use Zabbix;" cat/tmp/zabbix-$ZBX _ver/database/mysql/schema.sqlcat/tmp/zabbix-$ZBX _ver/database/mysql/images.sqlcat/tmp/zabbix-$ZBX _ver/database/mysql/data.sql) | Mysql-h${dbhost}-u${dbuser}--password=${dbpass}adduser-r-d/var/run/zabbix-server-s/sbin/nologin zabbixmkdir-p/V Ar/log/zabbix-servermkdir-p/var/log/zabbix-agentmkdir-p/var/run/zabbix-servermkdir-p/var/run/zabbix-agentchown Zabbix.zabbix/var/run/zabbix*chown zabbix.zabbix/var/log/zabbix*cp/tmp/zabbix-$ZBX _ver/misc/init.d/fedora/core5 /zabbix_server/etc/init.dcp/tmp/zabbix-$ZBX _ver/misc/init.d/fedora/core5/zabbix_agentd/etc/init.dcd/etc/ Zabbixpatch-p0-l << "EOF"---orig/zabbix_server.conf 2012-07-01 18:30:00.585612301-0700+++ zabbix_server.conf 2012-07-01 18:58:15.181605999-0700@@ -36,7 +36,7 @@ # Default: # logfile=-logfile=/tmp/zabbix_server.log+logfile=/var/ Log/zabbix-server/zabbix_server.log # # # option:logfilesize # Maximum size of log file in mb.@@ -65,7 +65,7 @@ # # Ma Ndatory:no # default:-# Pidfile=/tmp/zabbix_server.pid+pidfile=/var/run/zabbix-server/zabbix_server.pid # # # option:dbhost # Database host name.@@ -100,7 +100,7 @@ # Default: # DB User=-dbuser=root+dbuser=_dbuser_ # # # Option:dbpassword # Database password. Ignored for sqlite.@@ -109,6 +109,7 @@ # mandatory:no # Default: # dbpassword=+dbpassword=_dbpass_ # # Option:dbsocket # Path to MySQL socket.eofsed "s/_dbuser_/${dbuser}/g"/etc/zabbix/zabbix_server.conf >/tmp/mytmp393; Mv/tmp/mytmp393/etc/zabbix/zabbix_server.confsed "s/_dbpass_/${dbpass}/g"/etc/zabbix/zabbix_server.conf >/tmp /mytmp393; Mv/tmp/mytmp393/etc/zabbix/zabbix_server.confpatch-p0-l << "EOF"---orig/zabbix_agentd.conf 2012-07-01 18:30 : 00.585612301-0700+++ zabbix_agentd.conf 2012-07-01 18:55:40.566660188-0700@@ -9,6 +9,7 @@ # mandatory:no # Default: # Pidfile=/tmp/zabbix_agentd.pid+pidfile=/var/run/zabbix-agent/zabbix_agentd.pid # # # option:logfile # Name of log fil e.@@ -18,7 +19,7 @@ # Default: # LOGFILE=-LOGFILE=/TMP/ZABBIX_AGENTD.LOg+logfile=/var/log/zabbix-agent/zabbix_agentd.log # # # option:logfilesize # Maximum size of log file in mb.@@ -57,6 +58,7 @@ # mandatory:no # Default: # enableremotecommands=0+enableremotecommands=1 # # # option:logremotecommands # E nable logging of executed shell commands as Warnings.eofchkconfig zabbix_server onchkconfig zabbix_agentd onchmod +x/etc/ Init.d/zabbix_serverchmod +x/etc/init.d/zabbix_agentdservice zabbix_server restartservice zabbix_agentd restart#### END ZABBIX SERVER & AGENT PROCESS INSTALL & start#### BEGIN webrm-rf/usr/local/share/zabbixmkdir-p/usr/local/s Hare/zabbixcp-r/tmp/zabbix-$ZBX _ver/frontends/php/*/usr/local/share/zabbixecho "alias/zabbix/usr/local/share/ Zabbix ">/etc/httpd/conf.d/zabbix.confecho" post_max_size = 16M ">/etc/php.d/local_zabbix.iniecho" max_ Execution_time = ">>/etc/php.d/local_zabbix.iniecho" max_input_time = ">>/etc/php.d/local_ Zabbix.ini./etc/sysconfig/clockecho "Date.timezone = $ZONE ">>/etc/php.d/local_zabbix.inichkconfig httpd onservice httpd restart#sed" s/max_execution_time = 30/max_ Execution_time = 300/g "/etc/php.ini >/tmp/mytmp393; Mv/tmp/mytmp393/etc/php.ini#touch/usr/local/share/zabbix/conf/zabbix.conf.php#chmod 666/usr/local/share/zabbix/ Conf/zabbix.conf.phpcat >/usr/local/share/zabbix/conf/zabbix.conf.php << "EOF" <?php//Zabbix GUI Configuration Fileglobal $DB; $DB [' TYPE '] = "MYSQL"; $DB [' SERVER '] = "_dbhost_"; $DB [' PORT '] = "0"; $DB [' DATABASE '] = "Zabbix"; $DB [' USER '] = "_dbuser_"; $DB [' PASSWORD '] = "_dbpass_";//SC HEMA is relevant only for IBM_DB2 database$db[' SCHEMA '] = "; $ZBX _server =" 127.0.0.1 "; $ZBX _ Server_port = "10051"; $ZBX _server_name= "; $IMAGE _format_default = Image_format_png;? >eofsed "s/_dbhost_/${dbhost}/g"/usr/local/share/zabbix/conf/zabbix.conf.php >/tmp/mytmp393; Mv/tmp/mytmp393/usr/local/share/zabbix/cOnf/zabbix.conf.phpsed "s/_dbuser_/${dbuser}/g"/usr/local/share/zabbix/conf/zabbix.conf.php >/tmp/mytmp393; Mv/tmp/mytmp393/usr/local/share/zabbix/conf/zabbix.conf.phpsed "S/_dbpass_/${dbpass}/g"/usr/local/share/zabbix/ conf/zabbix.conf.php >/tmp/mytmp393; MV/TMP/MYTMP393/USR/LOCAL/SHARE/ZABBIX/CONF/ZABBIX.CONF.PHPCD echo "Load http://localhost/zabbix/" echo "Username: Admin "echo" Password:zabbix "
Zabbix One-click installation, provided MySQL is installed and has a password, has been tested on CentOS 6.5