为专用 IP Looker (Google Cloud Core) 实例设置自定义网域:来自不同区域的流量

您可以通过自定义网域(而不是 Looker (Google Cloud Core) 提供的默认网域)提供 Looker (Google Cloud Core) 实例。

本文档页面介绍了如何为同时满足以下两个条件的实例设置和访问自定义网域:

  • 该实例仅限专用 IP。
  • 流向实例的流量来自与实例所在区域不同的区域,或者来自混合网络。

要为此类实例实现自定义网域,请执行以下步骤:

  1. 设置自定义网域
  2. 创建虚拟机和专用区域
  3. 配置反向代理服务器
  4. 创建并配置负载均衡器
  5. 创建防火墙规则
  6. 更新 DNS A 记录
  7. 更新 OAuth 凭据

设置自定义域名

创建 Looker (Google Cloud Core) 实例后,您可以为实例设置自定义网域。

准备工作

在自定义 Looker (Google Cloud Core) 实例的网域之前,请先确定您网域的 DNS 记录的存储位置,以便更新这些记录。

所需的角色

如需获取为 Looker (Google Cloud Core) 实例创建自定义网域所需的权限,请让管理员向您授予该实例所在项目的 Looker Admin (roles/looker.admin) IAM 角色。 如需详细了解如何授予角色,请参阅管理访问权限

您也可以通过自定义角色或其他预定义角色来获取所需的权限。

创建自定义网域

在 Google Cloud 控制台中,请按照以下步骤自定义 Looker (Google Cloud Core) 实例的网域:

  1. 实例页面上,点击要为其设置自定义网域的实例的名称。
  2. 点击自定义网域标签页。
  3. 点击添加自定义网域

    此时将打开添加新的自定义网域面板。

  4. 为您要使用的网站域名输入主机名(最多 64 个字符),请仅使用字母、数字和短划线。例如:looker.examplepetstore.com

  5. 点击添加新的自定义网域面板上的完成,返回到自定义网域标签页。

Google Cloud 控制台实例页面上的实例网址列会显示您的自定义网域。

创建自定义网域后,您可以查看相关信息或将其删除

访问自定义网域

当流向仅专用 IP 的 Looker (Google Cloud Core) 实例的流量源自与该实例不同的区域时,您可以使用一个或多个专用 IP 反向代理服务器和一个负载均衡器来提供对该实例的安全访问。

准备工作

如需获取设置对专用 IP 自定义网域的访问权限所需的权限,请让管理员向您授予对实例所在项目的以下 IAM 角色:

如需详细了解如何授予角色,请参阅管理访问权限

您也可以通过自定义角色或其他预定义角色来获取所需的权限。

网络概览

以下部分介绍了如何使用负载均衡器创建冗余 NGINX 或 Apache 代理服务器设置,以将流量从任何区域或从本地路由到自定义网域。下图表示此拓扑:

一个 Google Cloud 网络,显示了使用 Cloud Router、内部负载均衡器和专用服务访问通道对 Looker (Google Cloud Core) 实例的安全访问。

创建虚拟机和专用区域

  1. 创建两个运行 RHEL 操作系统且仅支持专用 IP 的虚拟机实例。这些虚拟机将充当您的代理服务器。它们应该与 Looker (Google Cloud Core) 实例位于同一区域内,但彼此位于不同的可用区。
  2. 创建 Cloud DNS 专用区域以管理您的 Cloud DNS 记录。专用区域应该对 Looker (Google Cloud Core) 实例所在的 VPC 可见。VPC 和本地主机将使用 Cloud DNS 专用区域进行 DNS 解析,以访问 Looker (Google Cloud Core) 界面。由于您将使用负载均衡器,因此 Cloud DNS 专用区域中的 A 记录将映射到负载均衡器的 IP 地址。

配置反向代理服务器

您可以使用任何可配置为反向代理服务器的 Web 服务器。选择下列选项之一,查看如何使用 NGINX 或 Apache 设置反向代理服务器的示例:

NGINX

以下示例使用 NGINX 1.22.1 版和 Red Hat Enterprise Linux 8.9 版 (Ootpa)。如需查看您的虚拟机正在使用的 NGNIX 和 Red Hat 的哪个版本,请针对每个虚拟机运行以下命令。

  1. 首先,连接到虚拟机

  2. 使用以下命令安装 NGINX:

    sudo yum install nginx -y
    
  3. 如需查找虚拟机运行的 NGINX 版本,请运行以下命令:

    sudo nginx -v
    

    返回的内容应类似于以下内容:

    nginx version: nginx/1.22.1

  4. 如需检查虚拟机正在运行的 NGINX 版本,请运行以下命令:

    sudo rpm -qi nginx | grep Release
    

    返回的内容应类似于以下内容:

    Release : 1.module+el8.8.0+20355+6d9c8a63.1

  5. 如需检查您的虚拟机正在使用的 Red Hat 版本,请运行以下命令:

    sudo cat /etc/redhat-release
    

如需设置每个代理服务器,请分别针对您创建的两个虚拟机使用以下说明。

  1. 连接到虚拟机
  2. 修改 /etc/nginx/nginx.conf 文件以包含以下配置:

    events {
      worker_connections 1024;
    }
    
    http {
      log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';
    
      log_format debug  '$http_x_forwarded_for - $remote_user [$time_local] '
                        '"$request_method $scheme://$host$request_uri $server_protocol" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" $request_time';
    
      access_log  /var/log/nginx/access.log  debug;
    
      sendfile            on;
      tcp_nopush          on;
      keepalive_timeout   65;
        types_hash_max_size 4096;
    
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
    
    server {
      listen 443 ssl;
      # listen [::]:443 ssl;
      include snippets/self-signed.conf;
      # include snippets/ssl-params.conf;
      server_name CUSTOM_DOMAIN;
      location / {
        proxy_pass https://INGRESS_PRIVATE_IP/$request_uri;
        proxy_set_header Host $server_name;
        proxy_http_version 1.1;
      }
    }
    server {
      listen 80;
      # listen [::]:80;
      server_name CUSTOM_DOMAIN;
      return 302 https://$server_name$request_uri;
      }
    }
    

    请替换以下内容:

    • CUSTOM_DOMAIN:您的 Looker (Google Cloud Core) 实例的自定义网域
    • INGRESS_PRIVATE_IP:Looker (Google Cloud Core) 实例的入站流量专用 IP

    此外,请考虑以下事项:

    • 这是一项仅限 IPv4 的配置。如果您要求代理也监听其专用 IPv6 地址,请取消注释文件中 listen [::]:443 ssl 行。
    • 访问日志级别已设置为 debug;请务必将其调整为您的特定环境中使用的级别。
    • 如果您实现 ssl-params.conf 文件(这些步骤稍后会引用),请取消注释 include snippets/ssl-params.conf
  3. 创建引用 Looker (Google Cloud Core) 自定义网域网址的有效 TLS 证书。此证书将是代理向尝试访问 Looker (Google Cloud Core) 的客户端提供的证书。您的客户端必须信任用于签署证书的证书授权机构 (CA);您也可以使用内部私有 CA 对此 TLS 证书签名。(或者,您也可以使用自行管理的 SSL 证书。)

    在此示例中,假设已使用 Let's Encrypt 免费服务创建了证书,但没有通过 Certbot 设置自动续订。创建证书后,将相关文件保存在每个代理虚拟机上的 certsprivate 目录中:

    /etc/pki/tls/certs/custom-domain.custom-domain.com.fullchain.pem;
    /etc/pki/tls/private/custom-domain.custom-domain.com.key.pem;
    

    custom-domain.custom-domain.com 替换为您的自定义网域。

    如果安装中不存在 certsprivate 目录,您可以创建这些目录或使用其他文件夹。

  4. 为了确保 NGINX 能够提取证书文件,请创建 /etc/nginx/snippets 目录:

    sudo mkdir /etc/nginx/snippets
    
  5. 创建配置文件 /etc/nginx/snippets/self-signed.conf

    sudo touch /etc/nginx/snippets/self-signed.conf
    

    修改配置文件,添加保存的证书文件的路径:

    ssl_certificate /etc/pki/tls/certs/custom-domain.custom-domain.com.fullchain.pem;
    ssl_certificate_key /etc/pki/tls/private/custom-domain.custom-domain.com.key.pem;
    

    custom-domain.custom-domain.com 替换为您的自定义网域。

  6. 如需确认配置文件是否包含对上一步中提到的文件的引用,请运行以下命令:

    sudo more /etc/nginx/snippets/self-signed.conf
    

    它应该返回您添加的文件路径。

  7. (可选)创建 ssl-params.conf NGINX 文件,该文件可用于存储可在将来 NGINX 配置中重复使用的参数。

    该文件的内容应类似于以下内容,供您参考:

    ssl_protocols TLSv1.3;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparam.pem;
    ssl_ciphers EECDH+AESGCM:EDH+AESGCM;
    ssl_ecdh_curve secp384r1;
    ssl_session_timeout  10m;
    ssl_session_cache shared:SSL:10m;
    ssl_session_tickets off;
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 127.0.0.53 valid=300s;
    resolver_timeout 5s;
    # Disable strict transport security for now. You can uncomment the following
    # line if you understand the implications.
    #add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    
  8. 如需将 SELinux 配置为允许 NGINX 将流量转发到 Looker (Google Cloud Core) 入站流量 IP,请将 httpd_can_network_connect SELinux 布尔值参数设置为 1:

    sudo setsebool -P httpd_can_network_connect 1
    
  9. 现在,您可以使用以下命令重启 NGINX 进程:

    sudo systemctl restart nginx
    
  10. 使用以下命令验证 NGINX 是否已正确重启:

    sudo systemctl status nginx
    

    它应该返回类似于以下内容的输出:

    nginx.service - The nginx HTTP and reverse proxy server
      Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
      Active: active (running) since Tue 2024-05-14 11:58:00 UTC; 9min ago
      Process: 144044 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
      Process: 144042 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
      Process: 144039 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
    Main PID: 144045 (nginx)
        Tasks: 2 (limit: 11040)
      Memory: 2.6M
      CGroup: /system.slice/nginx.service
              ├─144045 nginx: master process /usr/sbin/nginx
              └─144046 nginx: worker process
    May 14 11:58:00 proxy-three-eu-w4 systemd[1]: nginx.service: Succeeded.
    May 14 11:58:00 proxy-three-eu-w4 systemd[1]: Stopped The nginx HTTP and reverse proxy server.
    May 14 11:58:00 proxy-three-eu-w4 systemd[1]: Starting The nginx HTTP and reverse proxy server...
    May 14 11:58:00 proxy-three-eu-w4 nginx[144042]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    May 14 11:58:00 proxy-three-eu-w4 nginx[144042]: nginx: configuration file /etc/nginx/nginx.conf test is successful
    May 14 11:58:00 proxy-three-eu-w4 systemd[1]: Started The nginx HTTP and reverse proxy server.
    

Apache

为每个虚拟机完成以下步骤。

  1. 首先,连接到虚拟机

  2. 安装 Apache:

    sudo yum install httpd -y
    
  3. 以下示例使用的是 Red Hat Enterprise Linux 7.9 版。如需检查您的虚拟机正在使用的 Red Hat 版本,请运行以下命令:

    cat /etc/redhat-release
    

    此时应返回以下内容:

    Red Hat Enterprise Linux Server release 7.9 (Maipo)

  4. 以下示例使用的是 Apache 版本 2.4.6。如需检查您的虚拟机正在使用的 Apache 版本,请针对每个虚拟机运行以下命令:

    sudo httpd -version
    

    此时应返回以下内容:

    Server version: Apache/2.4.6 (Red Hat Enterprise Linux)
    Server built:   date
    
  5. 如需详细了解 Apache 服务器,请运行以下命令:

    sudo rpm -qi httpd
    

    此命令应返回类似于以下内容的输出:

    Name        : httpd
    Version     : 2.4.6
    Release     : 99.el7_9.1
    Architecture: x86_64
    Install Date: Tue May  7 15:48:59 2024
    Group       : System Environment/Daemons
    Size        : 3899819
    License     : ASL 2.0
    Signature   : RSA/SHA256, Fri Apr 28 17:09:45 2023, Key ID 199e2f91fd431d51
    Source RPM  : httpd-2.4.6-99.el7_9.1.src.rpm
    Build Date  : Fri Apr 28 16:56:11 2023
    Build Host  : x86-vm-40.build.eng.bos.redhat.com
    Relocations : (not relocatable)
    Packager    : Red Hat, Inc. 
    Vendor      : Red Hat, Inc.
    URL         : http://httpd.apache.org/
    Summary     : Apache HTTP Server
    Description :
    The Apache HTTP Server is a powerful, efficient, and extensible
    web server.
    
  6. 在代理虚拟机上创建配置文件 /etc/httpd/conf.d/ssl.conf,并将以下配置添加到该文件中:

    ServerName custom domain of Looker (Google Cloud core)
    #   SSL Engine Switch:
    #   Enable/Disable SSL for this virtual host.
    SSLEngine on
    #   SSL Protocol support:
    # List the enable protocol levels with which clients will be able to
    # connect.  Disable SSLv2 access by default:
    SSLProtocol all -SSLv2 -SSLv3
    #   SSL Cipher Suite:
    #   List the ciphers that the client is permitted to negotiate.
    #   See the mod_ssl documentation for a complete list.
    SSLCipherSuite HIGH:3DES:!aNULL:!MD5:!SEED:!IDEA
    #   Server Certificate:
    # Point SSLCertificateFile at a PEM encoded certificate.  If
    # the certificate is encrypted, then you will be prompted for a
    # pass phrase.  Note that a kill -HUP will prompt again.  A new
    # certificate can be generated using the genkey(1) command.
    # SSLCertificateFile /etc/pki/tls/certs/localhost.crt
    SSLCertificateFile "/etc/pki/tls/certs/custom domain of Looker (Google Cloud core).crt"
    #   Server Private Key:
    #   If the key is not combined with the certificate, use this
    #   directive to point at the key file.  Keep in mind that if
    #   you've both a RSA and a DSA private key you can configure
    #   both in parallel (to also allow the use of DSA ciphers, etc.)
    # SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
    SSLCertificateKeyFile "/etc/pki/tls/private/custom domain of Looker (Google Cloud core).key"
    SSLProxyEngine On
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    ProxyPreserveHost On
    RewriteEngine On
    AllowEncodedSlashes NoDecode
    ProxyPass / https://private IP of Looker (Google Cloud core)>:443/
    RewriteCond %{REQUEST_URI} ^/render/
    RewriteRule ^(.*)$ https://private IP of Looker (Google Cloud core)>:443/$1 [P]
    RewriteRule ^(.*)$ https://private IP of Looker (Google Cloud core)>:443/$1 [P,NE]
    ProxyPassReverse / https://private IP of Looker (Google Cloud core):443/
    
    

    请替换以下内容:

    • custom domain of Looker (Google Cloud core):您的 Looker (Google Cloud Core) 实例的自定义网域。
    • private IP of Looker (Google Cloud core):您的 Looker (Google Cloud Core) 实例的专用 IP。
  7. 确认 /etc/httpd/conf.d/ssl.conf 文件中引用的目录中有 TLS 证书文件:

    SSLCertificateFile "/etc/pki/tls/certs/custom domain of Looker (Google Cloud core).crt"
    SSLCertificateKeyFile "/etc/pki/tls/private/custom domain of Looker (Google Cloud core).key"
    
  8. 检查是否已安装 mod_ssl

    sudo yum list installed | grep mod_ssl
    

    如果未安装 mod_ssl,请使用以下命令进行安装:

    sudo yum install mod_ssl
    

    安装 mod_ssl 后,您必须通过将以下行添加到 Apache 配置文件 /etc/httpd/conf/httpd.conf 来启用它:

    LoadModule ssl_module modules/mod_ssl.so
    
  9. 在 Apache 配置文件 /etc/httpd/conf/httpd.conf 中,将 Listen 80 替换为 Listen 443

  10. 执行以下命令,以允许 Apache 代理虚拟机将流量转发到 Looker (Google Cloud Core):

    /usr/sbin/setsebool -P httpd_can_network_connect 1
    
  11. 最后,重启 Apache 以应用更改:

    sudo systemctl restart httpd
    
  12. 使用以下命令验证重写模块是否已加载并在 Apache 上准备就绪:

    sudo httpd -M | grep rewrite
    

    它应该返回类似于以下内容的输出:

    rewrite_module (shared)

  13. 最后,启动或重启 Apache 进程,以确保执行所有配置更改:

    sudo systemctl restart httpd
    
  14. 使用以下命令验证 Apache 进程是否已正确重启:

    sudo systemctl status httpd
    

    它应该返回类似于以下内容的输出:

    httpd.service - The Apache HTTP Server
    Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
    Active: active (running) since Tue 2024-05-14 15:41:57 UTC; 1s ago
      Docs: man:httpd(8)
            man:apachectl(8)
    Main PID: 1400 (httpd)
    Status: "Processing requests..."
    CGroup: /system.slice/httpd.service
            ├─1400 /usr/sbin/httpd -DFOREGROUND
            ├─1401 /usr/sbin/httpd -DFOREGROUND
            ├─1402 /usr/sbin/httpd -DFOREGROUND
            ├─1403 /usr/sbin/httpd -DFOREGROUND
            ├─1404 /usr/sbin/httpd -DFOREGROUND
            └─1405 /usr/sbin/httpd -DFOREGROUND
    May 14 15:41:57 proxy-ingress-apache systemd[1]: Starting The Apache HTTP Server...
    May 14 15:41:57 proxy-ingress-apache systemd[1]: Started The Apache HTTP Server.
    

创建和配置负载均衡器

此示例使用具有 GCE_VM_IP 端点的可用区级网络端点组 (NEG) 作为内部直通式网络负载平衡器的后端。如果您希望使用基于实例组的后端,请按照使用虚拟机实例组后端设置内部直通式网络负载平衡器文档页面中的说明操作。

  1. 为您计划在其中部署代理服务器的每个计算可用区创建一个单独的可用区级 NEG。例如,如果您要在部署 Looker (Google Cloud Core) 的区域的三个计算可用区中分别部署代理服务器,则需要创建三个可用区级 NEG。请参阅配额和限制文档页面,了解每个可用区级 NEG 支持的端点数量。

    如需创建可用区级 NEG,请使用以下 gcloud 命令:

    gcloud compute network-endpoint-groups create NEG_NAME --network-endpoint-type=gce-vm-ip \
    --zone=PROXY_INSTANCE_ZONE --network=PROXY_INSTANCE_VPC \
    --subnet=PROXY_INSTANCE_SUBNET
    

    请替换以下内容:

    • NEG_NAME:您要创建的 NEG 的名称。
    • PROXY_INSTANCE_ZONE:代理服务器所在的区域。
    • PROXY_INSTANCE_VPC:包含代理服务器的 VPC。
    • PROXY_INSTANCE_SUBNET:代理服务器所在的子网。

    针对您将在其中部署代理服务器虚拟机的任何其他可用区重复此步骤。

  2. 将每个代理服务器添加到同一可用区内的 NEG:

    gcloud compute network-endpoint-groups update NEG_NAME --zone=PROXY_INSTANCE_ZONE \
    --add-endpoint='instance=PROXY_INSTANCE_NAME'
    

    请替换以下内容:

    • PROXY_INSTANCE_ZONE:代理服务器所在的区域。
    • NEG_NAME:代理服务器所在可用区中的 NEG 的名称。
    • PROXY_INSTANCE_NAME:代理服务器的名称。

    重复此步骤,直到将每个代理服务器虚拟机作为端点添加到 NEG 为止。

  3. 创建将由内部负载均衡器使用的区域健康检查。使用 compute health-checks create 命令:

    gcloud compute health-checks create PROTOCOL NAME \
        --region=REGION \
        --description=DESCRIPTION \
        --check-interval=CHECK_INTERVAL \
        --timeout=TIMEOUT \
        --healthy-threshold=HEALTHY_THRESHOLD \
        --unhealthy-threshold=UNHEALTHY_THRESHOLD \
        PORT_SPECIFICATION \
        ADDITIONAL_FLAGS
    

    请替换以下内容:

    • PROTOCOL:用于健康检查的协议。有效选项包括 grpchttphttpshttp2ssltcp
    • NAME:健康检查的名称。在给定项目中,每个全球健康检查都必须具有唯一的名称,并且区域性健康检查在给定区域内必须具有唯一的名称。
    • REGION:除了区域级外部应用负载均衡器和内部应用负载均衡器之外,其他所有负载均衡器均使用全球健康检查 (--global)。区域级内部应用负载均衡器使用区域级健康检查,其区域必须与后端服务的区域相匹配。
    • DESCRIPTION:可选说明。
    • CHECK_INTERVAL:从一次健康检查探测系统的连接开始到下一次相应连接开始之间的时间量。该时间以秒为单位。如果省略,Google Cloud 使用的值为 5s(5 秒)。
    • TIMEOUT:Google Cloud 等待探测响应的时间量。TIMEOUT 的值必须小于或等于 CHECK_INTERVAL。该时间以秒为单位。如果省略,Google Cloud 使用的值为 5s(5 秒)。
    • HEALTHY_THRESHOLDUNHEALTHY_THRESHOLD:指定虚拟机实例被视为运行状况良好或运行状况不佳所必须成功或失败的连续探测次数。如果省略了其中任何一项,Google Cloud 使用的默认阈值为 2
    • PORT_SPECIFICATION:使用端口指定标志之一定义端口指定方式。
    • ADDITIONAL_FLAGS:用于指定 PROTOCOL 特有的端口和选项的其他标志。请参阅用于 HTTP、HTTPS 和 HTTP/2 健康检查的额外标志用于 SSL 和 TCP 健康检查的额外标志用于 gRPC 健康检查的额外标志
  4. 创建后端服务

    gcloud compute backend-services create BS_NAME --load-balancing-scheme=INTERNAL \
    --protocol=tcp --region=PROXY_INSTANCES_REGION --health-checks=HC_NAME \
    --health-checks-region=HC_REGION --session-affinity=CLIENT_IP \
    --connection-persistence-on-unhealthy-backends=NEVER_PERSIST
    

    请替换以下内容:

    • BS_NAME:您要创建的负载均衡器的名称。
    • PROXY_INSTANCES_REGION:代理服务器所在的区域。
    • HC_NAME:您创建的区域性健康检查的名称。
    • HC_REGION:健康检查所在的区域。

    此外:

    • --session-affinity=CLIENT_IP 标志根据在客户端 IP 地址和目标地址中创建的哈希,将特定客户端的请求定向到同一个后端代理实例虚拟机。
    • --connection-persistence-on-unhealthy-backends=NEVER_PERSIST 标志表示连接在运行状况不佳的代理实例虚拟机上不会保留。
  5. 将每个 NEG 添加到后端服务:

    gcloud compute backend-services add-backend BS_NAME --region=BS_REGION \
    --network-endpoint-group=NEG_NAME --network-endpoint-group-zone=NEG_ZONE
    

    请替换以下内容:

    • BS_NAME:您创建的后端服务的名称。
    • BS_REGION:后端服务所在的区域;这应与代理服务器所在的区域相同。
    • NEG_NAME:您要添加的 NEG 的名称。
    • NEG_ZONE:NEG 所在的可用区。

    对您创建的其他 NEG 重复此步骤。

  6. 在连接了代理实例的子网的 IP 范围内的 VPC 中预留内部 IP 地址。这将是内部负载均衡器的虚拟 IP 地址 (VIP)。预留该地址可确保此 IP 不会被任何其他对象使用。如需预留内部 IP 地址,请使用 compute addresses create 命令

    gcloud compute addresses create ADDRESS_NAMES \
        --region REGION --subnet SUBNETWORK \
        --addresses IP_ADDRESS
    

    请替换以下内容:

    • ADDRESS_NAMES:您要创建的一个或多个 [--purpose=SHARED_LOADBALANCER_VIP] 地址的名称。对于多个地址,请将所有地址指定为列表(以空格分隔),例如 example-address-1 example-address-2 example-address-3
    • REGION:此请求对应的区域。
    • SUBNETWORK:此内部 IP 地址所属的子网。
    • IP_ADDRESS:要预留的 IP 地址,它必须位于子网的主要 IP 范围内。若未指定,则系统会自动从子网中分配 IP 地址。
  7. 创建转发规则并将其与后端服务和 VIP 相关联:

    gcloud compute forwarding-rules create FW_RULE_NAME --region=BS_REGION \
    --load-balancing-scheme=internal --network=PROXY_INSTANCES_VPC_NAME --subnet=RESERVED_IP_ADDRESS_SUBNET \
    --address=RESERVED_IP_ADDRESS --ip-protocol=tcp --ports=ALL --backend-service=BS_NAME \
    --backend-service-region=BS_REGION --allow-global-access
    

    请替换以下内容:

    • FW_RULE_NAME:您要创建的转发规则的名称。
    • BS_REGION:后端服务所在的区域
    • PROXY_INSTANCES_VPC_NAME:在其中创建代理服务器虚拟机的 VPC 的名称
    • RESERVED_IP_ADDRESS_SUBNET:VIP 所在的子网
    • RESERVED_IP_ADDRESS:负载均衡器的 VIP 地址
    • BS_NAME:后端服务的名称

    此外:

    • --allow-global-access 标志表示可以从任何区域(而不仅仅是 BS_REGION)访问负载均衡器的 VIP。这样,每个区域的客户端都可以访问 Looker (Google Cloud Core) 实例。

创建防火墙规则

为了使健康检查正常运行,请创建适用于经过负载均衡处理的代理虚拟机的入站防火墙规则,以允许来自健康检查探测工具 IP 地址范围的流量。

此外,您还可以创建入站防火墙规则,允许来自本地或多云环境的流量访问负载均衡器后端服务。

更新 DNS A 记录

将 Looker (Google Cloud Core) 自定义网域的 A 记录更改为指向负载均衡器的 VIP。您创建的 Cloud DNS 专用区域用于管理自定义网域,并由代理实例所在的 VPC 使用。

更新 OAuth 凭据

  1. 要访问您的 OAuth 客户端,请在 Google Cloud 控制台中依次转到 API 和服务 > 凭据,然后选择您的 Looker (Google Cloud Core) 实例使用的 OAuth 客户端的 OAuth 客户端 ID。
  2. 点击添加 URI 按钮,更新 OAuth 客户端中的已获授权的 JavaScript 来源字段,使其包含您的组织将用于访问 Looker (Google Cloud Core) 的 DNS 名称。因此,如果您的自定义网域是 looker.examplepetstore.com,请输入 looker.examplepetstore.com 作为 URI。

  3. 针对您在创建 Looker (Google Cloud Core) 实例时使用的 OAuth 凭据,将自定义网域更新或添加已获授权的重定向 URI 列表中。将 /oauth2callback 添加到 URI 的末尾。因此,如果您的自定义网域是 looker.examplepetstore.com,请输入 looker.examplepetstore.com/oauth2callback

添加用户

完成上述步骤后,用户就可以使用自定义网域网址了。

在将用户添加到 Looker (Google Cloud Core) 实例之前,请确保已为其完整设置用户身份验证方法

排查 HSTS 政策错误

如果您使用 Chrome 访问 Looker (Google Cloud Core) 自定义网域,并收到了 Chrome 错误(如 NET::ERR_CERT_COMMON_NAME_INVALID 或 HSTS 政策错误),则可以按照以下步骤解决此问题:

  1. 打开“chrome://net-internals/#hsts
  2. 输入自定义网域以查询 HSTS/PKP 集。该自定义网域的所有政策都会显示在找到:下方。
  3. 删除网域安全政策下方的网域字段中输入自定义网域。
  4. 点击删除以删除政策。

后续步骤