Airflow:如何从其他服务器进行SSH和运行BashOperator

编程入门 行业动态 更新时间:2024-10-28 00:18:25
本文介绍了Airflow:如何从其他服务器进行SSH和运行BashOperator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以使用SSH切换到其他服务器并使用Airbnb的Airflow运行BashOperator? 我正在尝试用Airflow运行一个配置单元sql命令,但是我需要SSH到另一个机器上才能运行配置单元外壳。 我的任务应如下所示:

  • SSH到server1
  • 启动Hive shell
  • 运行Hive命令
  • 谢谢!

    解决方案

    我认为我已经弄清楚了:

  • 创建一个用户界面中管理>连接下的SSH连接。注意:如果您重置数据库,连接将被删除

  • 在Python文件中添加以下内容

    导入SSHHook sshHook = SSHHook(conn_id =<您从UI中获得的连接ID>)

  • 添加SSH操作员任务

    t1 = SSHExecuteOperator( task_id = task1, bash_command =< YOUR COMMAND> ;, ssh_hook = sshHook, dag = dag)

  • 谢谢!

    Is there a way to ssh to different server and run BashOperator using Airbnb's Airflow? I am trying to run a hive sql command with Airflow but I need to SSH to a different box in order to run the hive shell. My tasks should look like this:

  • SSH to server1
  • start Hive shell
  • run Hive command
  • Thanks!

    解决方案

    I think that I just figured it out:

  • Create a SSH connection in UI under Admin > Connection. Note: the connection will be deleted if you reset the database

  • In the Python file add the following

    from airflow.contrib.hooks import SSHHook sshHook = SSHHook(conn_id=<YOUR CONNECTION ID FROM THE UI>)

  • Add the SSH operator task

    t1 = SSHExecuteOperator( task_id="task1", bash_command=<YOUR COMMAND>, ssh_hook=sshHook, dag=dag)

  • Thanks!

    更多推荐

    Airflow:如何从其他服务器进行SSH和运行BashOperator

    本文发布于:2023-11-24 05:01:45,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1624059.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:服务器   Airflow   BashOperator   SSH

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!