Install PostgreSQL in Linux

Source: Internet
Author: User
Install PostgreSQL in Linux

1. Add a user to create a directory
Useradd Postgres-D/usr/local/pgsql
Passwd ipvs
Mkdir/usr/local/pgsql/
Mkdir/usr/local/pgsql/Data
Chown-r Postgres/usr/local/pgsql
Chown Postgres/usr/local/pgsql/Data
 
2. Set Environment Variables
VI/etc/profile
Export LD_LIBRARY_PATH =/usr/local/pgsql/lib: $ LD_LIBRARY_PATH
Export Path =/usr/local/pgsql/bin: $ path
Export pgdata =/usr/local/pgsql/Data
Export manpath = $ manpath:/usr/local/pgsql/man

3 installation
./Configure -- prefix =/usr/local/pgsql; Make; make install

4. initialize the database
Su ipvs
/Usr/local/pgsql/bin/initdb-D/usr/local/pgsql/Data

5 add boot auto-start
Chmod A + x/postgresql-8.1.9 (PostgreSQL extract directory)/contrib/start-scripts/Linux
CP/tmp/ postgresql-8.1.9/contrib/start-scripts/Linux/etc/init. d/PostgreSQL
Chkconfig -- add PostgreSQL

6. Change the Postgres password of the database user.
Psql template1
Then
Alter User Login s with password 'Password ';

7. Add external access connections
Add

Host All all 0.0.0.0/0 Trust

Modify PostgreSQL. conf

Listen_addresses = '*'

Start
/Usr/local/pgsql/bin/postmaster-I-d/usr/local/pgsql/Data &
Or
/Usr/local/pgsql/bin/pg_ctl-I-d/usr/local/pgsql/data-l logfile start
Disable kill-int 'head-1/usr/local/pgsql/data/postmaster. pid'

 

========================================================== ========

Yes, I can only summarize it here,
In Linux, PostgreSQL. conf pg_hba.conf is stored in the $ pg_data directory, that is, under the general.../data directory.

The access control is to modify the pg_cmd.conf file, if the following line is added:
Host All all 192.168.0.0 255.255.255.0 MD5
At this time, when you access any database from that network segment, you need a password. The password is added during the transfer process,
Add the following line:
Host All all 192.168.0.0 255.255.255.0 Password
At this time, when you access any database from that network segment, you need a password. The password is not added during the transfer process,
Add the following line:
Host All all 192.168.0.0 255.255.255.0 Trust
At this time, when you access any database from that network segment, do not use a password,

Modify PostgreSQL. conf
Medium
Set # tcpip_socket = false
Change to tcpip_socket = true
In this way, whether or not you add the I parameter at startup can connect the client to your database!

 

 

1. implement remote connection to the PostgreSQL server on Linux.

There are two main steps:

<1> enable PostgreSQL on Linux to enable the Unix TCPIP socket ".

Edit the $ S/data/PostgreSQL. conf file,

Change tcpip_socket = off to tcpip_socket = on.

<2> set the remote access authentication mechanism.

Edit the $ Postgres/data/pg_hba.conf file,

This file contains a lot of information about how to use this file for configuration,

At the bottom is the place where we can enter things.

There is a line of comment:

# Type Database User CIDR-ADDRESS Method

It indicates that each row has five fields,

They are: Connection type, available database name, user, didr address, and verification method.

Below, I will only introduce some common options for each field.

Field 1: type.

You can select local or host.

The former can only allow local users to log on to the ipvs database; the latter can accept remote client login. So,

We should use "host ".

Field 2: datwabse.

Name of the database that can be used by the connection user. It can make a specific

Database name. You can also use "all" to allow users to access all databases.

Field 3: user.

You can specify a specific user to connect to the ipvs database (also combined with the following address field ),

You can also use "all" to allow all users to connect to the database.

Field 4: didr-address.

This may make you feel overwhelmed and do not know what it is.

In fact, it is another way to express the IP address and mask.

Ipvs uses this field to allow IP addresses or ip cidr blocks to connect to the server.

The format is IP Address/mask.

This mask and subnet mask are just represented by a positive number smaller than or equal to 32,

Indicates that the subnet mask is 1 in height,

For example, 255.255.255.0 is "24", indicating that the 24-bit height is 1.

192.168.0.1/32 is equivalent to IP address 192.168.0.1, subnet mask is 255.255.255.255 network segment,

Obviously, this only indicates the IP address 192.168.0.1.

If you are not familiar with the IP address and subnet mask, please refer to the relevant information.

Field 5: method.

This is the verification method. Optional values:

Reject: Deny Access From users of this IP address;

MD5: the password is hashed by MD5;

Password: the password is transmitted in plain text !);

Krb5: the password uses krb5 as the hash code.

The following example shows how to set the parameters:

# Type Database User CIDR-ADDRESS Method

# Allow all users with IP address 192.168.0.1 to log on to all databases on ipvs server and use MD5 verification.

Host All all 192.168.0.1/32 MD5

# Allow the user testuser to log on to the ipvs server on any machine in the network segment of 192.168.0.xx,

# Only the database testdb can be used and MD5 verification is used.

Host testdb testuser 192.168.0.1/24 MD5

 

 

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.