SHELL实现CentOS6,Ubuntu16下自动下载,编译安装LAMP

shell暂时没时间去写了, 等有时间慢慢来~ 未完待续。。。

目前第一版:
本人在Centos6上运行成功。
使用方法:先用root账号运行install脚本,然后用普通账号运行init(root账户也可以,不过我没试过).
init 参数说明:
–install-path 安装目录,当前执行的用户必须有这个目录的权限!!!并且不可使用相对目录!
比如:

./init --install-path=/home/sxin/soft    这个是对的
./init --install-path=~/soft             这个是错的

目前存在的问题:
mysql编译安装完执行生成data目录的随机密码暂时获取不到,以及mysql配置文件的内容没有修改.

install

#!/bin/bash
linuxver=`head -n 1 /etc/issue`
linuxver=`echo $linuxver | tr 'a-z' 'A-Z'`
[[ $linuxver =~ "CENTOS" ]] && yum install -y gcc gcc-c++ cmake git ncurses-devel libxml2 libxml2-devel.x86_64 
[[ $linuxver =~ "UBUNTU" ]] && apt-get install -y gcc g++ libxml2-dev libpcre3 libpcre3-dev libzlcore-dev cmake git libncurses5 libncurses5-dev 

init

#!/bin/bash
logname='log'
`true > $logname`
echo `date "+%Y-%m-%d %H:%M:%S" `' start' > $logname

isdownphp=true
isdownhttpd=true
isdownmysql=true
isdownnginx=true

downpath=~/downloads
phpcodepath=$downpath/php7
httpdcodepath=$downpath/httpd24/
mysqlcodepath=$downpath/mysql57/
nginxcodepath=$downpath/nginx/
toolscodepath=$downpath/tools
installpath=~/install

for para in $@
do
    [[ "${para}" =~ --php-code-path= ]] && isdownphp=false && phpcodepath=${para#--php-code-path=}
    [[ "${para}" =~ --httpd-code-path= ]] && isdownhttpd=false && httpdcodepath=${para#--httpd-code-path=}
    [[ "${para}" =~ --mysql-code-path= ]] && isdownmysql=false && mysqlcodepath=${para#--mysql-code-path=}
    [[ "${para}" =~ --nginx-code-path= ]] && isdownnginx=false && nginxcodepath=${para#--nginx-code-path=}
    [[ "${para}" =~ --install-path= ]] && installpath=${para#--install-path=}
done

user='sxin'

echo `date "+%Y-%m-%d %H:%M:%S" `' init path' >> $logname

#init path
if [ ! -d "$installpath" ]; then
    mkdir -p "$installpath"
fi
if [ ! -d "$downpath" ]; then
    mkdir -p "$downpath"
fi
if [ ! -d "$phpcodepath" ]; then
    mkdir -p "$phpcodepath"
fi
if [ ! -d "$httpdcodepath" ]; then
    mkdir -p "$httpdcodepath"
fi
if [ ! -d "$mysqlcodepath" ]; then
    mkdir -p "$mysqlcodepath"
fi
if [ ! -d "$nginxcodepath" ]; then
    mkdir -p "$nginxcodepath"
fi
if [ ! -d "$toolscodepath" ]; then
    mkdir -p "$toolscodepath"
fi

echo `date "+%Y-%m-%d %H:%M:%S" `' create path' >> $logname

#下载软件源码
$isdownphp && echo `date "+%Y-%m-%d %H:%M:%S" `' start download php code' >> $logname && wget -P $downpath/php7 "http://cn2.php.net/distributions/php-7.0.8.tar.gz" && echo `date "+%Y-%m-%d %H:%M:%S" `' download php code ok' >> $logname

$isdownnginx && echo `date "+%Y-%m-%d %H:%M:%S" `' start download nginx code' >> $logname && wget -P $downpath/nginx "http://nginx.org/download/nginx-1.11.1.tar.gz" && echo `date "+%Y-%m-%d %H:%M:%S" `' download nginx code ok' >> $logname

$isdownhttpd && echo `date "+%Y-%m-%d %H:%M:%S" `' start download httpd code' >> $logname && wget -P $downpath/httpd24 "http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.20.tar.gz" && echo `date "+%Y-%m-%d %H:%M:%S" `' download httpd code ok' >> $logname

$isdownmysql && echo `date "+%Y-%m-%d %H:%M:%S" `' start download mysql code' && wget -P $downpath/mysql57 "http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.13.tar.gz" && echo `date "+%Y-%m-%d %H:%M:%S" `' download mysql code ok' >> $logname && echo `date "+%Y-%m-%d %H:%M:%S" `' start download mysql-boost code' && wget -P $downpath/mysql57 "http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.13.tar.gz"&& echo `date "+%Y-%m-%d %H:%M:%S" `' download mysql-boost code ok' >> $logname 

wget -P $toolscodepath "http://apache.fayea.com//apr/apr-1.5.2.tar.gz" "http://apache.fayea.com//apr/apr-util-1.5.4.tar.gz" "http://zlib.net/zlib-1.2.8.tar.gz" "ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz"

echo `date "+%Y-%m-%d %H:%M:%S" `' download apr apr-util zlib pcre code' >> $logname

#extract
tar -zxvf $toolscodepath/apr-1.5.2.tar.gz -C $toolscodepath
echo `date "+%Y-%m-%d %H:%M:%S" `' extract apr success' >> $logname
tar -zxvf $toolscodepath/apr-util-1.5.4.tar.gz -C $toolscodepath
echo `date "+%Y-%m-%d %H:%M:%S" `' extract apr-util success' >> $logname
tar -zxvf $toolscodepath/pcre-8.39.tar.gz -C $toolscodepath
echo `date "+%Y-%m-%d %H:%M:%S" `' extract pcre success' >> $logname
tar -zxvf $toolscodepath/zlib-1.2.8.tar.gz -C $toolscodepath
echo `date "+%Y-%m-%d %H:%M:%S" `' extract zlib success' >> $logname
$isdownnginx && tar -zxvf $nginxcodepath/nginx-1.11.1.tar.gz -C $nginxcodepath && echo `date "+%Y-%m-%d %H:%M:%S" `' extract nginx success' >> $logname
$isdownphp && tar -zxvf $phpcodepath/php-7.0.8.tar.gz -C $phpcodepath && echo `date "+%Y-%m-%d %H:%M:%S" `' extract php success' >> $logname
$isdownmysql && tar -zxvf $mysqlcodepath/mysql-5.7.13.tar.gz -C $mysqlcodepath && echo `date "+%Y-%m-%d %H:%M:%S" `' extract mysql success' >> $logname
$isdownmysql && tar -zxvf $mysqlcodepath/mysql-boost-5.7.13.tar.gz -C $mysqlcodepath && echo `date "+%Y-%m-%d %H:%M:%S" `' extract mysql-boost success' >> $logname
$isdownhttpd && tar -zxvf $httpdcodepath/httpd-2.4.20.tar.gz -C $httpdcodepath && echo `date "+%Y-%m-%d %H:%M:%S" `' extract httpd success' >> $logname

#compile
#apr
echo `date "+%Y-%m-%d %H:%M:%S" `' start compile apr ' >> $logname
cd $toolscodepath/apr-1.5.2 && ./configure --prefix=$installpath/tools/apr && make && make install
echo `date "+%Y-%m-%d %H:%M:%S" `' compile install apr success' >> $logname
#apr-util
echo `date "+%Y-%m-%d %H:%M:%S" `' start compile apr-util ' >> $logname
cd $toolscodepath/apr-util-1.5.4 && ./configure --prefix=$installpath/tools/apr-util --with-apr=$installpath/tools/apr && make && make install
echo `date "+%Y-%m-%d %H:%M:%S" `'  apr-util success' >> $logname
#pcre
echo `date "+%Y-%m-%d %H:%M:%S" `' start compile pcre' >> $logname
cd $toolscodepath/pcre-8.39 && ./configure --prefix=$installpath/tools/pcre && make && make install
echo `date "+%Y-%m-%d %H:%M:%S" `'  pcre success' >> $logname
#zlib
echo `date "+%Y-%m-%d %H:%M:%S" `' start compile zlib' >> $logname
cd $toolscodepath/zlib-1.2.8 && ./configure --prefix=$installpath/tools/zlib && make && make install
echo `date "+%Y-%m-%d %H:%M:%S" `'  zlib success' >> $logname
#nginx
echo `date "+%Y-%m-%d %H:%M:%S" `' start compile nginx' >> $logname
cd $nginxcodepath/nginx-1.11.1 && ./configure --prefix=$installpath/nginx --with-pcre=$downpath/tools/pcre-8.39 --with-zlib=$downpath/tools/zlib-1.2.8 && make && make install
echo `date "+%Y-%m-%d %H:%M:%S" `'  nginx success' >> $logname
#httpd
echo `date "+%Y-%m-%d %H:%M:%S" `' start compile httpd' >> $logname
cd $httpdcodepath/httpd-2.4.20 && ./configure --prefix=$installpath/httpd24 --with-apr=$installpath/tools/apr --with-apr-util=$installpath/tools/apr-util/ --with-pcre=$installpath/tools/pcre/ && make && make install
echo `date "+%Y-%m-%d %H:%M:%S" `'  httpd success' >> $logname
#mysql
echo `date "+%Y-%m-%d %H:%M:%S" `' start compile mysql' >> $logname
ncuresespath=`find /usr -name libncurses.so`
cd $mysqlcodepath/mysql-5.7.13 && cmake . -DCMAKE_INSTALL_PREFIX=$installpath/mysql57 -DSYSCONFDIR=/etc/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_DATADIR=$installpath/mysql/data -DWITH_BOOST=boost -DCURSES_LIBRARY=$ncuresespath -DCURSES_INCLUDE_PATH=/usr/include && make && make install
echo `date "+%Y-%m-%d %H:%M:%S" `'  mysql success' >> $logname
#$installpath/mysql57/bin/mysqld --initialize --user=$user --basedir=$installpath/mysql --datadir=$installpath/mysql/data
echo `date "+%Y-%m-%d %H:%M:%S" `'  init mysql data success' >> $logname
#php
`sed -i "/PDO_MYSQL configure failed, MySQL 4.1 needed/"d $phpcodepath/php-7.0.8/configure`
echo `date "+%Y-%m-%d %H:%M:%S" `' start compile php' >> $logname
cd $phpcodepath/php-7.0.8 && ./configure --prefix=$installpath/php7 --with-config-file-path=$installpath/php7/conf --with-apxs2=$installpath/httpd24/bin/apxs --with-pdo-mysql=$installpath/mysql57 --with-mysqli --with-zlib-dir=$installpath/tools/zlib && make && make install
mkdir $installpath/php7/conf
cp $phpcodepath/php-7.0.8/php.ini-development $installpath/php7/conf/php.ini
echo `date "+%Y-%m-%d %H:%M:%S" `'  php success' >> $logname
还没写完。。。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值