题目
- 实战 YUM 构建 LNMP 发布 2 个网站:Discuz 论坛、Wordpress,MYSQL 采用主主架构。
- 以上实验 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
架构图
部署步骤
1. 部署 mysql
服务器:192.168.0.111, 192.168.0.112
-
安装 mysql 并搭建主主架构测试完成。
-
创建账号:
-- 创建用户 > 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
-
使用源码安装 nginx 到 /usr/local/nginx/ 下并测试完成。
-
配置 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; }
-
配置 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; } }
-
配置 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; } }
-
重启生效:
$ nginx -s reload
4. 部署 discuz
-
服务器: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/
-
服务器: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
-
浏览器访问 dz.jd.com,并按照提示安装 discuz。
-
服务器: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/
-
服务器:192.168.0.110
# 重启 nginx $ nginx -s reload
-
浏览器登陆测试:每次缺少 CSS 文件时都需要将 192.168.0.111 上的静态文件拷贝到 192.168.0.110。
5. 部署 wordpress
-
服务器:192.168.0.112
# 创建发布目录 $ /usr/local/html/ # 编辑 hosts $ vim /etc/hosts # 插入域名 127.0.0.1 mysql.jd.com
-
服务器: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/
-
服务器: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');
-
浏览器访问 wp.jd.com 根据提示安装。
-
服务器: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/
-
服务器:192.168.0.110
# 重启 nginx $ nginx -s reload
-
浏览器登陆测试: