Test: https://www.linuxidc.com/Linux/2017-10/147536.htm
http://blog.51cto.com/12482328/2090844
Https://www.cnblogs.com/think8848/p/5877076.html
Master/Slave configuration: https://www.linuxidc.com/Linux/2017-03/142145.htm
First, the system environment
System Environment centos7.4
PostgreSQL version 9.6.3
Second, installation
1. Install RPM Package
[HTML]View PlainCopy
- [email protected] share]# Yum install-y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/ pgdg-centos96-9.6-3.noarch.rpm
2. Install the Client
[HTML]View PlainCopy
- [email protected] share]# Yum install-y postgresql96
3. Install the server
[HTML]View PlainCopy
- [email protected] share]# Yum install-y postgresql96-server
- By default, a ' Postgres ' System account is created to perform PostgreSQL, and a ' postgres ' database is generated;
4. Initialization
[HTML]View PlainCopy
- [Email protected] share]#/usr/pgsql-9.6/bin/postgresql96-setup initdb
5. Set boot and start
[HTML]View PlainCopy
- [Email protected] share]# Systemctl enable postgresql-9.6
- [Email protected] share]# systemctl start postgresql-9.6
Third, the use of configuration
1. Modify User Password
[HTML]View PlainCopy
- [[email protected] ~]# su postgres//yum installed by default create a ' postgres ' user
- bash-4.2$ psql-u postgres//Enter Postgres database
- Psql (9.6.9)
- Type ' help ' for help.
- postgres=#
- postgres=# alter user postgres with password ' password '
2. Allow Remote access
[HTML]View PlainCopy
- [Email protected] ~]# Find/-name postgresql.conf
- /var/lib/pgsql/9.6/data/postgresql.conf
- [Email protected] ~]# vi/var/lib/pgsql/9.6/data/postgresql.conf
- Change listen_addresses = ' localhost ' to listen_addresses = ' * ' to restart service
3, host authentication.
[HTML]View PlainCopy
- [Email protected] ~]# vim/var/lib/pgsql/9.6/data/pg_hba.conf
- # IPV4 Local connections://ipv4 Add the following below, the first all is the database, the second is the USER,IP represents the client Ip,trust authentication method
- Host all 127.0.0.1/32 ident
- Host All 10.0.2.114/32 Trust
4. Setting Environment variables
[HTML]View PlainCopy
- [Email protected] ~]# Vi/etc/profile
- Export path= $PATH:/usr/pgsql-9.6/bin
- [Email protected] ~]# Source/etc/profile
- [Email protected] ~]# systemctl restart postgresql-9.6
5. Iptables
#postgresql默认开启tcp5432端口 [[Email protected]_master ~]# vim/etc/sysconfig/iptables-a input-m State--state new-m tcp-p t CP--dport 5432-j accept[[email protected]_master ~]# service iptables restart
Third, the use of verification
1. View Port
[HTML]View PlainCopy
- [Email protected] ~]# NETSTAT-TUNLP
- Active Internet connections (only servers)
- Proto recv-q send-q Local address Foreign address State Pid/program Name
- TCP 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 870/nginx:master p
- TCP 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 29768/postmaster
2. Easy to use
[HTML]View PlainCopy
- [[email protected] ~]# su-postgres//Switch User
- Last login: May 03:41:13 EDT 2018PTS/1
- -bash-4.2$
- -bash-4.2$ psql-u postgres//Enter the database
- Psql (9.6.9)
- Type ' help ' for help.
- postgres=#
2.1 Creating a User
[HTML]View PlainCopy
- postgres=# create user user1 with password ' user123 ';
- CREATE ROLE
2.2 Creating a Database
[HTML]View PlainCopy
- postgres=# CREATE database T1 owner User1;
- CREATE DATABASE
2.3 Database Authorization
[HTML]View PlainCopy
- postgres=# Grant all privileges on the database T1 to User1; Not authorized to log in to the console only
2.4 Logging back into the database
[HTML]View PlainCopy
- -bash-4.2$ psql-u user1-d t1-h 127.0.0.1-p 5432
2.5 Creating a Table
Postdb1=> CREATE TABLE TB1 ( ID int primary KEY, name VARCHAR (), salary real );
2.6 Inserting data
postdb1=> INSERT INTO TB1 ( ID, name, salary) values ( 101, ' Mike ', 5000.00 );
2.7 Queries
Postdb1=>select * from TB1;
CENTOS7 Installation Configuration PostgreSQL