#!/bin/bash

#debug info
#user:houzc
#date:2012/7/27
#Mysql   apache  nginx install directory , mysqldata diretory configuration.

DATA_DIR="/data/mysqldata/"
BASE_DIR="/usr/local/mysql/"
VERSION="mysql-5.5.15"
HTTPVERSION="httpd-2.2.21"
PHPVERSION="php-5.3.8"
APPA_DIR="/usr/local/apache-2.2.21"
NGINXVERSION="nginx-1.2.3"
NGPA_DIR="/usr/local/nginx-1.2.3"

mysql_install()
{
   
  if [ -e "$MYSQL_DIR" ];then
   echo "Mysql already exists……………………………….."
   exit 0
  else
      rm -rf /usr/src/$VERSION/
   mkdir -p /data/mysqldata/
   mkdir -p /usr/local/mysql
   tar zxvf $VERSION.tar.gz -C /usr/src
   cd /usr/src/$VERSION/  && echo "cd ok"
   /usr/bin/cmake -DCMAKE_INSTALL_PREFIX=$BASE_DIR  
   -DMYSQL_DATADIR=$DATA_DIR  
   -DWITH_INNOBASE_STORAGE_ENGINE=1
   -DSYSCONFDIR=/etc
   -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8
   -DDEFAULT_COLLATION=utf8_unicode_ci
   -DWITH_DEBUG=0 -DMYSQL_USER=mysql  
   make && echo "make ok"
   make install && echo "make install ok"
   cp -r /usr/src/$VERSION/support-files/my-large.cnf /etc/my.cnf
   sh /usr/local/mysql/scripts/mysql_install_db –user=mysql –basedir=$BASE_DIR –datadir=$DATA_DIR –no-defaults
   chown mysql:root  -R  $BASE_DIR
   chown mysql:mysql -R  $DATA_DIR
   sed "26 i basedir=${BASE_DIR}" -i /etc/my.cnf
   sed "27 i datadir=${DATA_DIR}" -i /etc/my.cnf
   cp -r /usr/src/$VERSION/support-files/mysql.server /etc/init.d/mysqld
   chmod +x /etc/init.d/mysqld
   sed "48 i basedir=${BASE_DIR}" -i /etc/init.d/mysqld
   sed "49 i datadir=${DATA_DIR}" -i /etc/init.d/mysqld
   echo ‘PATH=$PATH:/usr/local/mysql/bin/’ >> /etc/profile
   source /etc/profile
   cd –
  fi
   
   
}

apache_install()
{  
  if [ -e $APPA_DIR ];then
   echo "httpd already exists…………………….."
   exit 0
  else
        rm -rf /usr/src/$HTTPVERSION
     tar zxvf $HTTPVERSION.tar.gz -C /usr/src/
     cd /usr/src/$HTTPVERSION/srclib/apr
     ./configure –prefix=/usr/local/apr
     make && make install && echo "apr is ok………………………….."
     sleep 3
   cd –
     cd /usr/src/$HTTPVERSION/srclib/apr-util/
     ./configure –prefix=/usr/local/apr-util/
     –with-apr=/usr/local/apr
     make && make install && echo "apr-util is ok…………………………"
     sleep 3
   cd –
     cd /usr/src/$HTTPVERSION
     ./configure –prefix=$APPA_DIR
     –with-apr=/usr/local/apr/
     –with-apr-util=/usr/local/apr-util/
     –enable-so
     –enable-rewrite
     make && make install && echo "apache is ok…………………………"
     sed -i ‘s/#ServerName www.example.com:80/ServerName www.example.com:80/’  $APPA_DIR/conf/httpd.conf
     $APPA_DIR/bin/apachectl start
     cd –
  fi
}
php_install()
{
  if [ -e "/usr/local/$PHPVERSION" ];then
   echo "php already exists…………………….."
   exit 0
  else
      rm -rf /usr/src/freetype-2.4.3/
   tar zxvf freetype-2.4.3.tar.gz -C /usr/src/
   cd /usr/src/freetype-2.4.3/
   ./configure –prefix=/usr/local/freetype-2.4.3
   make && make install && echo "freetype is ok…………………………"
   sleep 3
   cd –
   rm -rf /usr/src/libpng-1.4.4/
   tar zxvf libpng-1.4.4.tar.gz -C /usr/src/
   cd  /usr/src/libpng-1.4.4/
   ./configure –prefix=/usr/local/libpng-1.4.4
   make && make install && echo "libpng is ok…………………………"
   sleep 3
   cd –
   rm -rf /usr/src/jpeg-8b
   tar zxvf jpegsrc.v8b.tar.gz -C /usr/src/
   cd  /usr/src/jpeg-8b/
   ./configure –prefix=/usr/local/jpeg-8b
   make && make install && echo "jpeg-8b is ok…………………………"
   sleep 3
   cd –
   rm -rf /usr/src/gd-2.0.33
   tar zxvf gd-2.0.33.tar.gz -C /usr/src/
   cp -r gd_png.c  /usr/src/gd-2.0.33/
   cd /usr/src/gd-2.0.33/
   ./configure –prefix=/usr/local/gd-2.0.33
          –with-jpeg=/usr/local/jpeg-8b
   –with-freetype=/usr/local/freetype-2.4.3
   –with-png=/usr/local/libpng-1.4.4   
   –with-zlib
   –enable-m4_pattern_allow
   make && make install && echo "gd is ok…………………………"
   sleep 3
   cd –
   rm -rf /usr/src/$PHPVERSION
   tar zxvf $PHPVERSION.tar.gz -C /usr/src/
   cd /usr/src/$PHPVERSION/
   ./configure –prefix=/usr/local/$PHPVERSION
   –with-apxs2=$APPA_DIR/bin/apxs
   –with-zlib –with-libxml-dir –enable-gd-native-ttf
   –enable-mbstring –with-gd=/usr/local/gd-2.0.33/
   –with-mysql=$BASE_DIR
   –with-freetype-dir=/usr/local/freetype-2.4.
3/
          –with-jpeg-dir=/usr/local/jpeg-8b/
          –with-png-dir=/usr/local/libpng-1.4.4/
   –enable-sockets
   make && make install && echo "php  is ok…………………………"
   cp -r php.ini-development /usr/local/$PHPVERSION/lib/php.ini
   sed -i "54 i AddType application/x-httpd-php .php " $APPA_DIR/conf/httpd.conf
   sed -i ‘s/DirectoryIndex index.html/DirectoryIndex index.html index.php/’ $APPA_DIR/conf/httpd.conf
   cd –
   cp -r info.php $APPA_DIR/htdocs/
   $APPA_DIR/bin/apachectl stop
   $APPA_DIR/bin/apachectl start
   
  fi
}
nginx_install()
{  
  if [ -e $NGPA_DIR ];then
   echo "nginx already exists…………………….."
   exit 0
  else
   groupadd -rf www
   useradd -g www www -s /bin/false
   rm -rf /usr/src/pcre-8.31
   rm -rf /usr/src/$NGINXVERSION
   tar zxvf pcre-8.31.tar.gz  -C /usr/src/
   cd /usr/src/pcre-8.31
   ./configure
   make &&  make install && echo "pcre is ok ………………………"
   cd –
   tar zxvf $NGINXVERSION.tar.gz -C /usr/src/
   cd /usr/src/$NGINXVERSION
   ./configure –prefix=$NGPA_DIR
   –user=www –group=www
   –with-http_stub_status_module
   –with-openssl=/usr
   make && make install && echo "nginx is  ok ………………….."
   ln -s /usr/local/lib/libpcre.so.1 /lib
   $NGPA_DIR/sbin/nginx
  fi
   }
case "$1" in
mysql_install)
  if [ -f /etc/debian_version ]; then
   apt-get -y install build-essential cmake libncurses5-dev bison
   groupadd  -r mysql && useradd -r -M -s /usr/sbin/nologin -g mysql mysql
   echo "The system is bing installed cmake,please waitting…"
   sleep 3
   mysql_install
   /etc/init.d/mysqld start
   update-rc.d mysqld defaults
         
  else
   yum -y install gcc gcc-c++  libtermcap-devel ncurses-devel  camke  bison
   useradd mysql -M -s /sbin/nologin
   echo "The system is bing installed cmake,please waitting…"
   sleep 3
   mysql_install
   /etc/init.d/mysqld start
   chkconfig –add mysqld
  fi
  ;;
apache_install)
  apache_install
  ;;
php_install)
  if [ -f /etc/debian_version ]; then
   apt-get  -y install zlib1g-dev libxml2-dev && php_install
  else
   yum -y install libxml2-devel libxml2  zlib zlib-devel  && php_install
  fi
  ;;
    AMP_install)
  
  if [ -f /etc/debian_version ]; then
   apt-get -y install build-essential cmake libncurses5-dev bison
   groupadd  -r mysql && useradd -r -M -s /usr/sbin/nologin -g mysql mysql
   echo "The system is bing installed cmake,please waitting…"
   sleep 3
   mysql_install
   /etc/init.d/mysqld start
   update-rc.d mysqld defaults   
   apache_install
   apt-get  -y install zlib1g-dev libxml2-dev
   php_install
  else
   yum -y install gcc gcc-c++  libtermcap-devel ncurses-devel  camke  bison
   useradd mysql -M -s /sbin/nologin
   echo "The system is bing installed cmake,please waitting…"
   sleep 3
   mysql_install
   /etc/init.d/mysqld start
   chkconfig –add mysqld
   apache_install
   yum -y install libxml2  libxml2-devel zlib zlib-devel
   php_install
  fi
  ;;
nginx_install)
  nginx_install
  ;;
mysql_remove)
  PLOCK=`ps aux | grep mysql | grep -v grep | awk ‘{ print $2 }’`
  if  [ -z $PLOCK ];then
   rm -rf $DATA_DIR
   rm -rf $BASE_DIR
  else
   /etc/init.d/mysqld stop
   rm -rf $DATA_DIR
   rm -rf $BASE_DIR
   rm -rf /etc/init.d/mysqld
  fi
  ;;
*)
  echo "Usage: install_AMP.sh {mysql_install|apache_install|php_install|AMP_install|nginx_install|mysqlremove}"
  exit
  ;;
esac

发表评论

电子邮件地址不会被公开。 必填项已用*标注