zoukankan      html  css  js  c++  java
  • 马哥博客作业第十六周

    1、前端有一个 LAMP 架构通过 wordpress 来部署,后端构建一个 NFS 服务器实现要求将用户上传的图片保存至后端 NFS 服务器上。

      准备3台主机

      一台apache+php:10.0.0.212

      一台mysql:10.0.0.216

      一台NFS:10.0.0.213

    一、在10.0.0.212上通过脚本编译安装apache和php 

      [root@localhost ~]#cat 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

      [root@localhost ~]#cat php-7.4.10_install.sh
      # 编译安装fastcgi方式的php-7.4.10

      # 安装相关包
      yum -y install wget gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel openssl-devel

      # 下载php源码进行编译安装
      wget -P /usr/local/src/ https://www.php.net/distributions/php-7.4.10.tar.xz
      cd /usr/local/src/
      tar xf php-7.4.10.tar.xz
      cd php-7.4.10/
      ./configure --prefix=/apps/php74 --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

      # 创建PATH变量
      echo "PATH=/apps/php74/bin:$PATH" > /etc/profile.d/php74.sh
      . /etc/profile.d/php74.sh

      # 准备php配置文件和service unit文件
      cp php.ini-production /etc/php.ini
      cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
      mv /apps/php74/etc/php-fpm.conf.default /apps/php74/etc/php-fpm.conf
      mv /apps/php74/etc/php-fpm.d/www.conf.default /apps/php74/etc/php-fpm.d/www.conf

      # 启用opcache加速
      cat >> /etc/php.ini << EOF
      [opcache]
      zend_extension=opcache.so
      opcache.enable=1
      EOF

      # 启动php-fpm服务并设为开机启动
      systemctl daemon-reload
      systemctl enable --now php-fpm.service

    二、修改配置文件

      1)、修改php-fpm进程所有者和支持status和ping页面,支持opcache加速

        [root@localhost ~]#vim /apps/php74/etc/php-fpm.d/www.conf   

        user = apache
        group = apache

        pm.status_path = /status

        ping.path = /ping

        [root@localhost ~]#vim /etc/php.ini  

        [opcache]
        zend_extension=opcache.so
        opcache.enable=1

        重启服务

        systemctl enable --now php-fpm

      2)、修改配置httpd支持php-fpm

        [root@localhost ~]#vim /apps/httpd/conf/httpd.conf

        #取消下面两行注释,打开代理功能

        LoadModule proxy_module modules/mod_proxy.so

        LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

        #加上下面5行,添加fcgi配置文件 

        AddType application/x-httpd-php .php
        ProxyRequests off
        DirectoryIndex index.php
        ProxyPassMatch ^/(.*.php)$ fcgi://localhost:9000/data/html/$1
        ProxyPassMatch ^/(status|ping) fcgi://localhost:9000/

      3)、准备wordpress相关文件

        tar xf wordpress-5.4.2-zh_CN.tar.gz

        chown apache.apache wordpress -R

        mv wordpress /data/html/

    三、在10.0.0.216上安装mysql并创建相关数据库和用户并授权

        MariaDB [(none)]> create database wordpress;

        MariaDB [(none)]> create user wpuser@'10.0.0.%' identified by '123456';

        MariaDB [(none)]> grant all on wordpress.* to  wpuser@'10.0.0.%';

    四、在10.0.0.213上安装nfs服务

      1)、安装软件包nfs-utils

        [root@centos7 ~]#yum -y install nfs-utils

      2)、nfs共享文件配置

        [root@centos7 ~]#vim /etc/exports 

        /data/nfsdir3 10.0.0.0/24(rw,no_root_squash)

        启动服务并设为开机启动

        systemctl enable --now nfs-server.service

        查看共享目录   

        [root@centos7 ~]#exportfs -v
        /data/nfsdir3 10.0.0.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)

    五、在10.0.0.212上安装nfs客户端,并将用户上传的图片保存至NFS服务器上

      1)、安装nfs-utils软件,并将远程NFS服务器的/data/nfsdir3目录挂载到本地/data/html/wordpress/wp-content/uploads/目录

        [root@localhost ~]#yum -y install nfs-utils

        [root@localhost ~]#mount 10.0.0.213:/data/nfsdir3 /data/html/wordpress/wp-content/uploads/

      2)、打开浏览器访问http://10.0.0.212/wordpress测试,创建博客并上传图片

      3)、在10.0.0.213NFS服务器上可以看到文件已保存    

        [root@centos7 nfsdir3]#tree
        .
        └── 2020
          └── 09
            └── vim351224256347233230345233276.png

        2 directories, 1 file

  • 相关阅读:
    试算平衡
    对账服务
    会计科目与账户
    支付系统难点全面梳理剖析:核算对账核心
    支付系统设计——你不可不知的会计核心(转发整理)
    支付系统设计之查漏补缺的一环:差错账处理
    支付清算业务总结
    财务对账系统v1.0立项到结项的整体回顾
    DNS视图及压力测试(四)
    一个快速检测系统CPU负载的小程序
  • 原文地址:https://www.cnblogs.com/babyblue3/p/13667362.html
Copyright © 2011-2022 走看看