postgres数据库在线安装和配置

1.通过yum安装 postgres

yum install postgresql-server.x86_64 

2.安装完成之后,初始化数据库

service postgresql initdb

3.启动数据库

启动:service postgresql start 
关闭:service postgresql stop

4.修改配置文件
配置文件的目录在 /var/lib/pgsql/data/ 下,我们修改postgresql.conf和pg_hba.conf。
4.1.如果有多个IP的服务器,建议修改一下postgresql.conf下的 listen_addresses ,绑定地址到你选择的IP。
不然会出现问题。
4.2通过pg_hba.conf最下面的那几行配置进行访问限制

# TYPE  DATABASE        USER            ADDRESS                 METHOD


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

修改完成之后重启数据库
5.登录数据库
5.1切换的postgres用户,并连接数据库

[root@localhost ~]$ su  postgres 
-bash-4.1$ psql 

进去后,修改默认用户postgres的密码。通过命令连接数据库

psql -U postgres -h 172.16.1.2

如果连接成功,代表配置正确,如果不成功,则检查pg_hba.conf配置 。

猜你喜欢

转载自blog.csdn.net/xfks55/article/details/53190048