PostgreSQL 17.0 编译安装
OS: CentOS 7
DB: PostgreSQL 17.0
1. 关闭默认防火墙 firewall
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
systemctl mask firewalld
systemctl stop firewalld
dnf remove firewalld
2.安装iptables防火墙
yum install -y iptables-services
3.编辑iptables配置文件
vim /etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
#最后重启防火墙使配置生效
systemctl restart iptables.service
#设置防火墙开机启动
systemctl enable iptables.service
#重启防火墙
/usr/libexec/iptables/iptables.init restart
4.关闭SELINUX
vim /etc/selinux/config
SELINUX=disabled
# 使配置生效
setenforce 0
5.安装依赖包
yum install -y uuid uuid-devel libuuid libuuid-devel python3 python3-devel
yum install -y tcl tcl-devel perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake gcc* readline-devel icu libicu-devel
6. 编译PostgreSQL
# 创建目录
mkdir -p /usr/local/pgsql
mkdir -p /usr/local/pgsql/data
mkdir -p /usr/local/pgsql/log
#解压postgreSQL 17.0
tar zxf postgresql-17.0.tar.gz
#编译
cd postgresql-17.0
./configure --prefix=/usr/local/pgsql --with-openssl --with-pgport=5432 --with-tcl --with-perl --with-python --with-libxml --with-libxslt --with-ossp-uuid --with-pam --with-ldap
make -j 8 && make install
7.创建用户组
groupadd postgres
useradd -g postgres postgres
8.配置权限
chown -R postgres:postgres /usr/local/pgsql
chown -R postgres:postgres /usr/local/pgsql/data
chown -R postgres:postgres /usr/local/pgsql/log
chmod -R 700 /usr/local/pgsql/log
9.配置环境变量
cat >> ~/.bash_profile <<"EOF"
export LANG=en_US.UTF-8
export PS1="[\u@\h \W]\$ "
export PGPORT=5432
export PGDATA=/usr/local/pgsql/data
export PGHOME=/usr/local/pgsql
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH:.
export DATE=`date +"%Y%m%d%H%M"`
export MANPATH=$PGHOME/share/man:$MANPATH
export PGHOST=$PGDATA
export PGUSER=postgres
export PGDATABASE=postgres
EOF
source ~/.bash_profile
10.初始化数据库
# 切换到postgres用户
su - postgres
#初始化数据库
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data --encoding=UTF8 --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8
11.启动数据库
#启动
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
#停止
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile stop
#重启
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile restart
#查看状态
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile status
不错哦,学习下。。。