考:https://www.linuxidc.com/Linux/2017-10/147536.htm

http://blog.51cto.com/12482328/2090844

https://www.cnblogs.com/think8848/p/5877076.html

主从配置:https://www.linuxidc.com/Linux/2017-03/142145.htm

一、系统环境

系统环境centos7.4

postgresql版本9.6.3

二、安装

1、安装rpm包

  1. [root@www 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、安装客户端

  1. [root@www share]# yum install -y postgresql96

3、安装服务器

  1. [root@www share]# yum install -y postgresql96-server
  2. 默认创建一个‘postgres’的系统账号,用于执行PostgreSQL;同时生成一个'postgres'的数据库;

4、初始化

  1. [root@www share]# /usr/pgsql-9.6/bin/postgresql96-setup initdb

5、设置开机自启、启动

  1. [root@www share]# systemctl enable postgresql-9.6
  2. [root@www share]# systemctl start postgresql-9.6

三、配置使用

1、修改用户密码

  1. [root@www ~]# su postgres    //yum安装的默认创建一个'postgres'用户
  2. bash-4.2$ psql -U postgres    //  进入postgres数据库
  3. psql (9.6.9)
  4. Type "help" for help.
  5. postgres=#
  6. postgres=# alter user postgres with password '密码'

2、允许远程访问

  1. [root@www ~]# find / -name postgresql.conf
  2. /var/lib/pgsql/9.6/data/postgresql.conf
  3. [root@www ~]# vi /var/lib/pgsql/9.6/data/postgresql.conf
  4. // 修改listen_addresses = 'localhost'  改为 listen_addresses = '*'   需重启服务

3、主机认证。

  1. [root@www ~]# vim /var/lib/pgsql/9.6/data/pg_hba.conf
  2. # IPv4 local connections:      //IPV4下面添加下面内容,第一个all是数据库,第二个是user,ip代表client ip,trust认证方法
  3. host    all             all             127.0.0.1/32            ident
  4. host    all             all             10.0.2.114/32           trust

4、设置环境变量

  1. [root@www ~]# vi /etc/profile
  2. export PATH=$PATH:/usr/pgsql-9.6/bin
  3. [root@www ~]# source /etc/profile
  4. [root@www ~]# systemctl restart postgresql-9.6

5. iptables

#postgresql默认开启tcp5432端口
[root@psql_master ~]# vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT [root@psql_master ~]# service iptables restart

三、使用验证

1、查看端口

  1. [root@www ~]# netstat -tunlp
  2. Active Internet connections (only servers)
  3. Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
  4. tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      870/nginx: master p
  5. tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      29768/postmaster

2、简单使用

  1. [root@www ~]# su - postgres     // 切换用户
  2. 上一次登录:一 5月 14 03:41:13 EDT 2018pts/1 上
  3. -bash-4.2$
  4. -bash-4.2$ psql -U postgres     // 进入数据库
  5. psql (9.6.9)
  6. Type "help" for help.
  7. postgres=#

2.1 创建用户

  1. postgres=# create user user1 with password 'user123';
  2. CREATE ROLE

2.2 创建数据库

  1. postgres=# create database t1 owner user1;
  2. CREATE DATABASE

2.3 数据库授权

  1. postgres=# grant all privileges on database t1 to user1;  // 未授权只能登录控制台

2.4 重新登录数据库

  1. -bash-4.2$ psql -U user1 -d t1 -h 127.0.0.1 -p 5432

2.5 创建表

postdb1=> create table tb1(
id int primary key,
name VARCHAR(20),
salary real
);

2.6 插入数据

postdb1=> insert into tb1(
id, name, salary)
values(
101, 'Mike', 5000.00
);

2.7 查询

postdb1=>select * from tb1;

centos7 安装配置postgresql的更多相关文章

  1. Centos7安装配置gitlab

    Centos7安装配置gitlab 这篇文字我会介绍在Centos7上安装gitlab,配置gitlab的smtp,并且创建项目demo. sudo yum install openssh-serve ...

  2. Centos7安装配置Apache+PHP+Mysql+phpmyadmin

    转载自: Centos7安装配置Apache+PHP+Mysql+phpmyadmin 一.安装Apache yum install httpd 安装成功后,Apache操作命令: systemctl ...

  3. Centos7安装配置JDK8

    Centos7安装配置JDK8 一.准备工作 第一步,去甲骨文官网下载Jdk相应的版本,我这里下载的是jdk1.8. 第二步将你从官网上下载下来的jdk使用FTP工具上传到云服务器上的相应目录,我的是 ...

  4. centos7命令行和图形界面的相互切换(附centos7安装配置教程)

    一.最近安装了centos7,发现在命令行和图形界面的相互切换命令上,与centos以往版本有很大不同,先整理如下,加深记忆. 1,centos7默认安装后,跟其他版本一样,启动默认进入图形界面: 2 ...

  5. (转)Centos7安装配置NFS服务和挂载

    Centos7安装配置NFS服务和挂载 原文:https://www.u22e.com/601.html NFS简介 NFS(Network File System)即网络文件系统,是FreeBSD支 ...

  6. CentOS7 安装配置笔记

    CentOS7 安装配置笔记 1.通过镜像安装 CentOS7 ==============================* 使用 UltraISO 9.7 或者 rufus-3.5p 制作ISO的 ...

  7. Centos7安装配置jenkins(Tomcat)

    Centos7安装配置jenkins(Tomcat) 一.准备工作 1.1 安装JDK1.8 具体安装过程不在赘述. 1.2 下载jenkins的war包 jenkins官网下载地址:https:// ...

  8. centos7安装配置zabbix4.0

    zabbix01    198.8.8.211    zabbix-server4.0 zabbix02    198.8.8.212    zabbix-agent4.0 一:zabbix服务端环境 ...

  9. CentOS7安装配置Bacula yum方法

    参考: https://www.baidu.com/link?url=o2QIy2YZWjsJPAFJuYFhrH3nPvtyRkSe-o5Q_FqFZ5E1EMOsIOmGeKm0HAonwHOw8 ...

随机推荐

  1. POJ3273--Monthly Expense(Binary Search)

    Description Farmer John is an astounding accounting wizard and has realized he might run out of mone ...

  2. Python自动化开发 - 进程、线程(一)

    本节内容 1.操作系统发展史 2.进程和线程 3.Python threading 模块 一.操系统发展史 手工操作(无操作系统) 1946年第一台计算机诞生--20世纪50年代中期,还未出现操作系统 ...

  3. unigui 设置单元格颜色

    procedure TF_Resource2.UniDBGrid1DrawColumnCell(Sender: TObject; ACol,  ARow: Integer; Column: TUniD ...

  4. Spring @Autowired注解用在集合上面,可以保持接口的所有实现类

    CourseService课程接口有2个子类,HistroyCourseServiceImpl和MathsCourseServiceImpl public interface CourseServic ...

  5. wpf 导出Excel

    private void Button_Click_1(object sender, RoutedEventArgs e) { ExportDataGridSaveAs(true, this.data ...

  6. MVC中通过ajax判断输入的内容是否重复(新手笔记,请各位多多指教)

    控制器代码: public string ValidateCarID(string carid)//这里接收ajax传递过来的值 { string result; Car car = db.Car.F ...

  7. Java - 阅读与查找

    WebSites http://www.importnew.com/ https://www.java-tips.org/ http://www.javaworld.com/ http://www.p ...

  8. Tools - Others

    01 - 一些网络工具 文档查阅 https://devdocs.io/ API文档 http://overapi.com/ 开源代码及文档搜索 https://searchcode.com/ 电子书 ...

  9. python 数据库连接及操作

    Python DB-API使用流程: 引入API模块. 获取与数据库的连接. 执行SQL语句和存储过程. 关闭数据库连接. def mysql_dbtest(): config = { 'host': ...

  10. Flask 初印象

    Flask 出生于2010年,集中了其他python web框架的长处,定位于微小项目上. 特点 1 内置开发服务器和调试器 2 于Python单元测试功能无缝衔接 Flask框架提供了一个与Pyth ...