Linux CentOS 7 Installation PostgreSQL9.3 Graphics Tutorial _postgresql

Source: Internet
Author: User
Tags postgresql

The title, this blog record in the Linux CentOS 7 installation postgressql the entire process as well as the database configuration, in the Linux system, PostgreSQL installation methods are divided into two kinds, namely:

1, binary installation package installation

2, the source code compilation installs

Because we don't have any special needs here. Choose the simpler way--binary installation package installation, binary package installation methods are generally through the different versions of Linux under the package Manager, For example, Debian and Ubuntu are installed using the Apt-get command or the Aptitude command, as follows:

sudo apt-get install PostgreSQL

And in Redhat. CentOS or Fedora uses the Yum tool to install the PostgreSQL, as follows:

Yum Install postgresql-server.x86_64

First of all, the following is a detailed description of the entire installation process and details.

Install PostgreSQL

I chose the Yum installation, the requirement is 9.3 version, so directly enter the location of the Software library (before the installation can be passed RPM-QA | The grep postgres command to see if there is an installed PostgreSQL RPM package, which can be uninstalled through the Yum Remove postgresql* command:

Copy Code code as follows:
Yum Install http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm

You can also manually download the specified version directly in the official RPM Repository address below: PostgreSQL rpm Repository (with Yum), based on the requirements of the CentOS 7 9.3 version can be:


After downloading, enter the RPM package directory to run RPM-IVH./pgdg-centos93-9.3-3.noarch.rpm Install the RPM package, then you can continue to install the PostgreSQL and some of the necessary components, such as the Official guide:

As shown above, since we are installing the 9.3 version here, you can install it directly by entering the following command:

Yum Install Postgresql93-server Postgresql93-contrib

The installation log is as follows:



The first thing to do after the installation is to initialize DB, and note that in CentOS 7 PostgreSQL The default installation directory is:/usr/pgsql-9.3, the default data directory is /var/lib/pgsql/ Version/data, the following is the official guide:

The note here is that to execute the initialization command in the installation directory that switches to PostgreSQL, we can find the Initdb script in the installation directory:

Enter the bin directory to run the initialization command to complete the initialization of the database:

Initialization successfully can start the database and log in, the startup command is as follows:

Systemctl Start Postgresql-9.3.service

Login after startup, we use Postgres user to login:

As shown in the figure above, you can see that you have successfully started the service and queried the database version, and then you can see which databases are currently available through the \l command:

As shown above, you can see that there are 4 databases by default,\q is the Exit command. For security reasons, let's change the password for the Postgres user, which is null by default:

Alter user postgres with password ' 111111 ';

The following figure:

Finally, if you are a DB server, you need to set the database service to boot:

The setup-related settings are complete and then look at how the client tools (NAVICAT) connect to the database.

Client Connection PostgreSQL

As the title, since the client to connect, first step is definitely open port, in CentOS 7 introduced a more powerful firewall--firewall, so we need to open in Firewall PostgreSQL default Port 5432, That is, adding 5432 ports to Zone (firewall's new feature, simply by defining the trusted level of network connectivity). The order is as follows:

Firewall-cmd--zone=public--add-port=5432/tcp--permanent

This successfully joins the 5432 port in the public area, the permanent parameter means permanent, that is, restart will not fail, and finally do not forget to update the firewall rules:

Firewall-cmd--reload

OK, let's take a look at all the open ports under the public area, as follows:

Firewall-cmd--zone=public--list-ports

You can see that port 5432 has been successfully opened:

Only open the port is not enough, PostgreSQL also do well in security, it can specify which IP addresses can remotely access the database server, by default is only monitoring local, so the first need to let PostgreSQL listen to the entire network, first into the PostgreSQL installation directory, Locate the configuration file with the following path:

cd/var/lib/pgsql/9.3/data/

Major changes to the following two documents:

As shown above, the first PostgreSQL of the main configuration file postgresql.conf, the listen_addresses before the # removed, and listen_addresses = ' localhost ' changed to listen_addresses = ' * ':

Next, modify the pg_hba.conf file to add a list of allowed IP addresses in the form "Type Database User Address Method". For example, I hope that only 192.168.111.1 this address can remotely access the PostgreSQL database, add the following configuration can be:

Finally, restart the database service for the configuration to take effect:

Systemctl Restart Postgresql-9.3.service

At this point, use the host's Navicat (192.168.111.1) to connect to the PostgreSQL server in the virtual machine to test:

As shown above, you can see a successful connection, so the installation of PostgreSQL is all covered.

Summarize

Simply record the entire process of installing the PostgreSQL 9.3 version under the Linux CentOS 7 system and the associated configuration, the end.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.