通过nginx正向代理离线安装部署datakit

1、代理安装

如果内网有可以通外网的机器,可以在该节点部署一个 proxy,将内网机器的访问流量通过该机器代理出来。正常1、我们有通过Datakit自己内置的proxy来做代理的方式

2、也可以通过nginx做正向代理,让内网机器下载安装dk

2、Datakit Proxy方式

1、配置代理

通过正常安装方式,在有公网出口的机器上安装一个 DataKit,开通该 DataKit 上的 proxy 采集器,假定 proxy 采集器所在 Datakit IP 为 1.2.3.4,有如下配置

[[inputs.proxy]]
  ## default bind ip address
  bind = "0.0.0.0" 
  ## default bind port
  port = 9530

2、使用 Datakit 代理安装dk

在内网机器上,增加环境变量 HTTPS_PROXY="1.2.3.4:9530",安装命令如下:

DK_DATAWAY=https://openway.guance.com?token=<TOKEN> HTTPS_PROXY=http://1.2.3.4:9530 bash -c 'eval "$(curl -L https://static.guance.com/datakit/install.sh)"'

3、Nginx 正向代理方式

由于是内网访问外网链接兵器使用正向代理所以需要CONNECT方法(这里我们用的是正向代理的方式让nginx代理客户端向我们的https链接建立隧道发送请求,当然也可以用nginx反向代理服务端的方式给内网机器提供服务),也就是需要安装并配置ngx_http_proxy_connect_module模块

注:ngx_http_proxy_connect_module模块需要注意查看下和nginx版本是否兼容,目前我找到的信息是到1.19.x之前的部分版本兼容,这里我以nginx1.18.x做示例可以参考

1、配置代理

  1. 安装依赖
sudo yum update -y
sudo yum install -y gcc pcre-devel zlib-devel make unzip wget
  1. 下载 NGINX 1.18.x 源代码
wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
  1. 下载 ngx_http_proxy_connect_module
    从 GitHub 下载最新的 ngx_http_proxy_connect_module:
cd ..
git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
  1. 应用补丁
    在应用补丁前,确保你在 nginx-1.18.0 目录下:
cd nginx-1.18.0
patch -p1 < ../ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.patch
  1. 配置 NGINX
    配置 NGINX 以添加 ngx_http_proxy_connect_module 模块,并启用 SSL 模块:
./configure --with-http_ssl_module --add-module=../ngx_http_proxy_connect_module

这里报错:./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl= option.

系统中缺少 OpenSSL 库,需要安装一下

sudo yum install -y openssl openssl-devel
  1. 编译和安装 NGINX
    编译并安装 NGINX:
make
sudo make install
  1. 配置 NGINX
    编辑 NGINX 配置文件来启用 proxy_connect 模块。通常,配置文件位于 /usr/local/nginx/conf/nginx.conf。
    sudo nano /usr/local/nginx/conf/nginx.conf
    添加以下配置以启用 proxy_connect 功能:

    server {
    listen 3128;
    # DNS resolver used by forward proxying
    resolver 8.8.8.8;

     # Forward proxy for CONNECT requests
     proxy_connect;
     proxy_connect_allow 443 563;
     proxy_connect_connect_timeout 10s;
     proxy_connect_read_timeout 10s;
     proxy_connect_send_timeout 10s;
    
     # Define other settings for non-CONNECT requests if needed
     location / {
     	proxy_pass http://$host;
     	proxy_set_header Host $host;
     }
    

    }
    在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

  1. 启动 NGINX
    启动 NGINX 并验证配置:
sudo /usr/local/nginx/sbin/nginx

重新加载配置,可以使用:

sudo /usr/local/nginx/sbin/nginx -s reload

验证安装
你可以检查 NGINX 是否正确运行并监听配置的端口(例如 3128):

sudo netstat -tulnp | grep nginx

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

2、通过nginx安装dk

在内网机器上,增加环境变量 DK_PROXY_TYPE="nginx"; DK_NGINX_IP="1.2.3.4";,安装命令如下

DK_DATAWAY=https://openway.guance.com?token=<TOKEN> DK_NGINX_IP=1.2.3.4 HTTPS_PROXY=http://1.2.3.4:9530 bash -c 'eval "$(curl -L https://static.guance.com/datakit/install.sh)"'

DK_DATAWAY=https://openway.guance.com?token=tkn_xxxxxxxxxxx DK_NGINX_IP=代理服务器IP HTTPS_PROXY=http://代理服务器IP:3128 bash -c ‘eval “$(curl -L https://static.guance.com/datakit/install.sh)”’

安装完成后执行datakit monitor,如图已经安装成功ß

在这里插入图片描述

  • 20
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值