Google 简介
什么是 Google Cloud?
Google Cloud Platform (GCP) 是 Google 提供的云计算服务,涵盖计算、存储、AI/ML、安全、数据库等领域。
info
GCP 适用于各类开发者和企业,提供高可用、可扩展的云计算解决方案。
Google Cloud 主要服务
| 服务 | 描述 | 适用场景 |
|---|---|---|
| Compute Engine | 提供可扩展的虚拟机实例 | 托管应用、Web 服务器 |
| Cloud Storage | 对象存储,适用于大规模数据存储 | 备份、日志存储、大数据 |
| Cloud SQL | 托管关系数据库,如 MySQL、PostgreSQL | 数据库托管 |
| Cloud Functions | 无服务器计算,按需运行代码 | 事件驱动应用、微服务 |
| Firestore | NoSQL 数据库,实时数据同步 | 移动端应用、IoT、实时数据 |
| IAM | 身份访问管理,控制 GCP 资源权限 | 访问控制、安全管理 |
GCP 代码示例
- Python
- JavaScript
from google.cloud import storage
client = storage.Client()
buckets = list(client.list_buckets())
for bucket in buckets:
print(bucket.name)
const { Storage } = require("@google-cloud/storage");
const storage = new Storage();
async function listBuckets() {
const [buckets] = await storage.getBuckets();
buckets.forEach((bucket) => console.log(bucket.name));
}
listBuckets();
GCP Cloud Functions 示例
- Python
- Node.js
def hello_world(request):
return 'Hello from Google Cloud Functions!'
exports.helloWorld = (req, res) => {
res.send("Hello from Google Cloud Functions!");
};
部署 Google Cloud 资源
如何使用 gcloud CLI 创建 Cloud Storage 存储桶
gcloud storage buckets create my-new-bucket --location=us-central1
如何使用 Terraform 部署 GCE 实例
provider "google" {
project = "my-gcp-project"
region = "us-central1"
}
resource "google_compute_instance" "vm_instance" {
name = "example-instance"
machine_type = "e2-micro"
zone = "us-central1-a"
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}
network_interface {
network = "default"
}
}
结论
Google Cloud 提供了丰富的云计算服务,适用于不同的业务场景。无论是计算、存储、数据库,还是无服务器架构,GCP 都能提供灵活高效的解决方案。