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 ...
随机推荐
- POJ3273--Monthly Expense(Binary Search)
Description Farmer John is an astounding accounting wizard and has realized he might run out of mone ...
- Python自动化开发 - 进程、线程(一)
本节内容 1.操作系统发展史 2.进程和线程 3.Python threading 模块 一.操系统发展史 手工操作(无操作系统) 1946年第一台计算机诞生--20世纪50年代中期,还未出现操作系统 ...
- unigui 设置单元格颜色
procedure TF_Resource2.UniDBGrid1DrawColumnCell(Sender: TObject; ACol, ARow: Integer; Column: TUniD ...
- Spring @Autowired注解用在集合上面,可以保持接口的所有实现类
CourseService课程接口有2个子类,HistroyCourseServiceImpl和MathsCourseServiceImpl public interface CourseServic ...
- wpf 导出Excel
private void Button_Click_1(object sender, RoutedEventArgs e) { ExportDataGridSaveAs(true, this.data ...
- MVC中通过ajax判断输入的内容是否重复(新手笔记,请各位多多指教)
控制器代码: public string ValidateCarID(string carid)//这里接收ajax传递过来的值 { string result; Car car = db.Car.F ...
- Java - 阅读与查找
WebSites http://www.importnew.com/ https://www.java-tips.org/ http://www.javaworld.com/ http://www.p ...
- Tools - Others
01 - 一些网络工具 文档查阅 https://devdocs.io/ API文档 http://overapi.com/ 开源代码及文档搜索 https://searchcode.com/ 电子书 ...
- python 数据库连接及操作
Python DB-API使用流程: 引入API模块. 获取与数据库的连接. 执行SQL语句和存储过程. 关闭数据库连接. def mysql_dbtest(): config = { 'host': ...
- Flask 初印象
Flask 出生于2010年,集中了其他python web框架的长处,定位于微小项目上. 特点 1 内置开发服务器和调试器 2 于Python单元测试功能无缝衔接 Flask框架提供了一个与Pyth ...