env centos7
1.更新包,避免安装时出错
yum update
2. PostgreSQL: Linux downloads (Red Hat family)
- sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
- sudo yum install -y postgresql15-server
- sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
- sudo systemctl enable postgresql-15
- sudo systemctl start postgresql-15
3. 安装遇到libzstd >= 1.4.0 问题
- wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/l/libzstd-1.5.5-1.el7.x86_64.rpm
- wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/l/llvm5.0-devel-5.0.1-7.el7.x86_64.rpm
- wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/l/llvm5.0-5.0.1-7.el7.x86_64.rpm
- wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/l/llvm5.0-libs-5.0.1-7.el7.x86_64.rpm
-
-
- yum install -y ./libzstd-1.5.5-1.el7.x86_64.rpm
- yum install -y centos-release-scl-rh llvm5*
4.重新安装:
- sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
- sudo yum install -y postgresql15-server
- sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
- sudo systemctl enable postgresql-15
- sudo systemctl start postgresql-15
5.修改监听端口
/var/lib/pgsql/15/data/postgresql.conf
- #listen_addresses = 'localhost' # what IP address(es) to listen on;
- listen_addresses = '0.0.0.0' # what IP address(es) to listen on;
简单监听所有ip
默认仅监听localhost
6.修改访问权限
/var/lib/pgsql/15/data/pg_hba.conf
新增:
host all all 192.168.1.0/24 password
- # METHOD can be "trust", "reject", "md5", "password", "scram-sha-256",
- # "gss", "sspi", "ident", "peer", "pam", "ldap", "radius" or "cert".
- # Note that "password" sends passwords in clear text; "md5" or
- # "scram-sha-256" are preferred since they send encrypted passwords.
-
-
- # Allow replication connections from localhost, by a user with the
- # replication privilege.
- local replication all peer
- host replication all 127.0.0.1/32 scram-sha-256
- host replication all ::1/128 scram-sha-256
- host all all 192.168.1.0/24 password
重启服务:
sudo systemctl restart postgresql-15
pg_hba.conf解决问题:
Connect failed: no pg_hba.conf entry for host
7.开放防火墙
- firewall-cmd --zone=public --add-port=5432/tcp --permanent
- 配置生效
- firewall-cmd --reload # 配置立即生效
参考:命令
- 开放TCP端口
- firewall-cmd --zone=public --add-port=80/tcp --permanent # 开放tcp80端口
- firewall-cmd --zone=public --add-port=443/tcp --permanent # 开放tcp443端口
- firewall-cmd --zone=public --add-port=3306/tcp --permanent # 开放tcp3306端口
- firewall-cmd --zone=public --add-port=6379/tcp --permanent # 开放tcp6379端口
-
- 开放UDP端口
- firewall-cmd --zone=public --add-port=9595/udp --permanent # 开放udp9595端口
-
- 关闭TCP端口
- firewall-cmd --zone=public --remove-port=80/tcp --permanent #关闭tcp5672端口
- firewall-cmd --zone=public --remove-port=443/tcp --permanent #关闭tcp443端口
- firewall-cmd --zone=public --remove-port=3306/tcp --permanent #关闭tcp3306端口
- firewall-cmd --zone=public --remove-port=6379/tcp --permanent #关闭tcp6379端口
-
- 关闭UDP端口
- firewall-cmd --zone=public --remove-port=9595/udp--permanent #关闭udp9595端口
-
- 配置生效
- firewall-cmd --reload # 配置立即生效
-
- 查看防火墙所有开放的端口
- firewall-cmd --zone=public --list-ports
-
- 关闭防火墙
- 如果要开放的端口太多,嫌麻烦,可以关闭防火墙
- systemctl stop firewalld.service
-
- 查看防火墙状态
- firewall-cmd --state
-
- 查看监听的端口
- TCP:netstat -ntlp
- UDP: netstat -nulp
8.修改postgres密码
- # sudo -u postgres psql
-
-
- psql (15.4)
- Type "help" for help.
-
- postgres=# ALTER USER postgres WITH PASSWORD 'xxxxxxxxxxx';
- ALTER ROLE
- postgres=# \q
使用修改后的密码登录测试ok
参考:
PostgreSQL: Linux downloads (Red Hat family)
centos7.9安装postgresql15报错_vah101的博客-CSDN博客
PostgreSQL 配置文件 postgresql.conf 及 postgresql.auto.conf-CSDN博客
Centos7开放端口及查看端口开放-腾讯云开发者社区-腾讯云 (tencent.com)