1. CentOS์ PostgreSQL ์ค์น
์ค์น ํ๊ฒฝ
- NHN Cloud ์ธ์คํด์ค ๋๋ Docker ์ปจํ ์ด๋
- CentOS 7.9
Workflow
- ์คํฌ๋ฆฝํธ ์คํ์ ์ค์นํ๊ณ ์ ํ๋ ๋ฒ์ ์ด ์ ๋ ฅ๋์๋์ง ํ์ธ
- ์ค์นํ๊ณ ์ ํ๋ PC์ OS, ์ํคํ ์ฒ๊ฐ ์ ํฉํ์ง ํ์ธ
- CentOS 7์ธ์ง ํ์ธ
- PostgreSQL์ด ์ด๋ฏธ ์ค์น๋ ๊ฒฝ์ฐ ์ ๊ฑฐ
- ํ์ํ ํจํค์ง ์ค์น ๋ฐ yum ๋ ํฌ์งํ ๋ฆฌ ์ ๋ฐ์ดํธ
- PostgreSQL ์ค์น
- ์ด๊ธฐํ ๋ฐ ์ ์ ๋น๋ฐ๋ฒํธ ์ค์
- ์ธ๋ถ ์ ์์ ์ํ pg_hba.conf์ postgresql.conf ์์ ๋ฐ ์ฌ์์
- PostgreSQL ์คํ
์ค์น ์คํฌ๋ฆฝํธ
#!/usr/bin/env bash
# ์ค์นํ๊ณ ์ ํ๋ ๋ฒ์
version=$1
major_version=${version%%.*} # 15.2 -> 15
# ์ค์นํ๋ ค๋ ๋ฒ์ ๋ฒํธ๋ฅผ ๋ฐ์๋์ง ํ์ธ
if [ $# -eq 0 ]; then
echo -e "\033[31;1m>> Error: Version number is missing. Usage: ./install_postgres_yum.sh <version>\033[0m"
exit 1
fi
# OS๊ฐ Linux x86_64์ธ์ง ํ์ธ
if [ "$(uname -s)" != "Linux" ]; then
echo -e "\033[31;1m>> Error: Your OS is not supported.\033[0m"
exit 1
fi
if [ "$(uname -m)" != "x86_64" ]; then
echo -e "\033[31;1m>> Error: Your architecture is not supported.\033[0m"
exit 1
fi
# CentOS๊ฐ Enterprise Linux 7 (EL7)์ธ์ง ํ์ธ
if [ "$(rpm -q --queryformat '%{VERSION}' centos-release)" != "7" ]; then
echo -e "\033[31;1m>> Error: This script is only compatible with Enterprise Linux 7 (EL7)\033[0m"
exit 1
fi
# PostgreSQL์ด ์ด๋ฏธ ์ค์น๋์ด ์๋ค๋ฉด ์ ๊ฑฐ
if yum list installed | grep postgresql; then
echo -e "\033[31;1m>> Remove PostgreSQL already installed...\033[0m"
sudo yum -y remove postgresql*
fi
# ํ์ํ ํจํค์ง ์ค์น
echo -e "\033[31;1m>> Install required packages...\033[0m"
yum install -y sudo
sudo yum -y update
sudo yum install -y epel-release
sudo yum install -y zstd
# PostgreSQL ์ค์น
echo -e "\033[31;1m>> Install PostgreSQL...\033[0m"
sudo yum install -y https://download.postgresql.org/pub/repos/yum/${major_version}/redhat/rhel-7-x86_64/postgresql${major_version}-libs-${version}-1PGDG.rhel7.x86_64.rpm
sudo yum install -y https://download.postgresql.org/pub/repos/yum/${major_version}/redhat/rhel-7-x86_64/postgresql${major_version}-${version}-1PGDG.rhel7.x86_64.rpm
sudo yum install -y https://download.postgresql.org/pub/repos/yum/${major_version}/redhat/rhel-7-x86_64/postgresql${major_version}-server-${version}-1PGDG.rhel7.x86_64.rpm
# ์ด๊ธฐํ
echo -e "\033[31;1m>> Initialize PostgreSQL...\033[0m"
sudo /usr/pgsql-${major_version}/bin/postgresql-${major_version}-setup initdb
# ์์
echo -e "\033[31;1m>> Start PostgreSQL...\033[0m"
sudo systemctl start postgresql-${major_version}
sudo systemctl enable postgresql-${major_version}
# ์ ์ ์์ฑ
username="postgres"
password="nhnpostgres123"
sudo adduser $username
echo "$username:$password" | sudo chpasswd
# postgres user๋ก ๋ณ๊ฒฝ ํ ์ค์ ํ์ผ ์์
echo -e "\033[31;1m>> Edit pg_hba.conf and postgresql.conf\033[0m"
sudo su - postgres <<EOF
echo "host all all 133.186.251.35/22 md5" >> /var/lib/pgsql/${major_version}/data/pg_hba.conf
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" /var/lib/pgsql/${major_version}/data/postgresql.conf
exit
EOF
# ์ฌ์์
echo -e "\033[31;1m>> Restart PostgreSQL...\033[0m"
sudo systemctl restart postgresql-${major_version}
# ์คํ
echo -e "\033[31;1m>> Run PostgreSQL...\033[0m"
sudo su - postgres -c "psql"