#!/bin/bash #coding:utf-8 #author:fjiangjun #date:2018/1/30 check_dir(){ if [ ! -d $1 ] then mkdir -p $1 else echo -e "\033[33m檢測到$1這個目錄已經存在\033[0m" fi } check_dir /tmp/lnmp BASE_DIR=/tmp/lnmp check_env(){ echo } first(){ echo -e "\033[32m安裝編譯工具\033[0m" yum install gcc gcc-c++ make epel-release -y echo -e ".\n.\n" echo -e "\033[32m安裝nginx的依賴包\033[0m" yum install pcre-devel zlib-devel openssl-devel -y echo -e ".\n.\n" echo -e "\033[32m安裝php的依賴包\033[0m" yum install -y libxml2-devel.x86_64 libxml2.x86_64 bzip2-devel curl-devel libjpeg-devel libpng-devel \ freetype-devel } nginx_install(){ cd $BASE_DIR check_dir $BASE_DIR/nginx echo -e "\033[32m進入$BASE_DIR/nginx目錄,準備下載\033[0m" echo -e "\033[32m開始下載安裝nginx.1.8.0\033[0m" wget -c http://nginx.org/download/nginx-1.8.0.tar.gz -O nginx-1.8.0.tar.gz tar -xf nginx-1.8.0.tar.gz cd nginx-1.8.0 echo -e "\033[32m開始編譯nginx-1.8.0\033[0m" ./configure --prefix=$BASE_DIR/nginx --with-http_stub_status_module --with-http_realip_module --with-http_ssl_module echo -e ".\n.\n" make make install echo -e ".\n.\n" echo -e "\033[32mNGINX安裝成功\033[0m" echo -e ".\n.\n" } php_install(){ cd $BASE_DIR check_dir $BASE_DIR/php echo -e "\033[32m進入$BASE_DIR/php目錄,準備下載\033[0m" echo -e "\033[32m開始下載安裝php-5.6.30.tar.gz\033[0m" #wget -c http://cn2.php.net/get/php-5.6.33.tar.gz/from/this/mirror -O php-5.6.33.tar.gz wget -c http://cn2.php.net/distributions/php-5.6.30.tar.gz -O php-5.6.30.tar.gz tar -xf php-5.6.30.tar.gz cd php-5.6.30 ./configure --prefix=$BASE_DIR/php \ --enable-fpm \ --enable-mysqlnd \ --enable-ftp \ --with-mysql=mysqlnd \ --with-mysqli \ --with-gettext \ --enable-mbstring \ --with-iconv \ --with-mcrypt \ --with-mhash \ --with-openssl \ --enable-bcmath \ --enable-soap \ --with-libxml-dir \ --enable-pcntl \ --enable-shmop \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-sockets \ --with-curl \ --with-zlib \ --enable-zip \ --with-bz2 \ --with-gd \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir make make install echo -e ".\n.\n" echo -e "\033[32m開始編譯PHP-5.6.30\033[0m" echo -e "\033[32mPHP-5.6.30安裝成功\033[0m" echo -e ".\n.\n" } mysql(){ echo -e "\033[32m開始下載mysql-server\033[0m" rpm -qa | grep mysql &>/dev/null && echo -e "\033[33m檢測到MYSQL已經用YUM安裝,跳過安裝!\033[0m" || yum install -y mysql-server } check_nginx(){ ls $BASE_DIR/nginx | xargs echo | grep conf |grep html | grep sbin | grep logs &>/dev/null if [ $? -eq 0 ] then echo -e "\033[31mNGINX 或許已經下載了,請檢查一下$BASE_DIR/nginx\033[0m" read -t 5 -p "你要下載嗎?(y/n) 默認爲不下載,將等待5秒 : " choose choose=${choose:-n} if [ $choose == "y" -o $choose == "Y" ] then #rm -fr $BASE_DIR/nginx $BASE_DIR/nginx-1.8.0 $BASE_DIR/nginx-1.8.0.tar.gz mv -f $BASE_DIR/nginx $BASE_DIR/nginx-1.8.0 $BASE_DIR/nginx-1.8.0.tar.gz -t /tmp echo "原NGINX安裝目錄備份在/tmp目錄下" nginx_install else echo -e "\033[33m你選擇跳太重新安裝NGINX\033[33m" fi else nginx_install fi } check_php(){ ls $BASE_DIR/php | xargs echo | xargs echo | grep bin | grep etc | grep include | grep lib | grep php | grep sbin | grep var &>/dev/null if [ $? -eq 0 ] then echo -e "\033[31mPHP 或許已經安裝了,請檢查$BASE_DIR/php\033[0m" read -t 5 -p "你要從新下載PHP嗎?(y/n) 默認爲不下載,將等待5秒 : " choose choose=${choose:-n} #echo $choose if [ $choose == "y" -o $choose == "Y" ] then #rm -fr $BASE_DIR/php $BASE_DIR/php-5.6.30 $BASE_DIR/php-5.6.30.tar.gz mv -f $BASE_DIR/php $BASE_DIR/php-5.6.30 $BASE_DIR/php-5.6.30.tar.gz -t /tmp echo "原PHP安裝目錄備份在/tmp目錄下" php_install else echo -e "\033[33m你選擇跳太重新安裝PHP\033[0m" fi else php_install fi } check_zabbix(){ echo "開始安裝ZABBIX的EPEL源" if [ -f /etc/yum.repo.d/zabbix.repo ] then rpm -i http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-release-3.2-1.el6.noarch.rpm else echo -e "\033[32mZABBIX的EPEL源或許已經安裝了,請檢測\033[0m" read -t 5 -p "要從新安裝嗎?默認爲不安裝,將等待5秒 : " choose choose=${choose:-n} if [ $choose == "y" ] then echo -e "\033[33m開始從新安裝ZABBIX的EPEL源\033[0m" rpm -i http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-release-3.2-1.el6.noarch.rpm else echo -e "\033[33m你選擇跳太重新安裝\033[0m" fi fi rpm -qa | xargs echo | grep zabbix-server | grep zabbix-web-mysql | grep zabbix-agent &>/dev/null if [ $? -ne 0 ] then echo "開始安裝ZABBIX-SERVER-MYSQL ZABBIX-WEB-MYSQL ZABBIX-AGETN" yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent echo "ZABBIX安裝完成" else echo -e "\033[33mZABBIX已經安裝了\033[0m" fi } main(){ echo -e "\033[32m--------------這個腳本用於在$BASE_DIR下載安裝LNMP----------\033[0m" #"\033[32m 綠色字 \033[0m" echo -e "\033[32mNGINX 下載網站 http://nginx.org/download/nginx-1.8.0.tar.gz\033[0m" echo -e "\033[32mPHP 下載網站 http://cn2.php.net/distributions/php-5.6.30.tar.gz\033[0m" echo -e "\033[32mMYSQL 下載網址 http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35.tar.gz\033[0m" echo -e "\033[32mZABBIX 下載網址 https://www.zabbix.com/download?zabbix=3.2&os_distribution=centos&os_version=6&db=MySQL \033[0m" echo -e ".\n.\n.\n" first echo -e ".\n.\n" check_nginx || exit 1 echo -e ".\n.\n" check_php || exit 2 echo -e ".\n.\n" mysql || exit 3 echo -e ".\n.\n" check_zabbix || exit 4 echo -e ".\n.\n" echo -e "\033[32m全部組件都安裝完成,開始配置吧\033[0m" } main