• 自动安装Redis服务端与PHP扩展Redis


    该脚本基于阿里云服务器安装脚本,并只能运用于centos / aliyun os,该脚本使用时,需要与阿里云安装脚本的install.sh放在同一目录下。有缘人切忌乱用:

      1 #! /bin/bash
      2 #by dxd in 2015-12
      3 #only suit for centos/aliyun os, and based on aliyun install script
      4 
      5 CURR_PATH=$(pwd);
      6 
      7 PHP_EXT_SOURCE_PATH=""
      8 PHP_BIN_PATH=/alidata/server/php/bin
      9 
     10 DOWNLOAD_TCL_URL=http://download.verymall.cn/tcl8.6.1.zip
     11 INSTALL_TCL_PATH=/alidata/lib/tcl
     12 
     13 DOWNLOAD_REDIS_URL=http://download.verymall.cn/redis-3.0.3.zip
     14 DOWNLOAD_REDIS_SCRIPT_URL=http://download.verymall.cn/redis.script
     15 INSTALL_REDIS_PATH=/alidata/server/redis
     16 
     17 REDIS_PORT=12302
     18 
     19 DOWNLOAD_REDIS_EXT_URL=http://download.verymall.cn/phpredis.zip
     20 PHP_INI_PATH=/alidata/server/php/etc/php.ini
     21 
     22 function check_curr_path_auth()
     23 {
     24     if [ ! -w "$CURR_PATH" ]
     25     then
     26         echo "no write"
     27         exit 1
     28     fi
     29 }
     30 
     31 function check_user_name()
     32 {
     33     if [ "$(whoami)" != "root" ]
     34     then
     35         echo "please run as root"
     36         exit 1
     37     fi
     38 }
     39 
     40 function is_curr_path_leagal()
     41 {
     42     if [ "$(ls | grep 'install.sh')" = "" ]
     43     then
     44         echo "please put this script where install.sh locates"
     45         exit 1
     46     fi
     47 }
     48 
     49 function get_php_ext_source_path()
     50 {
     51     for dir in $(ls)
     52     do
     53         TMP_PATH=$CURR_PATH/$dir/ext
     54         if [ -d $TMP_PATH ]
     55         then
     56             PHP_EXT_SOURCE_PATH=$TMP_PATH
     57             break
     58         fi
     59     done
     60     if [ -z "$PHP_EXT_SOURCE_PATH" ]
     61     then
     62         echo "could not find php install path"
     63         exit 1
     64     fi
     65 
     66     echo -n "php ext source path is $PHP_EXT_SOURCE_PATH , (Y/N): "
     67     read USER_ANSWER
     68     until [ "$USER_ANSWER" = "Y" ] || [ "$USER_ANSWER" = "y" ]
     69     do
     70         if [ "$USER_ANSWER" = "N" ] || [ "$USER_ANSWER" = "n" ]
     71         then
     72             echo "php ext source path is fault, then exit"
     73             exit 1
     74         fi
     75     
     76         echo -n "php ext source path is $PHP_EXT_SOURCE_PATH , (Y/N): "
     77         read USER_ANSWER
     78     done
     79 }
     80 
     81 function check_gcc()
     82 {
     83     which gcc > /dev/null 2>&1
     84     if [ "$?" != "0" ]
     85     then
     86         echo "please install gcc first"
     87         exit 1
     88     fi
     89 }
     90 
     91 function check_redis_port()
     92 {
     93     if [ -n "$(lsof -i:$REDIS_PORT)" ]
     94     then
     95         echo "PORT $REDIS_PORT is occupied"
     96         exit 1
     97     fi
     98 }
     99 
    100 function check_unzip()    #not tested yet!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    101 {
    102     unzip > /dev/null 2>&1
    103     if [ "$?" != "0" ]
    104     then
    105         yum install unzip
    106     fi
    107 }
    108 
    109 function check_alidata_path()
    110 {
    111     if [ ! -d /alidata ]
    112     then
    113         mkdir /alidata
    114     fi
    115 
    116     if [ ! -d /alidata/lib ]
    117     then
    118         mkdir /alidata/lib
    119     fi
    120 
    121     if [ ! -d /alidata/server ]
    122     then
    123         echo "alidata server has not been installed"
    124         exit 1
    125     fi
    126 }
    127 
    128 function install_tcl_lib()
    129 {
    130     if [ -n "$(ldconfig -p | grep 'libtcl8.6')" ]
    131     then
    132         return 0
    133     fi
    134 
    135     if [ -d $INSTALL_TCL_PATH ]
    136     then
    137         rm -rf $INSTALL_TCL_PATH
    138     fi
    139     mkdir $INSTALL_TCL_PATH
    140     chmod -R 0777 $INSTALL_TCL_PATH
    141 
    142     if [ -d ./tcl8.6.1 ]
    143     then
    144         rm -rf ./tcl8.6.1
    145     fi
    146 
    147     if [ -a ./tcl8.6.1.zip ] && [ -n "$(md5sum ./tcl8.6.1.zip | grep 'f3d76fa9f96eab32e2f2655dd48a21a8')" ]
    148     then
    149         echo "tcl8.6.1.zip exist"
    150     else
    151         rm -f ./tcl8.6.1.zip
    152         wget $DOWNLOAD_TCL_URL    
    153     fi
    154 
    155     unzip ./tcl8.6.1.zip
    156     chmod -R 0777 ./tcl8.6.1
    157     cd ./tcl8.6.1/unix
    158     ./configure --prefix=$INSTALL_TCL_PATH --without-tzdata --mandir=/usr/share/man $([ $(uname -m) = x86_64 ] && echo --enable-64bit)
    159     make
    160     sed -e "s@^(TCL_SRC_DIR=').*@1/usr/include'@" -e "/TCL_B/s@='(-L)?.*unix@='1/usr/lib@" -i tclConfig.sh
    161     make install
    162     make install-private-headers
    163     ln -v -sf tclsh8.6 /usr/bin/tclsh
    164     ln -s $INSTALL_TCL_PATH/lib/libtcl8.6.so /usr/lib/libtcl8.6.so
    165     chmod 0755 $INSTALL_TCL_PATH/lib/libtcl8.6.so
    166     chmod -v 755 /usr/lib/libtcl8.6.so
    167     ldconfig
    168 
    169     cd $CURR_PATH
    170 }
    171 
    172 function install_redis()
    173 {
    174     if [ -d $INSTALL_REDIS_PATH ]
    175     then
    176         rm -rf $INSTALL_REDIS_PATH
    177     fi
    178     mkdir $INSTALL_REDIS_PATH
    179     chmod -R 0777 $INSTALL_REDIS_PATH
    180 
    181     if [ -d ./redis-3.0.3 ]
    182     then
    183         rm -rf ./redis-3.0.3
    184     fi
    185 
    186     if [ -a ./redis-3.0.3.zip ] && [ -n "$(md5sum ./redis-3.0.3.zip | grep '05c5e89354bd14f1eb2dfbc88dec24ae')" ]
    187     then
    188         echo "redis-3.0.3.zip exist"
    189     else
    190         rm -f ./redis-3.0.3.zip
    191         wget $DOWNLOAD_REDIS_URL    
    192     fi
    193 
    194     unzip ./redis-3.0.3.zip
    195     chmod -R 0777 ./redis-3.0.3
    196     cd ./redis-3.0.3
    197     make
    198     make install
    199     
    200     
    201     sed "s/port 6379/port $REDIS_PORT/g" ./redis.conf >  $INSTALL_REDIS_PATH/redis.conf
    202     sed -i "s/daemonize no/daemonize yes/g" $INSTALL_REDIS_PATH/redis.conf > /dev/null 2>&1
    203     
    204     #start up redis
    205     redis-server $INSTALL_REDIS_PATH/redis.conf
    206 
    207     cd $CURR_PATH
    208 }
    209 
    210 function install_dos2unix()
    211 {
    212     which dos2unix > /dev/null 2>&1
    213     if [ "$?" != "0" ]
    214     then
    215         yum install dos2unix
    216     fi
    217 }
    218 
    219 function create_init_script()
    220 {
    221     rm -f /etc/rc.d/init.d/redis
    222     wget $DOWNLOAD_REDIS_SCRIPT_URL -O /etc/rc.d/init.d/redis
    223     chmod 0777 /etc/rc.d/init.d/redis
    224     chmod +x /etc/rc.d/init.d/redis
    225     dos2unix /etc/rc.d/init.d/redis
    226 
    227     chkconfig --add redis
    228     chkconfig --level 2345 redis on
    229 
    230     service redis restart
    231 }
    232 
    233 function install_php_redis_ext()
    234 {
    235     if [ -d ./phpredis ]
    236     then
    237         rm -rf ./phpredis
    238     fi
    239 
    240     if [ -d $PHP_EXT_SOURCE_PATH/ext/redis ]
    241     then
    242         rm -rf $PHP_EXT_SOURCE_PATH/ext/redis
    243     fi
    244 
    245     if [ -a ./phpredis.zip ] && [ -n "$(md5sum ./phpredis.zip | grep '1a6eef0989cab3b34eebc45e3f6d9b71')" ]
    246     then
    247         echo "php redis exist"
    248     else
    249         wget $DOWNLOAD_REDIS_EXT_URL
    250     fi
    251 
    252     unzip ./phpredis.zip
    253     chmod -R 0777 ./phpredis
    254     mv ./phpredis $PHP_EXT_SOURCE_PATH/redis
    255 
    256     cd $PHP_EXT_SOURCE_PATH/redis
    257     $PHP_BIN_PATH/phpize
    258     ./configure --with-php-config=$PHP_BIN_PATH/php-config 
    259     make 
    260     make install 
    261 
    262     #write php.ini
    263     redis_exist=$(cat $PHP_INI_PATH | grep 'redis.so')
    264     if [ -z "$redis_exist" ]
    265     then
    266         echo "extension=redis.so" >> $PHP_INI_PATH
    267     fi
    268 
    269     cd $CURR_PATH
    270 }
    271 
    272 function restart_php_fpm()
    273 {
    274     /etc/init.d/php-fpm restart
    275 }
    276 
    277 check_curr_path_auth
    278 check_user_name
    279 is_curr_path_leagal
    280 get_php_ext_source_path
    281 check_gcc
    282 check_redis_port
    283 check_unzip
    284 check_alidata_path
    285 install_tcl_lib
    286 install_redis
    287 install_dos2unix
    288 create_init_script
    289 install_php_redis_ext
    290 restart_php_fpm
    291 
    292 echo "redis install successfully"
    293 exit 0
  • 相关阅读:
    GB2312 字符集
    Excel导入
    Excel导出
    解决文件下载在火狐浏览器出现中文文件名乱码的方法
    Struts2将图片输出到页面
    jsp页面中日期的格式化
    java正则表达式笔记
    利用git将项目上传到github
    Java中枚举的写法和用法
    自定义JQuery插件
  • 原文地址:https://www.cnblogs.com/ddcoder/p/5050416.html
Copyright © 2020-2023  润新知