본문 바로가기

취미개발

AirFlow 환경 만들기(1) - Postgres 설치하기(feat. docker)

반응형

[취미개발] - AirFlow 환경 만들기(2) - Airflow 설치하기(feat. docker)


airflow를 실행하기 위해서는 linux환경이 필요합니다.

windows환경에서 airflow를 실행하려면 다음과 같은 방법이 존재합니다.
1) docker를 이용한 방법
2) WSL을 이용한 방법

여기서는 1번 방법인 docker를 이용한 방법을 소개할게요.

-----

airflow의 경우 postgres나 mysql와 같은 db를 붙여주어야만 병렬처리가 가능해집니다.
docker로 airflow를 위한 postgres설치 방법을 알아볼게요.

0. Docker & DBeaver 설치

아래 URL로 접속하여 본인의 OS에 맞는 docker desktop을 설치하고 재부팅 합시다.
https://www.docker.com/products/docker-desktop

 

Docker Desktop for Mac and Windows | Docker

Learn why Docker Desktop is the preferred choice for millions of developers building containerized applications. Download for Mac or Windows.

www.docker.com

DB관리를 위한 DBeaver도 설치합시다.
https://dbeaver.io/download/

 

Download | DBeaver Community

Download Tested and verified for MS Windows 7/8/10, Linux and Mac OS X. DBeaver requires Java 1.8 or higher. Windows and MacOS installers include OpenJDK 11 bundle. If you are on Mac OS X and you do NOT use PKG installer then you will need to setup Java. N

dbeaver.io

 

1. Docker상에서 Postgres 설정

Docker에서 Postgres Image를 Pull한 뒤 Container를 생성합니다.

$ docker pull postgres

$ docker run -d -p 5432:5432 --name postgres -e LC_ALL=C.UTF-8 -e POSTGRES_PASSWORD=0000 postgres

 

생성된 container로 접속하여 DB, User 생성 및 권한 설정을 해줍니다. 

$ docker exec -it postgres bash

:/# psql -U postgres

postgres=# CREATE DATABASE airflow;
postgres=# CREATE USER timmy with ENCRYPTED password '0000';
postgres=# GRANT all privileges on DATABASE airflow to timmy;

postgres=# \c airflow
airflow=# GRANT all privileges on  all tables in schema public to timmy;
airflow=# \q
:/# exit

 

다음 postgre cluster를 만들어줍니다. (이떄 postgres12라 cluster도 12로 만들어주었습니다.)

# pg_createcluster 12 main
# pg_ctlcluster 12 main start

(cluster 버전 확인 : https://www.postgresql.org/docs/current/creating-cluster.html)

다음 pg_hba.conf 파일을 수정해주어야 합니다.

# cd /etc/postgresql/12/main
# vim pg_hba.conf
# IPv4 local connections:                                                          
host		all             all             0.0.0.0/0               md5 

postgres를 재부팅 시켜줍니다.

# service postgresql restart

이제 DBeaver를 통해 해당 DB에 접근이 잘되는지 확인해보자

 

이제 완성된 Postgres 컨테이너를 commit합니다. 필요시 자신의 Docker hub에 Push할 수 있습니다.

$ docker commit postgres postgres:airflow

// 자신 {{id}}의 Docker Hub에 Push할 경우
$ docker commit postgres {{id}}/postgres:airflow
$ docker push {{id}}/postgres:airflow

 

(optional) 기존의 컨테이너를 삭제하고 새로 만든 image로 새롭게 컨테이너를 실행합니다.

$ docker run -d -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=0000 {{id}}/postgres:airflow

 

이제 airflow를 위한 DB세팅이 완료되었습니다.

 


[취미개발] - AirFlow 환경 만들기(2) - Airflow 설치하기(feat. docker)

반응형