大网数据广告活动
服务器运维问答

How to implement Cloud Monitoring Uptime checks for instances without external IP ( private websites )

· 52CE 我爱测

Cloud Monitoring Uptime checks allow users to send a request to a resource to see if it respond. Since the checks are performed outside Google Cloud infrastructure, an external ip is needed . Is there a way to implement Uptime ch…

问题原文

原帖链接 · Armando Cuevas · CC BY-SA 4.0

Cloud Monitoring Uptime checks allow users to send a request to a resource to see if it respond.

Since the checks are performed outside Google Cloud infrastructure, an external ip is needed.

Is there a way to implement Uptime checks for sites ( http requests ) that does not have a public IP?

已采纳解答

原帖链接 · Armando Cuevas · CC BY-SA 4.0

TL;DR: yes, by using a bastion host with external IP that can query reach the internal site and use a proxy ( NGINX , SquidProxy , etc ) to pass your health check request from the external services to your internal sites.

What you need:

  1. A VM with external IP in the same VPC of your private VMS ( the ones without public ip).
  2. Communication between the VM with external IP (from now referred as probe vm ) and the VMs that host your internal websites.
  3. (optional, but highly recommended) Your website should have a health-check webpage. This page should return a 200 if the site and system it’s ok and preferably an authentication protection.

The process:

  1. Create a VM within the same VPC where your internal website is. You can create basic linux VM running your preferred linux distribution. The size of your VM can be a n1-standard-1 or a e2-standard-2 the size really depends on how many sites you will monitor. You may need to adjust the size of your VM according to your needs.
  2. Allow communication between your probe vm and the internal vms that host your site. It’s recommended that you only allow the ports used by your internal sites.
  3. Restrict all traffic to your your probe vm to avoid any type of data leak. Use Google Cloud Firewall to achieve this. ( note: do not forget to whitelist your IP for port 22 so you can manage your probe vm )
  4. Allow HTTP (port 80) traffic to your probe vm to Cloud Monitoring ips.
  5. Install NGINX Opensource on your probe vm.

If you want to skip the installation process, you may choose to use NGINX PLUS and install it by using Google Cloud MarketPlace

You can also use NGINX Docker container for this task.

  1. Configure NGINX as Reverse Proxy
  2. Create your Uptime checks in Cloud Monitoring.

Some tips and tricks on how to configure nginx

When you install NGINX by following NGINX’s instructions, you will get a functional NGINX at the end of the process. But you may need extra configurations to achieve the goal.

  1. Modify the file /etc/nginx/conf.d/default.conf to answer a 404 to any request that does not includes a valid HOST header:
server {
    listen       80 default;
    location / {
        return 404;
    }
}
  1. Create a configuration file under /etc/nginx/conf.d/ directory for each site you want to monitor. i.e. /etc/nginx/conf.d/finance-sites.conf. Do not forget the .conf termination.

  2. Set a bogus host for each site you want to monitor and do not forget to set the host header in Cloud Monitoring.

  3. Do not forget to check syntax nginx -t and reload configuration nginx -s reload each time you perform a change in your configuration.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-05-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。