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.
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.
Download the latest installation package of NGINX, for example, nginx-1.19.6.
Go to the nginx: download page.
Click nginx-1.19.6 to download the nginx-1.19.6.tar.gz package.
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.
Log on to the proxy server as the root user.
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.
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
Install NGINX.
Upload the nginx-1.19.6.tar.gz package to the specified directory of the proxy server, for example, /usr/local.
Log on to the proxy server as the root user.
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
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
Run the following commands to install NGINX:
make install
make && make install
Run the following command to start NGINX:
./nginx
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.
Configure an NGINX proxy.
Run the following commands to create a directory named conf.d:
cd /usr/local/nginx-1.19.6/conf
mkdir conf.d
Run the following commands to create a file named forward.conf in the conf.d directory:
cd conf.d
vi forward.conf
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; } }
NoteThe 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 theproxy_pass
parameter to the URL that the proxy server accesses. Set thessl_certificate
parameter to the Secure Sockets Layer (SSL) certificate. Set thessl_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; } }
NoteFor more information about how to apply for an SSL certificate, see Submit a certificate application.
Press the Esc key, enter :wq, and then press the Enter key to save and close the forward.conf file.
Run the following commands to open the nginx.conf file:
cd ..
vi nginx.conf
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; ..... }
Press the Esc key, enter :wq, and then press the Enter key to save and close the nginx.conf file.
Run the following command to restart the NGINX proxy server:
nginx -s reload
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
Install the CloudMonitor agent on a host that is not provided by Alibaba Cloud.
For more information, see Install and uninstall the CloudMonitor agent for C++.
Configure the NGINX proxy server in the CloudMonitor agent.
Log on to the host where the CloudMonitor agent resides as the root user.
Run the following commands to open the agent.properties file:
cd /usr/local/cloudmonitor/conf
vi agent.properties
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.
Press the Esc key, enter :wq, and then press the Enter key to save and close the agent.properties file.
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
- Log on to the CloudMonitor console.
In the left-side navigation pane, click Host Monitoring.
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.