day28

题目

  1. 实战 YUM 构建 LNMP 发布 2 个网站:Discuz 论坛、Wordpress,MYSQL 采用主主架构。
  2. 以上实验 Nginx 单独 1 台(发布两个网站 wp.jd.com
    dz.jd.com),PHP-FPM 单独 2 台,MYSQL 主主 2 台,Nginx 和 2 台 PHP-FPM 不能部署在一台机器哦。将所有部署过程写出来和划出架构图。

解答

实验环境

  • mysql: 192.168.0.111
  • mysql: 192.168.0.112
  • nginx: 192.168.0.110
  • discuz: 192.168.0.110
  • wordpress: 192.168.0.110
  • php-fpm-1:192.168.0.111
  • php-fpm-2:192.168.0.112
  • client: 192.168.0.105

架构图

192.168.0.112
192.168.0.111
192.168.0.110
Wordpress-112
PHP-FRM-112
MySQL-112
Discuz-111
PHP-FPM-111
MySQL-111
Discuz-110
Nginx-110
Wordpress-110
internet-105
master:master

部署步骤

1. 部署 mysql

服务器:192.168.0.111, 192.168.0.112

  1. 安装 mysql 并搭建主主架构测试完成。

  2. 创建账号:

    -- 创建用户
    > create user 'discuz'@'%' identified with mysql_native_password by 'WahahaAyaya123!';
    > create user 'wordpress'@'%' identified with mysql_native_password by 'WahahaAyaya123!';
    
    -- 授权
    > grant all on *.* to 'discuz'@'%';
    > grant all on *.* to 'wordpress'@'%';
    
    -- 创建数据库
    -- discuz 会自己创建
    > create database wordpress;
    
2. 部署 php-fpm

服务器:192.168.0.111, 192.168.0.112

# 打开配置文件
$ vim /etc/php-fpm.d/www.conf
# 修改监听端口
listen = 0.0.0.0:9000
# 修改访问权限
listen.allowed_clients = 127.0.0.1,192.168.0.110

# 启动服务
$ systemctl restart php-fpm.service

# 查看端口
$ netstat -tnlp
3. 部署 nginx

服务器:192.168.0.110

  1. 使用源码安装 nginx 到 /usr/local/nginx/ 下并测试完成。

  2. 配置 nginx.conf:

    # 编辑主配置文件
    $ vim /usr/local/nginx/conf/nginx.conf
    # 将虚拟主机模块移除并添加引用字段
    worker_processes  1;
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
    
        keepalive_timeout  65;
    
        # 虚拟主机配置文件目录
        include       /usr/local/nginx/conf/modules/*.conf;
    }
    
  3. 配置 discuz.conf:

    # 编辑配置文件
    $ vim /usr/local/nginx/conf/modules/discuz.conf
    # 配置虚拟主机参数
    server {
        listen       80;
        server_name  dz.jd.com;
    
        location / {
            root   /usr/local/nginx/html/discuz;
            index  index.php index.html index.htm;
        }
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    
        location ~ \.php$ {
            root           /usr/local/html/;
            fastcgi_pass   192.168.0.111:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    
  4. 配置 wordpress.conf:

    # 编辑配置文件
    $ vim /usr/local/nginx/conf/modules/wordpress.conf
    # 配置虚拟主机参数
    server {
        listen       80;
        server_name  wp.jd.com;
    
        location / {
            root   /usr/local/nginx/html/wordpress;
            index  index.php index.html index.htm;
        }
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    
        location ~ \.php$ {
            root           /usr/local/html/;
            fastcgi_pass   192.168.0.112:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    
  5. 重启生效:$ nginx -s reload

4. 部署 discuz
  1. 服务器:192.168.0.110

    # 解压
    $ unzip Discuz_X3.4_SC_UTF8_20220811.zip -d /usr/local/nginx/html/discuz
    
    # 移动文件
    $ cd /usr/local/nginx/html/discuz/
    $ \mv upload/* ./
    
    # 拷贝配置文件文件
    $ cd config/
    $ cp config_global_default.php config_global.php
    $ cp config_ucenter_default.php config_ucenter.php
    
    # 将文件拷贝到 111
    $ cd ..
    $ scp -r ./* 192.168.0.111:/usr/local/html/
    
  2. 服务器:192.168.0.111

    # 授权
    $ cd /usr/local/html/
    $ chown -R apache.apache data/ config/ uc_client/ uc_server/
    
    # 编辑 hosts
    $ vim /etc/hosts
    # 插入域名
    127.0.0.1   mysql.jd.com
    
  3. 浏览器访问 dz.jd.com,并按照提示安装 discuz。

  4. 服务器:192.168.0.111

    # 将 192.168.0.111 发布目录下的文件同步到 192.168.0.110 的发布目录
    $ scp -r /usr/local/html/* 192.168.0.110:/usr/local/nginx/html/discuz/
    
  5. 服务器:192.168.0.110

    # 重启 nginx
    $ nginx -s reload
    
  6. 浏览器登陆测试:每次缺少 CSS 文件时都需要将 192.168.0.111 上的静态文件拷贝到 192.168.0.110。

    discuz

5. 部署 wordpress
  1. 服务器:192.168.0.112

    # 创建发布目录
    $ /usr/local/html/
    
    # 编辑 hosts
    $ vim /etc/hosts
    # 插入域名
    127.0.0.1   mysql.jd.com
    
  2. 服务器:192.168.0.110

    # 解压到发布目录
    $ tar xf ~/wordpress-4.9.4-zh_CN.tar.gz -C /usr/local/nginx/html/
    
    # 拷贝配置文件
    $ cd /usr/local/nginx/html/wordpress/
    $ cp wp-config-sample.php wp-config.php
    
    # 将文件拷贝到 192.168.0.112
    $ cd ..
    $ scp -r ./wordpress/* 192.168.0.112:/usr/local/html/
    
  3. 服务器:192.168.0.112

    # 编辑配置文件
    $ vim /usr/local/html/wp-config.php
    # 配置数据库信息
    define('DB_NAME', 'wordpress');
    define('DB_USER', 'wordpress');
    define('DB_PASSWORD', 'WahahaAyaya123!');
    define('DB_HOST', 'mysql.jd.com');
    
  4. 浏览器访问 wp.jd.com 根据提示安装。

  5. 服务器:192.168.0.112

    # 将 192.168.0.111 发布目录下的文件同步到 192.168.0.110 的发布目录
    $ scp -r /usr/local/html/* 192.168.0.110:/usr/local/nginx/html/wordpress/
    
  6. 服务器:192.168.0.110

    # 重启 nginx
    $ nginx -s reload
    
  7. 浏览器登陆测试:

    wordpress

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tp404

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值