Airflow 도커로 세팅 본문
도커 윈도우에서 설치 이후..
centOS 8.x 버전 설치
- 현재 최신 버전이 8.x 라서 latest로 설치하면 아마 8.x가 설치될 것임
docker run -p 8080:8080 --name [이름은 마음대로..] -it centos:latest
파이선 및 기타 개발 툴 설치
yum install python3 python3-devel vim
yum groupinstall "Development Tools"
centOS 접속 한 이후 ll 명령어를 추가해준다
bash 접속후 .. ll이 없어서 불편해서 추가해주는거
echo "alias ll='ls --color=auto -alF'" >> ~/.bashrc
source ~/.bashrc
pip 버전 업그레이드 (공식 문서 기준)
https://airflow.apache.org/docs/apache-airflow/stable/start/local.html
pip3 install --upgrade pip==20.2.4
airflow 설치
https://airflow.apache.org/docs/apache-airflow/stable/start/local.html
.sh 스크립트 만들어서 실행
그냥 /home에 airflow.sh 파일 만들어서 실행하면 됨
# airflow needs a home, ~/airflow is the default,
# but you can lay foundation somewhere else if you prefer
# (optional)
export AIRFLOW_HOME=~/airflow
AIRFLOW_VERSION=2.0.1
PYTHON_VERSION="$(python3 --version | cut -d " " -f 2 | cut -d "." -f 1-2)"
# For example: 3.6
CONSTRAINT_URL="https://raw.githubusercontent.com/apache/airflow/constraints-${AIRFLOW_VERSION}/constraints-${PYTHON_VERSION}.txt"
# For example: https://raw.githubusercontent.com/apache/airflow/constraints-2.0.2/constraints-3.6.txt
pip3 install "apache-airflow==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}"
airflow 실행 및 기타
# initialize the database
airflow db init
airflow users create \
--username admin \
--firstname Peter \
--lastname Parker \
--role Admin \
--email spiderman@superhero.org
# 패스워드 입력 하면 admin의 패스워드가 됨 (pw : admin)
# start the web server, default port is 8080
airflow webserver --port 8080
# start the scheduler
# open a new terminal or else run webserver with ``-D`` option to run it as a daemon
airflow scheduler
# visit localhost:8080 in the browser and use the admin account you just
# created to login. Enable the example_bash_operator dag in the home page
내일 아래꺼 다시 해보기 전에 ..
→ postgrel 그거 블로그에 있는 툴 가지고 로컬 postgre DB 생성 한번 확인해보기
이후
airflow + postgresql 연동하기
(아래에 POSTGRES_PASSWORD 이게 무슨 PW 인지 확인 필요 .. )
https://dhznsdl.tistory.com/18
$ docker pull postgres
$ docker run -d -p 5432:5432 --name postgres -e LC_ALL=C.UTF-8 -e POSTGRES_PASSWORD=0000 postgres
$ 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; --> 이거는 공식 사이트 기준으로 값을 줌--> https://airflow.apache.org/docs/apache-airflow/stable/howto/set-up-database.html
< 아래는 아직 안함 >postgres=# \c airflow airflow=# GRANT all privileges on all tables in schema public to timmy; airflow=# \q :/# exit
< postgre 현 버전이 13이라 13으로 클러스터 만들어줌 > # pg_createcluster 13 main # pg_ctlcluster 13 main start
cd /etc/postgresql/12/main # vim pg_hba.conf--> 여기서 command not found 뜨면 --> apt-get update / apt-get install vim
service postgresql restart
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
< airflow 서버 영역 >
cfg 파일 sql_alchemy_conn 세팅--> sql_alchemy_conn = postgresql+psycopg2://airflow_user:airflow_pass@172.17.0.3/airflow_db--> ipconfig 해서 ip 주소 잘 넣어야 함 (localhost가 아님!)--> 생각해보면 localhost가 안되는게 이해가 되기도 함 ..
pip3 install psycopg2 실패나면 아래--> pip3 install --upgrade pip==21.1.2--> pip3 못찾길래 which pip3 해서 해당 위치 가서 pip3 install psycopg2
airflow db init 해주고 나서 admin 계정 다시 생성해줘야해(postgre DB 에다가 다시 세팅해줘야 하기 때문)
→ admin 계정 다시 생성해줄때 서버 환경에서는 airflow 계정으로만 생성해야 /game/apps/airflow에 적용되기 때문에 SRE 통해 처리해야 함
'개발 > Airflow' 카테고리의 다른 글
Airflow 세팅 (0) | 2021.08.06 |
---|---|
Airflow 개념 (0) | 2021.08.06 |