{"id":34864,"date":"2024-08-12T14:57:49","date_gmt":"2024-08-12T07:57:49","guid":{"rendered":"http:\/\/jupitek.maudemo.vip\/index.php\/2024\/08\/12\/create-connections-and-variables-in-apache-airflow\/"},"modified":"2024-08-12T14:57:49","modified_gmt":"2024-08-12T07:57:49","slug":"create-connections-and-variables-in-apache-airflow","status":"publish","type":"post","link":"https:\/\/jupitek.maudemo.vip\/index.php\/2024\/08\/12\/create-connections-and-variables-in-apache-airflow\/","title":{"rendered":"T\u1ea1o Connections v\u00e0 Variables trong Apache Airflow"},"content":{"rendered":"<h2 id=\"what-is-apache-airflow\">Apache Airflow l\u00e0 g\u00ec?<a href=\"https:\/\/www.linode.com\/docs\/guides\/apache-airflow-tutorial-creating-connections-and-variables\/#what-is-apache-airflow\"><\/a><\/h2>\n<p><a href=\"https:\/\/airflow.apache.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Airflow<\/a>&nbsp;l\u00e0 m\u1ed9t n\u1ec1n t\u1ea3ng m\u00e3 ngu\u1ed3n m\u1edf m\u00e0 b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng \u0111\u1ec3 t\u1ef1 \u0111\u1ed9ng h\u00f3a, s\u1eafp x\u1ebfp v\u00e0 gi\u00e1m s\u00e1t c\u00e1c lu\u1ed3ng c\u00f4ng vi\u1ec7c v\u00e0 \u0111\u01b0\u1eddng \u1ed1ng d\u1eef li\u1ec7u. M\u1ed9t trong nh\u1eefng t\u00ednh n\u0103ng tuy\u1ec7t v\u1eddi nh\u1ea5t c\u1ee7a Airflow l\u00e0 b\u1ea1n c\u00f3 th\u1ec3 t\u1ea1o v\u00e0 th\u1ef1c hi\u1ec7n c\u00e1c lu\u1ed3ng c\u00f4ng vi\u1ec7c b\u1eb1ng m\u00e3. Khi b\u1ea1n s\u1eed d\u1ee5ng c\u00e1c lu\u1ed3ng c\u00f4ng vi\u1ec7c \u0111\u01b0\u1ee3c h\u1ed7 tr\u1ee3 b\u1edfi m\u00e3, b\u1ea1n c\u00f3 th\u1ec3 ki\u1ec3m so\u00e1t phi\u00ean b\u1ea3n, c\u1ed9ng t\u00e1c v\u00e0 g\u1ee1 l\u1ed7i c\u00e1c lu\u1ed3ng c\u00f4ng vi\u1ec7c c\u1ee7a m\u00ecnh.<\/p>\n<p>Airflow g\u1ecdi c\u00e1c quy tr\u00ecnh c\u00f4ng vi\u1ec7c l\u00e0&nbsp;<em>\u0110\u1ed3 th\u1ecb kh\u00f4ng c\u00f3 chu tr\u00ecnh c\u00f3 h\u01b0\u1edbng (DAG)<\/em>&nbsp;. DAG bao g\u1ed3m tr\u00ecnh t\u1ef1 c\u00e1c t\u00e1c v\u1ee5 c\u1ea7n th\u1ef1c hi\u1ec7n c\u00f9ng v\u1edbi m\u1ed1i quan h\u1ec7 gi\u1eefa c\u00e1c t\u00e1c v\u1ee5 v\u00e0 s\u1ef1 ph\u1ee5 thu\u1ed9c c\u1ee7a ch\u00fang. B\u1ea1n c\u00f3 th\u1ec3 th\u1ef1c hi\u1ec7n&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Extract,_transform,_load\" target=\"_blank\" rel=\"noreferrer noopener\">quy tr\u00ecnh ETL<\/a>&nbsp;(tr\u00edch xu\u1ea5t, t\u1ea3i v\u00e0 chuy\u1ec3n \u0111\u1ed5i d\u1eef li\u1ec7u) b\u1eb1ng Airflow v\u00e0 c\u0169ng c\u00f3 th\u1ec3 t\u1ef1 \u0111\u1ed9ng h\u00f3a email c\u00f3 t\u1ec7p \u0111\u00ednh k\u00e8m CSV v\u00e0 t\u1ea1o quy tr\u00ecnh c\u00f4ng vi\u1ec7c H\u1ecdc m\u00e1y (ML).<\/p>\n<p>B\u1ea1n c\u00f3 th\u1ec3 k\u1ebft n\u1ed1i c\u00e1c ngu\u1ed3n d\u1eef li\u1ec7u Airflow c\u1ee7a m\u00ecnh v\u1edbi m\u1ed9t&nbsp;<em>kho<\/em>&nbsp;d\u1eef li\u1ec7u trung t\u00e2m \u0111\u1ec3 c\u00e1c nh\u00e0 ph\u00e2n t\u00edch d\u1eef li\u1ec7u c\u1ee7a b\u1ea1n c\u00f3 th\u1ec3 truy c\u1eadp v\u00e0o t\u1ea5t c\u1ea3 d\u1eef li\u1ec7u c\u00f3 li\u00ean quan, gi\u00fap ng\u0103n ch\u1eb7n t\u00ecnh tr\u1ea1ng d\u1eef li\u1ec7u b\u1ecb ph\u00e2n m\u1ea3nh tr\u00ean to\u00e0n b\u1ed9 t\u1ed5 ch\u1ee9c. T\u01b0\u01a1ng t\u1ef1 nh\u01b0 v\u1eady, c\u00e1c quy tr\u00ecnh l\u00e0m vi\u1ec7c minh b\u1ea1ch v\u00e0 c\u00f3 th\u1ec3 t\u00e1i t\u1ea1o \u0111\u01b0\u1ee3c d\u1ef1a tr\u00ean m\u00e3 s\u1ebd gi\u1ea3m thi\u1ec3u t\u00ecnh tr\u1ea1ng t\u1eafc ngh\u1ebdn, v\u00ec b\u1ea5t k\u1ef3 ai c\u00f3 quy\u1ec1n truy c\u1eadp v\u00e0o m\u00e3 c\u1ee7a quy tr\u00ecnh l\u00e0m vi\u1ec7c \u0111\u1ec1u c\u00f3 th\u1ec3 g\u1ee1 l\u1ed7i.<\/p>\n<p>Airflow cung c\u1ea5p&nbsp;<a href=\"https:\/\/airflow.apache.org\/docs\/stable\/_api\/index.html\" target=\"_blank\" rel=\"noreferrer noopener\">giao di\u1ec7n l\u1eadp tr\u00ecnh \u1ee9ng d\u1ee5ng Python (API)<\/a>&nbsp;m\u00e0 b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng \u0111\u1ec3 m\u00e3 h\u00f3a DAG v\u00e0 g\u1ecdi b\u1ea5t k\u1ef3 t\u1eadp l\u1ec7nh k\u1ebft n\u1ed1i n\u00e0o b\u1ea1n t\u1ea1o.<\/p>\n<h2 id=\"in-this-guide\">Trong H\u01b0\u1edbng d\u1eabn n\u00e0y<a href=\"https:\/\/www.linode.com\/docs\/guides\/apache-airflow-tutorial-creating-connections-and-variables\/#in-this-guide\"><\/a><\/h2>\n<p>H\u01b0\u1edbng d\u1eabn n\u00e0y cung c\u1ea5p ph\u1ea7n gi\u1edbi thi\u1ec7u v\u1edbi c\u00e1c v\u00ed d\u1ee5 c\u01a1 b\u1ea3n v\u1ec1 hai kh\u00e1i ni\u1ec7m Airflow c\u01a1 b\u1ea3n,&nbsp;<em>Bi\u1ebfn<\/em>&nbsp;v\u00e0&nbsp;<em>K\u1ebft n\u1ed1i<\/em>&nbsp;. B\u1ea1n c\u00f3 th\u1ec3 k\u1ebft h\u1ee3p c\u00e1c \u00fd t\u01b0\u1edfng \u0111\u01b0\u1ee3c \u0111\u1ec1 c\u1eadp trong h\u01b0\u1edbng d\u1eabn n\u00e0y v\u00e0o c\u00e1c t\u1eadp l\u1ec7nh Python ph\u1ee9c t\u1ea1p h\u01a1n khi t\u1ea1o DAG v\u00e0 \u0111\u01b0\u1eddng \u1ed1ng d\u1eef li\u1ec7u c\u1ee7a m\u00ecnh.<\/p>\n<p>Trong h\u01b0\u1edbng d\u1eabn Apache Airflow n\u00e0y, b\u1ea1n s\u1ebd h\u1ecdc c\u00e1ch:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.linode.com\/docs\/guides\/apache-airflow-tutorial-creating-connections-and-variables\/#create-your-dag-variables\">l\u01b0u tr\u1eef c\u00e1c gi\u00e1 tr\u1ecb Airflow trong c\u00e1c bi\u1ebfn<\/a>&nbsp;b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng giao di\u1ec7n d\u00f2ng l\u1ec7nh Airflow (CLI)<\/li>\n<li><a href=\"https:\/\/www.linode.com\/docs\/guides\/apache-airflow-tutorial-creating-connections-and-variables\/#create-your-connection-script\">t\u1ef1 \u0111\u1ed9ng k\u1ebft n\u1ed1i v\u1edbi c\u00e1c ngu\u1ed3n d\u1eef li\u1ec7u c\u1ee7a b\u1ea1n<\/a>&nbsp;b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng m\u1ed9t t\u1eadp l\u1ec7nh \u0111\u01a1n gi\u1ea3n v\u00e0 Airflow CLI<\/li>\n<\/ul>\n<h2 id=\"airflow-variables-and-connections\">Bi\u1ebfn \u0111\u1ed5i lu\u1ed3ng kh\u00f4ng kh\u00ed v\u00e0 k\u1ebft n\u1ed1i<a href=\"https:\/\/www.linode.com\/docs\/guides\/apache-airflow-tutorial-creating-connections-and-variables\/#airflow-variables-and-connections\"><\/a><\/h2>\n<p>Airflow c\u1ea7n truy c\u1eadp d\u1eef li\u1ec7u t\u1eeb c\u00e1c ngu\u1ed3n b\u00ean ngo\u00e0i, nh\u01b0&nbsp;<a href=\"https:\/\/www.linode.com\/blog\/marketplace-apps\/new-web-development-and-database-marketplace-apps\/\" target=\"_blank\" rel=\"noreferrer noopener\">c\u01a1 s\u1edf d\u1eef li\u1ec7u<\/a>&nbsp;,&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/api\/\">API<\/a>&nbsp;v\u00e0&nbsp;<a href=\"https:\/\/www.linode.com\/products\/shared\/\" target=\"_blank\" rel=\"noreferrer noopener\">m\u00e1y ch\u1ee7<\/a>&nbsp;. B\u1ea1n s\u1eed d\u1ee5ng&nbsp;<a href=\"https:\/\/airflow.apache.org\/docs\/stable\/howto\/connection\/index.html\" target=\"_blank\" rel=\"noreferrer noopener\">Airflow&nbsp;<em>Connections<\/em><\/a>&nbsp;\u0111\u1ec3 t\u1ea1o k\u1ebft n\u1ed1i \u0111\u1ebfn c\u00e1c ngu\u1ed3n d\u1eef li\u1ec7u c\u1ee7a m\u00ecnh. C\u00e1c k\u1ebft n\u1ed1i c\u1ee7a b\u1ea1n t\u1ea1o th\u00e0nh c\u00e1c kh\u1ed1i x\u00e2y d\u1ef1ng c\u1ee7a Airflow DAG, v\u00ec ch\u00fang x\u00e1c \u0111\u1ecbnh ngu\u1ed3n d\u1eef li\u1ec7u,&nbsp;<a href=\"https:\/\/airflow.apache.org\/docs\/stable\/best-practices.html#staging-environment\" target=\"_blank\" rel=\"noreferrer noopener\">khu v\u1ef1c d\u00e0n d\u1ef1ng<\/a>&nbsp;v\u00e0 \u0111\u00edch \u0111\u1ebfn c\u1ee7a b\u1ea1n.<\/p>\n<p>B\u1ea1n s\u1eed d\u1ee5ng bi\u1ebfn Airflow \u0111\u1ec3 l\u01b0u tr\u1eef c\u00e1c gi\u00e1 tr\u1ecb c\u00f3 th\u1ec3 t\u00e1i s\u1eed d\u1ee5ng, nh\u01b0 URI, t\u00ean ng\u01b0\u1eddi d\u00f9ng c\u01a1 s\u1edf d\u1eef li\u1ec7u, c\u1ea5u h\u00ecnh v\u00e0 b\u1ea5t k\u1ef3 gi\u00e1 tr\u1ecb n\u00e0o kh\u00e1c m\u00e0 DAG c\u1ee7a b\u1ea1n y\u00eau c\u1ea7u. C\u00e1c bi\u1ebfn \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef trong c\u01a1 s\u1edf d\u1eef li\u1ec7u si\u00eau d\u1eef li\u1ec7u c\u1ee7a Airflow.<\/p>\n<h3 id=\"the-airflow-cli\">D\u00f2ng kh\u00ed CLI<a href=\"https:\/\/www.linode.com\/docs\/guides\/apache-airflow-tutorial-creating-connections-and-variables\/#the-airflow-cli\"><\/a><\/h3>\n<p>B\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng Airflow CLI \u0111\u1ec3 qu\u1ea3n l\u00fd DAG c\u1ee7a m\u00ecnh v\u00e0 t\u1ea1o, ch\u1ec9nh s\u1eeda v\u00e0 x\u00f3a c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng Airflow nh\u01b0 k\u1ebft n\u1ed1i v\u00e0 bi\u1ebfn. B\u1ea1n c\u00f3 th\u1ec3 k\u1ebft h\u1ee3p c\u00e1c l\u1ec7nh CLI v\u00e0o c\u00e1c t\u1eadp l\u1ec7nh \u0111\u1ec3 t\u1ef1 \u0111\u1ed9ng h\u00f3a c\u00e1c l\u1ec7nh Airflow CLI th\u01b0\u1eddng d\u00f9ng c\u1ee7a m\u00ecnh. Trong h\u01b0\u1edbng d\u1eabn n\u00e0y, b\u1ea1n s\u1ebd t\u00ecm hi\u1ec3u c\u00e1ch t\u1eadn d\u1ee5ng Airflow CLI \u0111\u1ec3 t\u1ef1 \u0111\u1ed9ng t\u1ea1o Bi\u1ebfn v\u00e0 K\u1ebft n\u1ed1i Airflow c\u1ee7a m\u00ecnh.<\/p>\n<h2 id=\"automate-creating-airflow-variables-and-connections\">T\u1ef1 \u0111\u1ed9ng t\u1ea1o bi\u1ebfn lu\u1ed3ng kh\u00ed v\u00e0 k\u1ebft n\u1ed1i<a href=\"https:\/\/www.linode.com\/docs\/guides\/apache-airflow-tutorial-creating-connections-and-variables\/#automate-creating-airflow-variables-and-connections\"><\/a><\/h2>\n<h3 id=\"create-your-dag-variables\">T\u1ea1o Bi\u1ebfn DAG c\u1ee7a B\u1ea1n<a href=\"https:\/\/www.linode.com\/docs\/guides\/apache-airflow-tutorial-creating-connections-and-variables\/#create-your-dag-variables\"><\/a><\/h3>\n<p>S\u1eed d\u1ee5ng t\u1ec7p JSON \u0111\u1ec3 t\u1ea3i&nbsp;<a href=\"https:\/\/airflow.apache.org\/docs\/stable\/concepts.html#variables\" target=\"_blank\" rel=\"noreferrer noopener\">c\u00e1c bi\u1ebfn Airflow<\/a>&nbsp;l\u00e0 ph\u01b0\u01a1ng ph\u00e1p t\u00e1i t\u1ea1o v\u00e0 nhanh h\u01a1n so v\u1edbi s\u1eed d\u1ee5ng giao di\u1ec7n ng\u01b0\u1eddi d\u00f9ng \u0111\u1ed3 h\u1ecda (GUI) c\u1ee7a Airflow \u0111\u1ec3 t\u1ea1o bi\u1ebfn. Ph\u1ea7n n\u00e0y s\u1eed d\u1ee5ng m\u1ed9t v\u00ed d\u1ee5 \u0111\u01a1n gi\u1ea3n \u0111\u1ec3 ch\u1ee9ng minh c\u00e1ch t\u1ea1o v\u00e0 l\u01b0u tr\u1eef c\u00e1c bi\u1ebfn Airflow b\u1eb1ng Airflow CLI.<\/p>\n<ol>\n<li>S\u1eed d\u1ee5ng tr\u00ecnh so\u1ea1n th\u1ea3o v\u0103n b\u1ea3n, t\u1ea1o t\u1ec7p JSON m\u1edbi \u0111\u1ec3 l\u01b0u tr\u1eef c\u00e1c c\u1eb7p kh\u00f3a-gi\u00e1 tr\u1ecb c\u1ee7a b\u1ea5t k\u1ef3 gi\u00e1 tr\u1ecb n\u00e0o b\u1ea1n c\u1ea7n s\u1eed d\u1ee5ng l\u1ea1i trong DAG c\u1ee7a m\u00ecnh. T\u1ec7p v\u00ed d\u1ee5 bao g\u1ed3m th\u00f4ng tin k\u1ebft n\u1ed1i cho c\u01a1 s\u1edf d\u1eef li\u1ec7u MySQL.T\u1ec7p: ~\/example_vars.json<code>1 2 3 4 5 6 7 <\/code><code><strong>{<\/strong> \"my_prod_db\": \"dbname\", \"my_prod_db_user\": \"username\", \"my_prod_db_pass\": \"securepassword\", \"my_prod_db_uri\": \"mysql:\/\/192.0.2.0:3306\/\" <strong>}<\/strong><\/code><\/li>\n<li>Ph\u00e1t h\u00e0nh l\u1ec7nh sau \u0111\u1ec3 t\u1ea3i t\u1ea5t c\u1ea3 c\u00e1c bi\u1ebfn c\u1ee7a b\u1ea1n. Thay th\u1ebf \u0111\u01b0\u1eddng d\u1eabn b\u1eb1ng v\u1ecb tr\u00ed&nbsp;<code>example_vars.json<\/code>t\u1ec7p c\u1ee7a b\u1ea1n.<code> airflow variables --import \/home\/username\/example_vars.json<\/code><\/li>\n<li>\u0110\u1ec3 l\u1ea5y gi\u00e1 tr\u1ecb bi\u1ebfn t\u1eeb Airflow, h\u00e3y s\u1eed d\u1ee5ng l\u1ec7nh sau:<code> airflow variables -g my_prod_db <\/code>Airflow tr\u1ea3 v\u1ec1 gi\u00e1 tr\u1ecb c\u1ee7a&nbsp;<code>my_prod_db<\/code>bi\u1ebfn.<code>dbname<\/code> <\/li>\n<\/ol>\n<p class=\"has-background\" style=\"background-color:#74f78c33\">Ghi ch\u00fa: Airflow l\u01b0u m\u1eadt kh\u1ea9u cho c\u00e1c k\u1ebft n\u1ed1i v\u00e0 b\u1ea5t k\u1ef3 gi\u00e1 tr\u1ecb bi\u1ebfn n\u00e0o d\u01b0\u1edbi d\u1ea1ng v\u0103n b\u1ea3n thu\u1ea7n t\u00fay trong c\u01a1 s\u1edf d\u1eef li\u1ec7u si\u00eau d\u1eef li\u1ec7u. Xem ph\u1ea7n&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/guides\/apache-airflow-tutorial-creating-connections-and-variables\/#a-recommended-workflow-for-sensitive-variables\">Quy tr\u00ecnh l\u00e0m vi\u1ec7c \u0111\u01b0\u1ee3c \u0111\u1ec1 xu\u1ea5t cho c\u00e1c bi\u1ebfn nh\u1ea1y c\u1ea3m<\/a>&nbsp;\u0111\u1ec3 bi\u1ebft c\u00e1ch gi\u1eef an to\u00e0n cho c\u00e1c bi\u1ebfn c\u1ee7a b\u1ea1n.<\/p>\n<h3 id=\"create-your-connection-script\">T\u1ea1o t\u1eadp l\u1ec7nh k\u1ebft n\u1ed1i c\u1ee7a b\u1ea1n<a href=\"https:\/\/www.linode.com\/docs\/guides\/apache-airflow-tutorial-creating-connections-and-variables\/#create-your-connection-script\"><\/a><\/h3>\n<p>C\u00f3 th\u1ec3 s\u1eed d\u1ee5ng Airflow CLI \u0111\u1ec3 t\u1ea1o&nbsp;<a href=\"https:\/\/airflow.apache.org\/docs\/stable\/howto\/connection\/index.html\" target=\"_blank\" rel=\"noreferrer noopener\">K\u1ebft n\u1ed1i<\/a>&nbsp;c\u1ee7a b\u1ea1n v\u1edbi b\u1ea5t k\u1ef3 h\u1ec7 th\u1ed1ng b\u00ean ngo\u00e0i n\u00e0o m\u00e0 DAG c\u1ee7a b\u1ea1n y\u00eau c\u1ea7u. Ph\u1ea7n n\u00e0y ch\u1ec9 cho b\u1ea1n c\u00e1ch t\u1ea1o k\u1ebft n\u1ed1i \u0111\u01a1n gi\u1ea3n v\u1edbi t\u1eadp l\u1ec7nh bash c\u00f3 th\u1ec3 t\u00e1i s\u1eed d\u1ee5ng m\u00e0 b\u1ea1n c\u00f3 th\u1ec3 \u00e1p d\u1ee5ng cho K\u1ebft n\u1ed1i Airflow c\u1ee7a ri\u00eang m\u00ecnh. V\u00ed d\u1ee5 b\u00ean d\u01b0\u1edbi bao g\u1ed3m k\u1ebft n\u1ed1i cho c\u01a1 s\u1edf d\u1eef li\u1ec7u MySQL.<\/p>\n<ol>\n<li>T\u1ea1o m\u1ed9t t\u1ec7p m\u1edbi c\u00f3 t\u00ean&nbsp;<code>connection.sh<\/code>. Thay th\u1ebf c\u00e1c gi\u00e1 tr\u1ecb b\u1eb1ng gi\u00e1 tr\u1ecb c\u1ee7a ri\u00eang b\u1ea1n ho\u1eb7c m\u1edf r\u1ed9ng t\u1eadp l\u1ec7nh \u0111\u1ec3 t\u1ea1o c\u00e1c K\u1ebft n\u1ed1i theo y\u00eau c\u1ea7u c\u1ee7a DAG c\u1ee7a b\u1ea1n.T\u1eadp tin: connection.sh<code>1 2 3 4 5 6 <\/code><code><strong><em>#!\/usr\/bin\/env bash <\/em><\/strong><strong><em><\/em><\/strong> airflow connections -d --conn_id db_conn airflow connections -a --conn_id db_conn --conn_type mysql --conn_host 'mysql:\/\/192.0.2.0:3306\/' --conn_schema 'dbname' --conn_login 'username' --conn_port '3306' --conn_password 'securepassword' <\/code>D\u00f2ng th\u1ee9 ba c\u1ee7a t\u1eadp l\u1ec7nh x\u00f3a m\u1ecdi k\u1ebft n\u1ed1i m\u00e0 t\u1eadp l\u1ec7nh c\u00f3 th\u1ec3 \u0111\u00e3 t\u1ea1o tr\u01b0\u1edbc \u0111\u00f3 \u0111\u1ec3 duy tr\u00ec&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Idempotence\" target=\"_blank\" rel=\"noreferrer noopener\"><em>t\u00ednh b\u1ea5t bi\u1ebfn<\/em><\/a>&nbsp;. \u0110i\u1ec1u n\u00e0y c\u00f3 ngh\u0129a l\u00e0 t\u1eadp l\u1ec7nh c\u1ee7a b\u1ea1n c\u00f3 th\u1ec3 ch\u1ea1y nhi\u1ec1u l\u1ea7n t\u00f9y \u00fd v\u1edbi c\u00f9ng k\u1ebft qu\u1ea3 mong \u0111\u1ee3i.<\/li>\n<li>\u0110\u1ea3m b\u1ea3o r\u1eb1ng b\u1ea1n c\u00f3 th\u1ec3 th\u1ef1c thi t\u1eadp l\u1ec7nh Connections c\u1ee7a m\u00ecnh:<code> chmod u+x \/home\/username\/connection.sh<\/code><\/li>\n<li>T\u1ea3i k\u1ebft n\u1ed1i c\u1ee7a b\u1ea1n b\u1eb1ng c\u00e1ch th\u1ef1c thi t\u1eadp l\u1ec7nh \u0111\u00e3 ho\u00e0n th\u00e0nh:<code> bash \/home\/username\/connection.sh<\/code><\/li>\n<li>S\u1eed d\u1ee5ng Airflow CLI \u0111\u1ec3 x\u00e1c minh r\u1eb1ng K\u1ebft n\u1ed1i m\u1edbi c\u1ee7a b\u1ea1n \u0111\u00e3 \u0111\u01b0\u1ee3c t\u1ea1o. Thay th\u1ebf&nbsp;<code>db_conn<\/code>b\u1eb1ng t\u00ean K\u1ebft n\u1ed1i c\u1ee7a b\u1ea1n.<code> airflow connections --list | grep 'db_conn'<\/code><\/li>\n<\/ol>\n<h2 id=\"a-recommended-workflow-for-sensitive-variables\">M\u1ed9t quy tr\u00ecnh l\u00e0m vi\u1ec7c \u0111\u01b0\u1ee3c \u0111\u1ec1 xu\u1ea5t cho c\u00e1c bi\u1ebfn nh\u1ea1y c\u1ea3m<a href=\"https:\/\/www.linode.com\/docs\/guides\/apache-airflow-tutorial-creating-connections-and-variables\/#a-recommended-workflow-for-sensitive-variables\"><\/a><\/h2>\n<p>N\u1ebfu b\u1ea1n s\u1eed d\u1ee5ng t\u1ec7p JSON \u0111\u1ec3 l\u01b0u tr\u1eef c\u00e1c bi\u1ebfn k\u1ebft n\u1ed1i nh\u1ea1y c\u1ea3m ho\u1eb7c n\u1ebfu b\u1ea1n s\u1eed d\u1ee5ng t\u1eadp l\u1ec7nh \u0111\u1ec3 t\u1ef1 \u0111\u1ed9ng h\u00f3a K\u1ebft n\u1ed1i Airflow c\u1ee7a m\u00ecnh, b\u1ea1n n\u00ean ph\u00e1t tri\u1ec3n quy tr\u00ecnh l\u00e0m vi\u1ec7c \u0111\u1ec3 m\u00e3 h\u00f3a v\u00e0 gi\u1ea3i m\u00e3 c\u00e1c gi\u00e1 tr\u1ecb nh\u1ea1y c\u1ea3m. Airflow l\u01b0u m\u1eadt kh\u1ea9u cho c\u00e1c k\u1ebft n\u1ed1i \u1edf d\u1ea1ng v\u0103n b\u1ea3n thu\u1ea7n t\u00fay trong c\u01a1 s\u1edf d\u1eef li\u1ec7u si\u00eau d\u1eef li\u1ec7u. Quy tr\u00ecnh l\u00e0m vi\u1ec7c cho d\u1eef li\u1ec7u k\u1ebft n\u1ed1i nh\u1ea1y c\u1ea3m c\u1ee7a b\u1ea1n \u0111\u1ea3m b\u1ea3o r\u1eb1ng c\u00e1c gi\u00e1 tr\u1ecb n\u00e0y kh\u00f4ng bao gi\u1edd \u0111\u01b0\u1ee3c hi\u1ec3n th\u1ecb \u1edf \u0111\u1ecbnh d\u1ea1ng chu\u1ed7i th\u00f4. Ph\u1ea7n b\u00ean d\u01b0\u1edbi bao g\u1ed3m b\u1ea3n ph\u00e1c th\u1ea3o cho quy tr\u00ecnh l\u00e0m vi\u1ec7c m\u00e0 b\u1ea1n c\u00f3 th\u1ec3 c\u00e2n nh\u1eafc \u0111\u1ec3 gi\u1eef an to\u00e0n cho c\u00e1c bi\u1ebfn nh\u1ea1y c\u1ea3m c\u1ee7a m\u00ecnh.<\/p>\n<ul>\n<li><strong>M\u00e3 h\u00f3a<\/strong>&nbsp;: B\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng c\u00e1c c\u00f4ng c\u1ee5 nh\u01b0&nbsp;<a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/user_guide\/vault.html\" target=\"_blank\" rel=\"noreferrer noopener\">Ansible Vault<\/a>&nbsp;\u0111\u1ec3 m\u00e3 h\u00f3a c\u00e1c gi\u00e1 tr\u1ecb nh\u1ea1y c\u1ea3m tr\u01b0\u1edbc khi l\u01b0u tr\u1eef ch\u00fang trong kho l\u01b0u tr\u1eef t\u1eeb xa, nh\u01b0&nbsp;<a href=\"https:\/\/github.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a>&nbsp;. M\u1ed9t c\u00f4ng c\u1ee5 ph\u1ed5 bi\u1ebfn kh\u00e1c \u0111\u1ec3 l\u01b0u tr\u1eef c\u00e1c gi\u00e1 tr\u1ecb nh\u1ea1y c\u1ea3m l\u00e0&nbsp;<a href=\"https:\/\/www.vaultproject.io\/\" target=\"_blank\" rel=\"noreferrer noopener\">HashiCorp Vault<\/a>&nbsp;. G\u00f3i Python&nbsp;<a href=\"https:\/\/airflow.apache.org\/docs\/stable\/howto\/secure-connections.html#securing-connections\" target=\"_blank\" rel=\"noreferrer noopener\">Crypto<\/a>&nbsp;l\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 kh\u00e1c m\u00e0 b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng \u0111\u1ec3 b\u1eadt m\u00e3 h\u00f3a cho m\u1eadt kh\u1ea9u.<\/li>\n<li><strong>Gi\u1ea3i m\u00e3<\/strong>&nbsp;: \u0110\u1ec3 ch\u1ea1y b\u1ea5t k\u1ef3 t\u1eadp l\u1ec7nh t\u1ef1 \u0111\u1ed9ng h\u00f3a n\u00e0o ch\u1ee9a c\u00e1c gi\u00e1 tr\u1ecb bi\u1ebfn \u0111\u01b0\u1ee3c m\u00e3 h\u00f3a c\u1ee7a b\u1ea1n, b\u1ea1n ph\u1ea3i bao g\u1ed3m b\u01b0\u1edbc gi\u1ea3i m\u00e3 tr\u01b0\u1edbc khi th\u1ef1c hi\u1ec7n ch\u00fang. Airflow c\u1ea7n c\u00e1c gi\u00e1 tr\u1ecb \u0111\u01b0\u1ee3c gi\u1ea3i m\u00e3 \u0111\u1ec3 ch\u1ea1y DAG c\u1ee7a b\u1ea1n. C\u1ea3 Ansible Vault v\u00e0 HaschiCorp Vault \u0111\u1ec1u bao g\u1ed3m c\u00e1c c\u01a1 ch\u1ebf cung c\u1ea5p c\u00e1c gi\u00e1 tr\u1ecb bi\u1ebfn \u0111\u01b0\u1ee3c gi\u1ea3i m\u00e3 cho Airflow.<\/li>\n<li><strong>T\u1ea3i<\/strong>&nbsp;: Sau khi gi\u1ea3i m\u00e3 \u0111\u01b0\u1ee3c c\u00e1c gi\u00e1 tr\u1ecb, h\u00e3y th\u1ef1c thi c\u00e1c t\u1eadp l\u1ec7nh c\u1ee7a b\u1ea1n.<\/li>\n<li><strong>M\u00e3 h\u00f3a<\/strong>&nbsp;: Sau khi c\u01a1 s\u1edf h\u1ea1 t\u1ea7ng t\u1ef1 \u0111\u1ed9ng c\u1ee7a b\u1ea1n t\u1ea3i c\u1ea3 Bi\u1ebfn Airflow v\u00e0 K\u1ebft n\u1ed1i, h\u00e3y m\u00e3 h\u00f3a c\u00e1c gi\u00e1 tr\u1ecb nh\u1ea1y c\u1ea3m c\u1ee7a b\u1ea1n. Theo c\u00e1ch n\u00e0y, d\u1eef li\u1ec7u nh\u1ea1y c\u1ea3m ch\u1ec9 \u0111\u01b0\u1ee3c ti\u1ebft l\u1ed9 th\u00f4ng qua C\u01a1 s\u1edf d\u1eef li\u1ec7u Airflow \u0111\u01b0\u1ee3c m\u00e3 h\u00f3a m\u00e0 ch\u1ec9 Airflow m\u1edbi c\u00f3 th\u1ec3 truy c\u1eadp.<\/li>\n<\/ul>\n<h2 id=\"conclusion\">Ph\u1ea7n k\u1ebft lu\u1eadn<a href=\"https:\/\/www.linode.com\/docs\/guides\/apache-airflow-tutorial-creating-connections-and-variables\/#conclusion\"><\/a><\/h2>\n<p>T\u1ef1 \u0111\u1ed9ng t\u1ea1o Bi\u1ebfn v\u00e0 K\u1ebft n\u1ed1i Airflow c\u1ee7a b\u1ea1n l\u00e0 b\u01b0\u1edbc c\u01a1 b\u1ea3n h\u01b0\u1edbng t\u1edbi d\u1eef li\u1ec7u minh b\u1ea1ch \u0111\u1ec3 th\u1eed nghi\u1ec7m, t\u1ea1o m\u1eabu v\u00e0 ph\u00e2n t\u00edch nhanh ch\u00f3ng. Vi\u1ec7c c\u00f3 t\u1ea5t c\u1ea3 c\u00e1c k\u1ebft n\u1ed1i d\u1eef li\u1ec7u c\u00f3 li\u00ean quan c\u1ee7a b\u1ea1n trong m\u1ed9t kho l\u01b0u tr\u1eef trung t\u00e2m v\u00e0 an to\u00e0n s\u1ebd thi\u1ebft l\u1eadp t\u1ed5 ch\u1ee9c c\u1ee7a b\u1ea1n \u0111\u1ec3 c\u1ed9ng t\u00e1c. \u0110i\u1ec1u n\u00e0y cho ph\u00e9p b\u1ea1n d\u00e0nh \u00edt th\u1eddi gian h\u01a1n cho c\u00e1c b\u01b0\u1edbc tr\u00edch xu\u1ea5t v\u00e0 t\u1ea3i c\u1ee7a quy tr\u00ecnh c\u00f4ng vi\u1ec7c v\u00e0 nhi\u1ec1u th\u1eddi gian h\u01a1n cho b\u01b0\u1edbc chuy\u1ec3n \u0111\u1ed5i.<\/p>\n<p>Sau khi ho\u00e0n th\u00e0nh h\u01b0\u1edbng d\u1eabn n\u00e0y, h\u00e3y t\u00ecm hi\u1ec3u c\u00e1ch x\u00e2y d\u1ef1ng \u0111\u01b0\u1eddng \u1ed1ng d\u1eef li\u1ec7u b\u1eb1ng Python th\u00f4ng qua&nbsp;<a href=\"https:\/\/airflow.apache.org\/docs\/stable\/tutorial.html\" target=\"_blank\" rel=\"noreferrer noopener\">h\u01b0\u1edbng d\u1eabn Pipeline m\u1eabu<\/a>&nbsp;c\u1ee7a Airflow .<\/p>\n<h2 id=\"more-information\">Th\u00f4ng tin th\u00eam<\/h2>\n<p>B\u1ea1n c\u00f3 th\u1ec3 mu\u1ed1n tham kh\u1ea3o c\u00e1c ngu\u1ed3n sau \u0111\u1ec3 bi\u1ebft th\u00eam th\u00f4ng tin v\u1ec1 ch\u1ee7 \u0111\u1ec1 n\u00e0y. M\u1eb7c d\u00f9 ch\u00fang t\u00f4i cung c\u1ea5p v\u1edbi hy v\u1ecdng r\u1eb1ng ch\u00fang s\u1ebd h\u1eefu \u00edch, nh\u01b0ng xin l\u01b0u \u00fd r\u1eb1ng ch\u00fang t\u00f4i kh\u00f4ng th\u1ec3 \u0111\u1ea3m b\u1ea3o t\u00ednh ch\u00ednh x\u00e1c ho\u1eb7c t\u00ednh k\u1ecbp th\u1eddi c\u1ee7a c\u00e1c t\u00e0i li\u1ec7u \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef b\u00ean ngo\u00e0i.<\/p>\n<ul>\n<li><a href=\"https:\/\/airflow.apache.org\/docs\/stable\/\" target=\"_blank\" rel=\"noreferrer noopener\">T\u00e0i li\u1ec7u ch\u00ednh th\u1ee9c c\u1ee7a Apache Airflow<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Apache Airflow l\u00e0 g\u00ec? Airflow&nbsp;l\u00e0 m\u1ed9t n\u1ec1n t\u1ea3ng m\u00e3 ngu\u1ed3n m\u1edf m\u00e0 b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng \u0111\u1ec3 t\u1ef1 \u0111\u1ed9ng h\u00f3a, s\u1eafp x\u1ebfp v\u00e0 gi\u00e1m s\u00e1t c\u00e1c lu\u1ed3ng c\u00f4ng vi\u1ec7c v\u00e0 \u0111\u01b0\u1eddng \u1ed1ng d\u1eef li\u1ec7u. M\u1ed9t trong nh\u1eefng t\u00ednh n\u0103ng tuy\u1ec7t v\u1eddi nh\u1ea5t c\u1ee7a Airflow l\u00e0 b\u1ea1n c\u00f3 th\u1ec3 t\u1ea1o v\u00e0 th\u1ef1c hi\u1ec7n c\u00e1c lu\u1ed3ng<\/p>\n","protected":false},"author":1,"featured_media":35459,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-34864","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-big-data"],"_links":{"self":[{"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/posts\/34864","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/comments?post=34864"}],"version-history":[{"count":0,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/posts\/34864\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/media\/35459"}],"wp:attachment":[{"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/media?parent=34864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/categories?post=34864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/tags?post=34864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}