zabbix server&agent端自動(dòng)安裝腳本-純編譯版

摘要

本腳本實(shí)現(xiàn)了一鍵配置zabbix的server端或者agent端的環(huán)境负蠕,由于MariaDB采取了編譯安裝的方法表蝙,所以在測(cè)試的時(shí)候系統(tǒng)內(nèi)存不建議小余4GB荔棉。
當(dāng)然你也可以自由的修改本腳本和反饋本腳本的各種錯(cuò)誤和不足蔫劣。

zabbixInstall.png
zabbixInstall01.png
  • 下載并執(zhí)行腳本
wget -q https://www.dwhd.org/wp-content/uploads/2015/05/zabbix_server_agent.sh && bash zabbix_server_agent.sh
  • 腳本內(nèi)容
#!/bin/bash
#########################################################################
# File Name: zabbixserver.sh
# Author: LookBack
# Email: 393411264@qq.com
# Version:
# Created Time: Mon Dec 22 23:09:24 CST 2014
#########################################################################

#########################################################################
##本腳本的作用:
##    在一個(gè)全新的CentOS系統(tǒng)上編譯安裝nginx1.6.2 cmake3.1 php5.5.20 
##    MariaDB10.0.15 zabbix2.4.6 或者 安裝zabbix Agent端
##
##    實(shí)現(xiàn)一個(gè)基于LNMP環(huán)境的zabbix server端配置 或zabbix agent端配置
#########################################################################

nginxDir="/usr/local/nginx/"
phpDir="/usr/local/php/"
mysqlDir="/usr/local/mysql/"
mysqlPass="lookback"
zbmysqlName="zabbix"
zbmysqlUser="zabbixuser"
zbmysqlPass="zabbixpass"
zbserverconf="/etc/zabbix/zabbix_server.conf"


##下面的源碼下載地址請(qǐng)勿在不理解腳本的前提下做修改
nginxUrl="http://nginx.org/download/nginx-1.6.2.tar.gz"
phpUrl="http://cn2.php.net/get/php-5.5.20.tar.gz/from/this/mirror"
cmakeUrl="http://www.cmake.org/files/v3.1/cmake-3.1.0.tar.gz"
mariadbUrl="https://downloads.mariadb.org/interstitial/mariadb-10.0.15/source/mariadb-10.0.15.tar.gz"
zabbixUrl="http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.4.6/zabbix-2.4.6.tar.gz"

#檢測(cè)是否是root用戶執(zhí)行腳本
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1 
if ! which whiptail &>/dev/null; then yum install newt;fi
if ! which wget &>/dev/null; then yum install wget;fi

install_nginx() {
    #添加nginx的系統(tǒng)用戶和系統(tǒng)組
    findUidGid nginx
    #下載 解壓 編譯 安裝nginx
    cd && [ ! -f nginx-1.6.2.tar.gz ] && downFile "$1" "nginx-1.6.2.tar.gz" "Dwonload Nginx 1.6.2"
    tar xf nginx-1.6.2.tar.gz 
    cd nginx-1.6.2
    ./configure \
--prefix=$nginxDir \
--error-log-path=/home/wwwlogs/nginx/error.log \
--http-log-path=/home/wwwlogs/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid  \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_spdy_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-client-body-temp-path=${nginxDir}client/ \
--http-proxy-temp-path=${nginxDir}proxy/ \
--http-fastcgi-temp-path=${nginxDir}fcgi/ \
--http-uwsgi-temp-path=${nginxDir}uwsgi \
--http-scgi-temp-path=${nginxDir}scgi \
--with-pcre
    make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install
    [ $? != 0 ] && exit 1
    sed -i '$i\\t include vhost/*.conf;' ${nginxDir}conf/nginx.conf
    mkdir ${nginxDir}conf/vhost/
    #設(shè)置環(huán)境變量
    echo "export PATH=${nginxDir}sbin:\$PATH" > /etc/profile.d/nginx162.sh
    . /etc/profile.d/nginx162.sh
    #下載nginx啟動(dòng)腳本和設(shè)置開機(jī)啟動(dòng)
    downFile "http://www.05hd.com/wp-content/uploads/2014/12/Nginx-init-CentOS.sh" "/etc/rc.d/init.d/nginx" "Download Nginx Init File" 
    chmod +x /etc/rc.d/init.d/nginx
    chkconfig --add nginx
    chkconfig nginx on
}

install_php() {
    #下載 解壓 編譯 安裝PHP5.5.20
    cd && [ ! -f php-5.5.20.tar.gz ] && downFile "$1" "php-5.5.20.tar.gz" "Download PHP 5.5.20"  
    tar xf php-5.5.20.tar.gz 
    cd php-5.5.20
    ./configure  --prefix=${phpDir} \
--with-config-file-path=${phpDir}etc \
--with-bz2 \
--with-curl \
--enable-ftp \
--enable-dom \
--enable-xml \
--enable-fpm \
--enable-ipv6 \
--enable-bcmath \
--enable-sockets \
--enable-mbstring \
--enable-calendar \
--enable-gd-native-ttf \
--with-gd \
--with-zlib \
--with-gettext \
--with-libdir=lib64 \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-png-dir=/usr/local \
--with-jpeg-dir=/usr/local \
--with-iconv-dir=/usr/local \
--with-libxml-dir=/usr/local \
--with-freetype-dir=/usr/local 
    make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install
    [ $? != 0 ] && exit 1
    #設(shè)置環(huán)境變量
    echo "export PATH=${phpDir}bin:\$PATH" > /etc/profile.d/php5520.sh
    . /etc/profile.d/php5520.sh
    #檢測(cè)php是否安裝成功
    [ -z $(which php) ] && exit 1
    #拷貝配置文件
    cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    cp php.ini-production ${phpDir}etc/php.ini
    cp ${phpDir}etc/php-fpm.conf.default ${phpDir}etc/php-fpm.conf
    #修改配置文件
    sed -ri 's/^(max_execution_time = ).*/\1300/' ${phpDir}etc/php.ini
    sed -ri 's/^(memory_limit = ).*/\1128M/' ${phpDir}etc/php.ini
    sed -ri 's/^(post_max_size = ).*/\116M/' ${phpDir}etc/php.ini
    sed -ri 's/^(upload_max_filesize = ).*/\12M/' ${phpDir}etc/php.ini
    sed -ri 's/^(max_input_time = ).*/\1300/' ${phpDir}etc/php.ini
    sed -ri '/date.timezone =/a date.timezone = PRC' ${phpDir}etc/php.ini
    #添加啟動(dòng)項(xiàng)
    chmod +x /etc/init.d/php-fpm
    chkconfig --add php-fpm
    chkconfig php-fpm on
    #啟動(dòng)php-fpm 且檢測(cè)是否啟動(dòng)成功
    service php-fpm restart
    ss -tnl | grep ':9000' &>/dev/null
    [ $? != 0 ] && exit 1
}

install_cmake() {
    #下載 解壓 編譯 安裝cmake
    cd && [ ! -f cmake-3.1.0.tar.gz ] && downFile "$1" "cmake-3.1.0.tar.gz" "Download CMAKE 3.1.0"
    tar xf cmake-3.1.0.tar.gz
    cd cmake-3.1.0
    ./configure --prefix=/usr/local/cmake --mandir=/usr/local/share/man --datadir=/usr/share/ --docdir=/usr/share/doc --no-system-libs --system-curl --no-system-libarchive --system-bzip2 --system-expat
    make -j $(awk '{if($1=="processor"){i++}}END{print i}' /proc/cpuinfo) && make install
    [ $? != 0 ] && exit 1
    #檢測(cè)cmake是否ok,不ok 退出腳本
    [ $? != 0 ] && exit 1
    echo "export PATH=/usr/local/cmake/bin:\$PATH" > /etc/profile.d/cmake310.sh
    . /etc/profile.d/cmake310.sh
}

install_mariadb() {
    #添加mysql系統(tǒng)用戶和系統(tǒng)組
    findUidGid mysql
    #下載 解壓 編譯 安裝MariaDB
    cd && [ ! -f mariadb-10.0.15.tar.gz ] && downFile "$1" "mariadb-10.0.15.tar.gz" "Download MariaDB 10.0.15"
    [ -f mariadb-10.0.15 ] && rm -rf mariadb-10.0.15
    tar xf mariadb-10.0.15.tar.gz && cd mariadb-10.0.15
    cmake . -DCMAKE_INSTALL_PREFIX=$mysqlDir \
-DMYSQL_DATADIR=${mysqlDir}data/ \
-DWITH_SSL=system \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_SPHINX_STORAGE_ENGINE=1 \
-DWITH_ARIA_STORAGE_ENGINE=1 \
-DWITH_XTRADB_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATEDX_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_READLINE=1 \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DWITH_EXTRA_CHARSETS=all \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
    make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install
    [ $? != 0 ] && exit 1
    #重置編譯
    #make clean
    #rm CMakeCache.txt

    #設(shè)置啟動(dòng)腳本
    cp ${mysqlDir}support-files/mysql.server /etc/rc.d/init.d/mysqld
    chmod +x /etc/rc.d/init.d/mysqld
    #配置配置文件
    \cp ${mysqlDir}support-files/my-large.cnf /etc/my.cnf
    sed -i "/query_cache_size/a datadir = ${mysqlDir}data/" /etc/my.cnf
    #初始化MariaDB
    cd ${mysqlDir}
    ${mysqlDir}scripts/mysql_install_db --user=mysql --datadir=${mysqlDir}data/
    #設(shè)置MariaDB的環(huán)境變量
    echo "export PATH=${mysqlDir}bin:\$PATH" > /etc/profile.d/mariadb10015.sh
    . /etc/profile.d/mariadb10015.sh
    chkconfig --add mysqld
    chkconfig mysqld on
    #啟動(dòng)MariaDB
    service mysqld start
    #檢測(cè)MariaDB啟動(dòng)正常否赊颠,不正常就退出腳本
    ss -tnl | grep ':3306' &>/dev/null && [ $? != 0 ] && exit 1

    #刪除MariaDB中的空賬戶和設(shè)置root帳戶密碼
    mysql <<< "USE mysql;
update user set password=PASSWORD('$mysqlPass') WHERE USER='root';
DELETE FROM user WHERE User='';
SELECT USER,PASSWORD,HOST FROM user;
FLUSH PRIVILEGES;"

    #打印mysql status信息,不成功則退出腳本
    mysql -uroot -p$mysqlPass <<< status && [ $? != 0 ] && exit 1
    
    #添加zabbix的數(shù)據(jù)庫和用戶
    mysql -uroot -p$mysqlPass <<< "USE mysql;
CREATE DATABASE $zbmysqlName CHARACTER SET utf8;
GRANT ALL on $zbmysqlName.* TO '$zbmysqlUser'@'localhost' IDENTIFIED BY '$zbmysqlPass';
GRANT ALL on $zbmysqlName.* TO '$zbmysqlUser'@'127.0.0.1' IDENTIFIED BY '$zbmysqlPass';
GRANT ALL on $zbmysqlName.* TO '$zbmysqlUser'@'::1' IDENTIFIED BY '$zbmysqlPass';
GRANT ALL on $zbmysqlName.* TO '$zbmysqlUser'@'192.168.%.%' IDENTIFIED BY '$zbmysqlPass';
GRANT ALL on $zbmysqlName.* TO '$zbmysqlUser'@'172.16.%.%' IDENTIFIED BY '$zbmysqlPass';
GRANT ALL on $zbmysqlName.* TO '$zbmysqlUser'@'$(hostname)' IDENTIFIED BY '$zbmysqlPass';
SELECT USER,PASSWORD,HOST FROM user;
FLUSH PRIVILEGES;"
}

install_JDK() {
    if [ "64" = "$(getconf LONG_BIT)" ]; then
        downFile "http://www.05hd.com/wp-content/uploads/2014/12/jdk-8u25-linux-x64.rpm" "jdk-8u25-linux-x64.rpm" "Download JDK 8u25 RPM"
        rpm -ivh jdk-8u25-linux-x64.rpm && [ $? != 0 ] && exit 1
    elif [ "32" = "$(getconf LONG_BIT)" ]; then
        downFile "http://www.05hd.com/wp-content/uploads/2014/12/jdk-8u25-linux-i586.rpm" "jdk-8u25-linux-i586.rpm" "Download JDK 8u25 RPM"
        rpm -ivh jdk-8u25-linux-i586.rpm && [ $? != 0 ] && exit 1
    else
        echo "I don't know your OS BIT" && exit 1
    fi
    cat > /etc/profile.d/java.sh << EOF
JAVA_HOME=/usr/java/latest
PATH=\$JAVA_HOME/bin:\$PATH
export JAVA_HOME PATH
EOF
    source /etc/profile.d/java.sh
}

install_zabbix() {
    #添加zabbix系統(tǒng)用戶和系統(tǒng)組
    findUidGid zabbix
    #讓zabbix支持使用jmx方式監(jiān)控tomcat劈彪,安裝JDK環(huán)境
    install_JDK
    #下載 解壓 編譯 安裝zabbix
    cd && [ ! -f zabbix-2.4.6.tar.gz ] && downFile "$1" "zabbix-2.4.6.tar.gz" "Download Zabbix 2.4.6"
    [ ! -f zabbix-2.4.6 ] && tar xf zabbix-2.4.6.tar.gz 
    cd zabbix-2.4.6
    ./configure --prefix=/usr/local/zabbix/ \
--sysconfdir=$(dirname $zbserverconf) \
--enable-server \
--enable-agent \
--enable-ipv6 \
--enable-java \
--with-mysql=$(find ${mysqlDir} -name "mysql_config") \
--with-net-snmp \
--with-libcurl \
--with-openipmi \
--with-libxml2
    make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install
    [ $? != 0 ] && exit 1
    echo "export PATH=/usr/local/zabbix/sbin:\$PATH" > /etc/profile.d/zabbix243.sh
    . /etc/profile.d/zabbix243.sh
    zabbixsrcDir="/root/zabbix-2.4.6"
    . /etc/profile.d/mariadb10015.sh
    for i in schema.sql images.sql data.sql; do mysql -uroot -p$mysqlPass $zbmysqlName < ${zabbixsrcDir}/database/mysql/$i;done
    #[ -f /etc/zabbix ] || mkdir /etc/zabbix/
    zbserverconf="/etc/zabbix/zabbix_server.conf"
    cp ${zabbixsrcDir}/conf/zabbix_server.conf /etc/zabbix/
    sed -ri /^DBName=/d $zbserverconf
    sed -ri /^DBUser=/d $zbserverconf
    sed -ri /^DBPassword=/d $zbserverconf
    sed -ri "s/(DBName=)/&\n\1$zbmysqlName/" $zbserverconf
    sed -ri "s/(DBUser=)/&\n\1$zbmysqlUser/" $zbserverconf
    sed -ri "s/.*(DBPassword=).{0,}/&\n\1$zbmysqlPass/" $zbserverconf
    sed -i '/JavaGateway=/a JavaGateway=127.0.0.1\nJavaGatewayPort=10052\nStartJavaPollers=5' $zbserverconf
    sed -i '/LISTEN_IP="0.0.0.0"/a LISTEN_IP="0.0.0.0"' /usr/local/zabbix/sbin/zabbix_java/settings.sh
    sed -i '/LISTEN_PORT=10052/a LISTEN_PORT=10052' /usr/local/zabbix/sbin/zabbix_java/settings.sh
    sed -i '/START_POLLERS=5/a START_POLLERS=5' /usr/local/zabbix/sbin/zabbix_java/settings.sh
    #CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=12345 -Djava.rmi.server.hostname=192.168.0.102"

    ln -s ${mysqlDir}lib/libmysqlclient.so.18 /usr/lib
    ln -s ${mysqlDir}lib/libmysqlclient.so.18 /usr/lib64
    ldconfig
    cat >> /etc/services << EOF
zabbix-agent    10050/tcp       #ZabbixAgent
zabbix-agent    10050/udp       #Zabbix Agent
zabbix-trapper  10051/tcp       #ZabbixTrapper
zabbix-trapper  10051/udp       #Zabbix Trapper
EOF

    mkdir -p /home/wwwroot/zabaix
    sed -i '/zh_CN/{s/false/true/}' ${zabbixsrcDir}/frontends/php/include/locales.inc.php
    sed -i 's/DejaVuSans/simkai/g' ${zabbixsrcDir}/frontends/php/include/defines.inc.php
    cp -rp ${zabbixsrcDir}/frontends/php/* /home/wwwroot/zabaix/
    downFile "http://www.05hd.com/wp-content/uploads/2014/12/simkai.ttf" "/home/wwwroot/zabaix/fonts/simkai.ttf" "Download Simkai.TTF"
    cp -rp ${zabbixsrcDir}/misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/
    cp -rp ${zabbixsrcDir}/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/
    sed -i 's@BASEDIR=/usr/local@&/zabbix@' /etc/rc.d/init.d/zabbix_server
    sed -i 's@BASEDIR=/usr/local@&/zabbix@' /etc/rc.d/init.d/zabbix_agentd
    chkconfig --add zabbix_server
    chkconfig --add zabbix_agentd
    chkconfig zabbix_server on
    chkconfig zabbix_agentd on
    service zabbix_server start
    service zabbix_agentd start
    echo -e "server {
listen       88;
\tserver_name www.abc.com;
\taccess_log  /home/wwwlogs/nginx/www.abc.com.access.log  combined;

\tindex index.html index.php index.html;
\troot /home/wwwroot/zabaix/;

\tlocation /
\t{
\t\ttry_files \$uri \$uri/ /index.php?\$args;
\t}

\tlocation ~ ^(.+.php)(.*)\$ {
\t\tfastcgi_split_path_info ^(.+.php)(.*)\$;
\t\tinclude fastcgi.conf;
\t\tfastcgi_pass  127.0.0.1:9000;
\t\tfastcgi_index index.php;
\t\tfastcgi_param  PATH_INFO          \$fastcgi_path_info;
\t\t}
\t}" > ${nginxDir}conf/vhost/zabbix.conf
    service nginx start
}

install_zabbix_agent() {
    findUidGid zabbix
    cd && [ ! -f zabbix-2.4.6.tar.gz ] && downFile "$1" "zabbix-2.4.6.tar.gz" "Download Zabbix 2.4.6"
    [ ! -f zabbix-2.4.6 ] && tar xf zabbix-2.4.6.tar.gz
    cd zabbix-2.4.6
    ./configure --prefix=/usr/local/zabbix \
    --sysconfdir=$(dirname $zbserverconf) \
    --enable-agent \
    --enable-ipv6 
    make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install
    [ $? != 0 ] && exit 1
    sed -ri "s/(Server=)127.0.0.1/\1$ZabbixServerIp/" $(dirname $zbserverconf)/zabbix_agentd.conf
    sed -ri "s/(ServerActive=).*/\1$ZabbixServerIp/" $(dirname $zbserverconf)/zabbix_agentd.conf
    sed -ri "s/(Hostname=).*/\1$(hostname)/" $(dirname $zbserverconf)/zabbix_agentd.conf
    sed -ri '/BufferSize=/a BufferSize=1024' $(dirname $zbserverconf)/zabbix_agentd.conf
    sed -ri '/Timeout=/a Timeout=5' $(dirname $zbserverconf)/zabbix_agentd.conf
    sed -ri '/StartAgents=/a StartAgents=3' $(dirname $zbserverconf)/zabbix_agentd.conf
    sed -ri '/DebugLevel=/a DebugLevel=2' $(dirname $zbserverconf)/zabbix_agentd.conf
    sed -ri '/PidFile=/a PidFile=/var/tmp/zabbix_agentd.pid' $(dirname $zbserverconf)/zabbix_agentd.conf
    sed -ri 's@(LogFile=).*@\1/var/log/zabbix/zabbix_agentd.log@' $(dirname $zbserverconf)/zabbix_agentd.conf
    sed -ri '/LogFileSize=/a LogFileSize=10' $(dirname $zbserverconf)/zabbix_agentd.conf
    sed -ri '/EnableRemoteCommands=/a EnableRemoteCommands=1' $(dirname $zbserverconf)/zabbix_agentd.conf
    sed -ri "/Include=$/a Include=$(dirname $zbserverconf)/zabbix_command.conf" $(dirname $zbserverconf)/zabbix_agentd.conf

    mkdir /var/log/zabbix && chown -R zabbix:zabbix /var/log/zabbix/
    touch $(dirname $zbserverconf)/zabbix_command.conf

    cat >> /etc/services << EOF
zabbix-agent 10050/tcp #Zabbix Agent
zabbix-agent 10050/udp #Zabbix Agent
EOF
    cp /root/zabbix-2.4.6/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/
    sed -i 's@BASEDIR=/usr/local@&/zabbix@' /etc/rc.d/init.d/zabbix_agentd
    chmod +x /etc/rc.d/init.d/zabbix_agentd 
    chkconfig --add zabbix_agentd
    chkconfig zabbix_agentd on
    service zabbix_agentd start
}

downFile() {
    wget "$1" -4O "$2" 2>&1 | stdbuf -o0 awk '/[.] +[0-9][0-9]?[0-9]?%/ {print substr($0,63,3)}' | whiptail --gauge "$3" 6 80 0 && clear
}

findUidGid() {
    for i in `seq 400 500`;do
        if [ -z "$(awk -F: '{print$3,$4}' /etc/passwd | grep "$i")" -a -z "$(awk -F: '{print$3}' /etc/group | grep "$i")" ]; then
            ugidNo=$i
            break
        fi
    done
    groupadd -g $ugidNo $1 && useradd -M -u $ugidNo -g $ugidNo -s /sbin/nologin $1
}

donotDel() {
    if (whiptail --title "防止手賤誤刪除功能" --yesno "是否需要在本系統(tǒng)上實(shí)現(xiàn)防手賤誤刪除功能竣蹦,\n開啟之后在運(yùn)行rm -rf 命令時(shí)會(huì)再次提醒是否確認(rèn)刪除。" 10 60); then
        #防手賤運(yùn)行rm -rf
        downFile "http://www.05hd.com/wp-content/uploads/2014/12/securityremove" "/bin/securityremove" "Download securityremove"
        chmod 755 /bin/securityremove
        test -f /etc/bash.bashrc && sed -i "/securityremove/d" /etc/bash.bashrc && echo 'alias rm="/bin/securityremove"' >> /etc/bash.bashrc && . /etc/bash.bashrc
        test -f /etc/bashrc && sed -i "/securityremove/d" /etc/bashrc && echo 'alias rm="/bin/securityremove"' >> /etc/bashrc && . /etc/bashrc
        test -f /root/.bashrc && sed -i "/alias rm/d" /root/.bashrc && echo 'alias rm="/bin/securityremove"' >> /root/.bashrc && . /root/.bashrc
        echo "防止手賤誤刪除功能已經(jīng)開啟."
    else
        echo "不開啟防手賤誤刪除功能."
    fi
}

changTime() {
    [ -z "$(grep -E '8.8.8.8|114.114.114.114' /etc/resolv.conf )" ] && sed -i '1i\nameserver 114.114.114.114\nnameserver 8.8.8.8' /etc/resolv.conf
    if (whiptail --title "網(wǎng)絡(luò)自動(dòng)校時(shí)" --yesno "是否需要在本系統(tǒng)上開啟定時(shí)自動(dòng)網(wǎng)絡(luò)校時(shí)功能" 10 60); then
        #設(shè)置定制網(wǎng)絡(luò)校時(shí)和關(guān)閉系統(tǒng)發(fā)郵件給用戶
        [ -f /var/spool/cron/root ] && sed -i '/ntpdate/d' /var/spool/cron/root
        echo "*/5 * * * * /usr/sbin/ntpdate cn.pool.ntp.org >/dev/null 2>&1" >> /var/spool/cron/root
        /usr/sbin/ntpdate cn.pool.ntp.org >/dev/null 2>&1
        [ -z "$(grep 'unset MAILCHECK' /etc/profile)" ] && echo "unset MAILCHECK" >> /etc/profile && . /etc/profile
        echo "定時(shí)自動(dòng)網(wǎng)絡(luò)校時(shí)已經(jīng)開啟."
    else
        echo "不開啟自動(dòng)網(wǎng)絡(luò)小時(shí)功能."
    fi
}

changYum() {
    if (whiptail --title "更改YUM源" --yesno "是否需將YUM源修改為阿里云鏡像源" 10 60); then
        yumDir="/etc/yum.repos.d/"
        aliUrl="mirrors.aliyun.com"
        [ ! -d ${yumDir}backup -a ! -f ${yumDir}backup ] && mkdir ${yumDir}backup
        mv -f ${yumDir}*.repo ${yumDir}backup/
        if (whiptail --title "系統(tǒng)版本確認(rèn)" --yes-button "CentOS 6.*" --no-button "CentOS 5.*"  --yesno "請(qǐng)謹(jǐn)慎選擇您的系統(tǒng)版本" 10 60) then
            wget -4qO ${yumDir}CentOS-Base.repo "http://$aliUrl/repo/Centos-6.repo"
            wget -4qO ${yumDir}epel.repo "http://$aliUrl/repo/epel-6.repo"
            rpm -ivh http://www.05hd.com/wp-content/uploads/2014/12/axel-2.4-1.el6.rf.x86_64.rpm &>/dev/null
        else
            wget -4O ${yumDir}CentOS-Base.repo "http://$aliUrl/repo/Centos-5.repo"
            wget -4O ${yumDir}epel.repo "http://$aliUrl/repo/epel-5.repo"
            rpm -ivh http://www.05hd.com/wp-content/uploads/2014/12/axel-2.4-1.el5.rf.x86_64.rpm &>/dev/null
        fi
        echo "YUM源已經(jīng)修改."
    else
        echo "YUM源不做修改."
    fi
}

addAlias() {
    #設(shè)置快捷命令
    if ! grep "alias vi='vim'" /root/.bashrc &>/dev/null; then
        cat >> /root/.bashrc << EOF
alias vi='vim'
alias grep='grep --color=auto'
export VISUAL=vim
export EDITOR=vim
EOF
        #取消vim搜索歷史高亮
        sed -i 's/.*set hlsearch.*/"&/' /etc/vimrc
        #如果能聯(lián)網(wǎng)則下載VIM配置文件
        wget -cq http://www.05hd.com/wp-content/uploads/2014/12/vim.tar.gz
        tar xf vim.tar.gz -C /root/ && rm -rf vim.tar.gz
    fi
}

clear #&& addAlias && donotDel && changTime && changYum

#開始安裝
#清空yum 安裝一些所需
OPTION=$(whiptail --title "Zabbix Server OR Agent Install" --menu "Choose your option" 15 60 4 \
"1" "Install Zabbix Server" \
"2" "Install Zabbix Agent" \
"3" "Exit Script" 3>&1 1>&2 2>&3)
  
exitstatus=$?
if [ $exitstatus = 0 ]; then
    if [ $OPTION = 1 ]; then
        yum clean all && yum makecache
        yum groupinstall "Development tools" "Server Platform Development" -y
        yum -y install gcc-c++ make perl libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel xz xz-devel expat expat-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel libxslt-devel libevent-devel libtool libtool-ltdl bison gd-devel vim-enhanced pcre-devel zip unzip ntpdate sysstat patch expect automake autoconf libtool net-snmp-devel OpenIPMI OpenIPMI-devel vim perl-ZMQ-LibZMQ3
        for i in nginx php cmake mariadb zabbix; do
            if [ "$i" != "zabbix" ]; then
                if ! which $i &>/dev/null; then 
                    install_$i "$(eval echo \$${i}Url)" 2>&1 | tee -a /root/${i}_install.log
                else
                    echo "$i Install Done!"
                fi
            else
                if ! which zabbix_server &>/dev/null; then 
                    install_$i "$(eval echo \$${i}Url)" 2>&1 | tee -a /root/${i}_install.log
                else
                    echo "$i server Install Done!"
                fi
            fi
        done
    elif [ $OPTION = 2 ]; then
        PET=$(whiptail --title "Server IP Address Input" --inputbox "Please Input Zabbix Server IP Address" 10 60 172.16.41.163 3>&1 1>&2 2>&3)
        exitstatus=$?
        if [ $exitstatus = 0 ]; then
            ZabbixServerIp=$PET
        else
            echo "You chose Cancel."
        fi
        yum clean all && yum makecache
        yum groupinstall "Development tools" "Server Platform Development" -y
        yum install net-snmp-devel net-snmp -y
        install_zabbix_agent "$zabbixUrl" | tee -a /root/zabbix_agent_install.log
        service snmpd start
    elif [ $OPTION = 3 ]; then
        echo "Exit Script" && exit 1
    fi
else
    echo "You chose Cancel."
fi

#wget -q http://www.dwhd.org/wp-content/uploads/2015/05/zabbix_server_agent.sh && bash zabbix_server_agent.sh

轉(zhuǎn)載:zabbix server&agent端自動(dòng)安裝腳本-純編譯版 | Linux–不是那么難https://www.dwhd.org/20150519_162243.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末沧奴,一起剝皮案震驚了整個(gè)濱河市痘括,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌滔吠,老刑警劉巖纲菌,帶你破解...
    沈念sama閱讀 211,348評(píng)論 6 491
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異疮绷,居然都是意外死亡翰舌,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,122評(píng)論 2 385
  • 文/潘曉璐 我一進(jìn)店門冬骚,熙熙樓的掌柜王于貴愁眉苦臉地迎上來椅贱,“玉大人,你說我怎么就攤上這事只冻”勇螅” “怎么了?”我有些...
    開封第一講書人閱讀 156,936評(píng)論 0 347
  • 文/不壞的土叔 我叫張陵喜德,是天一觀的道長山橄。 經(jīng)常有香客問我,道長舍悯,這世上最難降的妖魔是什么驾胆? 我笑而不...
    開封第一講書人閱讀 56,427評(píng)論 1 283
  • 正文 為了忘掉前任涣澡,我火速辦了婚禮,結(jié)果婚禮上丧诺,老公的妹妹穿的比我還像新娘入桂。我一直安慰自己,他們只是感情好驳阎,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,467評(píng)論 6 385
  • 文/花漫 我一把揭開白布抗愁。 她就那樣靜靜地躺著,像睡著了一般呵晚。 火紅的嫁衣襯著肌膚如雪蜘腌。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,785評(píng)論 1 290
  • 那天饵隙,我揣著相機(jī)與錄音撮珠,去河邊找鬼。 笑死金矛,一個(gè)胖子當(dāng)著我的面吹牛芯急,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播驶俊,決...
    沈念sama閱讀 38,931評(píng)論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼娶耍,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了饼酿?” 一聲冷哼從身側(cè)響起榕酒,我...
    開封第一講書人閱讀 37,696評(píng)論 0 266
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎故俐,沒想到半個(gè)月后想鹰,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,141評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡药版,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,483評(píng)論 2 327
  • 正文 我和宋清朗相戀三年杖挣,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片刚陡。...
    茶點(diǎn)故事閱讀 38,625評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡惩妇,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出筐乳,到底是詐尸還是另有隱情歌殃,我是刑警寧澤,帶...
    沈念sama閱讀 34,291評(píng)論 4 329
  • 正文 年R本政府宣布蝙云,位于F島的核電站氓皱,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜波材,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,892評(píng)論 3 312
  • 文/蒙蒙 一股淡、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧廷区,春花似錦唯灵、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,741評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至玖绿,卻和暖如春敛瓷,著一層夾襖步出監(jiān)牢的瞬間授账,已是汗流浹背野来。 一陣腳步聲響...
    開封第一講書人閱讀 31,977評(píng)論 1 265
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留变丧,地道東北人蚀瘸。 一個(gè)月前我還...
    沈念sama閱讀 46,324評(píng)論 2 360
  • 正文 我出身青樓狡蝶,卻偏偏與公主長得像,于是被迫代替她去往敵國和親苍姜。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,492評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容

  • 1.寫在前面 本文主要介紹的是zabbix的編譯安裝過程悬包,包含它的基礎(chǔ)環(huán)境LNMP衙猪,雖然zabbix官方一般推薦的...
    天之藍(lán)色閱讀 2,529評(píng)論 0 16
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn)布近,斷路器垫释,智...
    卡卡羅2017閱讀 134,629評(píng)論 18 139
  • 先通過lnmp一鍵安裝包吧nginx和數(shù)據(jù)庫、php搞起來撑瞧!然后:實(shí)現(xiàn):1. 獲取zabbix centos:獲取...
    老夫劉某閱讀 2,237評(píng)論 0 3
  • Zabbix簡介 Zabbix官方網(wǎng)站Zabbix中文文檔 本文系統(tǒng)環(huán)境是CentOS7x86_64, Zabbi...
    Zhang21閱讀 7,968評(píng)論 0 37
  • 夕陽西下 快悶壞的大地 長長地吸氣 深深地吐了口氣 躁熱的空氣 頓時(shí)溫順了許多 像個(gè)孩子 乖乖地趴在媽媽的腿上 河...
    格伊閱讀 218評(píng)論 0 0