【发布时间】:2021-01-29 09:13:33
【问题描述】:
This is the screenshot of the problem
我正在创建一个 NGINX 实例,在管理实例组时,我遇到了这个问题。云中的提示说“请使用 2 个 NGINX Web 服务器创建托管实例组”。久违了,我该怎么办?
【问题讨论】:
标签: nginx google-cloud-platform cloud
This is the screenshot of the problem
我正在创建一个 NGINX 实例,在管理实例组时,我遇到了这个问题。云中的提示说“请使用 2 个 NGINX Web 服务器创建托管实例组”。久违了,我该怎么办?
【问题讨论】:
标签: nginx google-cloud-platform cloud
您正在尝试使用 GCP 托管实例组 (MIG),为此您需要有一个实例模板,MIG 将从该模板中获取信息以进行部署。
长话短说,您是在定义您希望您的资源有多大,但您并没有指定这些资源是什么。
如果您愿意,可以关注此guide,但这是它的简短版本:
gcloud compute instance-templates create nginx-template \
--machine-type e2-standard-4 \
--image-family debian-9 \
--image-project debian-cloud \
--boot-disk-size 250GB
由于您使用的是 qwiklabs,因此该模板或您正在使用的模板不再存在,并且这些项目会在一段时间后被删除。
【讨论】:
您可以按照以下步骤完成任务-
创建startup.sh文件
#! /bin/bash
apt-get update
apt-get install -y nginx
service nginx start
sed -i -- 's/nginx/Google Cloud Platform - '"\$HOSTNAME"'/' /var/www/html/index.nginx-debian.html
EOF
gcloud compute instance-templates create web-server-template \
--metadata-from-file startup-script=startup.sh \
--network nucleus-vpc \
--machine-type g1-small \
--region us-east1
gcloud compute instance-groups managed create web-server-group \
--base-instance-name web-server \
--size 2 \
--template web-server-template \
--region us-east1
gcloud compute firewall-rules create web-server-firewall \
--allow tcp:80 \
--network nucleus-vpc
gcloud compute http-health-checks create http-basic-check
gcloud compute instance-groups managed \
set-named-ports web-server-group \
--named-ports http:80 \
--region us-east1
gcloud compute backend-services create web-server-backend \
--protocol HTTP \
--http-health-checks http-basic-check \
--global
gcloud compute backend-services add-backend web-server-backend \
--instance-group web-server-group \
--instance-group-region us-east1 \
--global
gcloud compute url-maps create web-server-map \
--default-service web-server-backend
gcloud compute target-http-proxies create http-lb-proxy \
--url-map web-server-map
gcloud compute forwarding-rules create http-content-rule \
--global \
--target-http-proxy http-lb-proxy \
--ports 80
gcloud compute forwarding-rules list
等待额外 10 分钟以在 HTTP 负载平衡器后面创建网站。
【讨论】:
对于上一条评论,我只想补充一点,需要多一行 -
gcloud container clusters create nucleus-jumphost-webserver1
取自这里 - https://gist.github.com/Tambunan26/9063521fdf406645aad4527ccd069149
【讨论】: