728x90
🚀 개요
이 문서에서는 Python 3.10.14와 PostgreSQL 13.18을 활용하여 Apache Airflow 2.7.3을 설치하고 설정하는 방법을 단계별로 설명합니다. 또한, 발생 가능한 문제에 대한 트러블슈팅 방법도 포함되어 있습니다.
💡 1. 사전 준비
✅시스템 환경 확인
# python --version
Python 3.10.14
# psql --version
psql (PostgreSQL) 13.18
Python 과 PostgreSQL 설치는 이전에 포스팅 한글을 참고하면 됩니다.
2024.08.28 - [OS/Linux] - [Ubuntu] PostgreSQL 수동 설치
[Ubuntu] PostgreSQL 수동 설치
컴파일 등에 필요한 기본 패키지들은 구성이 되있다고 가정하고 진행하겠다.PostgreSQL 파일 설치wget http://ftp.postgresql.org/pub/source/v12.1/postgresql-12.1.tar.gztar zxvf postgresql-12.1.tar.gzcd postgresql-12.1mkdir -p /A
www.estar987.com
2025.02.04 - [OS/Linux] - [Linux] CentOS7.4 버전에서 Python 3.10.14 설치 및 Troubleshooting 매뉴얼
🚧 2. PostgreSQL 후속 작업
✅환경 변수 설정
# cat /APP/enhpc/profile.d/postgresql-v13.18
-----------------------------------------------
#!/bin/bash
export PG_HOME=/APP/enhpc/postgresql
export PATH=$PG_HOME/bin:$PATH
export LD_LIBRARY_PATH=$PG_HOME/lib:$LD_LIBRARY_PATH
export MANPATH=$PG_HOME/share/man:$MANPATH
✅소스 적용
# source /APP/enhpc/profile.d/postgresql-v13.18
✅PostgreSQL 초기화 및 시작
- postgres 사용자 생성
# useradd -m -d /home/postgres -s /bin/bash postgres
# passwd postgres
- 데이터 디렉토리 생성 및 권한 설정
# mkdir -p /APP/enhpc/postgresql/data
# chown -R postgres:postgres /APP/enhpc/postgresql/data
- 데이터 베이스 초기화
# su - postgres
$ /APP/enhpc/postgresql/bin/initdb -D /APP/enhpc/postgresql/data
- PostgreSQL 서버 시작
$ /APP/enhpc/postgresql/bin/pg_ctl -D /APP/enhpc/postgresql/data -l logfile start
✅시스템 서비스 등록
# cat /etc/systemd/system/postgresql.service
-----------------------------------------------------
[Unit]
Description=PostgreSQL 13.18 Database Server
After=network.target
[Service]
Type=forking
User=postgres
ExecStart=/APP/enhpc/postgresql/bin/pg_ctl start -D /APP/enhpc/postgresql/data -l /APP/enhpc/postgresql/logfile
ExecStop=/APP/enhpc/postgresql/bin/pg_ctl stop -D /APP/enhpc/postgresql/data
ExecReload=/APP/enhpc/postgresql/bin/pg_ctl reload -D /APP/enhpc/postgresql/data
Restart=always
[Install]
WantedBy=multi-user.target
- 데몬 reload 및 start&enable
# systemctl daemon-reload
# systemctl start postgresql
# systemctl enable postgresql
🌟3. Airflow 2.7.3 설치
✅Airflow 설치 경로 설정 및 설치
# /APP/enhpc/python/v3.10.14/bin/pip install --upgrade pip setuptools wheel
# export AIRFLOW_VERSION=2.7.3
# export PYTHON_VERSION=3.10
# export CONSTRAINT_URL="https://raw.githubusercontent.com/apache/airflow/constraints-${AIRFLOW_VERSION}/constraints-${PYTHON_VERSION}.txt"
# /APP/enhpc/python/v3.10.14/bin/pip install "apache-airflow[postgres]==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}" --target=/APP/enhpc/python/v3.10.14/airflow
✅ 환경 변수 설정
# vi /APP/enhpc/profile.d/python-v3.10.14
------------------------------------------------------------------
# 라이브러리 및 컴파일러 설정
export LDFLAGS="-L/usr/local/lib -L/usr/local/openssl/lib"
export CPPFLAGS="-I/usr/local/include -I/usr/local/openssl/include"
# Python 환경 설정
export PYTHONHOME=/APP/enhpc/python/v3.10.14
export PYTHONPATH=/APP/enhpc/python/v3.10.14/lib/python3.10
# 라이브러리 경로 설정
export LD_LIBRARY_PATH=/APP/enhpc/sqlite/lib:/usr/local/openssl/lib:/usr/local/lib:/APP/enhpc/postgresql/lib:$LD_LIBRARY_PATH
# 패키지 설정 경로
export PKG_CONFIG_PATH=/APP/enhpc/sqlite/lib/pkgconfig
# 실행 경로 우선순위 설정
export PATH=/APP/enhpc/sqlite/bin:/APP/enhpc/python/v3.10.14/bin:/APP/enhpc/postgresql/bin:$PATH
# openssl & python 경로 설정
export LD_LIBRARY_PATH=/usr/local/openssl/lib:$LD_LIBRARY_PATH
export PATH=/APP/enhpc/python/v3.10.14/bin:$PATH
✅적용하기
# source /APP/enhpc/profile.d/python-v3.10.14
📈PostgreSQL 과 Airflow 연결
✅PostgreSQL 사용자 및 데이터 베이스 생성
# su - postgres
$ psql
CREATE DATABASE airflow_db;
CREATE USER airflow_user WITH PASSWORD 'airflow_password';
GRANT ALL PRIVILEGES ON DATABASE airflow_db TO airflow_user;
\q
✅Airflow 설정 및 초기화
$ source /APP/enhpc/profile.d/python-v3.10.14
$ airflow db init
✅Airflow 자동 활성화(선택 사항)
# echo "source /APP/enhpc/profile.d/python-v3.10.14" >> /home/postgres/.bash_profile
# source /home/postgres/.bash_profile
🖥️Airflow 초기화 및 실행
✅데이터 베이스 초기화
# airflow db init
✅관리자 계정 생성
# airflow users create \
--username admin \
--password admin_password \
--firstname Admin \
--lastname User \
--role Admin \
--email admin@example.com
✅웹 서버 및 스케줄러 실행
# airflow webserver --port 8080 &
# airflow scheduler &
📸 Airflow 로그인 화면 (설치 완료 후)
⚠️ Troubleshooting
1️⃣ Airflow 명령어 인식 불가 오류
bash: airflow: command not found
- 원인: 환경 변수 설정 누락
- 해결 방법
source /APP/enhpc/profile.d/python-v3.10.14
2️⃣ 서비스 시작 실패 (systemctl 오류)
systemctl status postgresql.service
journalctl -xe
- 원인: 설정 파일 문법 오류
- 해결: /etc/systemd/system/postgresql.service의 [Unit] 섹션 확인
3️⃣ 로그 파일 권한 문제
/bin/sh: /APP/enhpc/postgresql/logfile: Permission denied
- 해결 방법
touch /APP/enhpc/postgresql/logfile
chown postgres:postgres /APP/enhpc/postgresql/logfile
chmod 644 /APP/enhpc/postgresql/logfile
4️⃣ 포트 충돌 또는 중복 실행
- postgres 관련한 모든 프로세스들을 kill -9 명령어로 종료 시킨다.
ps aux | grep postgres
kill -9 <PID>
5️⃣ 데이터베이스 연결 오류
psql: could not connect to server: No such file or directory
- 원인: PostgreSQL 서버가 비정상적으로 종료됨
- 해결: 서버 재시작
systemctl restart postgresql
6️⃣ SQLite C 라이브러리 버전 오류
airflow.exceptions.AirflowConfigException: error: SQLite C library too old (< 3.15.0)
- 원인: 시스템에 설치된 SQLite C 라이브러리 버전이 너무 낮음
- 해결 방법:
# 최신 SQLite 소스 다운로드
wget https://www.sqlite.org/2024/sqlite-autoconf-3480000.tar.gz
# 컴파일 및 설치
cd ~/sqlite-autoconf-3480000
tar -xvzf sqlite-autoconf-3480000.tar.gz
cd sqlite-autoconf-3480000
./configure --prefix=/APP/enhpc/sqlite
make -j$(nproc)
make install
# 환경 변수 설정
export LD_LIBRARY_PATH=/APP/enhpc/sqlite/lib:$LD_LIBRARY_PATH
export PATH=/APP/enhpc/sqlite/bin:$PATH
# 적용하기
source /APP/enhpc/profile.d/python-v3.10.14
🎯 최종 확인
psql --version # PostgreSQL 13.18
which psql # /APP/enhpc/postgresql/bin/psql
# Airflow 버전 확인
airflow version # 2.7.3
브라우저에서 http://localhost:8080으로 접속하여 Airflow UI 확인이 가능하면 성공적으로 설정이 완료된 것입니다. 🚀
'OS > Linux' 카테고리의 다른 글
[Linux] Dell 서버 iDRAC(IPMI) 관리용 ipmitool 소스 컴파일 설치 가이드 (0) | 2025.02.19 |
---|---|
[Linux] PostgreSQL, Airflow 및 OS 계정 연동 (0) | 2025.02.18 |
[Linux] CentOS7.4 버전에서 Python 3.10.14 설치 및 Troubleshooting 매뉴얼 (0) | 2025.02.16 |
[Linux] watch 명령어 : 실시간 모니터링 (0) | 2025.02.09 |
[Linux] 파일 시스템 오류 복구 : fsck (0) | 2025.01.31 |