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