我從事一個專案,該專案維護一個資料湖,該資料湖集中了來自巴西政府的公共資訊。我們的管道在 Kubernetes 集群上運行。
我目前正在為勞動力市場資料建立管道。這是我用來下載資料的 bash 腳本:
#!/bin/bash
# To run this script the user must run 'bash download.sh group', where group is cagedmov | cagedfor | cageddex.
# See explanation in the next comment:
# The microdata resulting from the new consolidation are made available in accordance with the
# month of disclosure, as of January 2020, containing three files for each
# competence. Following a consistent naming pattern, CAGEDMOVAYYYMM files
# bring the movements declared within the deadline with declaration competence
# same as YYYYMM. The CAGEDFORAAAMM files bring the declared moves
# outside the deadline with declaration competence equal to YYYYMM. the files
# CAGEDEXCAAAAMM bring the excluded movements with declaration competence
# of exclusion equal to YYYYMM
lower_group=$1
upper_group=${lower_group^^}
mkdir -p /tmp/novo_caged/$lower_group/input
ufs=('RO' 'AC' 'AM' 'RR' 'PA' 'AP' 'TO' 'MA' 'PI' 'CE' 'RN' 'PB' 'PE' 'AL' 'SE' 'BA' 'MG' 'ES' 'RJ' 'SP' 'PR' 'SC' 'RS' 'MS' 'MT' 'GO' 'DF')
anos=(2020 2021 2022)
meses=($(seq 1 1 12))
for uf in "${ufs[@]}"
do
for ano in "${anos[@]}"
do
for mes in "${meses[@]}"
do
mkdir -p /tmp/novo_caged/$lower_group/ano=$ano/mes=$mes/sigla_uf=$uf/
done
done
done
cd /tmp/novo_caged/$lower_group/input
ftp_path="ftp://anonymous:[email protected]/pdet/microdados/NOVO CAGED/"
pad_meses=($(echo {01..12}))
folders=($(seq 202001 1 202012))
for ano in "${anos[@]}"
do
for mes in "${pad_meses[@]}"
do
wget "$ftp_path$ano/$ano$mes/$upper_group$ano$mes.7z"
7z x -y $upper_group$ano$mes.7z
rm *7z
done
done
該腳本在我的計算機上完美運行,但是當我部署到 Kubernetes 集群時,該腳本會拋出錯誤Failed to connect to ftp.mtps.gov.br port 21: Connection timed out。顯然,該地址ftp.mtps.gov.br僅接受來自巴西 IP 地址的請求。有沒有辦法繞過這個限制?對于我們的專案來說,自動化這個 ETL 并以更新的方式發布這些資料是非常重要的。
uj5u.com熱心網友回復:
您可以將 Tor 用作 sockx5 代理,并將其配置為允許流量從特定國家/地區退出。
在 torrc 組態檔中添加這些行,或者最終修改現有的。
ExitNodes {br}
StrictNodes 1
最后一件事,你需要告訴你的 bash 腳本使用 tor。
這可以通過不同的方式完成,最簡單的一種是使用torify命令。
我建議測驗在腳本頂部添加這一行的所有內容
#!/bin/bash
curl https://api.myip.com;exit
這將為您提供該國家被用作 Tor 出口節點的證據。如果沒問題,去掉這條測驗線。
https://www.torproject.org/
https://linux.die.net/man/1/torify
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/468233.html
標籤:重击 Kubernetes ftp
