CentOS7 Method for installing PostgreSQL and PostGIS using yum

  • 2021-07-03 01:19:02
  • OfStack

1. Update the yum source

The PostgreSQL version of the CentOS7 default yum source is too low to be used on this version. Find the RPM source suitable for CentOS7 on https://yum.postgresql.org/repopackages.php, copy its url address, and install it using yum.

Install epel at the same time (Extra Packages for Enterprise Linux 7). For stability, the default yum source of CentOS 7 lacks many components, which can be found on epel.

Command:


yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm
yum -y install epel-release

2. Install PostgreSQL


 Use yum search postgre Command can see multiple versions of the PostgreSQL Here I choose PostgreSQL10 . 
yum install -y postgresql10-server postgresql10-contrib
 Initialization 
/usr/pgsql-10/bin/postgresql10-setup initdb
 Set up startup 
systemctl enable postgresql-10
 Start the database 
systemctl start postgresql-10

3. Configure the database

Configure remote access, edit /var/lib/pgsql/10/data/postgresql.conf, find listen_addresses, change the value of listen_addresses to '*' if you want to open to all IP, and separate multiple IP with a comma and a space if it is only open to some IP. Configure account access rights, edit /var/lib/pgsql/10/data/pg_hba. conf, the file is divided into 5 columns, which are TYPE, DATABASE, ADDRESS, METHOD. You can set access rights to different databases for users with different IP addresses. The last column of METHOD parses as follows: trust Any connection is allowed, no password is required reject rejects requests that meet the conditions (the first few conditions) MD5 Receives 1 MD5 Encrypted Password password receives a password to log in, using this method only on trusted networks gss uses gssapi authentication and is only available on tcp/ip connections sspi is only available in windows in one way krb5 is not commonly used and is only available in TCP/IP ident uses operating system username authentication to verify that it matches the requested database username ldap uses LDAP server authentication cert uses ssl client authentication pam uses the operating system's pam module service

Configure host all all 0.0. 0.0 md5 if all IP are required to login with a password.

4. Install PostGIS

You can see multiple versions of PostGIS by using yum search postgis command. Here I select postgis25, yum install-y postgis25_10. After installation, I switch to postgres user and start extension.


//  Open plug-in  
# su postgres 
# psql 
//  Open pgsql Plug-ins of  
postgres=# create extension postgis; 
postgres=# create extension postgis_topology; 
postgres=# create extension fuzzystrmatch; 
postgres=# create extension address_standardizer; 
postgres=# create extension address_standardizer_data_us; 
postgres=# create extension postgis_tiger_geocoder;

At this point, PostgreSQL and PostGIS are installed.

Summarize

Above is this site to introduce you to CentOS7 yum installation PostgreSQL and PostGIS, I hope to help you, if you have any questions welcome to leave me a message, this site will reply to you in time!


Related articles: