如何准备Google Associate云工程师认证考试?

负载均衡:

1: 谷歌负载均衡

按照地区分成global & region
按照外部和内部流量LB可以分为:HTTPS load balancing, SSL Proxy, TCP proxy Network TCP/UDP LB(外部);和Intern TCP/UDP LB(内部)。
谷歌的LB针对全球的LB可以使用谷歌的premier tier network(谷歌自主拥有光网)如果是regional LB可以考虑使用standard tier network(就是谷歌和其他服务商共享网路)
如何准备Google Associate云工程师认证考试?_第1张图片
参考文档:
【1】L3 Network Load Balancer:外部 TCP/UDP 网络负载平衡概览
【2】L7 HTTP(s) Load Balancer:外部 HTTP(S) 负载平衡概览

cat << EOF > 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
gcloud compute instance-templates create nginx-template \
         --metadata-from-file startup-script=startup.sh

Create a target pool. A target pool allows a single access point to all the instances in a group and is necessary for load balancing in the future steps.
创建一个目标池。 目标池允许对组中所有实例的单个访问点,并且对于将来的步骤中的负载平衡是必需的。

gcloud compute target-pools create nginx-pool

Create a managed instance group using the instance template:

gcloud compute instance-groups managed create nginx-group \
         --base-instance-name nginx \
         --size 2 \
         --template nginx-template \
         --target-pool nginx-pool

如何准备Google Associate云工程师认证考试?_第2张图片
创建后查看instance创建详情:

gcloud compute instances list

在这里插入图片描述
现在配置防火墙,以便您可以通过EXTERNAL_IP地址连接到端口80上的计算机:

gcloud compute firewall-rules create www-firewall --allow tcp:80

您应该能够通过http:// EXTERNAL_IP /通过其外部IP地址连接到每个实例,如运行上一条命令的结果所示。
在这里插入图片描述
网络负载平衡使您可以根据传入的IP协议数据(例如地址,端口和协议类型)来平衡系统的负载。 通过HTTP(S)负载平衡,您还会获得一些不可用的选项。 例如,您可以负载均衡其他基于TCP / UDP的协议,例如SMTP通信。 并且,如果您的应用程序对与TCP连接相关的特性感兴趣,则网络负载平衡允许您的应用程序检查数据包,而HTTP(S)负载平衡则不需要。

gcloud compute forwarding-rules create nginx-lb \
         --region us-central1 \
         --ports=80 \
         --target-pool nginx-pool

在这里插入图片描述
然后,您可以从浏览器http:// IP_ADDRESS /访问负载均衡器,其中IP_ADDRESS是运行上一条命令的结果显示的地址。
注意这是一个L3 Network Load Balancer that points to the webservers.


创建一个HTTP负载均衡器

HTTP(S)负载平衡为发往您实例的HTTP(S)请求提供全局负载平衡。 您可以配置URL规则,这些规则将某些URL路由到一组实例,而将其他URL路由到其他实例。 始终将请求路由到最接近用户的实例组,前提是该组具有足够的容量并且适合该请求。 如果最近的组没有足够的容量,则将请求发送到确实有容量的最近的组。

第一步:创建实例健康检查

gcloud compute http-health-checks create http-basic-check

第二步:
Define an HTTP service and map a port name to the relevant port for the instance group. Now the load balancing service can forward traffic to the named port:

gcloud compute instance-groups managed \
       set-named-ports nginx-group \
       --named-ports http:80

Create a backend service:

gcloud compute backend-services create nginx-backend \
      --protocol HTTP --http-health-checks http-basic-check --global

Add the instance group into the backend service:

gcloud compute backend-services add-backend nginx-backend \
    --instance-group nginx-group \
    --instance-group-zone us-central1-a \
    --global

Create a default URL map that directs all incoming requests to all your instances:

gcloud compute url-maps create web-map \
    --default-service nginx-backend

你可能感兴趣的:(Google,Cloud)