前置准备
下载对应版本的安装包
我这边默认用的postgresql13.5
postgresql13-13.5-1PGDG.rhel7.x86_64.rpm
postgresql13-libs-13.5-1PGDG.rhel7.x86_64.rpm
postgresql13-server-13.5-1PGDG.rhel7.x86_64.rpm
在所需要安装postgresql的服务器上上传安装软件
安装步骤
通过rpm方式安装对应的postgresql13.5
[root@server10 tmp]# rpm -ivh postgresql13-libs-13.5-1PGDG.rhel7.x86_64.rpm
warning: postgresql13-libs-13.5-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing... ################################# [100%]
package postgresql13-libs-13.5-1PGDG.rhel7.x86_64 is already installed
[root@server10 tmp]# rpm -ivh postgresql13-13.5-1PGDG.rhel7.x86_64.rpm
warning: postgresql13-13.5-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing... ################################# [100%]
package postgresql13-13.5-1PGDG.rhel7.x86_64 is already installed
[root@server10 tmp]# rpm -ivh postgresql13-server-13.5-1PGDG.rhel7.x86_64.rpm
warning: postgresql13-server-13.5-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing... ################################# [100%]
package postgresql13-server-13.5-1PGDG.rhel7.x86_64 is already installed
查找postgresql安装文件(其中查到2个路径,第一个为软链接)
[root@server10 pgsql]# find / -name postgresql-*-setup
/usr/bin/postgresql-13-setup
/usr/pgsql-13/bin/postgresql-13-setup
初始化数据库
[root@server10 bin]# /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database ... OK
修改远程配置文件pg_hba.conf和postgresql.conf
[root@server10 bin]# find / -name pg_hba.conf
[root@server10 bin]# cd /var/lib/pgsql/13/data/
[root@server10 data]# vim pg_hba.conf
添加标红信息
[root@server10 bin]# find / -name postgresql.conf
[root@server10 data]# vim pg_postgresql.conf
修改监听和端口如标红所示
设置开机启动数据库
systemctl enable postgresql-13 #设置数据库的开机启动
sudo systemctl start postgresql-13 #启动数据库
systemctl statuspostgresql-13 #查看数据库状态
设置防火墙通过该端口
firewall-cmd --zone=public --add-port=5432/tcp –permanent #修改
systemctl restart firewalld.service #重启防火墙
修改数据库密码
[root@server10 bin]# su - postgres
-bash-4.2$ psql
psql (13.5)
Type "help" for help.
postgres=# ALTER USER postgres WITH PASSWORD 'postgres';
ALTER ROLE
远程连接postgresql测试
能够正常连接至此完成postgresql数据库13.5版本的安装。