该脚本基于阿里云服务器安装脚本,并只能运用于centos / aliyun os,该脚本使用时,需要与阿里云安装脚本的install.sh放在同一目录下。有缘人切忌乱用:
#! /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_TCL_URL=http://download.verymall.cn/tcl8.6.1.zip
INSTALL_TCL_PATH=/alidata/lib/tcl DOWNLOAD_REDIS_URL=http://download.verymall.cn/redis-3.0.3.zip
DOWNLOAD_REDIS_SCRIPT_URL=http://download.verymall.cn/redis.script
INSTALL_REDIS_PATH=/alidata/server/redis REDIS_PORT= DOWNLOAD_REDIS_EXT_URL=http://download.verymall.cn/phpredis.zip
PHP_INI_PATH=/alidata/server/php/etc/php.ini function check_curr_path_auth()
{
if [ ! -w "$CURR_PATH" ]
then
echo "no write"
exit
fi
} function check_user_name()
{
if [ "$(whoami)" != "root" ]
then
echo "please run as root"
exit
fi
} function is_curr_path_leagal()
{
if [ "$(ls | grep 'install.sh')" = "" ]
then
echo "please put this script where install.sh locates"
exit
fi
} function get_php_ext_source_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 "could not find php install path"
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_redis_port()
{
if [ -n "$(lsof -i:$REDIS_PORT)" ]
then
echo "PORT $REDIS_PORT is occupied"
exit
fi
} function check_unzip() #not tested yet!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
{
unzip > /dev/null >&
if [ "$?" != "" ]
then
yum install unzip
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_tcl_lib()
{
if [ -n "$(ldconfig -p | grep 'libtcl8.6')" ]
then
return
fi if [ -d $INSTALL_TCL_PATH ]
then
rm -rf $INSTALL_TCL_PATH
fi
mkdir $INSTALL_TCL_PATH
chmod -R $INSTALL_TCL_PATH if [ -d ./tcl8.6.1 ]
then
rm -rf ./tcl8.6.1
fi if [ -a ./tcl8.6.1.zip ] && [ -n "$(md5sum ./tcl8.6.1.zip | grep 'f3d76fa9f96eab32e2f2655dd48a21a8')" ]
then
echo "tcl8.6.1.zip exist"
else
rm -f ./tcl8.6.1.zip
wget $DOWNLOAD_TCL_URL
fi unzip ./tcl8.6.1.zip
chmod -R ./tcl8.6.1
cd ./tcl8.6.1/unix
./configure --prefix=$INSTALL_TCL_PATH --without-tzdata --mandir=/usr/share/man $([ $(uname -m) = x86_64 ] && echo --enable-64bit)
make
sed -e "s@^\(TCL_SRC_DIR='\).*@\1/usr/include'@" -e "/TCL_B/s@='\(-L\)\?.*unix@='\1/usr/lib@" -i tclConfig.sh
make install
make install-private-headers
ln -v -sf tclsh8. /usr/bin/tclsh
ln -s $INSTALL_TCL_PATH/lib/libtcl8..so /usr/lib/libtcl8..so
chmod $INSTALL_TCL_PATH/lib/libtcl8..so
chmod -v /usr/lib/libtcl8..so
ldconfig cd $CURR_PATH
} function install_redis()
{
if [ -d $INSTALL_REDIS_PATH ]
then
rm -rf $INSTALL_REDIS_PATH
fi
mkdir $INSTALL_REDIS_PATH
chmod -R $INSTALL_REDIS_PATH if [ -d ./redis-3.0. ]
then
rm -rf ./redis-3.0.
fi if [ -a ./redis-3.0..zip ] && [ -n "$(md5sum ./redis-3.0.3.zip | grep '05c5e89354bd14f1eb2dfbc88dec24ae')" ]
then
echo "redis-3.0.3.zip exist"
else
rm -f ./redis-3.0..zip
wget $DOWNLOAD_REDIS_URL
fi unzip ./redis-3.0..zip
chmod -R ./redis-3.0.
cd ./redis-3.0.
make
make install sed "s/port 6379/port $REDIS_PORT/g" ./redis.conf > $INSTALL_REDIS_PATH/redis.conf
sed -i "s/daemonize no/daemonize yes/g" $INSTALL_REDIS_PATH/redis.conf > /dev/null >& #start up redis
redis-server $INSTALL_REDIS_PATH/redis.conf cd $CURR_PATH
} function install_dos2unix()
{
which dos2unix > /dev/null >&
if [ "$?" != "" ]
then
yum install dos2unix
fi
} function create_init_script()
{
rm -f /etc/rc.d/init.d/redis
wget $DOWNLOAD_REDIS_SCRIPT_URL -O /etc/rc.d/init.d/redis
chmod /etc/rc.d/init.d/redis
chmod +x /etc/rc.d/init.d/redis
dos2unix /etc/rc.d/init.d/redis chkconfig --add redis
chkconfig --level redis on service redis restart
} function install_php_redis_ext()
{
if [ -d ./phpredis ]
then
rm -rf ./phpredis
fi if [ -d $PHP_EXT_SOURCE_PATH/ext/redis ]
then
rm -rf $PHP_EXT_SOURCE_PATH/ext/redis
fi if [ -a ./phpredis.zip ] && [ -n "$(md5sum ./phpredis.zip | grep '1a6eef0989cab3b34eebc45e3f6d9b71')" ]
then
echo "php redis exist"
else
wget $DOWNLOAD_REDIS_EXT_URL
fi unzip ./phpredis.zip
chmod -R ./phpredis
mv ./phpredis $PHP_EXT_SOURCE_PATH/redis cd $PHP_EXT_SOURCE_PATH/redis
$PHP_BIN_PATH/phpize
./configure --with-php-config=$PHP_BIN_PATH/php-config
make
make install #write php.ini
redis_exist=$(cat $PHP_INI_PATH | grep 'redis.so')
if [ -z "$redis_exist" ]
then
echo "extension=redis.so" >> $PHP_INI_PATH
fi cd $CURR_PATH
} function restart_php_fpm()
{
/etc/init.d/php-fpm restart
} check_curr_path_auth
check_user_name
is_curr_path_leagal
get_php_ext_source_path
check_gcc
check_redis_port
check_unzip
check_alidata_path
install_tcl_lib
install_redis
install_dos2unix
create_init_script
install_php_redis_ext
restart_php_fpm echo "redis install successfully"
exit