##!/bin/bash #Data: Fri May 4 09:37:26 CST 2018 #Founder: <daasbank-yankai> #describe: One button installation zabbix3.4 #Edition: V1 #OS: Centos7.2x86_64 cp . /etc/init.d/functions MMM=`rpm -qa | grep mariadb` Route=/usr/local/src ################################################################ #mount iamges! ################################################################ function MOUNT(){ rm -rf /etc/yum.repos.d/* mount /usr/local/src/CentOS-7-x86_64-DVD-1511.iso /mnt \cp -f /usr/local/src/conf/zabbix.repo /etc/yum.repos.d/zabbix.repo sleep 3 yum install -y make apr* autoconf automake curl-devel gcc gcc-c++ openssl openssl-devel perl compat* mpfr cpp glibc libgomp sleep 3 yum install -y libstdc++-devel keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* sleep 3 yum install -y freetype libjpeg* libpng* libtool* libxml2 libxml2-devel patch libcurl-devel bzip2-devel freetype-devel2 sleep 3 yum install -y freetype-devel net-snmp-devel freetype-devel net-snmp-devel net-snmp net-snmp-devel curl-devel sleep 3 yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel OpenIPMI-devel libssh2-devel } ################################################################ #Install MySQL5.7.18 ################################################################ function Mysql(){ if [ -n $MMM ];then rpm -e mariadb-libs --nodeps 2&>/dev/null else echo "Mariadb error!!!" fi tar zxf $Route/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz && { mv $Route/mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql && \ cd /usr/local/mysql/ && mkdir data && mkdir log && echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile if [ "$?" -eq 0 ];then source /etc/profile && groupadd mysql && useradd -r -g mysql -s /bin/false mysql else echo "Mysql error !!!" fi } \cp -f /usr/local/src/conf/my.cnf /etc/my.cnf if [ -f /etc/my.cnf ];then chmod 750 data/ && chown -R mysql . && chgrp -R mysql . && bin/mysqld --initialize --user=mysql && cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld && service mysqld start else echo "/etc/my.cnf error !!!" fi ####################################################################### #Mysql password install ####################################################################### ln -s /usr/local/mysql/bin/mysql /usr/local/sbin ln -s /usr/local/mysql/bin/mysqladmin /usr/local/sbin PASS=`cat /usr/local/mysql/log/mysql.err | grep password | awk '{print $11}'` mysqladmin -uroot -p${PASS} password 111111 &> /dev/null if [ "$?" -eq 0 ];then echo "Mysql password is ok!" else echo "Mysql password is not ok!!!" fi } ####################################################################### #Install Nginx1.12.2 ####################################################################### function Nginx(){ cd $Route && { tar zxf $Route/nginx-1.12.2.tar.gz && cd nginx-1.12.2/ && \ ./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx && make && make install useradd -M -s /sbin/nologin nginx } if [ "$?" -eq 0 ];then ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin && /usr/local/nginx/sbin/nginx else echo "Nginx Install error!!!" exit 1 fi } ######################################################################## #Intsall LIB.so ######################################################################## function Lib(){ cd $Route && { tar zxf libevent-2.1.8-stable.tar.gz && cd libevent-2.1.8-stable && ./configure && make && make install if [ "$?" -eq 0 ];then echo "libevent install is ok!!!" else echo "libevent install is not ok!!!" fi } cd $Route && { tar zxf libmcrypt-2.5.7.tar.gz && cd libmcrypt-2.5.7 && ./configure && make && make install if [ "$?" -eq 0 ];then echo "libmcrypt-2.5.7 install is ok!!!" else echo "libmcrypt-2.5.7 install is not ok!!!" fi } cd $Route && { tar zxf fping-3.10.tar.gz && cd fping-3.10.tar.gz && ./configure && make && make install if [ "$?" -eq 0 ];then echo "fping-3.10.tar.gz install is ok!!!" else echo "fping-3.10.tar.gz install is not ok!!!" fi } } ########################################################################## #Install php5.6 ########################################################################## function php(){ cd $Route && { tar zxf php-5.6.25.tar.gz && cd php-5.6.25 && \ ./configure --prefix=/usr/local/php5.6 --with-config-file-path=/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/usr/local/mysql/mysql.sock --with-gd --with-iconv --with-libxml-dir=/usr --with-mhash --with-mcrypt --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-zlib --with-freetype-dir --with-png-dir --with-jpeg-dir --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl if [ "$?" -eq 0 ];then make && make install else echo "php install ./configure error!!!!" fi } cd $Route/php-5.6.25 && { cp php.ini-production /etc/php.ini && cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm && chmod +x /etc/init.d/php-fpm && chkconfig --add php-fpm && chkconfig php-fpm on } if [ "$?" -eq 0 ];then \cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf else echo "php Environmental Science ERROR!!!" fi if [ ! -d /usr/local/php5.6/etc/php-fpm.conf ] then \cp -f /usr/local/src/conf/php-fpm.conf /usr/local/php5.6/etc/php-fpm.conf else echo "php-fpm.conf ERROR!!!" fi systemctl start php-fpm && echo "php install is ok!!!" } ################################################################################## #Install nginx && php config! ################################################################################## function nginx-php(){ if [ -f /usr/local/nginx/conf/nginx.conf ];then \cp -f /usr/local/src/conf/nginx.conf /usr/local/nginx/conf/nginx.conf else echo "Nginx && php ERROR!!!" fi touch /usr/local/nginx/html/daasbank.php cat << daasbank-lnmp >/usr/local/nginx/html/daasbank.php <?php phpinfo(); ?> daasbank-lnmp /usr/local/nginx/sbin/nginx -s reload if [ "$?" -eq 0 ];then echo "LNMP is ok! Please Visit http://IP/daasbank.php" else echo "LNMP is not ok!!!" fi } ############################################################################ #Install zabbix3.4.1 ############################################################################ function zabbix(){ groupadd zabbix && useradd -g zabbix zabbix \cp -f /usr/local/src/conf/php.ini /etc/php.ini cd $Route && { tar zxf zabbix-3.4.1.tar.gz && cd zabbix-3.4.1 && \ ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-java --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl if [ "$?" -eq 0 ];then make && make install else echo "zabbix install error !!!" fi } ln -s /usr/local/zabbix/bin/* /usr/local/bin/ ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/ /usr/local/mysql/bin/mysql -uroot -p111111 -e "create database zabbix character set utf8;" /usr/local/mysql/bin/mysql -uroot -p111111 -e "grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';" if [ "$?" -eq 0 ] then echo "user zabbix mysql is ok!!!" else echo "user zabbix mysql is not ok!!!" fi cd $Route/zabbix-3.4.1/database/mysql && { /usr/local/mysql/bin/mysql -uzabbix -pzabbix -hlocalhost zabbix < schema.sql /usr/local/mysql/bin/mysql -uzabbix -pzabbix -hlocalhost zabbix < images.sql /usr/local/mysql/bin/mysql -uzabbix -pzabbix -hlocalhost zabbix < data.sql } if [ "$?" -eq 0 ] then echo "zabbix is mysql database is ok!" else echo "zabbix is mysql database is not ok!" fi \cp -f /usr/local/src/conf/zabbix_server.conf /usr/local/zabbix/etc/zabbix_server.conf mkdir -p /usr/local/zabbix/logs && chown -R zabbix:zabbix /usr/local/zabbix/ cat << daasbank-zabbix >/etc/ld.so.conf include ld.so.conf.d/*.conf /usr/local/mysql/lib /usr/local/lib daasbank-zabbix /usr/local/nginx/sbin/nginx -s reload && /etc/init.d/php-fpm restart if [ "$?" -eq 0 ];then echo "zabbix && nginx && php restart is ok!!!" else echo "zabbix && nginx && php restart is not ok!!!" fi cd $Route/zabbix-3.4.1/ && { \cp misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server \cp misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd chmod +x /etc/rc.d/init.d/zabbix_server && chmod +x /etc/rc.d/init.d/zabbix_agentd chkconfig --add zabbix_server chkconfig --add zabbix_agentd chkconfig zabbix_server on chkconfig zabbix_agentd on sed -i 's$BASEDIR=/usr/local$BASEDIR=/usr/local/zabbix/$g' /etc/rc.d/init.d/zabbix_server sed -i 's*PIDFILE=/tmp/$BINARY_NAME.pid*PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid*g' /etc/rc.d/init.d/zabbix_server sed -i 's$BASEDIR=/usr/local$BASEDIR=/usr/local/zabbix/$g' /etc/rc.d/init.d/zabbix_agentd sed -i 's*PIDFILE=/tmp/$BINARY_NAME.pid*PIDFILE=/usr/local/zabbix/logs/$BINARY_NAME.pid*g' /etc/rc.d/init.d/zabbix_agentd ldconfig && systemctl daemon-reload /etc/init.d/zabbix_agentd start &>/dev/null /etc/init.d/zabbix_server start &>/dev/null } if [ "$?" -eq 0 ];then mkdir /usr/local/nginx/html/zabbix/ && echo "zabbix Being configured....." else echo "zabbix start is not ok!!!" fi if [ -d /usr/local/nginx/html/zabbix ];then \cp -r $Route/zabbix-3.4.1/frontends/php/* /usr/local/nginx/html/zabbix/ else echo "zabbix mkdir error!!!" fi chown -R nginx:nginx /usr/local/nginx/html/zabbix if [ "$?" -eq 0 ];then echo "zabbix install is ok pleses http://IP/zabbix" else echo "zabbix install is not ok!!! error!" fi } function main(){ MOUNT Mysql Nginx Lib php nginx-php zabbix } main