【CentOS 7】yum安装【PostgreSQL 9.6】
xixuefeng
Other
2017-11-16 14:18:59
1,586 次浏览
postgresql
【CentOS 7】yum安装【PostgreSQL 9.6】已关闭评论
1:下载pg9.6的yum源
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@Yjiu ~]# yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm -y …… Running transaction Installing : pgdg-centos96-9.6-3.noarch 1/1 Verifying : pgdg-centos96-9.6-3.noarch 1/1 Installed: pgdg-centos96.noarch 0:9.6-3 Complete! [root@Yjiu ~]# [root@Yjiu ~]# ls -l /etc/yum.repos.d |grep pg -rw-r--r-- 1 root root 1012 Sep 21 2016 pgdg-96-centos.repo [root@Yjiu ~]# |
2:安装客户端
1 2 3 4 5 6 7 8 9 10 |
[root@Yjiu ~]# yum install postgresql96 -y …… Installed: postgresql96.x86_64 0:9.6.6-1PGDG.rhel7 Dependency Installed: postgresql96-libs.x86_64 0:9.6.6-1PGDG.rhel7 Complete! [root@Yjiu ~]# |
3:安装服务端
1 2 3 4 5 6 7 |
[root@Yjiu ~]# yum install postgresql96-server -y …… Installed: postgresql96-server.x86_64 0:9.6.6-1PGDG.rhel7 Complete! [root@Yjiu ~]# |
4:初始化数据库
1 2 3 4 |
[root@Yjiu ~]# /usr/pgsql-9.6/bin/postgresql96-setup initdb Initializing database ... OK [root@Yjiu ~]# |
5:设置开机自动启动、启动数据库
1 2 3 4 |
[root@Yjiu ~]# systemctl enable postgresql-9.6 Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-9.6.service to /usr/lib/systemd/system/postgresql-9.6.service. [root@Yjiu ~]# systemctl start postgresql-9.6 [root@Yjiu ~]# |
6:修改密码
直接输入psql,默认也是以postgres用户登录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@Yjiu ~]# su - postgres -bash-4.2$ -bash-4.2$ psql -U postgres psql (9.6.6) Type "help" for help. postgres=# postgres=# alter user postgres with password 'Yjiuadmin'; ALTER ROLE postgres=# \q -bash-4.2$ -bash-4.2$ exit logout [root@Yjiu ~]# |
7:修改配置,允许所有地址都可登录
1 2 3 |
[root@Yjiu ~]# vi /var/lib/pgsql/9.6/data/postgresql.conf 文件尾部追加 listen_addresses = '*' |
8:主机认证
1 2 3 |
[root@Yjiu ~]# vi /var/lib/pgsql/9.6/data/pg_hba.conf 尾部追加 host all all 192.168.31.231/32 trust |
9:设置环境变量
1 2 3 4 5 6 7 |
[root@Yjiu ~]# vi ~/.bash_profile 追加 export PATH=$PATH:/usr/pgsql-9.6/bin ## 使其生效 [root@Yjiu ~]# . ~/.bash_profile [root@Yjiu ~]# |
10:重启pg服务
1 2 |
[root@Yjiu ~]# systemctl restart postgresql-9.6 [root@Yjiu ~]# |
各版本、平台安装,参考官方文档https://www.postgresql.org/download/
CentOS安装:https://www.postgresql.org/download/linux/redhat/