개발/운영 서버를 구축 해보자!

개발 서버

OS : ubuntu22.04LTS

Python 설치

  • Dependencies 업데이트, 설치
sudo apt update
sudo apt install -y build-essential libssl-dev zlib1g-dev libncurses5-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
  • Python 3.12.4 다운로드
cd /tmp
wget https://www.python.org/ftp/python/3.12.4/Python-3.12.4.tgz
tar -xf Python-3.12.4.tgz
cd Python-3.12.4
  • Build and Install Python
./configure --enable-optimizations
make -j $(nproc)
sudo make altinstall

Python 3.12.4 기본 버전 설정

  • Update Alternatives
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.12 1
sudo update-alternatives --config python
  • 설정 확인
python --version

pip 설치

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py

Git 설치

sudo apt install git
git --version

Docker 설치

  • 업데이트 Package list
sudo apt update
  • 구 버전 도커 제거(있는 경우)
sudo apt remove docker docker-engine docker.io containerd runc

-도커 공식 Repository 설치, First, add Docker's official GPG key and repository

sudo apt install ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  • 도커 공식 Repository 추가
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  • 도커 엔진 설치
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
  • ERROR 발생
conai-ubuntu22-04lts@conai-ubuntu22-04lts-B760M-AORUS-ELITE-AX:/tmp/Python-3.12.4$ sudo apt install docker-ce docker-ce-cli containerd.io
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package docker-ce is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package docker-ce-cli is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'docker-ce' has no installation candidate
E: Package 'docker-ce-cli' has no installation candidate
E: Unable to locate package containerd.io
E: Couldn't find any package by glob 'containerd.io'
  • 도커 공식 Repository 다시 추가
sudo rm /etc/apt/sources.list.d/docker.list
sudo rm /usr/share/keyrings/docker-archive-keyring.gpg
  • 도커 공식 GPG key 추가
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  • 도커 공식 APT Repository 추가
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  • package database 업데이트
sudo apt update
  • 도커 엔진, Dependency 설치
sudo apt install docker-ce docker-ce-cli containerd.io
  • 도커 설치 확인
sudo systemctl start docker
sudo systemctl enable docker
docker --version
  • 도커 테스트
sudo docker run hello-world

Docker-compose 설치

  • Docker Compose Binary 다운로드
sudo curl -L "https://github.com/docker/compose/releases/download/v2.21.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  • 실행 권한 부여
sudo chmod +x /usr/local/bin/docker-compose
  • Docker Compose 설치 확인
docker-compose --version

PostgreSQL 설치

  • System Package 업데이트
sudo apt update
  • Dependecies 설치
sudo apt install -y wget ca-certificates
  • PostgreSQL repository 추가
wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
  • ERROR 발생
ubuntu:~/Development/service$ wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK
ubunt:~/Development/service$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
ubunt:~/Development/service$ 
  • old key 제거
sudo rm /etc/apt/trusted.gpg.d/pgdg.asc
  • PostgreSQL 키 추가
wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc
  • Package list 업데이트
sudo apt update
  • PostgreSQL14.12 설치
sudo apt install postgresql-14
  • PostgreSQL 실행 및 활성화
sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo systemctl status postgresql
  • PostgreSQL 연결(postgres user로 변경)
sudo -i -u postgres
  • PostgreSQL 접속
psql
  • PostgreSQL 버전 확인
SELECT version();

PostgreSQL 설정

  • PostgreSQL 연결(postgres user로 변경)
sudo -i -u postgres
  • PostgreSQL Command line tool 접속
psql
  • 신규 사용자(Role) 생성
CREATE USER username WITH PASSWORD 'password';
  • 슈퍼 유저 권한 부여
ALTER USER username WITH SUPERUSER;
  • 데이터 베이스 생성 권한 부여
ALTER USER username CREATEDB;
  • postgres 계정 비밀번호 설정(비밀 번호 없음)
ALTER USER postgres WITH PASSWORD 'your_new_password';

외부 접근 허용

  • postgresql.conf 설정 수정 => listen_addresses = '*'
sudo nano /etc/postgresql/14/main/postgresql.conf
  • pg_hba.conf 설정 수정
    => host all all 192.168.1.0/24 md5
sudo nano /etc/postgresql/14/main/pg_hba.conf
  • PostgreSQL 서비스 재시작
sudo systemctl restart postgresql
profile
The Man Who Lift

0개의 댓글