All Products
Search
Document Center

CloudMonitor:How do I report the monitoring data of hosts that are not provided by Alibaba Cloud to CloudMonitor by using an NGINX proxy server?

Last Updated:May 04, 2023

This topic describes how to report the monitoring data of hosts that are not provided by Alibaba Cloud to CloudMonitor by using an NGINX proxy server.

Step 1: Deploy an NGINX proxy server

We recommend that you use a Linux server as your proxy server because CloudMonitor is deployed on a Linux server. In this example, a Linux server that runs CentOS is used.

Important

You can deploy the NGINX proxy server only by using the root user account (an administrator account). If you use an administrator account, certain risks may occur. For example, system stability or data security issues may occur. Proceed with caution.

  1. Download the latest installation package of NGINX, for example, nginx-1.19.6.

    1. Go to the nginx: download page.

    2. Click nginx-1.19.6 to download the nginx-1.19.6.tar.gz package.

  2. Download NGINX patch packages to the specified directory of the proxy server, for example, /opt.

    In this example, the proxy_connect_1014.patch patch package is installed.

    1. Log on to the proxy server as the root user.

    2. Run the following commands to download NGINX patch packages:

      cd /opt

      yum install -y git

      git clone https://github.com/chobits/ngx_http_proxy_connect_module.git

      The following figure shows the downloaded patch packages.http_proxy_connect

  3. Run the following commands to install the sample NGINX patch package.

    yum install -y patch pcre pcre-devel

    patch -p1 < ngx_http_proxy_connect_module/patch/proxy_connect_1014.patch

  4. Install NGINX.

    1. Upload the nginx-1.19.6.tar.gz package to the specified directory of the proxy server, for example, /usr/local.

    2. Log on to the proxy server as the root user.

    3. Run the following commands to decompress the nginx-1.19.6.tar.gz package to the nginx-1.19.6 directory:

      cd /usr/local

      tar zxvf nginx-1.19.6.tar.gz

    4. Run the following commands to initialize NGINX:

      cd nginx-1.19.6

      ./configure --prefix=/usr/local/nginx-1.19.6 --with-http_stub_status_module --with-http_ssl_module --add-module=ngx_http_proxy_connect_module

    5. Run the following commands to install NGINX:

      make install

      make && make install

    6. Run the following command to start NGINX:

      ./nginx

    7. Check whether NGINX is installed.

      In the address bar of your browser, enter IP address of the proxy server:80. If the following output is displayed, the installation is successful.

      Nginx
  5. Configure an NGINX proxy.

    1. Run the following commands to create a directory named conf.d:

      cd /usr/local/nginx-1.19.6/conf

      mkdir conf.d

    2. Run the following commands to create a file named forward.conf in the conf.d directory:

      cd conf.d

      vi forward.conf

    3. Configure a forward proxy or a reverse proxy in the forward.conf file.

      • Forward proxy

        If you consider the Internet outside the LAN as a huge resource pool, the clients in the LAN need to access the Internet by using a forward proxy.

        Copy the following code to the forward.conf file. Set the resolver parameter to the IP address of the proxy server and do not change the default values of other parameters.

        server {
             listen                         80;
         
             # dns resolver used by forward proxying
             resolver                       192.168.XX.XX;  # The IP address of the proxy server. 
         
             # forward proxy for CONNECT request
             proxy_connect;
             proxy_connect_allow            443;
             proxy_connect_connect_timeout  10s;
             proxy_connect_read_timeout     10s;
             proxy_connect_send_timeout     10s;
         
             # forward proxy for non-CONNECT request
             location / {
                 proxy_pass http://$http_host$request_uri;  # The protocol and request URI of the proxy server. Do not change the default values. 
                 proxy_set_header Host $host;
             }
         }
        Note

        The forward proxy of NGINX does not support HTTPS.

      • Reverse proxy

        If the LAN provides resources and services for the Internet, the clients on the Internet need to access resources in the LAN by using a reverse proxy.

        Copy the following code to the forward.conf file. Set the server_name parameter to the IP address of the proxy server. Set the proxy_pass parameter to the URL that the proxy server accesses. Set the ssl_certificate parameter to the Secure Sockets Layer (SSL) certificate. Set the ssl_certificate_key parameter to the key of the SSL certificate. Do not change the default values of other parameters.

        server {
            listen              443 ssl;
            server_name         192.168.XX.XX; # The IP address of the proxy server. 
            ssl_certificate     XXXX.pem; # The SSL certificate. 
            ssl_certificate_key XXXX.key; # The key of the SSL certificate. 
        
            location / {
                proxy_pass  https://www.aliyun.com; # The URL that the proxy server accesses. 
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header REMOTE-HOST $remote_addr;
                proxy_set_header X-Forward`ed-For $proxy_add_x_forwarded_for;
                }
        }
        Note

        For more information about how to apply for an SSL certificate, see Submit a certificate application.

    4. Press the Esc key, enter :wq, and then press the Enter key to save and close the forward.conf file.

    5. Run the following commands to open the nginx.conf file:

      cd ..

      vi nginx.conf

    6. Edit the nginx.conf file.

      Copy the following code to the nginx.conf file and set the include parameter to the path of the forward.conf file.

      http {
      .....
      include /usr/local/nginx-1.19.6/conf/conf.d/forward.conf;
      .....
      }
    7. Press the Esc key, enter :wq, and then press the Enter key to save and close the nginx.conf file.

    8. Run the following command to restart the NGINX proxy server:

      nginx -s reload

    9. Check whether the NGINX proxy is installed.

      • Forward proxy

        Run the following command to access a URL. If the URL can be accessed, the NGINX proxy is configured.

        curl -x192.168.XX.XX (IP address of the proxy server)http://example.aliyundoc.com (Any URL)

      • Reverse proxy

        Run the following command. If you can access only the URL specified in the nginx.conf file, the NGINX proxy is configured.

        curl -x192.168.XX.XX (IP address of the proxy server)https://example.aliyundoc.com (Any URL)

Step 2: Install and configure the CloudMonitor agent

Important You can manage the CloudMonitor agent only by using the root user account (an administrator account). If you use an administrator account, certain risks may occur. For example, system stability or data security issues may occur. Proceed with caution.
  1. Install the CloudMonitor agent on a host that is not provided by Alibaba Cloud.

  2. Configure the NGINX proxy server in the CloudMonitor agent.

    1. Log on to the host where the CloudMonitor agent resides as the root user.

    2. Run the following commands to open the agent.properties file:

      cd /usr/local/cloudmonitor/conf

      vi agent.properties

    3. Configure the NGINX proxy server in the configuration file of the CloudMonitor agent.

      The following code provides an example on how to configure an NGINX proxy server:

      http.proxy.auto=false
      # Manually configure the proxy server.
      http.proxy.host=192.168.XX.XX
      # The IP address of the NGINX proxy server. 
      http.proxy.port=8080
      # The port number of the NGINX proxy server. 
      #http.proxy.user=user  # The NGINX proxy server does not require a username for HTTP authentication. 
      #http.proxy.password=password  # The NGINX proxy server does not require a password for HTTP authentication. 
    4. Press the Esc key, enter :wq, and then press the Enter key to save and close the agent.properties file.

    5. Run the following command to restart the CloudMonitor agent:

      ./cloudmonitorCtl.sh restart

Step 3: View the monitoring data of the host not provided by Alibaba Cloud

  1. Log on to the CloudMonitor console.
  2. In the left-side navigation pane, click Host Monitoring.

  3. On the Host Monitoring page, click the host name or click Monitoring Charts in the Actions column of the host.

    View the monitoring data of the host not provided by Alibaba Cloud.