#!/bin/bash
# auth:you
# QQ:354389478
HELP(){
echo "Prepare 3 packages:"
echo "1.zabbix-3.2.3.tar.gz"
echo "2.php-bcmath-5.4.45-13.el7.remi.x86_64.rpm"
echo "3.php-mbstring-5.4.45-13.el7.remi.x86_64.rpm"
echo "user:zabbix password:123456"
}
#------------------------------------------------------
YUM(){
if [ "$(yum repolist|grep repolist|awk ‘{print $2}‘)" != "0" ];then
/usr/bin/yum -y install gcc gcc-c++ autoconf httpd php mariadb mariadb-server mariadb-devel php-mysql httpd-manual mod_ssl mod_perl mod_auth_mysql php-gd php-xml php-ldap php-pear php-xmlrpc mysql-connector-odbc mysql-devel libdbi-dbd-mysql net-snmp-devel curl-devel &>/dev/null
else
echo "yum on exist!"
exit 0
fi
}
#-------------------------------------------------------------------
MOzabbix(){
if [ -f /etc/php.ini ];then
sed -i -r ‘/;date.timezone/s/;(.*)=/date.timezone = Asia\/Shanghai/‘ /etc/php.ini;
sed -i ‘/max_execution_time/s/30/300/‘ /etc/php.ini;
sed -i ‘/^max_input_time/s/60/300/‘ /etc/php.ini;
sed -i ‘/post_max_size/s/8M/16M/‘ /etc/php.ini;
else
echo "/etc/php.ini no exist!"
exit 1
fi
}
#-------------------------------------------------------------------------
INcreateZabbix(){
id zabbix &>/dev/null
if [ $? -ne 0 ];then
/usr/sbin/useradd -s /sbin/nologin zabbix -M
else
echo "zabbix user alrealy exist!"
fi
/usr/bin/cd /soft
if [ -f /soft/php-bcmath-5.4.45-13.el7.remi.x86_64.rpm ]&&[ -f /soft/php-mbstring-5.4.45-13.el7.remi.x86_64.rpm ];then
/usr/bin/rpm -ivh --nodeps php-bcmath-5.4.45-13.el7.remi.x86_64.rpm &>/dev/null
/usr/bin/rpm -ivh --nodeps php-mbstring-5.4.45-13.el7.remi.x86_64.rpm &>/dev/null
else
echo "zabbix soft packages!"
exit 4
fi
}
#--------------------------------------------------------------------------
INZABBIX(){
if [ -f /soft/zabbix-3.2.3.tar.gz ];then
/usr/bin/tar -zxf /soft/zabbix-3.2.3.tar.gz
if [ -d /soft/zabbix-3.2.3 ];then
cd /soft/zabbix-3.2.3
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql &>/dev/null
if [ $? -eq 0 ];then
make &>/dev/null && make install &>/dev/null
if [ $? -eq 0 ];then
echo "zabbix install OK!"
fi
else
echo "./configure error!"
exit 5
fi
else
echo "/soft/zabbix-3.2.3 no exist!"
exit 6
fi
else
echo "/soft/zabbix-3.2.3.tar.gz no exist!"
exit 7
fi
}
#--------------------------------------------------------------------
IMPORTdate(){
/usr/bin/cp -r /soft/zabbix-3.2.3/frontends/php /var/www/html/zabbix
if [ -d /var/www/html/zabbix ];then
chmod o+w /var/www/html/zabbix/conf
else
exit 2
fi
/usr/bin/systemctl start httpd;systemctl enable httpd &>/dev/null
/usr/bin/systemctl start mariadb;systemctl enable mariadb &>/dev/null
/usr/bin/mysqladmin -uroot password "111"
/usr/bin/mysql -uroot -p111 -e "create database zabbix;"
if [ $? -eq 0 ];then
/usr/bin/mysql -uroot -p111 -e "grant all on zabbix.* to zabbix@‘localhost‘ identified by ‘123456‘;" &>/dev/null
if [ -d /soft/zabbix-3.2.3/database/mysql ];then
cd /soft/zabbix-3.2.3/database/mysql
/usr/bin/mysql -uroot -p111 zabbix < schema.sql
/usr/bin/mysql -uroot -p111 zabbix < images.sql
/usr/bin/mysql -uroot -p111 zabbix < data.sql
fi
fi
}
#----------------------------------------------------------------------
MOconfig(){
if [ -f /usr/local/zabbix/etc/zabbix_server.conf ];then
/usr/bin/sed -i "/^DBUser/s/zabbix/zabbix/" /usr/local/zabbix/etc/zabbix_server.conf;
/usr/bin/sed -i "/DBPassword/s/# DBPassword=/DBPassword=123456/" /usr/local/zabbix/etc/zabbix_server.conf;
else
echo "zabbix configure file no exist!"
fi
}
#---------------------------------------------------------------------
INbootZABBIX(){
/usr/bin/cp /soft/zabbix-3.2.3/misc/init.d/fedora/core/zabbix_server /etc/init.d/
/usr/bin/chmod +x /etc/init.d/zabbix_server
if [ -f /etc/init.d/zabbix_server ];then
/usr/bin/sed -i ‘/BASEDIR=/s;\/usr\/local;\/usr\/local/zabbix;‘ /etc/init.d/zabbix_server
/etc/init.d/zabbix_server start &>/dev/null
if [ $? -eq 0 ];then
echo "zabbix install OK!"
else
echo "zabbix install faild!"
fi
fi
}
#---------------------------------------------------------------------
case $1 in
"-h")
HELP
;;
"INSTALL"|"install")
YUM
MOzabbix
INcreateZabbix
INZABBIX
IMPORTdate
MOconfig
INbootZABBIX
;;
*)
echo "Usage: $0 {-h|INSTALL|install}"
esac
本文出自 “12177655” 博客,谢绝转载!
原文地址:http://12187655.blog.51cto.com/12177655/1974020