centos7 安装配置postgresql
考: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包
- [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、安装客户端
- [root@www share]# yum install -y postgresql96
3、安装服务器
- [root@www share]# yum install -y postgresql96-server
- 默认创建一个‘postgres’的系统账号,用于执行PostgreSQL;同时生成一个'postgres'的数据库;
4、初始化
- [root@www share]# /usr/pgsql-9.6/bin/postgresql96-setup initdb
5、设置开机自启、启动
- [root@www share]# systemctl enable postgresql-9.6
- [root@www share]# systemctl start postgresql-9.6
三、配置使用
1、修改用户密码
- [root@www ~]# su postgres //yum安装的默认创建一个'postgres'用户
- bash-4.2$ psql -U postgres // 进入postgres数据库
- psql (9.6.9)
- Type "help" for help.
- postgres=#
- postgres=# alter user postgres with password '密码'
2、允许远程访问
- [root@www ~]# find / -name postgresql.conf
- /var/lib/pgsql/9.6/data/postgresql.conf
- [root@www ~]# vi /var/lib/pgsql/9.6/data/postgresql.conf
- // 修改listen_addresses = 'localhost' 改为 listen_addresses = '*' 需重启服务
3、主机认证。
- [root@www ~]# vim /var/lib/pgsql/9.6/data/pg_hba.conf
- # IPv4 local connections: //IPV4下面添加下面内容,第一个all是数据库,第二个是user,ip代表client ip,trust认证方法
- host all all 127.0.0.1/32 ident
- host all all 10.0.2.114/32 trust
4、设置环境变量
- [root@www ~]# vi /etc/profile
- export PATH=$PATH:/usr/pgsql-9.6/bin
- [root@www ~]# source /etc/profile
- [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、查看端口
- [root@www ~]# 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、简单使用
- [root@www ~]# su - postgres // 切换用户
- 上一次登录:一 5月 14 03:41:13 EDT 2018pts/1 上
- -bash-4.2$
- -bash-4.2$ psql -U postgres // 进入数据库
- psql (9.6.9)
- Type "help" for help.
- postgres=#
2.1 创建用户
- postgres=# create user user1 with password 'user123';
- CREATE ROLE
2.2 创建数据库
- postgres=# create database t1 owner user1;
- CREATE DATABASE
2.3 数据库授权
- postgres=# grant all privileges on database t1 to user1; // 未授权只能登录控制台
2.4 重新登录数据库
- -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的更多相关文章
- Centos7安装配置gitlab
Centos7安装配置gitlab 这篇文字我会介绍在Centos7上安装gitlab,配置gitlab的smtp,并且创建项目demo. sudo yum install openssh-serve ...
- Centos7安装配置Apache+PHP+Mysql+phpmyadmin
转载自: Centos7安装配置Apache+PHP+Mysql+phpmyadmin 一.安装Apache yum install httpd 安装成功后,Apache操作命令: systemctl ...
- Centos7安装配置JDK8
Centos7安装配置JDK8 一.准备工作 第一步,去甲骨文官网下载Jdk相应的版本,我这里下载的是jdk1.8. 第二步将你从官网上下载下来的jdk使用FTP工具上传到云服务器上的相应目录,我的是 ...
- centos7命令行和图形界面的相互切换(附centos7安装配置教程)
一.最近安装了centos7,发现在命令行和图形界面的相互切换命令上,与centos以往版本有很大不同,先整理如下,加深记忆. 1,centos7默认安装后,跟其他版本一样,启动默认进入图形界面: 2 ...
- (转)Centos7安装配置NFS服务和挂载
Centos7安装配置NFS服务和挂载 原文:https://www.u22e.com/601.html NFS简介 NFS(Network File System)即网络文件系统,是FreeBSD支 ...
- CentOS7 安装配置笔记
CentOS7 安装配置笔记 1.通过镜像安装 CentOS7 ==============================* 使用 UltraISO 9.7 或者 rufus-3.5p 制作ISO的 ...
- Centos7安装配置jenkins(Tomcat)
Centos7安装配置jenkins(Tomcat) 一.准备工作 1.1 安装JDK1.8 具体安装过程不在赘述. 1.2 下载jenkins的war包 jenkins官网下载地址:https:// ...
- centos7安装配置zabbix4.0
zabbix01 198.8.8.211 zabbix-server4.0 zabbix02 198.8.8.212 zabbix-agent4.0 一:zabbix服务端环境 ...
- CentOS7安装配置Bacula yum方法
参考: https://www.baidu.com/link?url=o2QIy2YZWjsJPAFJuYFhrH3nPvtyRkSe-o5Q_FqFZ5E1EMOsIOmGeKm0HAonwHOw8 ...
随机推荐
- (转)EntityFramework.Extensions
转自:http://www.symbolsource.org/Public/Metadata/NuGet/Project/EntityFramework.Extended/1.0.0.20/Relea ...
- web-day11
第11章WEB11-Cookie&Session篇 今日任务 显示用户的上次访问时间 登录系统以后显示商品浏览记录 购买商品将商品添加到购物车 系统登录的验证码的校验 教学导航 教学目标 了解 ...
- noip第16课作业
1. 猴子吃桃 [问题描述] 猴子第一天摘了若干个桃子,当即吃了一半,还不解馋,又多吃了一个:第二天,吃剩下的桃子的一半,还不过瘾,又多吃了一个:以后每天都吃前一天剩下的一半多一个,到第10天想再吃时 ...
- QOpenGLFunctions的使用(2)
QOpenGLFunctions的使用(2) 前一小结请参考:QOpenglFuncations(1) www.icmzn.com 本小节介绍相关的类: 1. The QGLContext class ...
- To datafix AR DATE
http://www.cnblogs.com/benio/archive/2012/07/07/2580203.html AR transactions should be created on 6- ...
- 直接端口打印 支持USB接口的打印机吗?解决办法
直接端口打印 支持USB接口的打印机吗?解决办法 www.MyException.Cn 网友分享于:2013-09-15 浏览:488次 直接端口打印 支持USB接口的打印机吗?问题如 ...
- Android-Kotlin-枚举enum
案例一 星期: 星期的枚举:enum class 类名 {} package cn.kotlin.kotlin_oop09 /** * 定义星期的枚举类 */ enum class MyEnumera ...
- CentOS 7通过Firewall开放防火墙端口
发现在CentOS 7上开放端口用iptables没效果(或者是sodino没找到正确的命令,传说Centos7 下默认的防火墙是 Firewall,替代了之前的 iptables)… 使用firew ...
- strom ui Topology 可视化视图各个指标含义说明
In the visualization, spout components are represented as blue, while bolts are colored between gree ...
- Django:常见的orm操作
ArticlePost模型对应的表如下: 1.查询两个日期之间2019.04.20到2019.04.25之间的文章 import datetime from.models import Article ...