- 安装rpm文件
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
- 安装PostgreSQL
sudo yum install -y --nogpgcheck postgresql14-server
- 初始化数
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
- 设备开机启动
sudo systemctl enable postgresql-14
- 启动PostgreSQL服务
sudo systemctl start postgresql-14
- 设置数据库密码
数据库安装后,默认创建账号postgres
使用postgres账号身份操作
su - postgres
- 使用postgres账号登录数据库
psql -U postgres
- 设置密码
alter user postgres with password '123456'
- 退出
\q #退出数据库
exit #退出postgres账号
- 开启远程访问
对所有IP开放访问
打开postgresql.conf文件
vi /var/lib/pgsql/14/data/postgresql.conf
- 修改listen_address配置(对所有IP开发访问)
listen_address = '*'
增加信任连接
打开pg_hba.conf文件
vi /var/lib/pgsql/14/data/pg_hba.conf
- 增加新人连接配置
# IPv4 local connections:
host all all 0.0.0.0/0 trust
- 重启服务
systemctl restart postgresql-14
- 添加防火墙端口号
- 添加端口号
firewall-cmd --zone=public --add-port=5432/tcp --permanent
- 重载防火墙立即生效
firewall-cmd --reload