Linux centos7 online and offline installation postgresql12 detailed tutorial

Table of contents

1. Online installation

1. Configure yum source

2. Install PostgreSQL

3. Initialize PostgreSQL

4. Start the PostgreSQL service

5. Change password

6. Configure remote access

7. Turn off the firewall

8. After all shutdown, navicat test

2. Offline installation

1. Find the corresponding version on the official website, download the package and upload it to the machine on the intranet

2. Install PostgreSQL

3. Modify the path

4. Initialize PostgreSQL

5. Start the PostgreSQL service

6. Change password

7. Configure remote access

8. Turn off the firewall

9. After fully shutting down, test navicat


1. Online installation

Find the corresponding version on the official website

PostgreSQL: The world's most advanced open source database

1. Configure yum source

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

2. Install PostgreSQL

sudo yum install -y postgresql12-server

After the installation is complete, check the configuration path and modify the configuration file in this path later.

(PostgreSQL has two important configuration files: postgresql.conf and pg_hba.conf are located in this path. This path can be modified, and is generally only modified in the actual use environment)

I will use the default path here without modification. I will modify it to the specified path during offline installation later.

3. Initialize PostgreSQL

sudo /usr/pgsql-12/bin/postgresql-12-setup initdb

4. Start the PostgreSQL service

#设置开机自启动
sudo systemctl enable postgresql-12

#启动PostgreSQL服务
sudo systemctl start postgresql-12

5. Change password

#切换用户,postgressql安装时会自启创建postgres用户
su - postgres

#进入数据库
psql

#修改密码
alter user postgres with password 'postgres';

6. Configure remote access

#进入该postgresql.conf文件中修改一下
vi /var/lib/pgsql/12/data/postgresql.conf

​#listen_addresses = '*' #表示监听所有的ip信息(记得去掉#)
#​port = 5432 #表示服务的端口,可以自定义为其他端口
#/ 后面加要匹配的内容

#进入该pg_hba.conf文件中修改一下
vi /var/lib/pgsql/12/data/pg_hba.conf


#在最下面添加
host    all             all             0.0.0.0/0               md5

#修改完成,需要重启服务才生效
systemctl restart postgresql-12

Modify the IPs allowed to access (the following configuration allows access from all IPs)

TYPE DATABASE USER ADDRESS METHOD
host all all 0.0.0.0/0 md5

7. Turn off the firewall

systemctl stop firewalld

systemctl disable firewalld

setenforce 0

#关闭并禁用 NetworkManager
systemctl stop NetworkManager

systemctl disable NetworkManager

#重启网络服务
systemctl restart network

8. After all shutdown, navicat test

2. Offline installation

1. Find the corresponding version on the official website, download the package and upload it to the machine on the intranet

PostgreSQL: The world's most advanced open source database

After entering, slide to the bottom

Find the version you need

Download these four, the minor version numbers you download must be the same.

After the download is completed, upload it to the intranet server

2. Install PostgreSQL

The installation order of rpm, please note that you must follow the order, otherwise the installation will fail.

rpm -ivh postgresql12-libs-12.15-1PGDG.rhel7.x86_64.rpm

rpm -ivh postgresql12-12.15-1PGDG.rhel7.x86_64.rpm

Installation of  postgresql12-12.15-1PGDG.rhel7.x86_64.rpm failed and execution dependencies were missing.

Because it is on the intranet, you cannot directly download and install the dependencies, so you need to download the package on a machine on the external network and then transfer it to the intranet server.

#在外网的机器上执行,下载暂不安装
yum install --downloadonly --downloaddir=/pg12_rpm libicu

Upload the package to the intranet server. After uploading, install it in the folder where the package is located.

yum install -y libicu-50.2-4.el7_7.x86_64.rpm

After the installation is complete, reinstall postgresql12-12.15-1PGDG.rhel7.x86_64.rpm and install in order

rpm -ivh postgresql12-12.15-1PGDG.rhel7.x86_64.rpm

rpm -ivh postgresql12-server-12.15-1PGDG.rhel7.x86_64.rpm

rpm -ivh postgresql12-contrib-12.15-1PGDG.rhel7.x86_64.rpm

#注:如果有其他包也报依赖缺失,也是按上面的教程补全依赖

3. Modify the path

In the intranet, it is generally the actual use environment. Sometimes the path needs to be modified, so I will demonstrate it. If you don’t need it, you can skip this item and directly initialize PostgreSQL.

#创建自定义目录
mkdir /pgsqldata

#修改所属用户和用户组
chown postgres:postgres –R /pgdata
chmod -R 700 /pgdata

#配置PostgreSQL库自定义目录,在该路径下的/usr/lib/systemd/system/postgresql-12.service文件中修改
vi /usr/lib/systemd/system/postgresql-12.service

#修改后执行
systemctl daemon-reload

4. Initialize PostgreSQL

sudo /usr/pgsql-12/bin/postgresql-12-setup initdb

5. Start the PostgreSQL service

#设置开机自启动
sudo systemctl enable postgresql-12

#启动PostgreSQL服务
sudo systemctl start postgresql-12

6. Change password

#切换用户,postgressql安装时会自启创建postgres用户
su - postgres

#进入数据库
psql

#修改密码
alter user postgres with password 'postgres';

7. Configure remote access

#配置文件postgresql.conf,在自定义的目录/pgsqldata下,进文件中修改一下
vi /pgsqldata/postgresql.conf

​#listen_addresses = '*' #表示监听所有的ip信息
#port = 5432 #表示服务的端口,可以自定义为其他端口
#/ 后面加要匹配的内容

#配置文件pg_hba.conf,在自定义的目录/pgsqldata下,进文件中修改一下
vi /pgsqldata/pg_hba.conf

#在最下面添加
host    all             all             0.0.0.0/0               md5

#修改完成,需要重启服务才生效
systemctl restart postgresql-12

8. Turn off the firewall

systemctl stop firewalld
systemctl disable firewalld

setenforce 0

#关闭并禁用 NetworkManager
systemctl stop NetworkManager
systemctl disable NetworkManager

#重启网络服务
systemctl restart network

9. After fully shutting down, test navicat

Guess you like

Origin blog.csdn.net/weixin_68547003/article/details/132181137