马哥博客作业第十五周

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

  prefork MPM: 有一个主控制进程,然后生成多个子进程,每个子进程有一个独立的线程处理用户的请求,相对比较占用内存,但是比较稳定,可以设置最大和最小进程数,适用于访问量不是很大的场景。

  worker MPM: 是一种多进程和多线程混合的模型,有一个控制进程,启动多个子进程,每个子进程里面包含固定的线程,使用线程来处理请求,当线程不够使用的时候会再启动一个新的子进程,然后在新的进程里面启动线程来处理请求,由于使用了线程来处理请求,因此可以承受更高的并发。

  event MPM: worker模型的变种,一个主进程,生成多个子进程,每个子进程生成多个线程,每个线程处理一个请求。和worker模型的区别在于,它解决了keep-alive场景下,长期被占用的线程的资源浪费问题,有一个专门的线程来管理keep-alive的线程,当有真实请求的时候,将请求传递给服务线程,执行完毕后,又允许它释放,这样增强了高并发场景下的请求处理能力。

2、编译安装httpd 2.4

  [root@localhost ~]#cat scripts/httpd-2.4.46_install.sh
  #! /bin/bash

  # 安装相关包
  yum -y install wget gcc make pcre-devel openssl-devel expat-devel

  # 下载源代码并解压缩
  wget -P /usr/local/src/ https://mirror.bit.edu.cn/apache//apr/apr-1.7.0.tar.gz
  wget -P /usr/local/src/ https://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
  wget -P /usr/local/src/ https://mirrors.bfsu.edu.cn/apache//httpd/httpd-2.4.46.tar.gz
  cd /usr/local/src/
  tar xf apr-1.7.0.tar.gz
  tar xf apr-util-1.6.1.tar.gz
  tar xf httpd-2.4.46.tar.gz

  # 将apr和apr-util源码与httpd源码合并,三者共同编译安装
  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 --prefix=/apps/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre
  --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
  make && make install

  # 创建apache账户
  useradd -r -s /sbin/nologin apache

  # 修改配置文件
  sed -i 's/^User.*/User apache/' /apps/httpd/conf/httpd.conf
  sed -i 's/^Group.*/Group apache/' /apps/httpd/conf/httpd.conf

  # 配置环境变量
  echo 'PATH="/apps/httpd/bin:$PATH"' > /etc/profile.d/httpd.sh
  . /etc/profile.d/httpd.sh

  # 配置man帮助
  echo 'MANDATORY_MANPATH /apps/httpd/man' >> /etc/man_db.conf

  # 创建service unit文件,设置开机启动
  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=/apps/httpd/bin/apachectl start
  ExecReload=/apps/httpd/bin/apachectl graceful
  ExecStop=/apps/httpd/bin/apachectl stop
  # We want systemd to give httpd some time to finish gracefully, but still want
  # it to kill httpd after TimeoutStopSec if something went wrong during the
  # graceful stop. Normally, Systemd sends SIGTERM signal right after the
  # ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
  # httpd time to finish.
  KillSignal=SIGCONT
  PrivateTmp=true

  [Install]
  WantedBy=multi-user.target
  EOF

  systemctl daemon-reload
  systemctl enable --now httpd.service

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

  [root@CentOS8 ~]#cat centos8_lamp_wordpress.sh
  #!/bin/bash

  # 下载相关包
  yum -y install wget httpd php php-json php-mysqlnd mariadb-server

  # 修改httpd的mpm工作模型为prefork
  sed -Ei 's/LoadModule mpm_event_module.*/#&/' /etc/httpd/conf.modules.d/00-mpm.conf
  sed -Ei 's/#(LoadModule mpm_prefork_module.*)/1/' /etc/httpd/conf.modules.d/00-mpm.conf

  # 开启相应的服务并设置为开机启动
  systemctl enable --now httpd mariadb

  # 下载wordpress安装包,并将解压缩的目录文件移动到html目录下,修改文件的属性
  wget https://cn.wordpress.org/latest-zh_CN.tar.gz
  tar xf wordpress-5.4.2-zh_CN.tar.gz
  mv wordpress/* /var/www/html/
  chown apache.apache /var/www/html/ -R

  # 创建对应的数据库和用户
  echo 'create database wordpress;' | mysql
  echo "grant all on wordpress.* to wpuser@'localhost' identified by '123456';" | mysql

  # 浏览器访问http://lamp服务器

原文地址:https://www.cnblogs.com/babyblue3/p/13622676.html