Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
airflow-doc-zh
提交
fef23f6b
A
airflow-doc-zh
项目概览
OpenDocCN
/
airflow-doc-zh
9 个月 前同步成功
通知
3
Star
208
Fork
63
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
airflow-doc-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
fef23f6b
编写于
1月 17, 2019
作者:
T
tssujt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Proofread manage-connections section
上级
ed352937
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
99 addition
and
37 deletion
+99
-37
README.md
README.md
+1
-1
zh/10.md
zh/10.md
+97
-35
zh/9.md
zh/9.md
+1
-1
未找到文件。
README.md
浏览文件 @
fef23f6b
...
@@ -60,7 +60,7 @@
...
@@ -60,7 +60,7 @@
|
[
7 设置配置选项
](
zh/7.md
)
|
[
@ImPerat0R\_
](
https://github.com/tssujt
)
|
|
[
7 设置配置选项
](
zh/7.md
)
|
[
@ImPerat0R\_
](
https://github.com/tssujt
)
|
|
[
8 初始化数据库后端
](
zh/8.md
)
|
[
@ImPerat0R\_
](
https://github.com/tssujt
)
|
|
[
8 初始化数据库后端
](
zh/8.md
)
|
[
@ImPerat0R\_
](
https://github.com/tssujt
)
|
|
[
9 使用操作器
](
zh/9.md
)
|
[
@ImPerat0R\_
](
https://github.com/tssujt
)
|
|
[
9 使用操作器
](
zh/9.md
)
|
[
@ImPerat0R\_
](
https://github.com/tssujt
)
|
|
[
10 管理连接
](
zh/10.md
)
| |
|
[
10 管理连接
](
zh/10.md
)
|
[
@ImPerat0R\_
](
https://github.com/tssujt
)
|
|
[
11 保护连接
](
zh/11.md
)
| |
|
[
11 保护连接
](
zh/11.md
)
| |
|
[
12 写日志
](
zh/12.md
)
| |
|
[
12 写日志
](
zh/12.md
)
| |
|
[
13 用Celery扩大规模
](
zh/13.md
)
| |
|
[
13 用Celery扩大规模
](
zh/13.md
)
| |
...
...
zh/10.md
浏览文件 @
fef23f6b
# 管理连接
# 管理连接
Airflow需要知道如何连接到您的环境。
其他系统和服务的主机名,端口,登录名和密码等信息在UI的
`Admin->Connection`
部分中处理。 您将创作
的管道代码将引用Connection对象的“conn_id”。
Airflow需要知道如何连接到您的环境。
其他系统和服务的主机名,端口,登录名和密码等信息在UI的
`Admin->Connection`
部分中处理。您编写
的管道代码将引用Connection对象的“conn_id”。
![
https://airflow.apache.org/_images/connections.png
](
../img/b1caba93dd8fce8b3c81bfb0d58cbf95.jpg
)
![
https://airflow.apache.org/_images/connections.png
](
../img/b1caba93dd8fce8b3c81bfb0d58cbf95.jpg
)
可以使用UI或环境变量创建和管理连接。
可以使用UI或环境变量创建和管理连接。
有关更多信息,请参阅
[
Connenctions Concepts
](
https://apachecn.github.io/airflow-doc-zh/concepts.html
)
文档。
有关更多信息,请参阅
[
Connenctions Concepts
](
20.md
)
文档。
## 使用UI创建连接
## 使用UI创建连接
打开UI的
`Admin-
>Connection`
部分。 单击“
`Create`
链接
以创建新连接。
打开UI的
`Admin-
>Connection`
部分。 单击
`Create`
按钮
以创建新连接。
![
https://airflow.apache.org/_images/connection_create.png
](
../img/635aacab53c55192ad3e31c28e65eb43.jpg
)
![
https://airflow.apache.org/_images/connection_create.png
](
../img/635aacab53c55192ad3e31c28e65eb43.jpg
)
1.
使用所需的连接ID填写
`Conn Id`
字段。
建议您使用小写字符和单独的带下划线的单词。
1.
使用所需的连接ID填写
`Conn Id`
字段。
建议您使用小写字符和单独的带下划线的单词。
2.
使用
`Conn Type`
字段选择连接类型。
2.
使用
`Conn Type`
字段选择连接类型。
3.
填写其余字段。
有关属于不同连接类型的字段的说明,请参阅连接类型。
3.
填写其余字段。
有关属于不同连接类型的字段的说明,请参阅连接类型。
4.
单击“
`Save`
按钮以创建连接。
4.
单击
`Save`
按钮以创建连接。
## 使用UI编辑连接
## 使用UI编辑连接
打开UI的
`Admin-
>
Connection`
部分。 单击连接列表中要编辑的连接旁边的铅笔图标。
打开UI的
`Admin-
>
Connection`
部分。 单击连接列表中要编辑的连接旁边的铅笔图标。
![
https://airflow.apache.org/_images/connection_edit.png
](
../img/08e0f3fedf871b535c850d202dda1422.jpg
)
![
https://airflow.apache.org/_images/connection_edit.png
](
../img/08e0f3fedf871b535c850d202dda1422.jpg
)
修改连接属性,然后单击
“
`Save`
按钮以保存更改。
修改连接属性,然后单击
`Save`
按钮以保存更改。
## 使用环境变量创建连接
## 使用环境变量创建连接
可以使用环境变量创建
气流管道中的连接。 环境变量需要具有
`AIRFLOW_CONN_`
for Airflow的前缀,
`AIRFLOW_CONN_`
URI格式的值
才能正确使用连接。
可以使用环境变量创建
Airflow管道中的连接。环境变量需要具有
`AIRFLOW_CONN_`
的前缀的URI格式
才能正确使用连接。
在引用Airflow管道中的连接时,
`conn_id`
应该是没有前缀的变量的名称。 例如,如果
`AIRFLOW_CONN_POSTGRES_MASTER`
名为
`postgres_master`
则环境变量应命名为
`AIRFLOW_CONN_POSTGRES_MASTER`
(请注意,环境变量必须全部为大写)。
Airflow假定环境变量返回的值为URI格式(例如
`postgres://user:password@localhost:5432/master`
或
`s3://accesskey:secretkey@S3`
)。
在引用Airflow管道中的连接时,
`conn_id`
应该是没有前缀的变量的名称。例如,如果
`conn_id`
名为
`postgres_master`
,则环境变量应命名为
`AIRFLOW_CONN_POSTGRES_MASTER`
(请注意,环境变量必须全部为大写)。
Airflow假定环境变量返回的值为URI格式(例如
`postgres://user:password@localhost:5432/master`
或
`s3://accesskey:secretkey@S3`
)。
## 连接类型
## 连接类型
### Google
云端平台
### Google
Cloud Platform
Google Cloud Platform连接类型支持
[
GCP集成
](
https://apachecn.github.io/airflow-doc-zh/integration.html
)
。
Google Cloud Platform连接类型支持
[
GCP集成
](
28.md
)
。
#### 对GCP进行身份验证
#### 对GCP进行身份验证
有两种方法可以使用Airflow连接到GCP。
有两种方法可以使用Airflow连接到GCP。
1.
使用
[
应用程序默认凭据
](
https://google-auth.readthedocs.io/en/latest/reference/google.auth.html
)
,例如在Google Compute Engine上运行时通过元数据服务器。
1.
使用
[
应用程序默认凭据
](
https://google-auth.readthedocs.io/en/latest/reference/google.auth.html
)
,例如在Google Compute Engine上运行时通过元数据服务器。
2.
在磁盘上使用
[
服务帐户
](
https://cloud.google.com/docs/authentication/
)
密钥文件(JSON格式)。
2.
在磁盘上使用
[
服务帐户
](
https://cloud.google.com/docs/authentication/
)
密钥文件(JSON格式)。
#### 默认连接ID
#### 默认连接ID
默认情况下使用以下连接ID。
默认情况下使用以下连接ID。
```
```
bigquery_default
bigquery_default
```
```
由
[
`BigQueryHook`
](
https://apachecn.github.io/airflow-doc-zh/integration.html
"airflow.contrib.hooks.bigquery_hook.BigQueryHook"
)
钩子使用。
由
[
`BigQueryHook`
](
28.md
)
钩子使用。
```
```
google_cloud_datastore_default
google_cloud_datastore_default
```
```
由
[
`DatastoreHook`
](
https://apachecn.github.io/airflow-doc-zh/integration.html
"airflow.contrib.hooks.datastore_hook.DatastoreHook"
)
钩子使用。
由
[
`DatastoreHook`
](
28.md
)
钩子使用。
```
```
google_cloud_default
google_cloud_default
```
```
由
[
`GoogleCloudBaseHook`
](
https://apachecn.github.io/airflow-doc-zh/code.html
"airflow.contrib.hooks.gcp_api_base_hook.GoogleCloudBaseHook"
)
,
[
`DataFlowHook`
](
https://apachecn.github.io/airflow-doc-zh/integration.html
"airflow.contrib.hooks.gcp_dataflow_hook.DataFlowHook"
)
,
[
`DataProcHook`
](
https://apachecn.github.io/airflow-doc-zh/code.html
"airflow.contrib.hooks.gcp_dataproc_hook.DataProcHook"
)
,
[
`MLEngineHook`
](
https://apachecn.github.io/airflow-doc-zh/integration.html
"airflow.contrib.hooks.gcp_mlengine_hook.MLEngineHook"
)
和
[
`GoogleCloudStorageHook`
](
https://apachecn.github.io/airflow-doc-zh/integration.html
"airflow.contrib.hooks.gcs_hook.GoogleCloudStorageHook"
)
挂钩使用。
由
[
`GoogleCloudBaseHook`
](
28.md
)
,
[
`DataFlowHook`
](
28.md
)
,
[
`DataProcHook`
](
31.md
)
,
[
`MLEngineHook`
](
28.md
)
和
[
`GoogleCloudStorageHook`
](
28.md
)
挂钩使用。
#### 配置连接
#### 配置连接
```
##### Project Id (required)
Project Id (required)
```
要连接的Google Cloud项目ID。
要连接的Google Cloud项目ID。
```
##### Keyfile Path
Keyfile Path
```
磁盘上
[
服务帐户
](
https://cloud.google.com/docs/authentication/
)
密钥文件(JSON格式)的路径。
磁盘上
[
服务帐户
](
https://cloud.google.com/docs/authentication/
)
密钥文件(JSON格式)的路径。
如果使用应用程序默认凭据则不需要
如果使用应用程序默认凭据则不需要
```
##### Keyfile JSON
Keyfile JSON
```
磁盘上的
[
服务帐户
](
https://cloud.google.com/docs/authentication/
)
密钥文件(JSON格式)的内容。 如果使用此方法进行身份验证,建议
[
保护您的连接
](
secure-connections.html
)
。
磁盘上的
[
服务帐户
](
https://cloud.google.com/docs/authentication/
)
密钥文件(JSON格式)的内容。 如果使用此方法进行身份验证,建议
[
保护您的连接
](
11.md
)
。
如果使用应用程序默认凭据则不需要
如果使用应用程序默认凭据则不需要
##### Scopes (comma separated)
要通过身份验证的逗号分隔
[
Google云端范围
](
https://developers.google.com/identity/protocols/googlescopes
)
列表。
> 注意
> 使用应用程序默认凭据时,将忽略范围。 请参阅[AIRFLOW-2522](https://issues.apache.org/jira/browse/AIRFLOW-2522) 。
### MySQL
MySQL连接类型允许连接MySQL数据库。
#### 配置连接
##### 主机(必填)
要连接的主机。
##### 模式(选填)
指定要在数据库中使用的模式名称。
##### 登陆(必填)
指定要连接的用户名
##### 密码(必填)
指定要连接的密码
##### 额外参数(选填)
指定可以在mysql连接中使用的额外参数(作为json字典)。支持以下参数:
-
charset:指定连接的charset
-
cursor:指定使用的cursor,“sscursor”、“dictcurssor”、“ssdictcursor”其中之一
-
local_infile:控制MySQL的LOCAL功能(允许客户端加载本地数据)。有关详细信息,请参阅
[
MySQLdb文档
](
https://mysqlclient.readthedocs.io/user_guide.html
)
。
-
unix_socket:使用UNIX套接字而不是默认套接字
-
ssl:控制使用SSL连接的SSL参数字典(这些参数是特定于服务器的,应包含“ca”,“cert”,“key”,“capath”,“cipher”参数。有关详细信息,请参阅
[
MySQLdb文档
](
https://mysqlclient.readthedocs.io/user_guide.html
)
。请注意,以便在URL表示法中很有用,此参数也可以是SSL字典是字符串编码的JSON字典的字符串。
示例“extras”字段:
```
```
Scopes (comma separated)
{
"charset": "utf8",
"cursorclass": "sscursor",
"local_infile": true,
"unix_socket": "/var/socket",
"ssl": {
"cert": "/tmp/client-cert.pem",
"ca": "/tmp/server-ca.pem'",
"key": "/tmp/client-key.pem"
}
}
```
```
要通过身份验证的逗号分隔
[
Google云端范围
](
https://developers.google.com/identity/protocols/googlescopes
)
列表。
或
```
{
"charset": "utf8",
"cursorclass": "sscursor",
"local_infile": true,
"unix_socket": "/var/socket",
"ssl": "{\"cert\": \"/tmp/client-cert.pem\", \"ca\": \"/tmp/server-ca.pem\", \"key\": \"/tmp/client-key.pem\"}"
}
```
注意
将连接指定为URI(在AIRFLOW_CONN_
*
变量中)时,应按照DB连接的标准语法指定它,其中附加项作为URI的参数传递(请注意,URI的所有组件都应进行URL编码)。
举个例子:
```
mysql://mysql_user:XXXXXXXXXXXX@1.1.1.1:3306/mysqldb?ssl=%7B%22cert%22%3A+%22%2Ftmp%2Fclient-cert.pem%22%2C+%22ca%22%3A+%22%2Ftmp%2Fserver-ca.pem%22%2C+%22key%22%3A+%22%2Ftmp%2Fclient-key.pem%22%7D
```
使用应用程序默认凭据时,将忽略范围。 请参阅
[
AIRFLOW-2522
](
https://issues.apache.org/jira/browse/AIRFLOW-2522
)
。
> 注意
\ No newline at end of file
> 如果在使用MySQL连接时遇到UnicodeDecodeError,请检查定义的字符集是否与数据库字符集匹配。
zh/9.md
浏览文件 @
fef23f6b
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
操作器代表一个理想情况下是幂等的任务。操作器决定DAG运行时实际执行的内容。
操作器代表一个理想情况下是幂等的任务。操作器决定DAG运行时实际执行的内容。
有关更多信息,请参阅
[
Operators Concepts
](
https://apachecn.github.io/airflow-doc-zh/concepts.html
)
文档和
[
Operators API Reference
](
https://apachecn.github.io/airflow-doc-zh/code.html
)
。
有关更多信息,请参阅
[
Operators Concepts
](
20.md
)
文档和
[
Operators API Reference
](
31.md
)
。
*
[
BashOperator
](
9.md
)
*
[
BashOperator
](
9.md
)
*
[
模板
](
9.md
)
*
[
模板
](
9.md
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录