- 解压文件-》进入路径
tar -zvxf postgresql-9.6.3.tar.gz
cd postgresql-9.6.3
- 配置
./configure --prefix=/opt/pgsq
如果报以下错误:
执行yum -y install -y readline-devel
再执行./configure --prefix=/opt/pgsq
2、/编译
make
- 安装
make install
- 创建用户组和用户
groupadd postgres
useradd –g postgres postgres
- 创建数据库库文件存储目录、给postgres赋予权限
mkdir /opt/pgsq/data
cd /opt/pgsq
chown postgres.postgres data
- 初始化数据库目录
切换用户
su - postgres
初始化数据
/opt/pgsq/bin/initdb -D /opt/pgsq/data
启动数据库
/opt/pgsq/bin/postmaster -D /opt/pgsq/data
- 配置监听地址和端口
vi /opt/pgsq/data/postgresql.conf
取消注释并改为一下内容:
- 允许远程连接
vi /opt/pgsq/data/pg_hba.conf
添加以下配置
配置iptables让远程主机能访问
Vi /etc/sysconfig/iptables
添加
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
Service iptables restart
如果失败了,如下图:
iptables -N RH-Firewall-1-INPUT
service iptables save
- 让postgresql数据库随系统启动而启动
Cd /etc/rc.d/init.d
cp /root/postgresql-9.6.3/contrib/start-scripts/linux postgresql
chmod +x postgresql
vi postgresql
chkconfig --add postgresql
- 启动数据库