postgres用户密码为空,需立即修改为强密码(包含大小写字母、数字、特殊字符,长度≥12位)。执行命令:sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'YourStrongPassword123!'";admin123)。sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.100" port port=5050 protocol=tcp accept' # 替换为你的IP
sudo firewall-cmd --permanent --add-port=5050/tcp
sudo firewall-cmd --reload
sudo ufw allow from 192.168.1.100 to any port 5050 && sudo ufw enable。sudo openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout /etc/pgadmin4/server.key -out /etc/pgadmin4/server.crt/usr/lib/python3.6/site-packages/pgadmin4-web/config_local.py,路径因Python版本可能不同),添加证书路径:SSL_CERTFILE = '/etc/pgadmin4/server.crt'SSL_KEYFILE = '/etc/pgadmin4/server.key'sudo chown root:pgadmin /etc/pgadmin4/server.key /etc/pgadmin4/server.crtsudo chmod 640 /etc/pgadmin4/server.key /etc/pgadmin4/server.crtsudo systemctl restart pgadmin4https://<服务器IP>:5051(默认端口为5051,若修改过需替换),确认地址栏显示锁图标(表示HTTPS加密连接成功)。pg_hba.conf文件(通常位于/etc/postgresql/<版本>/main/),限制允许连接到数据库的用户和IP地址。例如,仅允许本地用户通过密码认证连接,远程客户端需使用SSL:host all all 127.0.0.1/32 md5
hostssl all all 192.168.1.0/24 md5 # 仅允许192.168.1.0/24网段通过SSL连接
修改后重启PostgreSQL服务:sudo systemctl restart postgresqladmin账户或修改其密码,防止未授权访问。sudo yum update -y/usr/lib/python3.6/site-packages/pgadmin4-web/config_local.py),开启详细日志记录,保留足够长时间(建议≥1年,满足PCI DSS要求)。示例如下:LOG_LEVEL = 'DEBUG'LOG_FILE = '/var/log/pgadmin/audit.log'LOG_ROTATION_SIZE = 10 # 单个日志文件最大10MBLOG_ROTATION_AGE = 7 # 日志保留7天后轮转/var/log/pgadmin/audit.log文件,关注异常登录(如多次失败登录)、未授权操作(如删除数据库)等行为。可结合fail2ban工具自动封禁频繁失败的IP地址。postgresql.conf,通常位于/etc/postgresql/<版本>/main/),关闭未使用的功能,减少攻击面。示例如下:wal_level = replica # 仅保留必要的WAL级别max_replication_slots = 0 # 禁用复制槽server {
listen 443 ssl;
server_name pgadmin.example.com;
ssl_certificate /etc/letsencrypt/live/pgadmin.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/pgadmin.example.com/privkey.pem;
location / {
proxy_pass http://localhost:5050;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
重启Nginx服务:sudo systemctl restart nginx/etc/pgadmin4/)和PostgreSQL数据库,将备份文件存储在安全位置(如异地服务器、云存储)。测试备份文件的恢复流程,确保在安全事件(如数据泄露、系统崩溃)发生时能够快速恢复。