注意:本环境是基于centos8,其他可能不适合,谨慎使用
shelldnf module list postgresql
输出显示可用的postgresql.每个个都包含服务器喝客户端,postgresql10是默认设置。【可以通过stream数字后边如何包含d,就是默认设置】
shellsudo dnf install @postgresql:10
安装其他版本的,请输入:
shellsudo dnf install @postgresql:9.6
shellsudo dnf install postgresql-contrib
shellsudo postgresql-setup initdb
输出
shellInitializing database ... OK
shellsudo systemctl enable --now postgresql
shellsudo -u postgres psql -c "SELECT version();"
输出:
shellPostgreSQL 10.6 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 8.2.1 20180905 (Red Hat 8.2.1-3), 64-bit
PostgreSQL支持多种身份验证方法。最常用的方法是:
shell/var/lib/pgsql/data/pg_hba.conf
PostgreSQL客户端身份验证在名为pg_hba.conf的配置文件中定义。默认情况下,对于本地连接,PostgreSQL设置为使用对等身份验证方法。
在你安装PostgreSQL服务器过程中postgres用户会被自动创建。该用户是PostgreSQL实例的超级用户,你可以看成等效于MySQL的root用户。
要以postgres用户身份登录到PostgreSQL服务器,需要首先切换到该用户,然后运行psql命令程序访问PostgreSQL提示符:
shellsudo su - postgres psql
退出,输入q.
shellsudo -u postgres psql
shellcreate role john;
shellcreate database johndb;
shellgrant all privileges on database johndb to john;
shellalter role postgres with password 'xiaosan121009';
shellsudo systemctl restart postgresql 或者 sudo systemctl reload postgresql
系统配置文件路径:
shell/var/lib/pgsql/10/data/postgresql.conf
打开配置文件,进行如下修改:
shelllisten_address='*'
重启服务:
shellsudo systemctl restart postgresql
使用ss实用程序验证更改:
shellss -nlt | grep 5432
上面的输出显示PostgreSQL服务器正在所有接口(0.0.0.0)的默认端口上侦听。
最后一步是通过编辑/var/lib/pgsql/data/pg_hba.conf文件将服务器配置为接受远程连接。 以下是一些显示不同用例的示例:
shell# TYPE DATABASE USER ADDRESS METHOD
# The user jane can access all databases from all locations using an md5 password
host all jane 0.0.0.0/0 md5
# The user jane can access only the janedb database from all locations using an md5 password
host janedb jane 0.0.0.0/0 md5
# The user jane can access all databases from a trusted location (192.168.1.134) without a password
host all jane 192.168.1.134 trust
本文作者:Eric
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!