使用 WordOps 在 Google Cloud Platform (GCP) 上启动高性能 WordPress 网站的分步指南。
如果您刚开始作为博主或经营小型企业,共享托管是一个不错的选择,因为它更便宜,并且不需要任何托管技能来安装/设置/维护基础设施平台。
然而,随着您的流量和用户群的增加,您需要一个强大的托管平台,可以为数百万客户提供服务,而不会减慢您的网站速度。
有几家针对高流量网站的高级托管提供商,但它们的费用每月高达 100 美元。
注意:Kinsta 最近宣布了一项利用 GCP 的入门计划,起价为每月 30 美元。
但是,如果您不介意花一点时间学习或自己动手,可以考虑使用 VPS/云服务器。本文向您展示如何在 15 分钟内在Google Cloud Platform 上运行 WordPress 网站。
此设置每月的费用约为 25 美元,可让您每月提供 500,000 次页面浏览量。设置后,运行负载测试以检查性能。
先决条件
- 我假设您已经有一个域。如果没有,您可以从 Namecheap 或 Google 购买。
- 已启用结算功能的 Google 云帐户
- 有几个 WordPress 主题,但我使用带有标签 div 的 Newspaper 。

配置新的 Google Cloud 服务器
- 登录 Google Cloud 并转到 Compute Engine >> VM 实例( 直接链接)。
- 单击创建实例并输入所需信息。
- 选择区域(选择最接近目标受众的位置)
- 选择您的机器类型。
- 将启动磁盘更改为 Ubuntu 18.04 LTS,并将启动磁盘类型更改为 10 GB 大小的 SSD 永久磁盘。
- 允许 HTTP 和 HTTPS 防火墙并单击创建。
您的新实例将在几秒钟内准备就绪。

使用 WordOps 安装 WordPress
安装 WordPress 的方法有多种,但最简单的方法之一是使用WordOps 。
WordOps 是一个脚本包装器,用于处理必要组件的安装,例如数据库、PHP-FPM、Nginx、WordPress、Redis、phpMyAdmin 等。手动安装这些可能非常耗时并且容易出现人为错误。
- 登录新创建的Google Cloud VM并切换到root用户
注意:虽然我们建议在生产环境中设置普通用户对 root 的 sudo 访问权限,但我们将在本练习中使用 root。
- 使用以下命令安装WordOps
wget -qO wo wops.cc && sudo bash wo- 这将需要一两分钟,但完成后您将返回到提示。
Synchronizing wo database, please wait... WordOps (wo) installed successfully To enable bash-completion, just use the command: bash -l To install WordOps recommended stacks, you can use the command: wo stack install To create a first WordPress site, you can use the command: wo site create site.tld --wp WordOps Documentation : https://docs.wordops.net WordOps Community Forum : https://community.wordops.net WordOps Community Chat : https://chat.wordops.net Give WordOps a GitHub star : https://github.com/WordOps/WordOps/ root@ubuntu-s-1vcpu-2gb-lon1-01:~#
现在是时候创建一个 WordPress 网站了。 WordOps 为您提供了安装带有缓存插件的 WordPress 的选项。
目前支持 WP Super、W3 Total、Nginx 和 Redis。我都尝试过, Redis总是表现得更好。
- 让我们使用 Redis 缓存创建一个站点。
wo site create lab.com --wpredis上面,我们要求 WordOps 使用 Redis 缓存为 lab.com(这是我实验室的域)创建一个站点。这将需要一两分钟,系统将提示您创建站点。
root@ubuntu-s-1vcpu-2gb-lon1-01:~# wo site create lab.com --wpredis
Start : wo-kernel [OK]
Adding repository for MySQL, please wait...
Adding repository for NGINX, please wait...
Adding repository for PHP, please wait...
Adding repository for Redis, please wait...
Updating apt-cache [OK]
Installing APT packages [OK]
Applying Nginx configuration templates
Testing Nginx configuration [OK]
Restarting Nginx [OK]
Testing Nginx configuration [OK]
Restarting Nginx [OK]
Configuring php7.2-fpm
Restarting php7.2-fpm [OK]
Tuning MariaDB configuration
Stop : mysql [OK]
Start : mysql [OK]
Tuning Redis configuration [OK]
Restarting redis-server [OK]
Running pre-update checks [OK]
Setting up NGINX configuration [Done]
Setting up webroot [Done]
Downloading WordPress [Done]
Setting up database [Done]
Configuring WordPress [OK]
Installing WordPress [OK]
Installing plugin nginx-helper [OK]
Setting plugin nginx-helper [OK]
Installing plugin redis-cache [OK]
Testing Nginx configuration [OK]
Reloading Nginx [OK]
HTTP Auth User Name: WordOps
HTTP Auth Password : XXXXXX
WordOps backend is available on https://XX.XX.XX.XX:22222 or https://ubuntu-s-1vcpu-2gb-lon1-01:22222
WordPress admin user : Chandan Kumar
WordPress admin password : lyWwnfOhD8XXXXXXNTS3vXri
Configure redis-cache: http://lab.com/wp-admin/options-general.php?page=redis-cache
Object Cache: Enable
Successfully created site http://lab.com
root@ubuntu-s-1vcpu-2gb-lon1-01:~#- 请安全保存您的密码。
现在 WordPress 已成功安装,请将您的域名指定为服务器 IP。那很容易。不是吗?

获取静态IP
默认情况下,Google Cloud 会将临时 IP分配给您不希望配置域名的实例,因为该 IP 可能会在实例下次重新启动时发生更改。
预留静态IP,规避风险。
- 从左侧导航导航至 VPC 网络 >> 外部 IP 地址。
- 下拉临时类型并选择静态
- 为其命名并单击“保留”。
- 可以看到类型已经变成static了。
GCP 虚拟机配有静态外部 IP 和 WordPress。最后要做的是将您的域映射到静态 IP 。

更新域A记录
- 前往域名注册商
- 将您域的 A 记录更新为您保留的外部 IP。
它可能需要一段时间才能在全球范围内流行。您可以使用 DNS 记录搜索工具进行检查。
更新域 A 记录后,您现在可以在 WordOps 命令中使用的域上访问您的 WordPress 网站。在我的例子中 – http://lab.com

运行负载测试
让我们看一下在 Google Cloud Platform 上新建立的 WordPress 网站是如何工作的。在进行速度测试之前,请如上所述使用Tagdiv安装主题。
这不是必需的,但它可以确保您拥有帖子/媒体文件来模拟真实的站点场景。
如您所见,lab.com 已在 GCP 上做好准备。
运行基准测试的方法有多种,但最简单的方法之一是从云端运行它们。以下是使用Loader.io加载 100-500 个用户 1 分钟的结果:
平均响应时间 = 695 毫秒
我们知道这是一个基本的 WordPress 设置,生产环境需要额外的插件安装、安全性、SSL 证书等。但是,加载时间会增加几个百分点。
结论
我们希望这可以帮助您了解如何在 Google Cloud Platform 上设置 WordPress。设置需要一些时间和技巧,但如果您想每月节省 $$,我认为这是值得的。
或者,如果您没有时间设置或管理 WordPress,但又想同时使用 Google Cloud,则可以尝试Cloudways 托管平台。




![2021 年如何设置 Raspberry Pi Web 服务器 [指南]](https://i0.wp.com/pcmanabu.com/wp-content/uploads/2019/10/web-server-02-309x198.png?w=1200&resize=1200,0&ssl=1)

