Top Banner
Installation Rangson Sangboonruang [email protected] 1
25

Install PostgreSQL on CentOS

Sep 03, 2014

Download

Education

Rang Sang

How to install Postgresql 9.1 on CentOS 6.5. #
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Install PostgreSQL on CentOS

InstallationRangson [email protected]

1

Page 2: Install PostgreSQL on CentOS

2

https://www.youtube.com/watch?v=yTsirtODBX8

You can find video demonstration on YouTube

Page 3: Install PostgreSQL on CentOS

3

Update repository Creating a user group of sudoers Putting sudogroup in sudoer file Installing Postgresql Starting Postgresql Server Editing configuration files Connecting from local computer Connecting from other computers Configuring the firewall

Things to be covered

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

Page 4: Install PostgreSQL on CentOS

4

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

It is assumed that you already had CentOSInstalled. Let’s log on to CentOS.

Page 5: Install PostgreSQL on CentOS

5

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

Updating repository

ls

- Download pgdg-redhat91-9.1-5.noarch.rpm from this urlo –http://yum.pgrpms.org/9.1/redhat/rhel-6-x86_64/pgdg-redhat91-9.1-5.noarch.rpm

1

- Place the file in your preferred directory, e.g. /tmp. - Open Terminal window and go to /tmp.cd /tmp

- List all the files in the directory to ensure that pgdg-redhat91-9.1-5.noarch.rpm is already there.

- The screen shall display something like the following.

Page 6: Install PostgreSQL on CentOS

6

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

- Try updating repository.rpm –Uvh pgdg-redhat91-9.1-5.noarch.rpm

Explanation:You get this permission denied message because the user you are logging on is not a privileged user. You can log on using root but using root is not recommended because root is super powerful and accidental damage can potentially happen using root to perform admin tasks. On CentOS you can use sudo to obtain supper user privilege and the command will be like the following.

sudo rpm –Uvh pgdg-redhat91-9.1-5.noarch.rpm

Page 7: Install PostgreSQL on CentOS

7

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

Explanation:You get this message because the user you are using is not listed in sudoers file. It is recommended that you create a group called sudogroup (or anything you like) and add the user you are using to this group and put the whole group in sudoer file. To do all these, follow the following steps.

Page 8: Install PostgreSQL on CentOS

8

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

Creating a user group of sudoers

- From the menu bar choose System>Administration>Users and Groups and you’ll be prompted to enter root’s password.

- For those you are familiar with Linux command line, you can ignore this and perform the geek stuff.

2

Page 9: Install PostgreSQL on CentOS

9

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

- Now, you should see User Manager window. Click Add Group button and enter the group name then click OK.

Page 10: Install PostgreSQL on CentOS

10

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

- Add your current user to “sudogroup” by choosing “Users” tab, click Properties button (as highlighted). You should see User Properties window. In the list box scroll to the “sudogroup” and have it checked. Do not forget to specify the Primary Group as “sudogroup”.

Page 11: Install PostgreSQL on CentOS

11

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

Putting sudogroup in sudoer file

- Go back to Terminal window and type the following command.

su root

Explanation:“su” is used to switch user from one to another. Now you are root. This is because to edit sudoer file you need root’s privilege. Next command is as followed.

visudo

3

Page 12: Install PostgreSQL on CentOS

12

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

Explanation:The Terminal window is now a text editor called “vi”. Now go through these steps

- Locate the cursor to the line that looks like “root ALL=(ALL) ALL”.- Press “i” on your keyboard insert text.- Put “$sudogroup ALL=(ALL) ALL” underneath.- Press “esc” on your keyboard then type :wq- Press “Enter”

Explanation:You have just exited the vi editor and are ready to proceed the next step by typing the following command.

sudo rpm –Uvh pgdg-redhat91-9.1-5.noarch.rpm

Page 13: Install PostgreSQL on CentOS

13

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

Explanation:After running the previous command you should receive the response like the above.

- Run the following command to list all available Postgresql packages.

yum list postgresql*

Page 14: Install PostgreSQL on CentOS

14

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

Installing PostgresqlExplanation:Among all the listed packages the highlighted one is what we are about to use for our installation.

- Type the following command

sudo yum install postgresql91-server.x86_64

4

Page 15: Install PostgreSQL on CentOS

15

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

Explanation:After running yum install you should see the screen like the above and you’ll be prompted to say y (for yes) or n (for no) to proceed downloading the package and finish the installation.

- Type y for now and wait until the screen displays “Complete!”

Explanation:Now you have done with the installation. Next, let’s move on to the next slide.

Page 16: Install PostgreSQL on CentOS

16

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

Starting Postgresql Server- Type the following command.sudo service postgresql-9.1 start

Starting the server FAILED because you need to initialize the database first. So let’s do it by typing the following command.sudo service postgresql-9.1 initdb

5

Page 17: Install PostgreSQL on CentOS

17

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

You are supposed to see the following screen.

Now try starting the server again. This time you should see the following screen.

Page 18: Install PostgreSQL on CentOS

18

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

Editing configuration files- Type the following command to edit postgresql.confsudo vi /var/lib/pgsql/9.1/data/postgresql.conf

- Edit the file by changing these two lines:

Uncomment by removing #, and Change from ‘localhost’ to ‘*’Uncomment

6

Page 19: Install PostgreSQL on CentOS

19

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

- Type the following command to edit pg_hba.confsudo vi /var/lib/pgsql/9.1/data/pg_hba.conf

- Edit the file by changing these two lines:Before

After

Insert new line

Change from “indent” to “md5”

The new line added contains the network address of you machine. This is to allow other computer to connect to your sever.

Page 20: Install PostgreSQL on CentOS

20

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

- Type the following command to restart the server.sudo service postgresql-9.1 restart

- If successful you should see the following.

- Type the following command to test your server.sudo su postgrescreatedb testpsql test

Explanation:You should see this screen after running the command above.sudo su postgres => To switch to user postgrescreatedb test => To create a database called testpsql test => To login to test database

<<Successful screen>>

Page 21: Install PostgreSQL on CentOS

21

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

Connecting from local computer- Type the following command to crate a role for the database.CREATE ROLE testuser WITH SUPERUSER LOGIN PASSWORD ‘test’;

- Type the following command to test the connection to the server.psql -h localhost –U testuser test

- Type the following command to exit test database\q

<<Successful screen>>

7

Page 22: Install PostgreSQL on CentOS

22

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

Connecting from other computers

Explanation:I used pgAdmin III to connect to the Postgresql Server. And, first, failed to connect saying the server was not listening on port 5432. Of cause, there is something you have to do with the server.

8

Page 23: Install PostgreSQL on CentOS

23

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

Configuring the firewall (iptables)

- Type the following command to exit test database\q

- Type the following command to exit from postgresexit

<<Successful screen>>

9

Page 24: Install PostgreSQL on CentOS

24

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

- Type the following command to edit iptablessudo vi /etc/sysconfig/iptables

Insert this line(before –A INPUT –j Reject….).

Page 25: Install PostgreSQL on CentOS

25

Installation of Postgresql on CentOSPostgresql Sever 9.1 and CentOS 6.5

- Type the following command to edit restart the firewallsudo service iptables restart

<<Successful screen>>

- Try connecting to the server from other computer again.

This time you should be able to connect to the server.