zabbix一鍵安裝,前提是mysql已安裝好,且已設好密碼,已在centos6.5上做過測試

來源:互聯網
上載者:User

zabbix一鍵安裝,前提是mysql已安裝好,且已設好密碼,已在centos6.5上做過測試

#!/bin/bash

#zabbix 一鍵安裝#資料庫使用者名稱DBUSER='root'#資料庫使用者密碼DBPASS='root'#本地地址DBHOST='localhost'#zabbix 下載的版本ZBX_VER='2.4.3'###檢查傳回值 function checkReturn {  if [ $1 -ne 0 ]; then     echo "fail: $2"     echo "$3"     exit  else     echo "pass: $2"  fi  sleep 3}###安裝的前提條件###只個版本只可在centos或redhat 6.0上安裝###前提需要先安裝mysql cat << "eof"=== RUN AT YOUR OWN RISK ===DO NOT RUN ON EXISTING INSTALLATIONS, YOU *WILL* LOSE DATAThis script: * Installs Zabbix 2.2.x on 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 install zabbix packages, it uses source from zabbix.com * Disables firewall * Disables SELinuxeof#####前提條 件read -p 'Type "go" to continue: ' RESPif [ "$RESP" != "go" ]; then  echo "Sorry to hear it"  exitelse  echo "Lets do this..."fi# check selinux###檢查防火牆是否關閉if [ "`sestatus |grep status|awk '{ print $3 }'`" == "enabled" ]; then   #checkReturn 1 "Disable SELinux and 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  ###檢查mysql 是否關閉if [ "`rpm -qa |grep mysql-server`" ]; then  chkconfig mysqld on  service mysqld restartfi# check mysqlmysql -h${DBHOST} -u${DBUSER} --password=${DBPASS} > /dev/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-devel 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 be 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 /var/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 @@ # # Mandatory: 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: # DBUser=-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 file.@@ -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 #      Enable 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/share/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 = 300" >> /etc/php.d/local_zabbix.iniecho "max_input_time = 300" >> /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_";// SCHEMA 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"

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.