安装:
https://www.postgresql.org/download/
进入链接后,选择系统等等配置,然后下面会有安装命令。
远程配置:
0. 切换root账户
a. su
2. 配置防火墙
a. firewall-cmd --permanent --add-port=5432/tcp (开启5432端口)
b. firewall-cmd --permanent --add-port=80/tcp (开启80端口)
c. firewall-cmd --reload (重启防火墙)
3. 修改配置文件postgresql.conf
a. vi /var/lib/pgsql/版本数字/data/postgresql.conf
b. 打开文件后定位 #listen_addresses=’localhost’,将localhost修改为*,并且把#注释去掉
c. 未修改时连接会报tcp/ip的错误
4. 修改配置文件pg_hba.conf
a. vi /var/lib/pgsql/版本数字/data/pg_hba.conf
b. 加入一行host all all 0.0.0.0/0 md5
c. 解释
1. host all all 192.168.1.1/32 md5 --/32代表只允许192.168.1.1访问
2. host all all 192.168.1.0/24 md5 --/24代表192.168.1.1~192.168.1.255都允许访问
3. host all all 192.168.0.0/16 md5 --/16代表192.168.1.1~192.168.255.255都允许访问
4. host all all 192.0.0.0/8 md5 --/8代表192.1.1.1~192.255.255.255都允许访问
5. host all all 0.0.0.0/0 md5 --/0代表所有ip地址都允许访问
d. 认证方式
1. trust:凡是能连接到服务器的,都是可信任的。只需要提供数据库用户名,可以没有对应的操作系统同名用户;
2. md5:password 和 md5:对于外部访问,需要提供 psql 用户名和密码。对于本地连接,提供 psql 用户名密码之外,还需要有操作系统访问权(用操作系统同名用户验证)。password 和 md5 的区别就是外部访问时传输的密码是否用 md5 加密;
3. peer:通过客户端操作系统内核来获取当前系统登录的用户名,并作为psql用户名进行登录。
5. 修改登录密码
a. su - postgres
b. psql
c. \password postgres
d. \q退出
e. exit退出
6. 切换回普通用户
a. su username
7. 重启服务器
a. systemctl restart postgresql-版本号