shell 安装软件脚本 – 改进版

2019年12月17日12:23:39 1
前言

工作中经常会安装基础运行软件 在此写了一个简版的shell,还有各种不足 日后慢慢补充

2020-1-7号 更新内容展开

1.安装时 不在输出编译内容 输出安装步骤 提供信息提示
2.安装有错误是 立即终止
3.安装完成后 打印以上执行成功的信息展示

#!/bin/bash

installlog=/opt/auto-install/install.log

#软件版本
nginx_version="nginx-1.14.0"
p54_version="php-5.4.45"
p56_version="php-5.6.31"
p71_version="php-7.1.18"
mysql5_6_31_version="mysql-5.6.13-linux-glibc2.5-x86_64"
mysql5_7_24_version="mysql-5.7.24-linux-glibc2.12-x86_64"
mongodb_3_0_6_version="mongodb-linux-x86_64-3.0.6"
redis5_0_2_version="redis-5.0.2"

#配置文件
conf_dir=/opt/auto-install/conf

#源码包文件
src_dir=/opt/auto-install/src

#日志问个目录
log_cut=/opt/auto-install/logrotate.d

#解压后的路径
tar_source=/opt/auto-install/tarsoft

function main() {
    echo -e "\033[36m 1.更换云源 初始化系统工具 \033[0m"
    echo -e "\033[36m 2.初始化数据盘 关闭selinux 安装ucloud-uma监控插件 \033[0m"
    echo -e "\033[36m 3.安装LNMP及其他组件 \033[0m"
    echo -e "\033[36m 4.退出 \033[0m"
    option=("1" "2" "3" "4")
    select no in "${option[@]}"
    do
        case $no in
            "1")
                Install_tools
                main
                ;;
            "2")
                CreateDirctory
                main
                ;;
            "3")
                Install_software
                main
                ;;
            "4")
                exit
                ;;
        esac
    done
}

function Install_tools() {
    echo "安装curl vim* tree sysstat net-tools psmisc工具........"
    yum -y install curl vim* tree sysstat net-tools psmisc  wget >> /dev/null
    echo "更换系统的云源地址为阿里云........"
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo >> /dev/null
    wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo >> /dev/null
    yum clean all && yum makecache >> /dev/null
    yum -y install nfs-utils >> /dev/null
    systemctl enable rpcbind.service
    systemctl start rpcbind.service
     if [ $? != 0 ]; then
        echo "NFS安装失败........" >> $installlog
    fi
    echo "拷贝RSA秘钥到主机 通过SSH登录........"
    if [ ! -d /root/.ssh ]; then
        mkdir -p /root/.ssh && touch /root/.ssh/authorized_keys
        cat >> /root/.ssh/authorized_keys << EOF
#controller rsa
ssh-rsa AAAAB3NzaC1yc2EABjRHlSpzo/SNFbWeg84Kvm+CLH45FaASLN root@eed5e4

#add guorui rsa
ssh-rsa AAAAB3NzaE6BVt2k+yzPE8DxXVz guorui@guoruideMacBook-Pro.local
EOF
    else
        if [ ! -f /root/.ssh/authorized_keys ]; then
            {
                touch /root/.ssh/authorized_keys
            }
        fi
        cat >> /root/.ssh/authorized_keys << EOF
#controller rsa
ssh-rsa AAAASNFbWeg84Kvm+CLH45FaASLN root@eed5e4

#add guorui rsa
ssh-rsa AAAAVt2k+yzPE8DxXVz guorui@guoruideMacBook-Pro.local
EOF
    fi
}

#创建目录方法
function CreateDirctory()
{
    echo "创建数据盘的MM目录........"
    mkdir -p /data/MM && ln -s /data/MM /MM
    echo "创建数据盘HTML LOG shell 目录........"
    mkdir -p /MM/{HTML/{git,Source},LOG/{nginx-sys/days,php-sys/days,phplogs/yaf},shell}
    chmod -R 777 /MM/LOG/phplogs/yaf
    echo "拷贝Nginx PHP 日志分割配置文件........"
    cp -r $log_cut/nginx /etc/logrotate.d/
    cp -r $log_cut/nginx /etc/logrotate.d/
    echo "关闭Linux权限设定........"
    sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
    echo "安装云主机监控插件 并启动........"
    wget http://umon.api.service.ucloud.cn/static/umatest/uma-1.1.5-1.x86_64.rpm >> /dev/null
    rpm -ivh uma-1.1.5-1.x86_64.rpm
    service uma start
}

#判断用户是否存在
function isnotexists() {
    web_name=`grep '^www:' /etc/passwd|awk -F : '{print $3}'`
    db_name=`grep '^mysql:' /etc/passwd|awk -F : '{print $3}'`
    if [ -z $web_name ]; then
        echo "www 用户不存在 创建www用户和组........"
        groupadd www -g 1001 && useradd -g www www
        ExecisSuccess
        echo "安装PHP 需要的系统依赖........"
        yum -y install libxml2 libxml2-devel bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel freetype gmp gmp-devel icu libicu libicu-devel libmcrypt unixODBC  unixODBC-devel gettext  pcre libpng libpng-devel freetype-devel libmcrypt-devel libxslt-devel m4 autoconf readline-devel >> /dev/null
        ExecisSuccess
    else
        echo "www 用户存在 跳过创建用户 安装需要的依赖组件........"
        yum -y install libxml2 libxml2-devel bzip2 bzip2-devel curl curl-devel libjpeg libjpeg-devel freetype gmp gmp-devel icu libicu libicu-devel libmcrypt unixODBC  unixODBC-devel gettext  pcre libpng libpng-devel freetype-devel libmcrypt-devel libxslt-devel m4 autoconf readline-devel >> /dev/null
    fi

    if [ -z $db_name ]; then
        echo "mysql 用户不存在 创建mysql用户和组........"
        groupadd mysql  && useradd -g mysql mysql
        ExecisSuccess
    fi
}

#显示安装后的信息
function ViewInfo() {
    cat /root/.ssh/authorized_keys >> $installlog
    tree -L 3 /MM >> $installlog
    cat /etc/selinux/config >> $installlog
    cat /etc/rc.local >> $installlog
    ps -ef | grep nginx >> $installlog
    ps -ef | grep php-fpm >> $installlog
    ps -ef | grep mysql >> $installlog
    ps -ef | grep mongo >> $installlog
    ps -ef | grep redis >> $installlog
    ps -ef | grep ffmpeg >> $installlog
}

#判断程序执行的结果是否为0 
function ExecisSuccess(){
    if [ $? -eq 0 ]; then
        echo "执行成功........继续向下执行........"
    else
        echo "执行失败........终止........"
        exit
    fi
}

#安装基础软件 选择序号统一安装
function Install_software() {
    clear
    while true
    do
    echo -e "\n\n \\033[36m =====请选择需要安装的组件=====\033[0m"
    #echo -e "\n"
    echo -e "\033[36m 1) Nginx-1.14.0 \033[0m" 
    echo -e "\033[36m 2) PHP-5.4.45 \033[0m" 
    echo -e "\033[36m 3) PHP-5.6.31 \033[0m" 
    echo -e "\033[36m 4) PHP-7.1.18 \033[0m" 
    echo -e "\033[36m 5) MySQL-5.6.13 \033[0m" 
    echo -e "\033[36m 6) MySQL-5.7.25 \033[0m" 
    echo -e "\033[36m 7) Redis-5.0.2\033[0m" 
    echo -e "\033[36m 8) MongoDB-3.0.6 \033[0m" 
    echo -e "\033[36m 9) FFMpeg-4.0.5 \033[0m" 
    echo -e "\033[36m 0)返回 \033[0m" 
    echo -e "\n"
    echo "请选择需要安装软件的序号,多选以逗号分隔:"
    read choice    #将屏幕输出的内容保存到choice变量里面

#一个case语句
    case $choice in
        0) break;;
    esac
    V_INPUT=`echo $choice|sed 's/,/\n/g'`   #|管道是将前面命令的输出作为后面命令的输入。sed 语句将逗号变成换行符,变成了多行文件。
    for i in $V_INPUT                #for循环读取该文件
    do
        if [ $i -eq 1 ]; then
            isnotexists
            echo "正在安装 Nginx-1.14.0......"
            Install_Nginx
            echo "Nginx-1.14.0 安装完成......"
        fi
        if [ $i -eq 2 ]; then
            isnotexists
            echo "正在安装 PHP-5.4.45......"
            Install_php5_4_45
            echo "PHP-5.4.45 安装完成......"
        fi
        if [ $i -eq 3 ]; then
            isnotexists
            echo "正在安装 PHP-5.6.31......"
            Install_php5_6_31
            echo "PHP-5.6.31 安装完成......"
        fi
        if [ $i -eq 4 ]; then
            isnotexists
            echo "正在安装 PHP-7.1.18......"
            Install_php7_1_18
            echo "PHP-7.1.18 安装完成....."
        fi
        if [ $i -eq 5 ]; then
            isnotexists
            echo "正在安装 MySQL-5.6.13......"
            Install_Mysql_5_6_13
            echo "MySQL-5.6.13 安装完成....."
        fi
        if [ $i -eq 6 ]; then
            isnotexists
            echo "正在安装 MySQL-5.7.24......"
            Install_Mysql_5_7_24
            echo "MySQL-5.7.24 安装完成....."
        fi
        if [ $i -eq 7 ]; then
            isnotexists
            echo "正在安装 Redis..."
            Install_Redis_5_0_2
            echo "Redis 安装完成......"
        fi
        if [ $i -eq 8 ]; then
            isnotexists
            echo "正在安装 MongoDB......"
            Install_Mongodb_3_0_6 
            echo "MongoDB 安装完成......"
        fi
        if [ $i -eq 9 ]; then
            isnotexists
            echo "正在安装 FFMpeg-4.0.5......"
            Install_FFMpeg-4_0_5
            echo "FFMpeg-4.0.5 安装完成......"
        fi
        sleep 5

        if [ $? -eq 0 ]; then
            echo "安装${var1}成功"| tee a install.log
        else
            echo"安装${var1}失败"| tee a install.log
        fi
    done
done
}

#安装Nginx-1.14.0版本
function Install_Nginx() {
    yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre pcre-devel unzip gd-devel GeoIP GeoIP-devel GeoIP-data >> /dev/null
    unzip $src_dir/nginx-http-concat-master.zip -d $tar_source >> /dev/null
    tar -zxvf $src_dir/$nginx_version.tar.gz -C $tar_source >> /dev/null && cd $tar_source/$nginx_version 
    ./configure --prefix=/usr/local/$nginx_version --with-poll_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-stream --with-mail --with-mail_ssl_module  --with-stream_ssl_module --add-module=$tar_source/nginx-http-concat-master >> /dev/null
    make install >> /dev/null
    echo "创建Nginx软链........"
    ln -s /usr/local/$nginx_version /usr/local/nginx
    echo "备份Nginx总配置文件"
    mv /usr/local/$nginx_version/conf/nginx.conf /usr/local/nginx/conf/nginx.conf_bak
    echo "拷贝Nginx配置文件........"
    cp -r $conf_dir/nginx.conf /usr/local/$nginx_version/conf/
    echo "创建Nginx SSL vhost 目录........"
    mkdir -p /usr/local/nginx/conf/{ssl,vhost}
    cp $conf_dir/localhost.conf /usr/local/$nginx_version/conf/vhost/
    rm -rf /usr/local/nginx/logs
    echo "创建Nginx软链的日志文件目录........"
    ln -s /MM/LOG/nginx-sys /usr/local/nginx/logs
    echo "写入Nginx到开机启动........"
    echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local
    echo "Nginx启动成功........"
    /usr/local/nginx/sbin/nginx 
}

function Install_php5_4_45() {
    yum install -y epel-release >> /dev/null
    yum install -y libmcrypt-devel >> /dev/null
    tar -zxvf $src_dir/$p54_version.tar.gz -C $tar_source >> /dev/null && cd $tar_source/$p54_version 
    ./configure \
    --prefix=/usr/local/$p54_version --with-config-file-path=/usr/local/$p54_version/etc \
    --with-gettext --with-gmp  --with-mysql  --with-openssl  --with-pdo-mysql  --with-mysqli  --with-bz2  --with-curl  --with-mcrypt  --with-mhash  --with-freetype-dir \
    --with-unixODBC=/usr/ --with-pdo-odbc=unixODBC,/usr/  --with-libxml-dir --with-zlib --with-pcre-dir --with-gd --with-jpeg-dir --with-png-dir --with-xmlrpc \
    --with-libxml-dir  --with-xsl  --enable-soap  --enable-sysvmsg --enable-wddx  --enable-zip --enable-exif --enable-intl \
    --enable-bcmath --enable-calendar --enable-mbstring --enable-shmop --enable-fpm --with-fpm-user=www  --with-fpm-group=www  --enable-sockets >> /dev/null && make install >> /dev/null
    echo "拷贝配置文件"
    cp -r $tar_source/$p54_version/php.ini-production /usr/local/$p54_version/etc/php.ini
    cp -r /usr/local/$p54_version/etc/php-fpm.conf.default /usr/local/$p54_version/etc/php-fpm.conf
    cp $tar_source/$p54_version/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    chmod +x /etc/init.d/php-fpm
    ln -s /usr/local/$p54_version /usr/local/php
    ln -s /MM/LOG/php-sys /usr/local/php/logs
    InstallExtension
    /etc/init.d/php-fpm start
}


function Install_php5_6_31() {
    tar -zxvf $src_dir/$p56_version.tar.gz -C $tar_source && >> /dev/null cd $tar_source/$p56_version 
    ./configure --prefix=/usr/local/$p56_version --with-config-file-path=/usr/local/$p56_version/etc \
    --enable-inline-optimization --disable-debug --disable-rpath  --enable-shared --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline >> /dev/null && make install >> /dev/null
    echo "拷贝配置文件"
    cp $tar_source/$p56_version/php.ini-production /usr/local/$p56_version/etc/php.ini
    cp -r /usr/local/$p56_version/etc/php-fpm.conf.default /usr/local/$p56_version/etc/php-fpm.conf
    cp $tar_source/$p56_version/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    chmod +x /etc/init.d/php-fpm
    ln -s /usr/local/$p56_version /usr/local/php
    ln -s /MM/LOG/php-sys /usr/local/php/logs
    InstallExtension
    /etc/init.d/php-fpm start
}

function Install_php7_1_18() {
    tar -zxvf $src_dir/$p71_version.tar.gz -C $tar_source >> /dev/null && cd $tar_source/$p71_version
    ./configure  --prefix=/usr/local/$p71_version --with-config-file-path=/usr/local/$p71_version/etc \
     --enable-fpm \
     --with-fpm-user=www  \
     --with-fpm-group=www  \
     --with-libxml-dir  \
     --with-xmlrpc  \
     --with-openssl \
     --with-mcrypt  \
     --with-mhash  \
     --with-pcre-regex \
     --with-sqlite3 --with-zlib --enable-bcmath \
     --with-iconv --with-bz2 --enable-calendar --with-curl \
     --with-cdb --enable-dom --enable-exif --enable-fileinfo \
     --enable-filter --with-pcre-dir --enable-ftp   --with-gd \
     --with-openssl-dir --with-jpeg-dir --with-png-dir \
     --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf \
     --enable-gd-jis-conv   --with-gettext   --with-gmp   --with-mhash  \
     --enable-json   --enable-mbstring   --enable-mbregex \
     --enable-mbregex-backtrack --with-libmbfl --with-onig \
     --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
     --with-zlib-dir --with-pdo-sqlite --with-readline \
     --enable-session --enable-shmop --enable-simplexml \
     --enable-sockets --enable-sysvmsg --enable-sysvsem \
     --enable-sysvshm   --enable-wddx   --with-libxml-dir \
     --with-xsl   --enable-zip   --enable-mysqlnd-compression-support \
     --with-pear   --enable-opcache >> /dev/null && make install >> /dev/null
    echo "拷贝配置文件........"
    cp $tar_source/$p71_version/php.ini-production /usr/local/$p71_version/etc/php.ini
    cp -r /usr/local/$p71_version/etc/php-fpm.conf.default /usr/local/$p71_version/etc/php-fpm.conf
    cp -r /usr/local/$p71_version/etc/php-fpm.d/www.conf.default /usr/local/$p71_version/etc/php-fpm.d/www.conf
    cp $tar_source/$p71_version/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
    chmod +x /etc/init.d/php-fpm
    ln -s /usr/local/$p71_version /usr/local/php7
    ln -s /MM/LOG/php-sys /usr/local/php7/logs
    /etc/init.d/php-fpm start
    echo "php-7.1.18 安装完成并已启动........" >> $installlog
    sleep 5
    echo "php 安装 amqp imagick mongo yaf memcached 扩展........"
    sleep 5
    tar -zxvf $src_dir/rabbitmq-c-0.8.0.tar.gz -C $tar_source >> /dev/null && cd  $tar_source/rabbitmq-c-0.8.0 
    ./configure --prefix=/usr/local/rabbitmq-0.8.0  >> /dev/null && make install >> /dev/null && cd ..
    tar -zxvf $src_dir/amqp-1.9.3.tgz -C $tar_source >> /dev/null && cd $tar_source/amqp-1.9.3
    /usr/local/php7/bin/phpize
    ./configure --with-php-config=/usr/local/php7/bin/php-config  --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-0.8.0 >> /dev/null && make install >> /dev/null && cd ..
    echo "amqp扩展安装完成......"
    sleep 5
    tar -zxvf $src_dir/mongodb-1.5.3.tgz -C $tar_source >> /dev/null && cd $tar_source/mongodb-1.5.3 
    /usr/local/php7/bin/phpize
    ./configure --with-php-config=/usr/local/php7/bin/php-config >> /dev/null && make install >> /dev/null && cd ..
    echo "mongodb扩展安装完成......"
    sleep 5
    tar -zxvf $src_dir/yaf-3.0.7.tgz -C $tar_source >> /dev/null && cd $tar_source/yaf-3.0.7
    /usr/local/php7/bin/phpize
    ./configure --with-php-config=/usr/local/php7/bin/php-config >> /dev/null && make install >> /dev/null && cd .. 
    echo "yaf扩展安装完成......"
    sleep 5
    tar -zxvf $src_dir/libmemcached-1.0.18.tar.gz -C $tar_source >> /dev/null && cd $tar_source/libmemcached-1.0.18 
    ./configure --prefix=/usr/local/libmemcached-1.0.18 --with-memcached >> /dev/null && make install >> /dev/null && cd .. 
    tar -zxvf $src_dir/memcached-3.1.3.tgz -C $tar_source >> /dev/null && cd $tar_source/memcached-3.1.3 
    /usr/local/php7/bin/phpize
    ./configure  --with-php-config=/usr/local/php7/bin/php-config  --enable-memcached --with-libmemcached-dir=/usr/local/libmemcached-1.0.18 --disable-memcached-sasl >> /dev/null && make install >> /dev/null && cd .. 
    echo "memcached扩展安装完成......"
    sleep 5
    tar -zxvf $src_dir/ImageMagick-7.0.8-40.tar.gz -C $tar_source >> /dev/null && cd $tar_source/ImageMagick-7.0.8-40 
    ./configure -prefix=/usr/local/imagemagick >> /dev/null && make install >> /dev/null && cd .. 
    tar -zxvf $src_dir/imagick-3.4.3.tgz -C $tar_source >> /dev/null && cd $tar_source/imagick-3.4.3 
    /usr/local/php7/bin/phpize
    ./configure  --with-php-config=/usr/local/php7/bin/php-config --with-imagick=/usr/local/imagemagick >> /dev/null && make install  >> /dev/null && cd ..
    echo "imagick扩展安装完成......"
    sleep 5
    echo -e "\033[36m 配置 " $p71_version " php.ini 文件......\033[0m"
    echo "extension=amqp.so" >> /usr/local/php7/etc/php.ini
    echo "extension=mongodb.so" >> /usr/local/php7/etc/php.ini
    echo "extension=imagick.so" >> /usr/local/php7/etc/php.ini
    echo "extension=memcached.so" >> /usr/local/php7/etc/php.ini
    echo "extension=yaf.so" >> /usr/local/php7/etc/php.ini
    echo "/etc/init.d/php-fpm start" >> /etc/rc.local
    /etc/init.d/php-fpm start
}

function InitializationDB() {
    if [ ! -d /MM/DB/server0 ]; then
        mkdir -p /MM/DB/server0/var
    fi
}

function Install_Mysql_5_6_13() {
    tar -zxvf $src_dir/$mysql_5_6_13_version.tar.gz -C /usr/local/ >> /dev/null
    mv /usr/local/$mysql_5_6_13_version /usr/local/mysql-5.6.13
    InitializationDB
    chown -R mysql:mysql /usr/local/mysql-5.6.13
    chown -R mysql:mysql /MM/DB
    ln -s /usr/local/mysql-5.6.13 /usr/local/mysql
    /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/MM/DB/server0/var
    cp -r $conf_dir/my.cnf /MM/DB/server0/
    cp -r $conf_dir/db_start.sh /usr/local/sbin/
    /usr/local/sbin/db_start.sh server0                                                                                                                        ith-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-0.8.0
}

function Install_Mysql_5_7_24() {
    tar -zxvf $src_dir/$mysql5_7_24_version.tar.gz -C /usr/local/ >> /dev/null
    mv /usr/local/$mysql5_7_24_version /usr/local/mysql-5.7.24
    InitializationDB
    touch /MM/DB/server0/err.log
    chown -R mysql:mysql /usr/local/mysql-5.7.24
    chown -R mysql:mysql /MM/DB
    ln -s /usr/local/mysql-5.7.24 /usr/local/mysql
    cp -r $conf_dir/my.cnf /MM/DB/server0/
    /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/MM/DB/server0/var --basedir=/usr/local/mysql
    cp -r $conf_dir/db_start.sh /usr/local/sbin/
    /usr/local/sbin/db_start.sh server0 
}

function Install_Mongodb_3_0_6() {
    tar -zxvf $src_dir/$mongodb_3_0_6_version.tgz -C $tar_source >> /dev/null && cd $tar_source/$mongodb_3_0_6_version
    mkdir -p /MM/DB/mongodb/{27017,27018,27019}
    mkdir -p /MM/LOG/mongodb
    touch /MM/LOG/mongodb/mongodb-27017.log
    touch /MM/DB/mongodb/27017/mongodb-27017.conf
    mv $tar_source/$mongodb_3_0_6_version /usr/local/mongodb-3.0.6 >> /dev/null
    ln -s /usr/local/mongodb-3.0.6 /usr/local/mongodb
    /usr/local/mongodb/bin/mongod --fork --port 27017 --config /MM/DB/mongodb/27017/mongo-27017.conf --logpath /MM/LOG/mongodb/mongo-27017.log
}

function Install_Redis_5_0_2() {
    tar -zxvf $src_dir/$redis5_0_2_version.tar.gz -C $tar_source >> /dev/null && mv $tar_source/redis-5.0.2 /usr/local/ 
    cd /usr/local/$redis5_0_2_version && make >> /dev/null && make install >> /dev/null
    ln -s /usr/local/$redis5_0_2_version /usr/local/redis
    sed -i 's/daemonize no/daemonize yes/g' /usr/local/redis/redis.conf
    sed -i 's/#requirepass 123456/requirepass modernmedia/g' /usr/local/redis/redis.conf
    /usr/local/redis/src/redis-server /usr/local/redis/redis.conf
}

function Install_FFMpeg-4_0_5() {
    yum install -y automake autoconf libtool gcc gcc-c++ libx264-dev >> /dev/null
    wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz >> /dev/null && ./configure >> /dev/null && make install >> /dev/null
    wget ftp://ftp.videolan.org/pub/x264/snapshots/last_x264.tar.bz2 >> /dev/null
    tar -jxvf last_x264.tar.bz2
    cd x264   
    ./configure --enable-static --enable-shared --disable-asm && make && make install
    wget https://nchc.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
    tar -zxvf lame-3.99.5.tar.gz
    cd lame-3.99.5 
    ./configure --enable-static --enable-shared && make && make install
    wget http://ffmpeg.org/releases/ffmpeg-4.0.5.tar.gz
    ./configure --enable-network --enable-protocols --enable-muxers  --enable-shared  --enable-libmp3lame --enable-libx264 --enable-gpl --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/lib --disable-x86asm && make && make install
}

#php-5.4.45和php-5.6.31安装的扩展版本是一样的 写一个方法 提供调用
function InstallExtension ()
{
    echo "php 安装 amqp imagick mongo yaf memcached 扩展......"
    sleep 5
    tar -zxvf $src_dir/rabbitmq-c-0.8.0.tar.gz -C $tar_source >> /dev/null && cd  $tar_source/rabbitmq-c-0.8.0
    ./configure --prefix=/usr/local/rabbitmq-0.8.0 >> /dev/null && make install >> /dev/null && cd .. 

    tar -zxvf $src_dir/amqp-1.7.1.tgz -C $tar_source >> /dev/null && cd $tar_source/amqp-1.7.1
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config  --with-amqp --with-librabbitmq-dir=/usr/local/rabbitmq-0.8.0 >> /dev/null && make install >> /dev/null && cd ..
    echo "amqp扩展安装完成......"
    sleep 5

    tar -zxvf $src_dir/mongo-1.6.11.tgz -C $tar_source >> /dev/null && cd $tar_source/mongo-1.6.11
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config >> /dev/null && make install >> /dev/null && cd ..
    echo "mongo扩展安装完成......"
    sleep 5

    tar -zxvf $src_dir/yaf-2.3.4.tgz -C $tar_source >> /dev/null && cd $tar_source/yaf-2.3.4 
    /usr/local/php/bin/phpize
    ./configure --with-php-config=/usr/local/php/bin/php-config >> /dev/null && make install >> /dev/null && cd ..
    echo "yaf扩展安装完成......"
    sleep 5

    tar -zxvf $src_dir/libmemcached-1.0.18.tar.gz -C $tar_source >> /dev/null && cd $tar_source/libmemcached-1.0.18 
    ./configure --prefix=/usr/local/libmemcached-1.0.18 --with-memcached >> /dev/null && make install >> /dev/null && cd .. 

    tar -zxvf $src_dir/memcached-2.2.0.tgz -C $tar_source >> /dev/null && cd $tar_source/memcached-2.2.0 
    /usr/local/php/bin/phpize
    ./configure  --with-php-config=/usr/local/php/bin/php-config  --enable-memcache --with-libmemcached-dir=/usr/local/libmemcached-1.0.18 --disable-memcached-sasl >> /dev/null && make install >> /dev/null && cd ..
    echo "memcached扩展安装完成......"
    sleep 5

    tar -zxvf $src_dir/ImageMagick-7.0.8-40.tar.gz -C $tar_source >> /dev/null && cd $tar_source/ImageMagick-7.0.8-40 && \
    ./configure -prefix=/usr/local/imagemagick >> /dev/null && make install >> /dev/null && cd ..

    tar -zxvf $src_dir/imagick-3.4.3.tgz -C $tar_source >> /dev/null && cd $tar_source/imagick-3.4.3
    /usr/local/php/bin/phpize
    ./configure  --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/imagemagick >> /dev/null && make install >> /dev/null && cd ..
    echo "imagick扩展安装完成......"
    sleep 5
    echo -e "\033[36m 配置 " $p56_version " php.ini 文件......\033[0m"
    echo "extension=amqp.so" >> /usr/local/php/etc/php.ini
    echo "extension=mongo.so" >> /usr/local/php/etc/php.ini
    echo "extension=imagick.so" >> /usr/local/php/etc/php.ini
    echo "extension=memcached.so" >> /usr/local/php/etc/php.ini
    echo "extension=yaf.so" >> /usr/local/php/etc/php.ini
    echo "/etc/init.d/php-fpm start" >> /etc/rc.local
}

main
weinxin
我的微信
这是我的微信扫一扫

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:1   其中:访客  1   博主  0

    • avatar 幻水梦天 来自天朝的朋友 谷歌浏览器 Mac OS X 10_15_1 广东省深圳市 电信

      很多内容,慢慢看