CentOS7 離線安裝fastDFS、jdk1.8、mysql5.7、nginx、libreOffice


**因工作需要,在內網環境下安裝運行環境,故寫成腳本以供參考。

以下軟件已在CentOS7下離線安裝成功,成功后個別配置文件(fastDFS,nginx等)需手動配置,腳本中不再贅述。

先說下離線安裝包在linux中的放置路徑:/opt/install_package

install_package文件夾下面文件列表:

 fastDFS:

 

jdk1.8

LibreOffice

mysql 5.7

 nginx

**完整shell代碼如下

#!/bin/bash
function install_JDK(){
    java -version >> /dev/null 2>&1
    if [ $? -eq 0 ];then
        echo "**************JDK is already installed***************"
        return
    fi
    if [ ! -f "/opt/install_package/jdk1.8/jdk1.8.tar.gz" ];then
        echo "*****************JDK installation package does not exist******************"
        return
    fi
    echo "begin to install jdk"
    cd jdk1.8
    tar zxvf jdk1.8.tar.gz -C /usr/local/
    chmod 777 /usr/local/jdk1.8/bin/java
    chmod 777 /usr/local/jdk1.8/bin/javac
    echo 'JAVA_HOME=/usr/local/jdk1.8' >> ~/.bash_profile
    echo 'JAVA_BIN=$JAVA_HOME/bin' >> ~/.bash_profile
    echo 'JRE_HOME=$JiAVA_HOME/jre' >> ~/.bash_profile
    echo 'JRE_BIN=$JRE_HOME/bin' >> ~/.bash_profile
    echo 'PATH=$JAVA_BIN:$JRE_BIN:$PATH' >> ~/.bash_profile
    echo 'export JAVA_HOME JRE_HOME PATH' >> ~/.bash_profile
    source ~/.bash_profile
    java -version
    if [ $? -eq 0 ];then
        echo "JDK installed successfully"
    else
        echo "jdk install failed!"
    fi
}
function install_mysql(){
    isExit=`ps -ef | grep mysql| grep -v grep`
    if [ -n "${isExit}" ];then
        echo "**********************MySQL is already installed*****************************"
        return
    fi
    if [ ! -f "mysql/mysql-5.7.9-1.el7.x86_64.rpm-bundle.tar" ];then
        echo "*****************MySQL installation package does not exist******************"
        return
    fi
    echo "**************begin to install mysql*********************"
    cp -rf mysql /usr/local/
    cd /usr/local/mysql
    tar xvf mysql-5.7.9-1.el7.x86_64.rpm-bundle.tar
    rpm -ivh mysql-community-common-5.7.9-1.el7.x86_64.rpm 
    rpm -ivh mysql-community-libs-5.7.9-1.el7.x86_64.rpm --nodeps --force
    rpm -ivh mysql-community-devel-5.7.9-1.el7.x86_64.rpm --nodeps --force
    rpm -ivh mysql-community-libs-compat-5.7.9-1.el7.x86_64.rpm --nodeps --force
    rpm -ivh mysql-community-client-5.7.9-1.el7.x86_64.rpm --nodeps --force
    rpm -ivh mysql-community-server-5.7.9-1.el7.x86_64.rpm --nodeps --force
    service mysqld stop
    echo "skip-grant-tables" >> /etc/my.cnf
    service mysqld start    
    echo "****************mysql install sucessed**********************"
    echo "****account:root,password is empty,Please change the password in time****"
}
function install_nginx(){
    isExit=`ps -ef | grep nginx |grep -v grep`
    if [ -n "${isExit}" ];then
        echo "**********************Nginx is already installed*****************************"
        return
    fi
    if [ ! -d "nginx" ];then
        echo "Nginx installation package does not exist"
        return
    fi
    pacakgeNum=`ls nginx|wc -w`
    if [ ${pacakgeNum} -ne 4 ];then
        echo "*********************Wrong number of installation packages*******************"
        return
    fi
    echo "**********************begin to install nginx***********************"    
    cp -rf nginx /usr/local/
    cd /usr/local/nginx
    tar zxvf openssl-fips-2.0.10.tar.gz
    cd openssl-fips-2.0.10
    ./config && make && make install
    cd ..
    tar zxvf pcre-8.42.tar.gz
    cd pcre-8.42
    ./configure && make && make install
    cd ..
    tar zxvf zlib-1.2.11.tar.gz
    cd zlib-1.2.11
    ./configure && make && make install
    cd ..
    tar zxvf nginx-1.14.2.tar.gz
    cd nginx-1.14.2
    ./configure && make && make install
    ln -s /usr/local/lib/libpcre.so.1 /lib64/
    path=`whereis nginx |awk -F: '{print $2}'`
    systemctl stop firewalld.service
    ${path}/sbin/nginx
    if [ $? -eq 0 ];then
        echo "****************Nginx installed successfully***********************"
    else
        echo "****************Nginx installation failed**************************"
    fi
}
function isntall_LibreOffice(){    
    isExit=`ps -ef | grep libreoffice5.3 | grep -v grep`
    if [ -n "${isExit}" ];then
        echo "*******************Libreoffice is already installed**********************"
        return
    fi
    if [ ! -f "libreOffice/LibreOffice_5.3.7_Linux_x86-64_rpm.tar.gz" ];then
        echo "*****************LibreOffice installation package does not exist******************"
        return
    fi
    tar zxvf libreOffice/LibreOffice_5.3.7_Linux_x86-64_rpm.tar.gz -C /usr/local/
    cd /usr/local/LibreOffice_5.3.7.2_Linux_x86-64_rpm/RPMS
    rpm -ivh *.rpm
    cd /opt/libreoffice5.3/program
    ./soffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard &
    isExit=`ps -ef | grep libreoffice5.3 | grep -v grep`
    if [ -n "${isExit}" ];then
        echo "*******************Libreoffice installed successfully**********************"
    else
        echo "*******************Libreoffice installation failed*************************"
    fi
    
}
function install_fastDFS(){
    while read -p "請輸入fastDFS服務器ip地址:" cur_ip
    do
        ipcalc -cs ${cur_ip}
        if [ "$?" -eq 0 ];then
            break
        else 
            echo "ip地址填寫錯誤,請重新填寫!"
            continue
        fi
    done
    cp -rf fastDFS /usr/local/
    cd /usr/local/fastDFS
    tar zxvf libevent-2.0.22-stable.tar.gz
    cd libevent-2.0.22-stable
    ./configure --prefix=/data/libevent
    cd /usr/local/fastDFS
    tar -zxvf libfastcommon.tar.gz
    cd libfastcommon
    ./make.sh
    ./make.sh install
    ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
    cd /usr/local/fastDFS/
    tar -zxvf FastDFS_v5.05.tar.gz
    cd FastDFS
    old='TARGET_PREFIX=$DESTDIR/usr'
    new='TARGET_PREFIX=$DESTDIR/usr/local'
    sed -i "s#$old#$new#g" make.sh
    ./make.sh && ./make.sh install
    ####配置tracker.conf
    mkdir -p /data/fdfs/tracker
    cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
    old=`cat /etc/fdfs/tracker.conf | grep  "^base_path="`
    new="base_path=/data/fdfs/tracker"
    sed -i "s#$old#$new#g" /etc/fdfs/tracker.conf
    if [ ! -f "/etc/init.d/fdfs_trackerd" ];then
        cp -rf /usr/local/fastDFS/FastDFS/init.d/fdfs_trackerd /etc/init.d/
    fi
    ##設置trackerd開機自啟
    chkconfig --add fdfs_trackerd
    chkconfig fdfs_trackerd on
    service fdfs_trackerd start
    ##配置storage.conf
    mkdir -p /data/fdfs/storage
    cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
    old=`cat /etc/fdfs/storage.conf | grep  "^base_path="`
    new="base_path=/data/fdfs/storage"
    sed -i "s#$old#$new#g" /etc/fdfs/storage.conf
    
    old=`cat /etc/fdfs/storage.conf | grep "^store_path0="`
    new="store_path0=/data/fdfs/storage"
    sed -i "s#$old#$new#g" /etc/fdfs/storage.conf
    
    
    old=`cat /etc/fdfs/storage.conf | grep "^tracker_server="`
    new="tracker_server=${cur_ip}:22122"    
    sed -i "s#$old#$new#g" /etc/fdfs/storage.conf
    
    if [ ! -f "/etc/init.d/fdfs_storaged" ];then
                cp -rf /usr/local/fastDFS/FastDFS/init.d/fdfs_storaged /etc/init.d/
        fi
    ##設置tracker開機自啟
    chkconfig --add fdfs_storaged
    chkconfig fdfs_storaged on
    service fdfs_storaged start

    ##配置client.conf
    cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
    old=`cat /etc/fdfs/client.conf | grep "^base_path="`
    new="base_path=/data/fdfs/tracker"
    sed -i "s#$old#$new#g" /etc/fdfs/client.conf
        
    old=`cat /etc/fdfs/client.conf | grep "^tracker_server="`
    new="tracker_server=${cur_ip}:22122"
    sed -i "s#$old#$new#g" /etc/fdfs/client.conf

    ##獲取tracker配置端口,需與client.conf保持一致    
    tracker_port=`cat /etc/fdfs/tracker.conf | grep "^http.server_port="|awk -F= '{print $2}'`
    old=`cat /etc/fdfs/client.conf | grep "http.tracker_server_port="`
    new="http.tracker_server_port=${tracker_port}"
    sed -i "s#$old#$new#g" /etc/fdfs/client.conf
    echo "*******************fastDFS installed successfully**********************"
    echo "path of storage.conf is /etc/fdfs/storage.conf"
    echo "path of tracker.conf is /etc/fdfs/tracker.conf"
    echo "path of client.conf is /etc/fdfs/tracker.conf"
    echo "path of data is /data/fdfs/storage/data"
    
    
}

 
Tips="
此腳本用來一鍵安裝各種應用程序軟件,包括jdk、應用程序、nginx等\n
1、離線安裝jdk並配置環境變量\n
2、離線安裝nginx\n
3、離線安裝mysql\n
4、離線安裝word轉pdf打印服務(Libreoffice)\n
5、離線安裝fastDFS\n
0、 退出
"
echo -e ${Tips}
while read -p "請輸入您的操作序號:" val
do
    if [ "$val" == "0" ];then
        break
    elif [ "$val" == "1" ];then
        install_JDK
        echo -e ${Tips}
        continue
    elif [ "$val" == "2" ];then
        install_nginx
        echo -e ${Tips}
        continue
    elif [ "$val" == "3" ];then
                install_mysql
        echo -e ${Tips}
                continue
    elif [ "$val" == "4" ];then
                isntall_LibreOffice
        echo -e ${Tips}
                continue
    elif [ "$val" == "5" ];then
                install_fastDFS
        echo -e ${Tips}
                continue
    else 
        echo "Wrong number input, please input again ."
    fi
done

 離線安裝包(1G)下載鏈接: https://pan.baidu.com/s/14_NbibeuGwf35K4CmZ7HzQ 提取碼: 829i


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM