shell 一键安装lAMP,lNMP

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群版 2核4GB 100GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用版 2核4GB 50GB
简介:

本文章仅供参考 想要使用请+本人Q :465717440发送完整的包和脚本,

 
#!/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 
 


本文转自 houzaicunsky 51CTO博客,原文链接:http://blog.51cto.com/hzcsky/977169


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
2月前
|
存储 JSON 分布式计算
MongoDB【部署 01】mongodb最新版本6.0.5安装部署配置使用及mongodb-shell1.8.0安装使用(云盘分享安装文件)
MongoDB【部署 01】mongodb最新版本6.0.5安装部署配置使用及mongodb-shell1.8.0安装使用(云盘分享安装文件)
270 0
|
2月前
|
Linux Shell 开发工具
10分钟让你的Linux Shell终端变得更优雅,更高效——【Linux服务器下OhMyZsh+P10k安装实践】
10分钟让你的Linux Shell终端变得更优雅,更高效——【Linux服务器下OhMyZsh+P10k安装实践】
171 1
|
1月前
|
Ubuntu Java Linux
Linux centos7 ubuntu 一键安装Java JDK 脚本 shell 脚本
Linux centos7 ubuntu 一键安装Java JDK 脚本 shell 脚本
58 2
|
2月前
|
运维 Java 应用服务中间件
Tomcat安装shell脚本
Tomcat安装shell脚本
48 7
|
2月前
|
Ubuntu Shell Linux
|
2月前
|
运维 应用服务中间件 Shell
Nginx安装与虚拟主机配置shell脚本
Nginx安装与虚拟主机配置shell脚本
39 0
|
2月前
|
存储 Shell Linux
ZooKeeper【部署 01】单机版安装+配置+添加到service服务+开机启动配置+验证+chkconfig配置+shell自动部署脚本(一篇入门zookeeper)
ZooKeeper【部署 01】单机版安装+配置+添加到service服务+开机启动配置+验证+chkconfig配置+shell自动部署脚本(一篇入门zookeeper)
238 0
|
13天前
|
JavaScript 前端开发 Shell
Shell 脚本编程保姆级教程(上)
Shell 脚本编程保姆级教程(上)