CentOS7安装PostgreSQL9.6

来源:互联网 发布:网络热点视频 编辑:程序博客网 时间:2024/05/17 23:48

       在centos 7 上安装postgresql 9.6,步骤如下:


1. 修改CentOS-Base.repo文件,在[base][updates]添加如下行

   exclude=postgresql*

     示例如下:

# vi /etc/yum.repos.d/CentOS-Base.repo

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
exclude=postgresql*

#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
exclude=postgresql*

2. 将postgresql9.6加入到yum的repository

#yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm


3. 更新、查看安装包列表

# yum list postgresql*

当提示“Is this ok [y/d/N]:”时,输入y

等待命令执行完成,检查96相关安装包信息如下

postgresql96.x86_64                                            9.6.3-1PGDG.rhel7                               pgdg96
postgresql96-contrib.x86_64                                    9.6.3-1PGDG.rhel7                               pgdg96
postgresql96-debuginfo.x86_64                                  9.6.3-1PGDG.rhel7                               pgdg96
postgresql96-devel.x86_64                                      9.6.3-1PGDG.rhel7                               pgdg96
postgresql96-docs.x86_64                                       9.6.3-1PGDG.rhel7                               pgdg96
postgresql96-libs.x86_64                                       9.6.3-1PGDG.rhel7                               pgdg96
postgresql96-odbc.x86_64                                       09.06.0300-1PGDG.rhel7                          pgdg96
postgresql96-plperl.x86_64                                     9.6.3-1PGDG.rhel7                               pgdg96
postgresql96-plpython.x86_64                                   9.6.3-1PGDG.rhel7                               pgdg96
postgresql96-pltcl.x86_64                                      9.6.3-1PGDG.rhel7                               pgdg96
postgresql96-server.x86_64                                     9.6.3-1PGDG.rhel7                               pgdg96
postgresql96-tcl.x86_64                                        2.1.1-1.rhel7                                   pgdg96
postgresql96-tcl-debuginfo.x86_64                              2.1.1-1.rhel7                                   pgdg96
postgresql96-test.x86_64                                       9.6.3-1PGDG.rhel7                               pgdg96


4.安装

# yum install postgresql96-server postgresql96-contrib  postgresql96-devel

提示“Is this ok [y/d/N]:”时,输入y


5.设置开机自启动

systemctl enable postgresql-9.6.service



6.初始化DB

红色标记为数据文件存放的路径

#/usr/pgsql-9.6/bin/postgresql96-setup initdb -D/var/lib/pgsql/9.6/data



7.DB监听端口及访问控制

7.1 修改pgdata文件夹(比如/var/lib/pgsql/9.6/data)下的postgresql.conf:

listen_addresses = '*' //使其能够监听所有的ip地址

port = 5432 //端口号,一个实例,一个端口号,不能重复


7.2 修改pg_hba.conf:

local   all             all                                    trust

host    all             all             127.0.0.1/32            trust

host    all             all             ::1/128                trust

host     all                all         0.0.0.0/0 md5



8.服务的启动及停止

systemctl stop postgresql-9.6.service  (停止)
systemctl start postgresql-9.6.service(启动)


9.修改postgres用户的密码

su - postgres
psql -p 5432
postgres=# ALTER USER postgres WITH PASSWORD '你要设置的密码';


原创粉丝点击