[英]Connect to ClickHouse from airflow DAG
I write this code:我写这个代码:
from airflow import DAG
from airflow.hooks.clickhouse_hook import ClickHouseHook
from airflow.operators.python_operator import PythonOperator
from airflow.utils.dates import days_ago
from datetime import datetime
default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': datetime(2020, 10, 18)
}
def _data_from_clickhouse():
ch_hook = ClickHouseHook(clickhouse_conn_id='ClickHouse_rnd_conn')
ch_hook.get_records('select * from cpa_traffic_costs')
with DAG(dag_id='data_to_clickhouse',
default_args=default_args) as dag:
get_data_from_clickhouse = PythonOperator(
task_id='get_data_from_clickhouse',
python_callable=_data_from_clickhouse,
)
get_data_from_clickhouse
But I have an error when I start this dag in Web UI但是当我在 Web UI 中启动此 dag 时出现错误
clickhouse_driver.errors.SocketTimeoutError: Code: 209. (85.***.***.***:8123)
This error happens only in airflow dag.此错误仅发生在气流 dag 中。 I set up a connection "ClickHouse_rnd_conn" via the web UI of airflow.
我通过气流的网络用户界面建立了一个连接“ClickHouse_rnd_conn”。 Maybe the problem is that the airflow does not have a connection type "clickhouse" and i used type "HTTP"
也许问题是气流没有连接类型“clickhouse”,我使用了类型“HTTP”
You may use the wrong port, see this github issue :您可能使用了错误的端口,请参阅此 github 问题:
This driver use native protocol (port 9000).
此驱动程序使用本机协议(端口 9000)。 Port 8123 is used for HTTP protocol.
端口 8123 用于 HTTP 协议。
clickhouse_driver.errors.SocketTimeoutError: Code: 209. (85. . .***:8123)
clickhouse_driver.errors.SocketTimeoutError: 代码: 209. (85. . .***:8123)
Your Web UI host does not have permission to access 85. .您的 Web UI 主机没有访问 85 的权限。. .***:8123 ?
.***:8123 ? Firewall is in between CH server and Web UI host.
防火墙位于 CH 服务器和 Web UI 主机之间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.