Linux中安装Postgresql数据库详细过程

x33g5p2x  于2020-09-08 发布在 Linux  
字(1.3k)|赞(0)|评价(0)|浏览(1580)

1 创建Database服务器Ubuntu18.04server

  • Hostname为database
  • Username为busuanzi
  • 静态IP地址为192.168.56.110

详细创建服务器步骤见第二章 Linux,关键步骤如下。

2 安装PostgreSQL

  1. sudo vim /etc/apt/sources.list.d/pgdg.list
  1. deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main
  1. wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
  2. sudo apt update
  1. sudo apt install postgresql-10

3 登录Postgresql、修改密码、创建新用户、新数据库

登录Postgresql

  1. sudo -u postgres psql postgres

修改密码

  1. ALTER ROLE postgres PASSWORD 'wxl1234' ;

创建新用户、新数据库

  1. CREATE ROLE busuanzi WITH PASSWORD 'wxl123' LOGIN ;
  2. CREATE DATABASE busuanzidb OWNER 'busuanzi';


退出

  1. \q

4 允许远程登录

修改postgresql.conf

  1. sudo vim /etc/postgresql/10/main/postgresql.conf

修改内容如下

  1. listen_addresses = '*'

修改pg_hba.conf

  1. sudo vim /etc/postgresql/10/main/pg_hba.conf

修改内容如下

  1. local all postgres md5
  2. # TYPE DATABASE USER ADDRESS METHOD
  3. # "local" is for Unix domain socket connections only
  4. local all all md5
  5. # IPv4 local connections:
  6. host all all 127.0.0.1/32 md5
  7. # IPv6 local connections:
  8. host all all ::1/128 md5
  9. host all all 192.168.56.0/0 md5
  10. # Allow replication connections from localhost, by a user with the
  11. # replication privilege.
  12. local replication all peer
  13. host replication all 127.0.0.1/32 md5
  14. host replication all ::1/128 md5

重启postgresql服务

  1. sudo service postgresql restart

5 postgres安装、配置完毕,使用客户端即可连接数据库。

6 PostgreSQL地址

  1. jdbc:postgresql://192.168.56.110:5432/busuanzidb

开源、源码获取 https://github.com/lycheeman/big-data

相关文章

最新文章

更多