码迷,mamicode.com
首页 > 系统相关 > 详细

shell脚本实现源码lamp自动化安装

时间:2016-04-09 15:21:26      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:

代码如下,写了好久,在centos6.3实践中用过,分享给大家@.·.@

       运行此脚本的前提有gcc/gcc-c++的编译环境,此脚本用到一些源码包(apr-1.2.7,apr-util-1.2.7,autoconf-2.59,cmake-2.6.4,curl-7.15.1,freetds-2.2.2,gd-2.0.33,httpd-2.2.31,jpegsrc-v7,libmcrypt-2.5.7,libpng-1.2.10,libxml2-2.6.26,mysql-5.0.77,openssh-4.3p2,pcre-6.6,php-5.3.29,zlib-1.2.3),需要自行下载,这些包放在脚本同级目录下的Centos.pkg目录下。

#!/bin/sh
#################################
##LAMP AUTOMATIC SOURCE INSTALL##
#################################

##Check the user(root)##
[ $ID -ne 0 ] && echo "The script must root can run ! " && echo  "Please switch user to root ! " && exit 1

##1. Platform
echo "**System Information**"
echo "redhat-release : $(cat /etc/redhat-release)"
echo "hostname : $HOSTNAME"
echo "operating system:$(uname -o)"
echo "kernel version:$(uname -v)"
echo "hardware platform:$(uname -i)"
echo

##2. Environment Variable
IPADDR=$(ifconfig eth0 | awk -F"[: ]+" NR==2 {print $4})
CENTOS_VER=$(cat /etc/redhat-release |awk -F"[ .]+" {print $3})
SYSTEM_BIT=$(getconf LONG_BIT)
INSTALL_PATH="/usr/local"
SOURCEPKG_PATH="$PWD/Centos.pkg"
RPM_PAHT="$PWD/rpm"
RPM=$(ls -r $RPM_PATH)
PACKAGE=$(ls -1 $SOURCEPKG_PATH | awk -F"-" {print $1})
[ ! -d extract.pkg ] && mkdir extract.pkg
EXTRACT_PATH="$PWD/extract.pkg"

##3. Package
#3.1 Download Rpm Package
# cd $RPM_PATH
# wget http://centos.mirror.fr.planethoster.net/5/os/x86_64/CentOS/kernel-headers-2.6.18-398.el5.x86_64.rpm
# wget http://centos.mirror.fr.planethoster.net/5/os/x86_64/CentOS/glibc-common-2.5-123.x86_64.rpm
# wget http://centos.mirror.fr.planethoster.net/5/os/x86_64/CentOS/glibc-2.5-123.x86_64.rpm
# wget http://centos.mirror.fr.planethoster.net/5/os/x86_64/CentOS/glibc-headers-2.5-123.x86_64.rpm
# wget http://centos.mirror.fr.planethoster.net/5/os/x86_64/CentOS/glibc-devel-2.5-123.x86_64.rpm
# wget http://centos.mirror.fr.planethoster.net/5/os/x86_64/CentOS/gcc-4.1.2-55.el5.x86_64.rpm
# wget ftp://rpmfind.net/linux/centos/5.11/os/i386/CentOS/ncurses-devel-5.5-24.20060715.i386.rpm
# wget ftp://rpmfind.net/linux/centos/5.11/os/x86_64/CentOS/ncurses-devel-5.5-24.20060715.x86_64.rpm
# echo
#3.2 Download Source Package
# cd $SOURCEPKG_PATH
# wget http://ftp.gnu.org/gnu/ncurses/ncurses-5.5.tar.gz
# wget http://apache.dataguru.cn//apr/apr-1.5.2.tar.gz
# wget http://apache.dataguru.cn//apr/apr-util-1.5.4.tar.gz
# wget http://exim.mirror.fr/pcre/pcre-8.32.tar.gz
# wget http://down1.chinaunix.net/distfiles/libxml2-2.7.2.tar.gz
# wget http://down1.chinaunix.net/distfiles/libmcrypt-2.5.7.tar.gz
# wget http://down1.chinaunix.net/distfiles/gd-2.0.33.tar.gz
# wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
# wget http://ftp.twaren.net/Unix/NonGNU//freetype/freetype-2.4.9.tar.gz
# wget ftp://ftp.simplesystems.org/pub/png/src/libpng15/libpng-1.5.23.tar.gz
# wget http://ijg.org/files/jpegsrc.v8b.tar.gz
# wget http://curl.haxx.se/download/curl-7.20.1.tar.gz
# wget http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.5/mysql-5.5.45.tar.gz
# wget http://www.apache.org/dist/httpd/httpd-2.4.17.tar.gz
# wget wget http://cn2.php.net/distributions/php-5.5.30.tar.gz

##4. Base Environmet Optimize
/bin/sh $PWD/optimize.sh

##5. Extract Package
echo "Start Extract Package ,Please wait for several minutes ..."
cd $SOURCEPKG_PATH
for i in `ls -1` ;do
    tar xf $i -C $EXTRACT_PATH;
    [ $(echo $?) -ne 0 ] && exit 1
done
echo "Complete Extract Package !"
echo

##6. Install Source Code
#Apache,Mysql,PHP version
echo "Apache_Version=$(ls $SOURCEPKG_PATH/httpd* |awk -F"[-t]+" ‘{print $5}‘)"
echo "Mysql_Version=$(ls $SOURCEPKG_PATH/mysql* |awk -F"[-t]+" ‘{print $4}‘)"
echo "Php_Version=$(ls $SOURCEPKG_PATH/mysql* |awk -F"[-t]+" ‘{print $4}‘)"

echo "Start Install All Source Code , The process will take a long time , When complete will print:"
echo "Please Wait ... !!!"
echo

#6.1 Install gcc
#GCC_VALUE=$(gcc -v >/dev/null 2>&1)
# for i in $(ls -1 /etc/yum.repos.d);do
#    mv $i $i.bak;
#    [ $(echo $?) -ne 0 ] && exit 1
#done
#wget --directory-prefix=/etc/yum.repos.d http://mirrors.163.com/.help/CentOS"$CENTOS_VER"-Base-163.repo
#if [[ $GCC_VALUE -ne 0 ]] ;then
#    echo "Install gcc ..."
#    #Install gcc
#    yum clean all >/dev/null 2>&1
#    yum makecache>/dev/null 2>&1
#    yum install gcc gcc-c++ >/dev/null 2>&1
#    echo "Gcc Install Complete."
#    done
#fi
#6.2 Install libxml2 
echo "Install libxml2 ..."
cd $EXTRACT_PATH/libxml2*
./configure --prefix=$INSTALL_PATH/libxml2 >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Libxml2 Install Completed ."
echo

#6.3 Install libmcrypt 
echo "Install libmcrypt ..."
cd $EXTRACT_PATH/libmcrypt*
./configure --with-mcrypt-dir=$INSTALL_PATH/libmcrypt > /dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Libcrypt Install Completed."
echo

#6.4 Install libltdl 
echo "Install libltdl ..."
cd $EXTRACT_PATH/libmcrypt*/libltdl*
./configure --enable-ltdl-install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Libltdl Install Completed."
echo

#6.5 Install zlib
echo "Install zlib ..."
cd $EXTRACT_PATH/zlib*
if [[ $SYSTEM_BIT -eq 32 ]]; then
    ./configure >/dev/null 2>&1
else
    CFLAGS="-O3 -fPIC" ./configure >/dev/null 2>&1
fi
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Zlib Install Complete."
echo

#6.6 Install libpng
echo "Install libpng ..."
cd $EXTRACT_PATH/libpng*
./configure --prefix=$INSTALL_PATH/libpng >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Libpng Install Complete."
echo

#6.7 Install jpeg
echo "Install jpegsrc ..."
mkdir $INSTALL_PATH/jpeg/{bin,lib,include,man/man1} -p
cd $EXTRACT_PATH/jpeg*
[ $(echo $?) -ne 0 ] && exit 1
./configure  --prefix=$INSTALL_PATH/jpeg/ --enable-shared --enable-static >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Jpegsrc Install Complete."
echo

#6.8 Install freetype
echo "Install freetype ..."
cd $EXTRACT_PATH/freetype*
./configure --prefix=$INSTALL_PATH/freetype >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Freetype Install Complete."
echo

#6.9 Install autoconf
echo "Install autoconf ..."
cd $EXTRACT_PATH/autoconf*
./configure >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Autoconf Install Complete."
echo

#6.10 Install ncurses
#echo "Install ncurses ..."
#cd $EXTRACT_PATH/ncurses*
#./configure --prefix=$INSTALL_PATH/ncurses --with-shared >/dev/null 2>&1
#[ $(echo $?) -ne 0 ] && exit 1
#make >/dev/null 2>&1
#[ $(echo $?) -ne 0 ] && exit 1
#make install >/dev/null 2>&1
#[ $(echo $?) -ne 0 ] && exit 1
#echo "Ncurses Install Complete."
#echo

#6.11 Install gd 
echo "Install GD ..."
cd $EXTRACT_PATH/gd*
sed -i 15s#png.h#$INSTALL_PATH/libpng/include/png.h# gd_png.c
[ $(echo $?) -ne 0 ] && exit 1
./configure --prefix=$INSTALL_PATH/gd --with-jpeg=$INSTALL_PATH/jpeg/ --with-png=$INSTALL_PATH/libpng/ --with-freetype=$INSTALL_PATH/freetype/ >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "GD Install Complete."
echo

#6.12 Install apr
echo "Install apr ..."
cd $EXTRACT_PATH/apr*
./configure --prefix=$INSTALL_PATH/apr >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Apr Install Complete."
echo

#6.13 Install apr-util
echo "Install apr-util ..."
cd $EXTRACT_PATH/apr-util*
./configure --prefix=$INSTALL_PATH/apr-util --with-apr=$INSTALL_PATH/apr >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Apr-util Install Complete."
echo

#6.14 Install pcre
echo "Install pcre ..."
cd $EXTRACT_PATH/pcre*
./configure --prefix=$INSTALL_PATH/pcre >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Pcre Install Complete."
echo

#6.15 Install freetds
echo "Install freetds ..."
cd $EXTRACT_PATH/freetds*
./configure --prefix=$INSTALL_PATH/freetds --enable-shared --enable-static --with-tdsver --enable-msdblib >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "freetds Install Complete."
echo

#6.16 Install apache
echo "Install apache ..."
cd $EXTRACT_PATH/httpd*
./configure --prefix=$INSTALL_PATH/apache --enable-mods-shared=all --enable-deflate --enable-speling --enable-cache --enable-file-cache --enable-disk-cache --enable-mem-cache --enable-so --enable-expires=shared --enable-rewrite=shared --enable-static-support --sysconfdir=/etc/httpd --with-apr=$INSTALL_PATH/apr --with-apr-util=$INSTALL_PATH/apr-util --with-pcre=$INSTALL_PATH/pcre --disable-userdir >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Apache Install Complete."
echo

#6.17 Install mysql
echo "Install mysql ..."
#6.17.1 Check Mysql user
id mysql >/dev/null 2>&1
MYSQL_USER="$(echo $?)"
if [[ $MYSQL_USER -ne 0 ]] ;then
    groupadd mysql
    useradd -g mysql mysql
[ $(echo $?) -ne 0 ] && exit 1
fi
#6.17.2 Install necessary dependice rpm package
rpm -ivh $RPM_PAHT/ncurses*.rpm >/dev/null 2>&1
#6.17.3 Install mysql server
cd $EXTRACT_PATH/mysql*
./configure --prefix=$INSTALL_PATH/mysql --enable-thread-safe-client --with-extra-charsets=all >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Mysql Install Complete."
echo

#6.18 Install php
echo "Install php"
cd $EXTRACT_PATH/php*
./configure --prefix=$INSTALL_PATH/php --with-config-file-path=$INSTALL_PATH/php/etc --with-apxs2=$INSTALL_PATH/apache/bin/apxs --with-mysql=$INSTALL_PATH/mysql --with-libxml-dir=$INSTALL_PATH/libxml2 --with-png-dir=$INSTALL_PATH/libpng --with-jpeg-dir=$INSTALL_PATH/jpeg --with-freetype-dir=$INSTALL_PATH/freetype --with-gd=$INSTALL_PATH/gd --with-zlib-dir=$INSTALL_PATH/zlib --with-mcrypt=$INSTALL_PATH/libmcrypt --with-mysqli=$INSTALL_PATH/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --with-mssql=$INSTALL_PATH/freetds --enable-sockets >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
make install >/dev/null 2>&1
[ $(echo $?) -ne 0 ] && exit 1
echo "Php Install Complete."
echo

##7. Configure LAMP Configuation Files
#7.1 Configure Apache Configuation Files
#7.1.1 Set apache configuation file
sed -i 203aServerName\ $HOSTNAME:80 /etc/httpd/httpd.conf
[ $(echo $?) -ne 0 ] && exit 1
#7.1.2 Make apache server can read ".php" file
sed -i 386aAddType\ application\/x-httpd-php\ \.php /etc/httpd/httpd.conf
[ $(echo $?) -ne 0 ] && exit 1
sed -i 386aAddType\ application\/x-httpd-php-source\ \.phps /etc/httpd/httpd.conf
[ $(echo $?) -ne 0 ] && exit 1
sed -i 386aAddType\ application\/x-httpd-php\ \.php\ \.phtml\ \.php3 /etc/httpd/httpd.conf
[ $(echo $?) -ne 0 ] && exit 1
#7.1.3 Set apache server start runing when system start-up
cp $INSTALL_PATH/apache/bin/apachectl /etc/init.d/httpd
sed -i -e 2a#\ chkconfig:\ 234\ 71\ 29 /etc/init.d/httpd -e 2a#\ description:\ Apache\ is\ a\ World\ Wide\ Web\ server. /etc/init.d/httpd
[ $(echo $?) -ne 0 ] && exit 1
chkconfig --add httpd >/dev/null 2>&1
#7.2.4 Set Envirment variable
sed -i "10s%$%&:$INSTALL_PATH/apache/bin%" /root/.bash_profile 
source /root/.bash_profile

#7.2 Configure Mysql Configuation Files
#7.2.1 Set mysql configuation file
cp $EXTRACT_PATH/mysql*/support-files/my-medium.cnf /etc/my.cnf
#7.2.2 Init mysql dababase
$INSTALL_PATH/mysql/bin/mysql_install_db --user=mysql >/dev/null 2>&1
#7.2.3 Set privileges for mysql server file
chmod +x $INSTALL_PATH/mysql/bin/* >/dev/null 2>&1
chown -R root $INSTALL_PATH/mysql >/dev/null 2>&1
chown -R mysql $INSTALL_PATH/mysql/var >/dev/null 2>&1
chgrp -R mysql $INSTALL_PATH/mysql >/dev/null 2>&1
#7.2.4 Set mysql server password (default 123456)
$INSTALL_PATH/mysql/bin/mysqladmin -u root password 123456 >/dev/null 2>&1
#7.2.5 Set mysql server start runing when system start-up
cp $EXTRACT_PATH/mysql*/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld >/dev/null 2>&1
#7.2.6 Set Envirment variable
sed -i "10s%$%&:$INSTALL_PATH/mysql/bin%" /root/.bash_profile 
source /root/.bash_profile


##8. Start LAMP Server
service httpd start
service mysqld start

##9. Clean Useless File Or Directory
rm -fr $EXTRACT_PATH

#10. LAMP Enviromnet Is Complete
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
echo @@@@!Thank You Use The script! Now You Can Enjoy Your LAMP Server!@@@@
echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

 

shell脚本实现源码lamp自动化安装

标签:

原文地址:http://www.cnblogs.com/foxsir/p/5371551.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!