美文网首页
Linux作业(7)——wordprees安装脚本

Linux作业(7)——wordprees安装脚本

作者: 羰基生物 | 来源:发表于2020-11-02 10:25 被阅读0次
    #!/bin/bash
    #
    #*********************************************************
    #Author:            blackbeard
    #Date:              2020-09-27
    #FileName:          wordpress_install.sh
    #Des:               The test file
    #*********************************************************
    APACHE_INSTALL_PATH=/data/apps/httpd
    PHP_INSTALL_PAYH=/data/apps/php74
    URL_APACHE="https://mirrors.bfsu.edu.cn/apache/httpd/httpd-2.4.46.tar.gz"
    URL_WORDPRESS="https://cn.wordpress.org/latest-zh_CN.zip"
    DATA_DIR="/data/mysql"
    MYSQL_PACKAGE_NAME='mysql-8.0.21-linux-glibc2.12-x86_64.tar'
    APACHE_PACKAGE_NAME='httpd-2.4.46.tar.gz'
    PHP_PACKAGE_NAME='php-7.4.12.tar.xz'
    RED="\e[1;31m"
    END="\e[0m" 
    
    
    ###################################################################################
    
    
    echo -e "$RED[---------------------初始化系统环境---------------------]$END"
    sed -i 's/SELINUX=enforcing/SELINUX=disbaled/g' /etc/selinux/config
    systemctl disable firewalld
    systemctl stop firewalld
    declare -A app1
    app1[a1]='gcc'
    app1[a2]='make'
    app1[a3]='zlib-devel'
    app1[a4]='libxml2-devel'
    app1[a5]='openssl-devel'
    app1[a6]='libaio-devel'
    app1[a7]='wget'
    app1[a8]='xz'
    app1[a9]='ncurses-compat-libs'
    app1[a10]='expat-devel'
    app1[a11]='bzip2-devel'
    app1[a12]='libmcrypt-devel'
    app1[a13]='sqlite-devel'
    #app1[a14]='oniguruma-devel'
    #wget http://mirror.centos.org/centos/8/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-1.el8.x86_64.rpm
    #用的阿里epel源,在线下载不成功,提前手动下载的
    yum install -y oniguruma-devel-6.8.2-1.el8.x86_64.rpm &> /dev/null
    
    for j in ${!app1[*]};do
        rpm -q ${app1[$j]} &> /dev/null || yum install -y ${app1[$j]} &> /dev/null
    done
        echo -e "$RED[--------------------通用依赖环境设置完成----------------]$END"
    
    
    ###################################################################################
    
    
    yum install -y pcre-devel &> /dev/null
    yum install -y redhat-rpm-config &> /dev/null
    rpm -q pcre-devel redhat-rpm-config &> /dev/null && echo -e "$RED[------------------Apache依赖环境设置完成----------------]$END"
    
    
    ###################################################################################
    rpm -q bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel &> /dev/null && echo -e "$RED[--------------------PHP依赖环境设置完成-----------------]$END"
    
    ###################################################################################
    
    cd /usr/local
    if [ -f $MYSQL_PACKAGE_NAME ];then
        tar xf $MYSQL_PACKAGE_NAME  
        rm -rf $MYSQL_PACKAGE_NAME
        xz -d $MYSQL_PACKAGE_NAME.xz
        tar xf $MYSQL_PACKAGE_NAME
         
    else
        echo -e "$RED[/usr/local目录不存在$MYSQL_PACKAGE_NAME]$END"  
    fi
    ###/usr/local下安装MySQL后切换回家目录
    cd 
    
    if [ -f $APACHE_PACKAGE_NAME ];then
        tar xf $APACHE_PACKAGE_NAME
    else 
        wget $URL_APACHE &> /dev/null
        tar xf $APACHE_PACKAGE_NAME
    fi
    
    if [ -f $PHP_PACKAGE_NAME ];then
        tar xf $PHP_PACKAGE_NAME &> /dev/null
    else
       echo -e "$RED[当前目录不存在$PHP_PACKAGE_NAME]$END" 
    fi
    
        
    
    
    ###################################################################################
    ##################################安装MYSQL########################################
    if  [ -h /usr/local/mysql ];then
        echo -e "$RED[----------------------MYSQL已安装-----------------------]$END"
        exit 1
    else
        echo -e "$RED[----------------------MYSQL未安装-----------------------]$END"
        sleep 3
        echo -e "$RED[---------------------开始安装MYSQL----------------------]$END"
    fi
    ###########检查系统是否已安装MYSQL
        ln -s /usr/local/mysql-8.0.21-linux-glibc2.12-x86_64 /usr/local/mysql
        id mysql &>/dev/null
    ###########解压文件到安装目录
    if [ $? -eq 0 ];then
        echo -e "$RED[-----------------------用户已存在-----------------------]$END"
    else
        groupadd mysql
        useradd -r -g mysql -u 306 -s /bin/false mysql
    fi
    ###########创建系统用户mysql
    cat > /usr/local/mysql/my.cnf <<-EOF
     [mysqld]
        pid_file=mysql.pid
        datadir=/data/mysql
        basedir=/usr/local/mysql
        log-error=/data/mysql/mysql.log
        socket=/data/mysql/mysql.sock
        [client]
        socket=/data/mysql/mysql.sock
        EOF
    
    echo "PATH=/usr/local/mysql/bin/:$PATH" >> /etc/profile
    . /etc/profile
    ############创建配置文件
    cd /usr/local/mysql/bin
    mysqld --initialize --user=mysql --datadir=$DATA_DIR &> /var/password.txt
    chown -R mysql:mysql $DATA_DIR
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    chkconfig --add mysqld
    chkconfig mysqld on
    #############设置系统环境
    ln -s /data/mysql/mysql.sock /tmp/mysql.sock
    systemctl start mysqld.service && echo -e "$RED[----------------------MYSQL安装完成---------------------]$END"
    OLD_PASSWORD=`grep  'temporary password' /var/password.txt | awk -F' ' '{printf $13}'`
    NEW_PASSWORD='Changeme_123'
    mysqladmin -uroot -p$OLD_PASSWORD password $NEW_PASSWORD
    ###需要提前在MYSQL创建wordpress库,以及用户并且授权。
    ###################################################################################
    ###################################编译apache,apr,apr-util######################################
    #三者一起编译,必须将apr、apr-util文件放在apache源码包httpd-2.4.46/srclib/目录下,并且不能携带版本号。
    cd
    wget https://mirror.bit.edu.cn/apache/apr/apr-1.7.0.tar.gz &> /dev/null
    wget https://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz &> /dev/null
    if [ -f apr-1.7.0.tar.gz ];then
        tar xf apr-1.7.0.tar.gz &> /dev/null
        mv apr-1.7.0 httpd-2.4.46/srclib/apr
    else
        echo -e "$RED[apr-1.7.0.tar.gz 下载失败]$END"
        exit 1
    fi    
    
    if [ -f apr-util-1.6.1.tar.gz ];then 
        tar xf apr-util-1.6.1.tar.gz &> /dev/null
        mv apr-util-1.6.1 httpd-2.4.46/srclib/apr-util
    else    
        echo -e "$RED[apr-util-1.6.1.tar.gz 下载失败]$END" 
        exit 1
    fi
    
    cd
    cd httpd-2.4.46
    ./configure --prefix=$APACHE_INSTALL_PATH \
    --enable-so \
    --enable-ssl \
    --enable-cgi \
    --enable-rewrite \
    --with-zlib \
    --with-pcre \
    --with-include-apr \
    --enable-modlues=most \
    --enable-mpms-shared=all \
    --with-mpm=prefork  &> /dev/null
    make -j 6 &> /dev/null && make install &> /dev/null 
    
    useradd -r -s /sbin/nologin apache
    sed -i 's/^User.*/User apache/' $APACHE_INSTALL_PATH/conf/httpd.conf
    sed -i 's/^Group.*/Group apache/' $APACHE_INSTALL_PATH/conf/httpd.conf
    echo 'PATH="/data/apps/httpd/bin:$PATH"' > /etc/profile.d/httpd.sh
    . /etc/profile.d/httpd.sh
    echo 'MANDATORY_MANPATH   /data/apps/httpd/man' >> /etc/man_db.conf
    mkdir -p /var/www/html
    cat > /lib/systemd/system/httpd.service <<EOF
    [Unit]
    Description=The Apache HTTP Server
    After=network.target remote-fs.target nss-lookup.target
    Documentation=man:httpd(8)
    Documentation=man:apachectl(8)
    [Service]
    Type=forking
    ExecStart=/data/apps/httpd/bin/apachectl start
    ExecReload=/data/apps/httpd/bin/apachectl graceful
    ExecStop=/data/apps/httpd/bin/apachectl stop
    KillSignal=SIGCONT
    PrivateTmp=true
    [Install]
    WantedBy=multi-user.target
    EOF
    systemctl daemon-reload
    systemctl enable --now httpd.service
    
    
    ###################################################################################
    #Centos8可以直接yum安装,不需要修改配置,默认支持fastcgi模式。
    ###################################################################################
    ####编译安装PHP,可以选择模块方式或者fastcgi方式安装,如果选择模块方式则只能使用apache,而使用fastcgi模式可以支持nginx。这里使用fastcgi方式编译。
    cd
    cd php-7.4.12
    ./configure \
    --prefix=$PHP_INSTALL_PATH \
    --enable-mysqlnd \
    --with-mysqli=mysqlnd \
    --with-pdo-mysql=mysqlnd \
    --with-openssl \
    --with-zlib \
    --with-config-file-path=/etc \
    --with-config-file-scan-dir=/etc/php.d \
    --enable-mbstring \
    --enable-xml \
    --enable-sockets \
    --enable-fpm \
    --enable-maintainer-zts \
    --disable-fileinfo &> /dev/null
    make -j 4 &> /dev/null && make install &> /dev/null
    
    
    cp php.ini-production /etc/php.ini
    cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
    cd $PHP_INSTALL_PATH/etc
    cp php-fpm.conf.default php-fpm.conf
    cp php-fpm.d/www.conf.default php-fpm.d/www.conf
    echo "#!/bin/bash
    PATH=/data/apps/php74/bin:$PATH" > /etc/profile.d/php.sh
    . /etc/profile.d/php.sh
    chkconfig --add php-fpm 
    chkconfig php-fpm on
    service php-fpm start
    
    cd 
    #wget $URL_WORDPRESS
    #unzip latest-zh_CN.zip
    #在线下载太慢,这里直接下载安装包解压后放在家目录
    unzip wordpress-5.4.2-zh_CN.zip &> /dev/null
    mv wordpress /var/www/html
    chown -R apache.apache /var/www/html/
    ######所有服务启动成功后,浏览器登录localhost/wordpress,开始安装wordpress应用。看不到页面将apache的主配置文件的DocumentRoot 改为/var/www/html。默认为安装目录下的/httpd/htdocs。
    echo -e "$RED[-------------------------安装完成------------------------]$END"
    

    相关文章

      网友评论

          本文标题:Linux作业(7)——wordprees安装脚本

          本文链接:https://www.haomeiwen.com/subject/blgpvktx.html