LNMP Install deployment scripts automatically _linux

Source: Internet
Author: User
Tags curl fpm install php mysql version openssl sleep zip epel repo

Our business uses nginx, MySQL, PHP, and Tomcat, wrote an automated installation of these software scripts, although there are many similar automated installation scripts on the Web, but this is written by yourself, hereby mark, hoping to give others some reference, At the same time also gray often welcome to see friends to make some suggestions for improvement. Words not much to say, directly on the script.

#!/bin/sh alias echo= ' echo-e ' # # #判断系统, this script applies only to 64-bit systems machine= ' uname-m ' if [$machine!= x86_64]; then echo "  \e[1;31m \nyour System is 32bit,but This script are only run on 64bit!\n \e[0m "exit-1 fi # # #创建保存下载文件的目录 mkdir /usr/local/src/auto_install &>/dev/null Source_dir=/usr/local/src/auto_install # #定义一个交互式的选择提示 function inte
    ract {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} ### defines a function to check the execution status of the previous command 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} ### define functions to download each software (here I hide our download address, we need you to set up the download address) function Download_install _epel {CD $source _dir rm-f epel* &>/dev/null echo "\e[1;32m---yum install epel repo---\e[0m \ n" Sy S_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 r
    PM-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.3 9-linux2.6-x86_64.tar.gz &>/dev/null If [$-ne 0];then Wget-nv Http://www.example.com/mysql-5.5.39-linu
  X2.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.b
  in check;
  FI} # # #定义依赖包安装函数 function Dependence_install {download_install_epel;
  echo "\e[1;32m---Yum install 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 cur L-devel libjpeg libjpeg-devel libpng libpng-devel freetype-devel pspell-devel libmcrypt libm crypt-devel freetype pcre-de Vel 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-de
Vel OpenSSL openssl-devel libaio* >/dev/null 2>&1 check; ### defines the MySQL installation function ### functions mysql_install {# # #判断本机是否已在运行mysql, or boot startup items have mysql### # # #判断机器上是否以运行mysql实例 EC Ho "\e[1;32m \ n---Check if there is already installed MySQL instence---\e[0m\n" ps-ef|grep-w mysqld|grep-v "grep" &A Mp;>/dev/null if [$-eq 0];then mysqlbasedir= ' ps-ef|grep-w ' mysqld ' |grep-v ' grep ' |awk ' {print $} ' |tr-d ' \-\-' mysqldatadir= ' ps-ef|grep-w ' mysqld ' |grep-v ' grep ' |awk ' {print $} ' |tr-d ' \-\-' ' echo ' \e[1;32m your sy Stem has run a MySQL instance already \ n Mysqlbasedir is: "$mysqlbasedir" \ n mysqldatadir is: "$mysqldatadir" \ r \ r stil L want to install a new mysql-server?
  \e[0m\n "interact; Fi # #判断系统是否已经有rpm方式安装的mysql echo "mysql-server-5.5.39-2.el6.x86_64.rpm" |while read line do prefix= ' echo "$ Line "|awk-f"-"' {print $ '-" $} ' # #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 $ '-" $ "-" $} "# #to get t He already installed MySQL version echo \e[1;31m---The $already _install are already installed by RPM!---\ n---do y
     ou really want to install a new MySQL?---\e[0m\n "interact; Fi done # # #判断chkconfig里面是否有mysql启动脚本并且为开机启动 chkconfig |grep Mysql|awk ' {print $ ' $} ' |grep-e ' Enable '-e ' on ' ;>/dev/null if [$-eq 0];then echo "There is a bootstart MySQL script in the chkconfig,please check" Exi T 0 Fi # # #判断/etc/rc.local file has a MySQL startup command cat/etc/rc.local|grep "mysqld" &>/dev/null if [$-eq 0];th En echo "There is a bootstart MySQL commond in the/etc/rc.local,please check it" Exit 0 fi ##### #判断结束 ### ### # # #检查是否有系统自带的mysql-lib-5.1, there is deleted 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 # # #选择d
  ATA directory 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 t
  o 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-linu
  x2.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 whether there are my.cnf, if any, renamed 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.cn F/ETC/MY.CNF # # #拷贝开机启动脚本到/etc/init.d/ls/etc/init.d/mysql &>/dev/null if [$ = 0];then \mv/etc/in It.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 script Basedi R and 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 # # #初始化数据库 echo ' \e[1;32m\n---initialize mysql databas E---\e[0m "sleep 1 chown-r mysql $mydatadir $mybasedir >/dev/null 2>&1 $mybasedir/scripts/mysql_install_d
    b--defaults-file=/etc/my.cnf--user=mysql--basedir= $mybasedir--datadir= $mydatadir check; # # #将basedir/bin/added to 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安装完毕} ### definition ng Inx Install 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/C
Onfigure--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_ngi
Nx.log check; echo "\e[1;32m---make install:install into/usr/local/nginx---\e[0m \ n" Sleep 1 make install &>/tmp/make_in Stall. log check;
  echo "\e[1;32m Nginx is installed successfully \e[0m \ n"} ### defines the PHP installation functions 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/n
  ULL check; CD php-5.3.28 Echo echo "\e[1;32m---Configure php:information in/tmp/php_configure.log---\e[0m \ n" echo "./confi Gure--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-- 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-- 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-- 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 C
  Heck # # #make install echo ' \e[1;32m---make install php:install into/usr/local/php---\ n---php cofigure file in the/usr/l OCAL/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 J Re_install {# # #删除系统自带的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 Chec
  K Ls-d/usr/java if [$-ne 0];then Mkdir/usr/java &>/dev/null else echo echo "\e[1;31m/usr/java ha S 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 >>/e Tc/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 instal LED success!\e[0m "echo" \e[1;32m\n---install cronolog---\e[0m "wget-nv http://www.example.com/cronolog-1.6.2.tar.g
  Z 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---Select which software needs to be installed---\e[0m \ n "Ech o "\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 does 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 
      Stall a mysqlclient\n Please make a softlink for all \ libmysqlclient.so.*\ ' file to both/var/lib64 and/var/lib ' echo "\e[1;31m Please input your choice\n\e[0m \e[1;32m1:go in by default\ (install mysql-client-5.5.39\) \ n 2:i wi ll check my \ ' libmysqlclient.so.*\ ' file and redo this script later\n 3:i had ' 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 ' {pri
        NT $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

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.