如何在 Google Cloud 上设置快速加载 WordPress 网站?

使用 WordOps 在 Google Cloud Platform (GCP) 上启动高性能 WordPress 网站的分步指南。

当你开始做博主或经营一家小企业时, 共享主机 很好,因为它成本更低,并且不需要托管技能来安装/设置/维护基础设施平台。

但是,当您的流量或用户群增加时,您需要一个强大的托管平台来为数百万客户提供服务,而不会降低网站速度。

有一些针对流量大的网站的高级托管服务提供商,但每月的费用很容易达到 100 美元以上。

笔记: 金斯塔 最近宣布了一项启动计划,起价为每月 30 美元,该计划利用了 GCP。

但是,如果您愿意花一点时间学习并自己动手,您可以考虑 VPS/云服务器。 本文将解释如何在不到 15 分钟的时间内让 WordPress 网站在 Google Cloud Platform 上运行。

这种设置每月花费大约 25 美元,并且准备好每月提供 500,000 次页面浏览量。 设置后,我将进行负载测试以验证性能。

先决条件

  • 我假设您已经有一个域; 如果没有,您可以从 Namecheap 或 Google 购买。
  • 已启用结算功能的 Google 云帐户
  • 一些 WordPress 主题,但我会使用 报纸标签 div.

配置新的 Google Cloud 服务器

  • 登录 Google Cloud 并转到 Compute Engine >> VM Instances (直接链接)
  • 单击“创建实例”并输入所需信息。
  • 选择区域(选择目标受众最近的位置)
  • 选择机器类型。
  • 将启动磁盘更改为 Ubuntu 18.04 LTS,并将启动磁盘类型更改为 10 GB 大小的 SSD 永久磁盘。
  • 允许 HTTP 和 HTTPS 防火墙并单击创建
  什么是 Deepfake,我应该担心吗?

几秒钟后,您将准备好新实例。

使用 WordOps 安装 WordPress

安装 WordPress 有多种方法,但最简单的方法之一是使用 文字操作.

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/

[email protected]:~#

现在是时候创建一个 WordPress 网站了。 如果您想安装带有缓存插件的 WordPress,WordOps 为您提供了一个选项。

目前支持WP Super、W3 Total、Nginx、Redis。 我已经尝试了所有方法,Redis 对我来说总是表现得更好。

  • 让我们用 Redis 缓存创建一个站点。
wo site create geekflarelab.com --wpredis

上面,我要求 WordOps 使用 Redis 缓存为 geekflarelab.com(这是我的实验室域)创建一个站点。 这将需要一两分钟的时间,然后确认有关站点创建的信息。

[email protected]:~# wo site create geekflarelab.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://geekflarelab.com/wp-admin/options-general.php?page=redis-cache
Object Cache:		Enable
Successfully created site http://geekflarelab.com
[email protected]:~#
  • 安全保存密码。
  创建和分享有趣内容的集合

WordPress 已成功安装,是时候将您的域指向服务器 IP。 那很简单。 不是吗?

获取静态 IP

默认情况下,Google Cloud 会为您不想使用域配置的实例分配一个临时 IP,因为它可能会在下次实例重启时发生变化。

为规避风险,我们将保留一个静态IP。

  • 从左侧导航转到 VPC 网络 >> 外部 IP 地址。
  • 下拉 Ephemeral 类型并选择 static

  • 提供名称并单击“保留”。
  • 您会注意到类型更改为静态。

GCP VM 已准备好静态外部 IP 和 WordPress,最后要做的是将域映射到静态 IP。

更新域 A 记录

  • 去域名注册商
  • 将您的域的 A 记录更新为您刚刚保留的外部 IP

可能需要一些时间才能在全球范围内传播。 您可以使用 DNS 记录查找工具进行验证。

更新域 A 记录后,您可以使用您在 WordOps 命令中使用的域访问 WordPress 站点。 在我的例子中——http://geekflarelab.com

执行负载测试

让我们看看 Google Cloud Platform 上新设置的 WordPress 网站的表现如何。 在进行速度测试之前,我将安装一个主题 塔格迪夫, 如前面提到的。

这不是必需的,但为了确保我有一些帖子/媒体文件来模拟真实场景。

如您所见,geekflarelab.com 已在 GCP 上准备就绪。

执行基准测试有多种方法,其中一种最简单的方法是从云中进行。 我使用 Loader.io 为 100 到 500 个用户加载了一分钟,结果是:

平均响应时间 = 695 毫秒

我知道这是一个基本的 WordPress 设置,需要安装额外的插件, 添加安全性, SSL 证书等在生产环境中。 但这会使加载时间增加几个百分比。

结论

我希望这能让您了解如何在 Google Cloud Platform 上设置 WordPress。 这需要一点时间来设置和技能,但如果您想每月节省 $$,我相信这是值得的。

  如何在 Pandora 中随机播放电台

或者,如果您没有时间设置或管理 WordPress,同时又想享受 Google Cloud,那么您可以尝试 Cloudways托管托管平台.