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

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

1 创建Database服务器Ubuntu18.04server

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

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

2 安装PostgreSQL

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

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

登录Postgresql

sudo -u postgres psql postgres

修改密码

ALTER ROLE postgres PASSWORD 'wxl1234' ;

创建新用户、新数据库

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


退出

\q

4 允许远程登录

修改postgresql.conf

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

修改内容如下

listen_addresses = '*'

修改pg_hba.conf

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

修改内容如下

local   all             postgres                                md5

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     md5
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
host    all             all             192.168.56.0/0          md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

重启postgresql服务

sudo service postgresql restart

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

6 PostgreSQL地址

jdbc:postgresql://192.168.56.110:5432/busuanzidb

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

相关文章