基于阿里云安装脚本扩展 之 自动安装mongodb及php扩展

好久没有发布文章了,有点跟不上当初这个博客的初衷。为了使自己的博客更新不半途而废,今天特意再写了一个自动安装脚本,一样是基于阿里云的服务端安装脚本进行的扩展。闲话不说,直接放代码:

 #!/bin/bash
#by dxd in -
#only suit for centos/aliyun os, and based on aliyun install script CURR_PATH=$(pwd) PHP_EXT_SOURCE_PATH=""
PHP_BIN_PATH=/alidata/server/php/bin DOWNLOAD_MONGODB_URL_X64=http://download.verymall.cn/mongodb-2.7.0.tgz
DOWNLOAD_MONGODB_URL_X86=http://download.verymall.cn/mongodb-linux-2.6.7-x86.tgz
DOWNLOAD_MONGODB_CONF_URL=http://download.verymall.cn/mongodb.conf
INSTALL_MONGODB_PATH=/alidata/server/mongodb
MONGODB_PORT= DOWNLOAD_MONGODB_EXT_URL=http://download.verymall.cn/php-mongo-1.6.14.tgz
PHP_INI_PATH=/alidata/server/php/etc/php.ini function check_user()
{
if [ "$(whoami)" != "root" ]
then
echo "please run as root"
exit
fi
} function check_os()
{
which yum > /dev/null >&
if [ "$?" != "" ]
then
echo "linux is not based on centos"
exit
fi #if [ "$(getconf LONG_BIT)" != "64" ]
#then
# echo "linux is not x64"
# exit
#fi
} function check_curr_path_auth()
{
if [ ! -w $CURR_PATH ]
then
echo "current path has no write auth"
exit
fi
} function is_curr_path_legal()
{
if [ "$(ls | grep install.sh)" == "" ]
then
echo "path is illegal"
exit
fi
} function get_php_ext_path()
{
for dir in $(ls)
do
TMP_PATH=$CURR_PATH/$dir/ext
if [ -d $TMP_PATH ]
then
PHP_EXT_SOURCE_PATH=$TMP_PATH
break
fi
done if [ -z "$PHP_EXT_SOURCE_PATH" ]
then
echo "php source path not found"
exit
fi echo -n "php ext source path is $PHP_EXT_SOURCE_PATH , (Y/N): "
read USER_ANSWER
until [ "$USER_ANSWER" = "Y" ] || [ "$USER_ANSWER" = "y" ]
do
if [ "$USER_ANSWER" = "N" ] || [ "$USER_ANSWER" = "n" ]
then
echo "php ext source path is fault, then exit"
exit
fi echo -n "php ext source path is $PHP_EXT_SOURCE_PATH , (Y/N): "
read USER_ANSWER
done
} function check_gcc()
{
which gcc > /dev/null >&
if [ "$?" != "" ]
then
echo "please install gcc first"
exit
fi
} function check_mongodb_port()
{
if [ -n "$(lsof -i:$MONGODB_PORT)" ]
then
echo "PORT $MONGODB_PORT is occupied"
exit
fi
} function check_alidata_path()
{
if [ ! -d /alidata ]
then
mkdir /alidata
fi if [ ! -d /alidata/lib ]
then
mkdir /alidata/lib
fi if [ ! -d /alidata/server ]
then
echo "alidata server has not been installed"
exit
fi
} function install_dos2unix()
{
which dos2unix > /dev/null >&
if [ "$?" != "" ]
then
yum install dos2unix
fi
} function install_mongodb_x64()
{
if [ -d $INSTALL_MONGODB_PATH ]
then
rm -rf $INSTALL_MONGODB_PATH
fi if [ -a ./mongodb-2.7..tgz ] && [ -n "$(md5sum ./mongodb-2.7.0.tgz | grep 66acfaacb40be88db07065163cc15857)" ]
then
echo "./mongodb-2.7.0.tgz exist"
else
rm -f ./mongodb-2.7..tgz
wget $DOWNLOAD_MONGODB_URL_X64
fi rm -rf ./mongodb-linux-x86_64-2.7.
tar -zxvf ./mongodb-2.7..tgz > /dev/null
if [ ! -d ./mongodb-linux-x86_64-2.7. ]
then
echo "tar fail"
exit
fi mv ./mongodb-linux-x86_64-2.7. $INSTALL_MONGODB_PATH
mkdir $INSTALL_MONGODB_PATH/data
mkdir $INSTALL_MONGODB_PATH/log
mkdir $INSTALL_MONGODB_PATH/pid
mkdir $INSTALL_MONGODB_PATH/conf wget -O $INSTALL_MONGODB_PATH/conf/mongodb.conf $DOWNLOAD_MONGODB_CONF_URL #run mongodb
echo "it will takes a few minutes to fork children process in the first, please be patient!"
$INSTALL_MONGODB_PATH/bin/mongod -f $INSTALL_MONGODB_PATH/conf/mongodb.conf
} function install_mongodb_x86()
{
if [ -d $INSTALL_MONGODB_PATH ]
then
rm -rf $INSTALL_MONGODB_PATH
fi if [ -a ./mongodb-linux-2.6.-x86.tgz ] && [ -n "$(md5sum ./mongodb-linux-2.6.7-x86.tgz | grep 87a57c05e428fe1ced619e63107140ff)" ]
then
echo "./mongodb-linux-2.6.7-x86.tgz exist"
else
rm -f ./mongodb-linux-2.6.-x86.tgz
wget $DOWNLOAD_MONGODB_URL_X86
fi rm -rf ./mongodb-linux-i686-2.6.
tar -zxvf ./mongodb-linux-2.6.-x86.tgz > /dev/null
if [ ! -d ./mongodb-linux-i686-2.6. ]
then
echo "tar fail"
exit
fi mv ./mongodb-linux-i686-2.6. $INSTALL_MONGODB_PATH
mkdir $INSTALL_MONGODB_PATH/data
mkdir $INSTALL_MONGODB_PATH/log
mkdir $INSTALL_MONGODB_PATH/pid
mkdir $INSTALL_MONGODB_PATH/conf wget -O $INSTALL_MONGODB_PATH/conf/mongodb.conf $DOWNLOAD_MONGODB_CONF_URL #run mongodb
echo "it will takes a few minutes to fork children process in the first, please be patient!"
$INSTALL_MONGODB_PATH/bin/mongod -f $INSTALL_MONGODB_PATH/conf/mongodb.conf
} function install_mongodb()
{
if [ "$(getconf LONG_BIT)" == "" ]
then
install_mongodb_x64
elif [ "$(getconf LONG_BIT)" == "" ]
then
install_mongodb_x86
else
echo "linux bit error"
exit
fi
} function install_mongodb_php_ext()
{
if [ -d ./mongo-1.6. ]
then
rm -rf ./mongo-1.6.
fi if [ -d $PHP_EXT_SOURCE_PATH/mongo ]
then
rm -rf $PHP_EXT_SOURCE_PATH/mongo
fi if [ -a ./php-mongo-1.6..tgz ] && [ -n "$(md5sum ./php-mongo-1.6.14.tgz | grep '19cd8bd94494f924ce8314f304fd83b6')" ]
then
echo "php mongo exist"
else
wget $DOWNLOAD_MONGODB_EXT_URL
fi tar -zxvf ./php-mongo-1.6..tgz
chmod -R ./mongo-1.6.
mv ./mongo-1.6. $PHP_EXT_SOURCE_PATH/mongo cd $PHP_EXT_SOURCE_PATH/mongo
$PHP_BIN_PATH/phpize
./configure --with-php-config=$PHP_BIN_PATH/php-config
make
make install write php.ini
mongo_exist=$(cat $PHP_INI_PATH | grep 'mongo.so')
if [ -z "$mongo_exist" ]
then
echo "extension=mongo.so" >> $PHP_INI_PATH
fi cd $CURR_PATH
} function restart_php_fpm()
{
/etc/init.d/php-fpm restart
} check_user
check_os
check_curr_path_auth
is_curr_path_legal
get_php_ext_path
check_gcc
check_mongodb_port
check_alidata_path
install_dos2unix
install_mongodb
install_mongodb_php_ext
restart_php_fpm echo "mongodb install successfully"
exit
上一篇:阿里云Linux CentOS 7 Docker部署使用gogs搭建自己的git服务器


下一篇:用conda创建python虚拟环境