云网牛站
所在位置:首页 > Linux云数据库 > 给在Linux虚拟机里运行的FreeBSD 12安装PostgreSQL 11

给在Linux虚拟机里运行的FreeBSD 12安装PostgreSQL 11

2019-03-08 15:09:13作者:增君郁稿源:云网牛站

本文介绍在FreeBSD 12系统中安装PostgreSQL 11的方法,使用Internet连接启动并运行FreeBSD 12,你还应该以root用户或具有sudo权限的用户身份运行安装程序。FreeBSD是运行在Linux虚拟机VMware里的,参考在Ubuntu 18.04系统下安装VMware Workstation Player的方法

给在Linux虚拟机里运行的FreeBSD 12安装PostgreSQL 11

 

一、更新所有软件包存储库目录

第一个操作是更新可用的远程存储库目录:

$ sudo pkg update

Updating FreeBSD repository catalogue…

FreeBSD repository is up to date.

All repositories are up to date.

如果要将软件包升级到存储库中提供的较新版本,请运行:

sudo pkg upgrade

 

二、在FreeBSD 12上安装PostgreSQL 11

使用pkg包管理器下载并安装PostgreSQL服务器和客户端软件包:

sudo pkg install postgresql11-server postgresql11-client

安装完成后,启动并启用PostgreSQL服务以在系统引导时启动:

sudo sysrc postgresql_enable=yes

然后通过运行初始化数据库:

# /usr/local/etc/rc.d/postgresql initdb

The files belonging to this database system will be owned by user "postgres".

This user must also own the server process.

The database cluster will be initialized with locale "C".

The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /var/db/postgres/data11 … ok

creating subdirectories … ok

selecting default max_connections … 100

selecting default shared_buffers … 128MB

selecting dynamic shared memory implementation … posix

creating configuration files … ok

running bootstrap script … ok

performing post-bootstrap initialization … ok

syncing data to disk … ok

WARNING: enabling "trust" authentication for local connections

You can change this by editing pg_hba.conf or using the option -A, or

--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

/usr/local/bin/pg_ctl -D /var/db/postgres/data11 -l logfile start

启动服务:

# /usr/local/etc/rc.d/postgresql start

2019-03-08 10:45:15.425 UTC [1586] LOG:  listening on IPv6 address "::1", port 5432

2019-03-08 10:45:15.426 UTC [1586] LOG:  listening on IPv4 address "127.0.0.1", port 5432

2019-03-08 10:45:15.430 UTC [1586] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"

2019-03-08 10:45:15.436 UTC [1586] LOG:  ending log output to stderr

2019-03-08 10:45:15.436 UTC [1586] HINT:  Future log output will go to log destination "syslog".

 

三、允许远程连接

默认情况下,只能从localhost访问PostgreSQL数据库:

# sockstat -4 -6 | grep 5432

postgres postgres   1586  3  tcp6   ::1:5432              :

postgres postgres   1586  5  tcp4   127.0.0.1:5432        :

要启用远程连接,请安装vim文本编辑器以编辑配置文件:

sudo pkg install vim

打开文件/var/db/postgres/data11/postgresql.conf并向下滚动到第54行附近的CONNECTIONS AND AUTHENTICATION部分:

sudo vim /var/db/postgres/data11/postgresql.conf

取消注释listen_address和line并更改为如下所示:

listen_addresses = '*'

wilcard *告诉PostregreSQL服务监听所有接口,但你可以限制为特定的IP地址:

listen_addresses = '192.168.1.20'

重启PostgreSQL服务:

#  service postgresql restart

2019-03-08 11:37:14.791 UTC [2649] LOG:  listening on IPv6 address "::", port 5432

2019-03-08 11:37:14.792 UTC [2649] LOG:  listening on IPv4 address "0.0.0.0", port 5432

2019-03-08 11:37:14.797 UTC [2649] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"

2019-03-08 11:37:14.821 UTC [2649] LOG:  ending log output to stderr

2019-03-08 11:37:14.821 UTC [2649] HINT:  Future log output will go to log destination "syslog".

现在,该服务应绑定到所有网络接口:

# sockstat -4 -6 | grep 5432

postgres postgres   2649  3  tcp6   *:5432                *:*

postgres postgres   2649  5  tcp4   *:5432                *:*

 

四、设置PostgreSQL管理员密码

安装PostgreSQL服务器时,默认情况下会创建postgres用户和组,你需要将此用户的密码重置为你能记住的密码:

# passwd  postgres

Changing local password for postgres

New Password:

Retype New Password:

你也可以使用参考在Debian 9/Debian 8系统上安装PostgreSQL 11的方法,包换测试PostgreSQL 11数据库功能部分内容。

 

相关主题

在CentOS 7系统上安装PostgreSQL 11的步骤

精选文章
热门文章