• 博客第20周


    1、写出 MPM multi-processing module 工作模式原理以及区别

    prefork mpm(无线程)启动一个主进程,主进程生成若干子进程。子进程数量可以配置。可以设置最小,最大进程数。优点:稳定,隔离行好。缺点:占用系统内存多。不适合高并发场景

    work  mpm (多进程多线程)启动一个主进程,主进程生成若干子进程。子进程数量,每个进程的线程数可以通过配置定义。每个子进程有固定的线程来处理客户端请求。优点:较少占用系统资源。可以实现高并发。缺点:在使用长连接方式时,会有线程不被使用也不释放的情况,且超时才释放。所以会出现无服务可用情况。

    event  基于work 模式,子进程中有监听器线程,该监听线程监听客户端连接请求并将连接到达时将其传递给工作线程进行处理,工作线程处理完请求可以被释放。提高并发 
    2、编译安装httpd 2.4 

    下载相应安装包依赖包

    yum -y install gcc make pcre-devel openssl-devel expat-devel

    wget https://downloads.apache.org//httpd/httpd-2.4.46.tar.bz2

    wget https://downloads.apache.org//apr/apr-1.7.0.tar.bz2

    wget https://downloads.apache.org//apr/apr-util-1.6.1.tar.bz2

    tar -xvf *.bz2

    mv apr-1.7.0 httpd-2.4.46/srclib/apr

    mv apr-util-1.6.1 httpd-2.4.46/srclib/apr-util

    cd httpd-2.4.46/

    ./configure --perfix=/usr/local/httpd --sysconfigdir=/etc/httpd --enable-ssl --enable-so --enable-cgi --enable-rewrite --with-pcre --with-inclued-apr --enable-modules=most --enable-mps-shared=all 

    make -j 4 && make install

    useradd -s /sbin/nologin -r apache

    echo PATH=/usr/local/httpd/bin:$PATH > /etc/profile.d/httpd.sh

    source /etc/profile.d/httpd.sh

    sed -i 's/User daemon/User apache/' /etc/httpd/httpd.conf
    sed -i 's/Group daemon/Group apache/' /etc/httpd/httpd.conf

    ##检查httpd 安装

    httpd -t

    启动httpd服务

    /usr/local/httpd/bin/apachectl -k start

    #开机启动

    sed  '$a/usr/local/httpd/bin/apachect start' /etc/rc.d/rc.local

    chmod +x /etc/rc.d/rc.local


    3、编写一个一键部署 LAMP 架构之 wordpress 脚本

    #!/bin/bash
    #
    #********************************************************************
    #Author: tyzh
    #QQ: 283399535
    #Date: 2020-09-11
    #FileName: install_lamp_wordpress.sh
    #URL: http://www.xxxx.com
    #Description: The test script
    #Copyright (C): 2020 All rights reserved
    #********************************************************************
    ###基于centos7 php7.4.10, mysql5.7.31,http2.4.43 wordpress-5.4.2 一键部署###

    ###注意配置好epel源。解决oniguruma缺少问题### 
    ###脚本语法检查测试用,正式安装可以注释掉##
    set uex

    ####脚本变量####

    colorGreen="33[32m"
    colorRed="33[31m"
    colorEnd="33[0m"

    SRC_DIR='/usr/local/src'
    CurrentVersion=`httpd -v|head -1`

    MYSQL='mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz'
    MYSQL_ROOT_PASSWORDG=tyzh2020

    APR_NAME='apr-1.7.0.tar.bz2'
    APR_UTIL_VERSION='apr-util-1.6.1.tar.bz2'
    HTTPD_NAME='httpd-2.4.46.tar.bz2'
    PHP_NAME='php-7.4.10.tar.bz2'

    WORDPRESS='wordpress-5.4.2-zh_CN.tar.gz'

    ###安装依赖包###
    yum -y install gcc make autoconf apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config libaio numactl-libs libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel

    ###httpd编译安装###
    install_httpd(){

    ###下载http,apr和apr-util源码包###
    echo -e "$colorGreen $HTTPD_NAME $APR_NAME $APR_UTIL_VERSION 下载starting......$colorEnd"
    [ -f $SRC_DIR/$APR_NAME ] || wget -P $SRC_DIR https://mirror.bit.edu.cn/apache/apr/$APR_NAME
    [ -f $SRC_DIR/$APR_UTIL_VERSION ] || wget -P $SRC_DIR https://mirror.bit.edu.cn/apache/apr/$APR_UTIL_VERSION
    [ -f $SRC_DIR/$HTTPD_NAME ] || wget -P $SRC_DIR https://mirror.bit.edu.cn/apache/httpd/$HTTPD_NAME
    echo -e "$colorGreen $HTTPD_NAME $APR_NAME $APR_UTIL_VERSION 下载finish ......$colorEnd"
    ####解压####
    echo -e "$colorGreen starting 解压......$colorEnd"
    cd $SRC_DIR
    tar xf $APR_NAME
    tar xf $APR_UTIL_VERSION
    tar xf $HTTPD_NAME
    mv ${APR_NAME%.tar*} $HTTPD_NAME/srclib/apr
    mv ${APR_UTIL_VERSION%.tar*} $HTTPD_NAME/srclib/apr-util
    cd $SRC_DIR/${HTTPD_NAME%.tar*}
    ###配置httpd###
    ./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd --enable-ssl --enable-so --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-inclued-apr --enable-modules=most --enable-mpm=event
    ###编译并安装####
    make -j 2 && make install
    echo -e "$colorGreen $HTTPD_NAME finished......$colorEnd"
    ####httpd启动环境配置,启动###
    echo PATH=/usr/local/httpd/bin:$PATH > /etc/profile.d/httpd.sh
    source /etc/profile.d/httpd.sh
    #修改http进程执行者
    sed -i 's/User daemon/User apache/' /etc/httpd/httpd.conf
    sed -i 's/Group daemon/Group apache/' /etc/httpd/httpd.conf

    ###检查安装文件####
    apachectl -t
    ###httpd serice服务配置###
    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=/usr/local/httpd/bin/apachectl start
    ExecReload=/usr/local/httpd/bin/apachectl graceful
    ExecStop=/usr/local/httpd/bin/apachectl stop
    KillSignal=SIGCONT
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target
    EOF

    #开机启动##
    sed '$a/usr/local/httpd/bin/apachect start' /etc/rc.d/rc.local
    chmod +x /etc/rc.d/rc.local

    ##启动http服务###
    systemctl daemon-reload
    systemctl enable httpd.service
    systemctl start httpd.service
    echo $CurrentVersion
    echo 'httpd 服务已经启动.......'
    }

    ####编译安装mysql###
    install_mysql(){
    ##下载数据库###
    [ -f $SRC_DIR/$MYSQL ] || wget -P $SRC_DIR http://mirrors.163.com/mysql/Downloads/MySQL-5.7/$MYSQL
    echo -e $colorGreen"开始安装MySQL数据库..."$colorEnd
    cd $SRC_DIR
    if [ -e /usr/local/mysql ];then
    echo -e $colorRed "数据库已存在,安装失败" $colorEnd
    exit
    else
    tar xf $MYSQL -C /usr/local/
    MYSQL_DIR=`echo $MYSQL| sed -nr 's/^(.*[0-9]).*/1/p'`
    ln -s /usr/local/$MYSQL_DIR /usr/local/mysql
    ##赋予目录权限###
    chown -R root.root /usr/local/mysql/
    id mysql &> /dev/null || { useradd -s /sbin/nologin -r mysql ; action "创建mysql用户"; }
    ###mysql环境变量配置###
    echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh
    source /etc/profile.d/mysql.sh
    ##配置mysql文件###
    cp /etc/my.cnf{,.bak}
    cat > /etc/my.cnf <<EOF
    [mysqld]
    port=3306
    socket=/data/mysql/mysql.sock
    datadir=/data/mysql
    log-error=/data/mysql/mysql.log
    character-set-server=utf8mb4
    max_connections=1000
    max_connect_errors=1000
    #safe-updates
    [client]
    port=3306
    socket=/data/mysql/mysql.sock
    default-character-set=utf8mb4
    EOF
    [ -d /data ] || mkdir /data
    #mysql初始化
    mysqld --initialize --user=mysql --datadir=/data/mysql

    #创建启动脚本并启动服务
    cat > /etc/systemd/system/mysqld.service << EOF
    [Unit]
    Description=MySQL Server
    Documentation=man:mysqld(8)
    Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
    After=network.target
    After=syslog.target

    [Install]
    WantedBy=multi-user.target

    [Service]
    User=mysql
    Group=mysql
    ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
    LimitNOFILE = 5000
    EOF
    systemctl daemon-reload
    systemctl enable mysqld.service
    systemctl start mysqld.service
    #修改数据库root密码
    [ $? -ne 0 ] && { $COLOR"数据库启动失败,退出!"$END;exit; }
    MYSQL_OLDPASSWORD=`awk '/A temporary password/{print $NF}' /data/mysql/mysql.log`
    mysqladmin -uroot -p$MYSQL_OLDPASSWORD password $MYSQL_ROOT_PASSWORD &> /dev/null
    #mysqla -uroot -p$MYSQL_OLDPASSWORD -e "SET PASSWORD = PASSWORD('tyzh2020')"
    #mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'tyzh2020' WITH GRANT OPTION"
    #mysql -e "flush privileges"
    #systemctl restart mysqld.service
    ##注意如果密码修改不成功。需手动执行mysql -uroot -p ,密码为初始密码(awk '/A temporary password/{print $NF}' /data/mysql/mysql.log)
    echo -e $colorGreen"MySQL数据库已经安装..."$colorEnd
    fi
    }

    ###php安装###

    install_php(){
    ###下载php###
    [ -f $SRC_DIR/$PHP_NAME ] || wget -P $SRC_DIR https://www.php.net/distributions/$PHP_NAME
    ###解压,编译###

    cd $SRC_DIR
    tar xf $PHP_NAME -C /usr/local/
    cd /usr/local/${PHP_NAME%.tar*}
    ./configure
    --prefix=/usr/local/php
    --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

    ##安装##
    make && make install

    ####php path变量配置,启动###
    echo PATH=/usr/local/php/bin:$PATH > /etc/profile.d/php.sh
    source /etc/profile.d/php.sh

    ##php启动配置##
    cp php.ini-production /etc/php.ini
    cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
    cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

    cat > /lib/systemd/system/php-fpm.service << EOF
    [Unit]
    Description=The PHP FastCGI Process Manager
    After=syslog.target network.target

    [Service]
    Type=simple
    PIDFile=/var/run/php-fpm.pid
    ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
    ExecReload=/bin/kill -USR2 $MAINPID
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target
    EOF

    #修改配置文件
    sed -ri 's#(user = )nobody#1apache#' /usr/local/php/etc/php-fpm.d/www.conf
    sed -ri 's#(group = )nobody#1apache#' /usr/local/php/etc/php-fpm.d/www.conf
    sed -ri 's#;(pm.status_path = )/status#1/php-fpm_status#' /usr/local/php/etc/php-fpm.d/www.conf
    sed -ri 's#;(ping.path = /ping)#1#' /usr/local/php/etc/php-fpm.d/www.conf
    mkdir /etc/php.d
    cat > /etc/php.d/opcache.ini << EOF
    [opacache]
    zend_extensio=opcache.so
    opcache.enable=1
    EOF
    systemctl daemon-reload
    systemctl enable php-fpm.service
    systemctl start php-fpm.service

    #修改httpd配置,支持php-fpm
    sed -ri 's@#(LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so)@1@' /etc/httpd/httpd.conf
    sed -ri 's@#(LoadModule proxy_module modules/mod_proxy.so)@1@' /etc/httpd/httpd.conf
    sed -ri 's@(DirectoryIndex )(index.html)@1index.php 2@' /etc/httpd/httpd.conf
    sed -ri '$aAddType application/x-httpd-php .php ProxyRequests Off' /etc/httpd/httpd.conf
    cat >> /etc/httpd/httpd.conf << EOF

    <VirtualHost *:80>
    ServerName localhost
    DocumentRoot /data/wordpress
    <Directory "/data/wordpress">
    Require all granted
    </Directory>
    ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/data/wordpress/$1
    ProxyPassMatch ^/(php-fpm_status|ping)$ fcgi://127.0.0.1:9000/$1
    CustomLog "logs/access_wordpress_log" common
    </VirtualHost>
    EOF
    systemctl restart httpd.service
    }


    install_wordpress() {
    #下载wordpress安装包
    [ -f $SRC_DIR/$WORDPRESS ] || wget -P $SRC_DIZR https://cn.wordpress.org/$WORDPRESS
    cd $SRC_DIR
    #解压安装包
    tar xf $WORDPRESS
    mv $SRC_DIR/wordpress /data
    chown -R apache:apache /data/wordpress
    echo -e $colorGreen"wordpress 安装完成。。。。"$colorEnd
    #创建数据库和用户
    mysql -uroot -ptyzh2020 -e 'create database wordpress;'
    mysql -uroot -ptyzh2020 -e 'grant all on wordpress.* to wpuser@"%" identified by "wppasswd";'
    mysql -uroot -ptyzh2020 -e "flush privileges"
    echo -e $colorGreen"wordpress 库用户密码设置完毕。。。"$colorEnd
    }

    install_httpd
    install_mysql
    install_php
    install_wordpress

  • 相关阅读:
    【HDU1698】 Just a Hook 【线段树入门】
    【转载】线段树 区间合并 小结
    Codeforces 1138B(列方程枚举)
    Codeforces 1132G(关系转化树+dfn+线段树)
    Codeforces 1132E(转化+dp)
    Codeforces 1132D(二分模拟)
    Codeforces 1131G(dp)
    洛谷1941(dp)
    洛谷2758(字符串dp)
    Codeforces 1143B(思维、技巧)
  • 原文地址:https://www.cnblogs.com/yazhan/p/13629039.html
Copyright © 2020-2023  润新知