欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

LNMP自動安裝部署腳本

 更新時間:2016年10月25日 14:26:29   作者:kaifly  
LNMP是一個基于CentOS/Debian編寫的Nginx、PHP、MySQL、phpMyAdmin、eAccelerator一鍵安裝包,這篇文章主要為大家分享了LNMP自動安裝部署腳本

我們的業(yè)務(wù)使用了nginx、MySQL、php、和tomcat,寫了一個自動化安裝這些軟件的腳本,雖然網(wǎng)上類似的自動安裝腳本很多,但這個是自己寫的,特此mark一下,希望能給別人一些參考,同時也灰常歡迎看到的朋友們提些改進意見。話不多說,直接上腳本。

#!/bin/sh
  alias echo='echo -e'
  ###判斷系統(tǒng),此腳本只適用于64位系統(tǒng)
  machine=`uname -m`
  if [ $machine != x86_64 ] ;then
    echo "\e[1;31m \nyour system is 32bit,but this script is only run on 64bit !\n \e[0m"
    exit -1
  fi 
  ###創(chuàng)建保存下載文件的目錄
  mkdir /usr/local/src/auto_install &> /dev/null
  source_dir=/usr/local/src/auto_install
  ###定義一個交互式的選擇提示
function interact {
  echo "Please input \"yes\" or \"no\""
  read choice
  case "$choice" in
    no)
     exit 0;;
    yes)
     echo;;
    *)
   echo "\e[1;31mInput Errot! \e[0m"
     exit -1;;
  esac
}
   ### 定義一個函數(shù)檢查上一條命令的執(zhí)行狀態(tài)
function check {
  if [ $? -ne 0 ];then
    echo "\e[1;31m\n the last commond exec failed,please check it !\e[0m \n"
  sleep 1
  exit -1
  fi
}
### 定義下載各軟件的函數(shù)(此處我隱藏了我們的下載地址,需各位自行設(shè)置下載地址)
function download_install_epel {
  cd $source_dir
  rm -f epel* &> /dev/null
  echo "\e[1;32m ---yum install epel repo--- \e[0m \n"    
  sys_version=`uname -r|cut -d '.' -f 4`
  if [ $sys_version = el7 ];then
    rpm -qa|grep -i epel > /dev/null
    if [ $? -ne 0 ];then
     wget -nv http://www.example.com/epel-release-7-2.noarch.rpm
     rpm -ivh $source_dir/epel-release-7-1.noarch.rpm
     check;
    fi
  elif [ $sys_version = el6 ];then
    rpm -qa|grep -i epel > /dev/null
    if [ $? -ne 0 ];then
     wget -nv http://www.example.com/epel-release-6-8.noarch.rpm
     rpm -ivh $source_dir/epel-release-6-8.noarch.rpm
     check;
    fi
  fi
}
function download_nginx {
  cd $source_dir
  echo "\e[1;32m\n ---download nginx-1.4.7---\e[0m \n"
  ls nginx-1.4.7.tar.gz &> /dev/null
  if [ $? -ne 0 ];then
     wget -nv http://www.example.com/nginx-1.4.7.tar.gz
     check;
  fi
}
function download_mysql {
  cd $source_dir
  echo "\e[1;32m\n ---download MySQL-5.5.39---\e[0m \n"
  ls mysql-5.5.39-linux2.6-x86_64.tar.gz &> /dev/null
  if [ $? -ne 0 ];then
     wget -nv http://www.example.com/mysql-5.5.39-linux2.6-x86_64.tar.gz
     check;
  fi
}
function download_php {
  cd $source_dir
  echo "\e[1;32m\n ---download php-5.3.28---\e[0m \n"
  ls php-5.3.28.tar.gz &> /dev/null
  if [ $? -ne 0 ];then
      wget -nv http://www.example.com/php-5.3.28.tar.gz
      check;
  fi
}
function download_jre {
  cd $source_dir
  echo "\e[1;32m ---download jre-6u33-linux-x64.bin---\e[0m"
  sleep 1
  ls jre-6u33-linux-x64.bin &> /dev/null
  if [ $? -ne 0 ];then
    wget -nv http://www.example.com/jre-6u33-linux-x64.bin
    check;
  fi
}
    ###定義依賴包安裝函數(shù)
function dependence_install {
  download_install_epel;
  echo "\e[1;32m ---yum install the Dependencies software--- \e[0m \n" 
  sleep 1
  pgrep yum|xargs kill -9 > /dev/null
  rm -f /var/run/yum.pid > /dev/null
  echo "yum install gcc zlib cmake libxml2 libxml2-devel bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype-devel pspell-devel libmcrypt libm
crypt-devel freetype pcre-devel openssl openssl-devel libaio*"
  yum -y install gcc zlib cmake libxml2 libxml2-devel bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype-devel pspell-devel libmcrypt libmcry
pt-devel freetype pcre-devel openssl openssl-devel libaio* >/dev/null 2>&1
  check;
}
    ### 定義mysql安裝函數(shù)###
function mysql_install {

    ###判斷本機是否已在運行mysql,或者開機啟動項有沒有mysql###
    ###判斷機器上是否以運行mysql實例
  echo "\e[1;32m \n ---check if there is already installed mysql instence---\e[0m\n"
  ps -ef|grep -w mysqld|grep -v "grep" &> /dev/null
  if [ $? -eq 0 ];then
    mysqlbasedir=`ps -ef|grep -w "mysqld"|grep -v "grep"|awk '{print $9}'|tr -d '\-\-'`
    mysqldatadir=`ps -ef|grep -w "mysqld"|grep -v "grep"|awk '{print $10}'|tr -d '\-\-'`
    echo "\e[1;32m your system has run a mysql instance already \n mysqlbasedir is: "$mysqlbasedir"\n mysqldatadir is: "$mysqldatadir"\n do you still want to install a new mysql-server? \e[0m\n"
    interact;
  fi
    ###判斷系統(tǒng)是否已經(jīng)有rpm方式安裝的mysql
   echo "MySQL-server-5.5.39-2.el6.x86_64.rpm"|while read line
   do
     prefix=`echo "$line"|awk -F "-" '{print $1"-"$2}'`               ##to get like "MySQL-server"
     rpm -qa|grep -i "$prefix" &> /tmp/check_mysql.log
   if [ $? -eq 0 ];then
      already_install=`cat /tmp/check_mysql.log|awk -F "-" '{print $1"-"$2"-"$3}'`  ##to get the already installed mysql version
      echo "\e[1;31m ---the $already_install is already installed by rpm!--- \n ---Do you really want to install a new mysql?--- \e[0m\n"
      interact;
     fi
   done
    ###判斷chkconfig里面是否有mysql啟動腳本并且為開機啟動
  chkconfig |grep mysql|awk '{print $5" "$7}'|grep -e "啟用" -e "on" &> /dev/null
  if [ $? -eq 0 ];then
    echo " there is a bootstart mysql script in the chkconfig,please check"
    exit 0
  fi

    ###判斷/etc/rc.local文件里是否有mysql啟動命令
  cat /etc/rc.local|grep "mysqld" &> /dev/null
  if [ $? -eq 0 ];then
    echo " there is a bootstart mysql commond in the /etc/rc.local,please check it"
    exit 0
  fi  
    ######判斷結(jié)束######

  ###檢查是否有系統(tǒng)自帶的mysql-lib-5.1,有則刪除
  rpm -qa|grep -i -e "mysql.*5\.1.*"|xargs rpm -e --nodeps 2> /dev/null
    ###交互式選擇mysql安裝路徑
  echo "\e[1;31m where do you want to install mysql(default is /usr/local/mysql)\e[0m"
  read mybasedir
  if [ "$mybasedir" = "" ];then
    mybasedir=/usr/local/mysql
  fi
    ###選擇data目錄
  echo "\e[1;31m where do you want to storage mysql data(default is /usr/local/mysql/data)\e[0m"
  read mydatadir
  if [ "$mydatadir" = "" ];then
    mydatadir=/usr/local/mysql/data
  fi  

    ###開始安裝mysql
  echo "\e[1;32m ---now start to install mysql---\e[0m\n"
  sleep 1
  #dependence_install;
  echo "\e[1;32m ---add user mysql---\e[0m"
  useradd mysql -s /sbin/nologin

  echo "\e[1;32m\n ---unpack mysql-5.5.39-linux2.6-x86_64.tar.gz---\e[0m"
  cd $source_dir
  tar zxf mysql-5.5.39-linux2.6-x86_64.tar.gz
  check;
  rm -rf $mybasedir
  mv mysql-5.5.39-linux2.6-x86_64 $mybasedir

    ###判斷/etc下是否有my.cnf,若有,重命名為my.cnf.bak
  ls /etc/my.cnf &> /dev/null
  if [ $? = 0 ];then
    \mv /etc/my.cnf /etc/my.cnf.bak
    echo "\e[1;32m\n ---detected /etc/my.cnf is already exit,rename it to /etc/my.cnf.bak--- \e[0m \n"
  fi
  cp $mybasedir/support-files/my-huge.cnf /etc/my.cnf
    ###拷貝開機啟動腳本到/etc/init.d/
  ls /etc/init.d/mysql &> /dev/null
  if [ $? = 0 ];then
    \mv /etc/init.d/mysql /etc/init.d/mysql.bak
    echo "\e[1;32m ---detected /etc/init.d/mysql is already exit,rename it to /etc/init.d/mysql.bak---\e[0m"
  fi
  cp $mybasedir/support-files/mysql.server /etc/init.d/mysql
    ###修改/etc/init.d/mysql腳本里面basedir和datadir
  sed -i -e "/^basedir*=$/i\basedir=$mybasedir" -e "/^datadir*=$/i\datadir=$mydatadir" /etc/init.d/mysql
  sed -i -e '/^basedir*=$/d' -e '/^datadir*=$/d' /etc/init.d/mysql  
    ###初始化數(shù)據(jù)庫
  echo "\e[1;32m\n ---initialize mysql database---\e[0m"
  sleep 1
  chown -R mysql $mydatadir $mybasedir >/dev/null 2>&1
  $mybasedir/scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql --basedir=$mybasedir --datadir=$mydatadir
  check;
    ###將basedir/bin/添加到PATH
  echo "PATH=$PATH:$mybasedir/bin" >> /etc/profile
  export PATH=$PATH:$mybasedir/bin

  echo "\e[1;32m install mysql success,you can run \"service mysql start\" to start the mysql \n do not forget to set a password for mysql \e[0m"
  ###至此mysql安裝完畢
}
  ### 定義nginx安裝函數(shù)
function nginx_install {
  echo
  echo "\e[1;32m ---start installing nginx,it's basedir is /usr/local/nginx--- \e[0m \n"
  sleep 1
  cd $source_dir
  ls -l |grep "^d"|grep nginx|xargs rm -rf &> /dev/null
  tar zxf nginx-1.4.7.tar.gz
  check;
  cd nginx-1.4.7
echo "\e[1;32m ---configure: configure information in /tmp/configure_nginx.log--- \e[0m \n"
  sleep 1
  ./configure --with-http_stub_status_module --prefix=/usr/local/nginx &> /tmp/configure_nginx.log
  check;
echo "\e[1;32m ---make: make information in /tmp/make_nginx.log--- \e[0m \n"
  sleep 1
  make &> /tmp/configure_nginx.log
  check;
echo "\e[1;32m ---make install: install into /usr/local/nginx--- \e[0m \n"
  sleep 1
  make install &> /tmp/make_install.log
  check;
  echo "\e[1;32m nginx is installed successfully \e[0m \n"
}
  ### 定義php安裝函數(shù)
function php_install {
  dependence_install;
  cd $source_dir
  ls -l |grep "^d"|grep php|xargs rm -rf &> /dev/null
  tar zxvf php-5.3.28.tar.gz &> /dev/null
  check;
  cd php-5.3.28
  echo
  echo "\e[1;32m ---configure php: information in /tmp/php_configure.log--- \e[0m \n"
  echo "./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql --with-mysqli --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-iconv-dir=/usr/local --with-zlib --enable-zip --with-curl"
  ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql --with-mysqli --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-iconv-dir=/usr/local --with-zlib --enable-zip --with-curl &> /tmp/php_configure.log
  check;

  ###make
  echo "\e[1;32m ---make php: information in /tmp/php_make.log--- \e[0m \n"
  make &> /tmp/php_make.log
  check;
  ###make install
  echo "\e[1;32m ---make install php: install into /usr/local/php--- \n ---php cofigure file in the /usr/local/php/etc--- \e[0m \n"
  make install > /tmp/make_install_php.log
  check;

  echo "\e[1;32m ---prepare php configure files--- \e[0m \n"
  echo "cp $source_dir/php-5.3.28/php.ini-production /usr/local/php/etc/php.ini"
  cp php.ini-production /usr/local/php/etc/php.ini
  echo "cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf"
  cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
  echo "\e[1;32m\n php is installed successfully!\n now,please start php and modification the php.ini \e[0m"
}
  ###安裝jre
function jre_install {
  ###刪除系統(tǒng)自帶的java
  rpm -qa|grep java|xargs rpm -e --nodeps

  cd $source_dir
  rm -rf jre1.6.0_33 &> /dev/null
  chmod +x jre-6u33-linux-x64.bin &> /dev/null
  ./jre-6u33-linux-x64.bin >/dev/null 2>&1
  check;
  ls -d /usr/java
  if [ $? -ne 0 ];then
    mkdir /usr/java &> /dev/null
  else
    echo echo "\e[1;31m /usr/java has already exits,move to /usr/java_bak !\e[0m"
    mkdir /usr/java_bak &> /dev/null
    mv /usr/java/* /usr/java_bak/
  fi
  mv jre1.6.0_33 /usr/java/
  echo "\e[1;32m\n ---add java path to /etc/profile---\e[0m"
  sleep 1

  echo >>/etc/profile
  echo 'JAVA_HOME=/usr/java/jre1.6.0_33'>>/etc/profile
  echo 'CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jar'>>/etc/profile
  echo 'PATH=$JAVA_HOME/bin:$PATH:$HOME/bin:$JAVA_HOME/jre/bin'>>/etc/profile
  echo 'export PATH JAVA_HOME'>>/etc/profile
  source /etc/profile
  echo "\e[1;32m\n JRE is installed success !\e[0m"
  echo "\e[1;32m\n ---install cronolog---\e[0m"
  wget -nv http://www.example.com/cronolog-1.6.2.tar.gz
  dependence_install;
  tar zxf cronolog-1.6.2.tar.gz
  cd cronolog-1.6.2
  ./configure &> /tmp/cronolog_configure.log && make > /dev/null && make install > /dev/null
  check;
  echo "\e[1;32m cronolog is installed success\e[0m\n"
}
  ###下面開始選擇那些軟件需要安裝
echo "\e[1;31m\n ---選擇哪些軟件需要安裝--- \e[0m \n"
echo "\e[1;32m \"Nginx\"   INPUT \"1\" \e[0m \n"
echo "\e[1;32m \"Mysql\"   INPUT \"2\" \e[0m \n"
echo "\e[1;32m \"Php\"    INPUT \"3\" \e[0m \n"
echo "\e[1;32m \"JRE\"    INPUT \"4\" \e[0m \n"
#echo "\e[1;32m \"Tomcat\"   INPUT \"5\" \e[0m \n"
read -p "please choice which software do you want to install ?" input

  if [ $input = 1 ];then
      download_nginx;
      dependence_install;
      nginx_install;
  elif [ $input = 2 ];then
    download_mysql;
      mysql_install;
  elif [ $input = 3 ];then
      echo "\e[1;32m\n php needs mysqlclient \e[0m"
      echo "\e[1;32m so if you had already install a mysqlclient\n please make a softlink for all \"libmysqlclient.so.*\" file to both /var/lib64 and /var/lib \e[0m\n"
      echo "\e[1;31m Please input your choice\n\e[0m \e[1;32m1: go on by default\(install mysql-client-5.5.39\)\n 2: I will check my \"libmysqlclient.so.*\" file and redo this script later\n 3: I had make the softlinks and I want to going on \e[0m"
      read choice
      case "$choice" in
       1)
        cd $sourcedir
        echo "\e[1;32m ---download mysql-client rpm files---\e[0m"
        wget -nv http://www.example.com/MySQL-client-5.5.39-2.el6.x86_64.rpm
        wget -nv http://www.example.com/MySQL-devel-5.5.39-2.el6.x86_64.rpm
        wget -nv http://www.example.com/MySQL-shared-5.5.39-2.el6.x86_64.rpm
        echo "\e[1;32m\n ---install mysql-client in the way of rpm---\e[0m"
        sleep 1
        rpm -ivh MySQL-client-5.5.39-2.el6.x86_64.rpm MySQL-devel-5.5.39-2.el6.x86_64.rpm MySQL-shared-5.5.39-2.el6.x86_64.rpm
        download_php;
        ###make soft link from /usr/lib64/libmysqlclient* to /usr/lib/
        ls -l /usr/lib64/libmysqlclient*|grep -v "^l"|awk '{print $NF}'|while read line
         do
          usrlib_fulldir=`ls -l /usr/lib64/libmysqlclient*|grep -v "^l"|awk '{print $NF}'|sed 's/lib64/lib/'`
          ln -s $line $usrlib_fulldir
         done

        php_install;
        ;;
      2)
        exit 0;;
      3)
        download_php;
        php_install;
        ;;
      *)
        echo "Input Errot!" && exit -1;;
     esac

   elif [ $input = 4 ];then
      download_jre;
      jre_install;
   else
    echo "\e[1;31m your input is worng!\e[0m"
    sleep 1
    exit -1
   fi

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Apache Shiro 框架簡介

    Apache Shiro 框架簡介

    Apache Shiro是一個強大易用的Java安全框架,提供了認證、授權(quán)、加密和會話管理等功能,下文給大家?guī)砹薃pache Shiro 框架簡介,感興趣的朋友一起看看吧
    2017-09-09
  • Red Hat Linux,Apache2.0+Weblogic9.2負載均衡集群安裝配置

    Red Hat Linux,Apache2.0+Weblogic9.2負載均衡集群安裝配置

    這篇文章主要介紹了Red Hat Linux,Apache2.0+Weblogic9.2負載均衡集群安裝配置,需要的朋友可以參考下
    2014-12-12
  • linux系統(tǒng)下如何掛載NTFS移動硬盤

    linux系統(tǒng)下如何掛載NTFS移動硬盤

    用命令行掛載移動硬盤是Linux的基本操作之一,雖然目前有些Linux系統(tǒng)能自動加載移動硬盤,但有些時候(比如使用Ubuntu Server或其它Linux系統(tǒng)的時候)仍然需要手動操作,下面這篇文章主要介紹了linux系統(tǒng)下如何掛載NTFS移動硬盤,需要的朋友可以參考借鑒。
    2017-01-01
  • linux網(wǎng)絡(luò)知識詳解:iptables 規(guī)則介紹

    linux網(wǎng)絡(luò)知識詳解:iptables 規(guī)則介紹

    這篇文章主要介紹了linux網(wǎng)絡(luò)知識詳解:iptables 規(guī)則介紹,需要的朋友可以參考下
    2024-02-02
  • Linux搭建DHCP服務(wù)器的詳細過程

    Linux搭建DHCP服務(wù)器的詳細過程

    DHCP動態(tài)主機配置協(xié)議是一個局域網(wǎng)的網(wǎng)絡(luò)協(xié)議,指的是由服務(wù)器控制一段IP地址范圍,客戶機登錄服務(wù)器時就可以自動獲得服務(wù)器分配的IP地址和子網(wǎng)掩碼,這篇文章主要介紹了Linux搭建DHCP服務(wù)器,需要的朋友可以參考下
    2022-10-10
  • Linux添加swap分區(qū)的方法

    Linux添加swap分區(qū)的方法

    這篇文章主要介紹了Linux添加swap分區(qū)的方法,首先需要我們建立一個普通的linux 分區(qū),具體實例代碼,大家跟隨腳本之家小編一起看看吧
    2018-08-08
  • Linux中使用top命令的技巧

    Linux中使用top命令的技巧

    今天小編就為大家分享一篇關(guān)于Linux中使用top命令的技巧,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-09-09
  • CentOS7+apache+php7+mysql5.7配置教程詳解

    CentOS7+apache+php7+mysql5.7配置教程詳解

    這篇文章主要介紹了CentOS7+apache+php7+mysql5.7配置教程詳解,需要的朋友可以參考下
    2017-10-10
  • centos7安裝nginx的兩種方法介紹

    centos7安裝nginx的兩種方法介紹

    本篇文章主要介紹了centos7安裝nginx的兩種方法介紹,主要是通過兩種方式進行安裝,有興趣的可以了解一下。
    2017-03-03
  • CentOS7下安裝Scrapy步驟詳細介紹

    CentOS7下安裝Scrapy步驟詳細介紹

    這篇文章主要介紹了CentOS7下安裝Scrapy步驟詳細介紹的相關(guān)資料,需要的朋友可以參考下
    2017-05-05

最新評論