配置postgresql
配置postgresql
创建数据库
su postgres
createdb mydb
psql mydb
创建新的用户 temp
CREATE USER temp WITH PASSWORD 'temp'
给权限
GRANT ALL PRIVILEGES ON DATABASE mydb to temp
允许来自外部的链接。
默认postgresql只允许本机连接数据库, 从其他机器不能够访问
$ telnet 107.170.11.79 5432
Trying 107.170.11.79...
telnet: connect to address 107.170.11.79: Connection refused
telnet: Unable to connect to remote host
修改配置文件 /etc/postgresql/9.5/main/postgresql.conf
把
listen_addresses = 'localhost'
改为
listen_addresses = '*'
此时
$ netstat -nlt
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:2812 0.0.0.0:* LISTEN
tcp6 0 0 ::1:11211 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 :::5432 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
配置 pg_hba.conf
这个文件指 host-based authentication
#/etc/postgresql/9.5/main/pg_hba.conf
local all temp trust
host all temp 0.0.0.0/0 md5
trust 指不管什么用户都可以连接且不需要密码
md5或者password指用密码登录,而password是明文,可能导致 sniffing attacks

浙公网安备 33010602011771号