由于接触了华为的elk大数据平台,里面封装的是postgres ,就想着安装一下,熟悉一下postgres数据。

安装包下载:https://www.postgresql.org/ftp/source/

可以选择自己想下载的版本。这里我们下载v10.5

随后开始安装:

1.把包上传到虚拟机中postgresql-10.5.tar.gz

2.解压缩:

gunzip postgresql-10.5.tar.gz

tar -xvf postgresql-10.5.tar

3.进行编辑安装:

./configure         --预编辑
make
su                       --进root用户
make install       --安装
adduser postgres               --创建postgres
mkdir /usr/local/pgsql/data   --创建目录
chown postgres /usr/local/pgsql/data   
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data   --初始化数据库

/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data >logfile 2>&1 &        --启动数据库

遇到错误:
[postgres@master ~]$ more logfile
2018-12-20 15:47:11.867 CST [28074] LOG: listening on IPv6 address "::1", port 5432
2018-12-20 15:47:11.867 CST [28074] LOG: listening on IPv4 address "127.0.0.1", port 5432
2018-12-20 15:47:11.868 CST [28074] FATAL: could not remove old lock file "/tmp/.s.PGSQL.5432.lock": 不允许的操作
2018-12-20 15:47:11.868 CST [28074] HINT: The file seems accidentally left over, but it could not be removed. Please remove the file by hand and try again.
2018-12-20 15:47:11.868 CST [28074] LOG: database system is shut down

解决方法:
chown -R postgres:postgres /tmp             --root用户

/usr/local/pgsql/bin/createdb test             --创建test数据库
/usr/local/pgsql/bin/psql test                    --进入test数据库

[postgres@master bin]$ /usr/local/pgsql/bin/psql test
psql (10.5)
Type "help" for help. test=#

启动或重启server
先确保是切换到了/pgsql/bin目录下,并且切换Linux用户postgres
cd /usr/local/pgsql/bin/
su – postgres
启动server:
./pg_ctl start -D /usr/local/pgsql/data

重启:
./pg_ctl restart -D /usr/local/pgsql/data

waiting for server to shut down....2018-12-20 16:34:51.304 CST [] LOG:  received fast shutdown request
2018-12-20 16:34:51.305 CST [] LOG: aborting any active transactions
2018-12-20 16:34:51.306 CST [] FATAL: terminating connection due to administrator command
2018-12-20 16:34:51.307 CST [] FATAL: terminating connection due to administrator command
2018-12-20 16:34:51.307 CST [] FATAL: terminating connection due to administrator command
2018-12-20 16:34:51.308 CST [] FATAL: terminating connection due to administrator command
2018-12-20 16:34:51.310 CST [] LOG: worker process: logical replication launcher (PID 28755) exited with exit code 1
2018-12-20 16:34:51.312 CST [] LOG: shutting down
2018-12-20 16:34:51.327 CST [] LOG: database system is shut down
done
server stopped
waiting for server to start....2018-12-20 16:34:51.413 CST [] LOG: listening on IPv4 address "0.0.0.0", port 5432
2018-12-20 16:34:51.413 CST [] LOG: listening on IPv6 address "::", port 5432
2018-12-20 16:34:51.415 CST [] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2018-12-20 16:34:51.438 CST [] LOG: database system was shut down at 2018-12-20 16:34:51 CST
2018-12-20 16:34:51.442 CST [] LOG: database system is ready to accept connections
done
server started

新建数据库和可以登录数据库的用户密码
确保是在/usr/local/pgsql/bin/目录下
./createdb mydb

创建用户(如用户名为lin,密码为LinBug)有两种方式:

第一种:
CREATE USER或CREATE ROLE:CREATE USER是CREATE ROLE的一个别名。
唯一的区别是CREATE USER命令缺省是LOGIN,而CREATE ROLE命令缺省是NOLOGIN。
先进入默认的postgres数据库:
./psql
然后执行:
CREATE USER zhang WITH PASSWORD 'zhang';
创建成功提示如下
[postgres@master bin]$ ./psql
psql (10.5)
Type "help" for help.

postgres=# CREATE USER zhang WITH PASSWORD 'zhang';
CREATE ROLE
postgres=#
第二种:
 pg封装的命令方式:
[postgres@master bin]$ ./createuser -P zhang
Enter password for new role:
Enter it again:
2018-12-20 16:04:01.792 CST [28674] ERROR:  role "zhang" already exists
2018-12-20 16:04:01.792 CST [28674] STATEMENT:  CREATE ROLE zhang PASSWORD 'md578d7c325e6ea326d9c1a5c5b1172a59d' NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;
createuser: creation of new role failed: ERROR:  role "zhang" already exists

访问数据库

* 确保在/usr/local/pgsql/bin/目录下,
以默认用户名访问默认数据库(默认的用户名和数据库名都是postgres):
./psql
于是进入PG的交互终端psql
[postgres@master bin]$ ./psql
psql (10.5)
Type "help" for help.

postgres=#

以名为zhang的角色登录名为mydb的数据库:

./psql mydb -U zhang
可以看出,当psql终端的提示符为=#时,表示当前登录的是超级用户,而当提示符为=>时则为普通用户
[postgres@master bin]$ ./psql mydb -U zhang
psql (10.5)
Type "help" for help.

mydb=>

远程访问数据库设置
* 远程访问数据库的认证方式主要有很多方式,我只设置基于TCP/IP连接的trust认证方式
需设置两个配置文件,
1)修改配置文件postgresql.conf,
vim /usr/local/pgsql/data/postgresql.conf
修改监听地址:
#listen_addresses=’localhost’
#将上面这行改成如下
listen_addresses=’*’

修改配置文件/pgsql/data/pg_hba.conf:
vim /usr/local/pgsql/data/pg_hba.conf
添加一条IP授权记录(如192.168.2.23),可以对一个网段授权
# 这是在/pgsql/data/pg_hba.conf文件里加
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
host    all             all             0.0.0.0/0               trust

设置完需要重启数据库才能生效。

远程客户端连接

使用的软件为:Dbeaver

主要的就是以上配置。

现在可以在客户端操作数据库了。

<<完>>

Linux上安装postgres 10.5的更多相关文章

  1. 通过xshell在linux上安装solr4.10.3

    通过xshell在linux上安装solr4.10.3 0)下载linux下的安装包 1)通过xftp6上传到linux上 3)在xshell下依次执行 解压命令:tar xvfz solr.tgz( ...

  2. RAC分解步骤之一,在oracle linux 4u4上安装oracle 10.2.0.1.0操作日志

    练习oracle的rac组建过程,第一步,先练习4u4上安装oracle 10.2.0.1.0.直接安装rac,有些难度.从简单的做起.总RAC步骤,参照小布老师的RAC组建. 1. 启动vc,登陆v ...

  3. Linux上安装ZooKeeper并设置开机启动(CentOS7+ZooKeeper3.4.10)

    1下载Zookeeper 2安装启动测试 2.1上载压缩文件并解压 2.2新建 zookeeper配置文件 2.3安装JDK 2.4启动zookeeper 2.5查看zookeeper的状态 3将Zo ...

  4. 在Windows和Linux上安装paramiko模块

    一.paramiko模块有什么用? paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接.由于使用的是python这样的能够跨平台运行的语言 ...

  5. 如何在Linux上安装Storm

    Storm是开源的分布式实时计算系统,能够让数据流处理变得简单.可靠,也因此在大数据领域有广泛的实际 应用.下面介绍一下如何在Linux系统上安装Storm.根据Storm官网介绍,安装Storm软件 ...

  6. linux上安装配置samba服务器

    linux上安装配置samba服务器 在linux上安装配置samba服务器 在这给大家介绍一个不错的家伙,samba服务.如果您正在犯愁,如何在Windows和Linux之间实现资源共享,就请看看这 ...

  7. ghmm在 Linux 上安装

    ghmm在 Linux 上安装 http://ghmm.sourceforge.net/documentation.html http://www.ghmm.org http://www.comp.l ...

  8. Linux上安装Zookeeper以及一些注意事项

    最近打算出一个系列,介绍Dubbo的使用. 分布式应用现在已经越来越广泛,Spring Could也是一个不错的一站式解决方案,不过据我了解国内目前貌似使用阿里Dubbo的公司比较多,一方面这个框架也 ...

  9. Redis之在Linux上安装和简单的使用

    我只是一个搬运工 Redis之在Linux上安装和简单的使用https://blog.csdn.net/qq_20989105/article/details/76390367 一.安装gcc 1.R ...

随机推荐

  1. 如何查看MySQL connection id连接id

    每个MySQL连接,都有一个连接ID,可以通过 connection_id()查看. 连接id也可以通过以下方式查看: show processlist中id列 information_schema. ...

  2. CSS鼠标效果手型效果

    Example:CSS鼠标手型效果 <a href="#" style="cursor:hand">CSS鼠标手型效果</a> Exam ...

  3. js字符串常用函数

    字符截取函数 1. array.slice(start, end) 第一个参数代表开始位置,第二个参数代表结束位置的下一个位置 start:规定从何处开始选取. 如果是负数,那么它规定从数组尾部开始算 ...

  4. 手机APP流量的发送与获取功能的实现

    package com.loaderman.trafficdemo; import android.content.Context; import android.content.Intent; im ...

  5. linux 基础 配置静态IP

    1.查看本机windows默认网关.DNS 2.配置linux 3.查询网络配置 4.xshell 登录 一 查看本机windows默认网关.DNS 二 配置linux(注意:默认网关.dns,必须跟 ...

  6. php文件夹上传下载控件分享

    用过浏览器的开发人员都对大文件上传与下载比较困扰,之前遇到了一个php文件夹上传下载的问题,无奈之下自己开发了一套文件上传控件,在这里分享一下.希望能对你有所帮助. 以下是实例的部分脚本文件 这里我先 ...

  7. 061. Rotate List

    题目链接:https://leetcode.com/problems/rotate-list/description/ Example 1: Input: 1->2->3->4-&g ...

  8. OpenCV阈值化处理

    图像的阈值化就是利用图像像素点分布规律,设定阈值进行像素点分割,进而得到图像的二值图像.图像阈值化操作有多种方法,常用方法有经典的OTSU.固定阈值.自适应阈值.双阈值及半阈值化操作.这里对各种阈值化 ...

  9. ES5与ES6常用语法教程之 ①函数写法、创建对象、导入导出模块方式

    函数写法区别 计算a, b两个数字之和,有返回值 es5 写法 function add(a, b) { return a + b; } es6 写法(箭头函数) let add = (a, b) = ...

  10. OpenStack组件——Keystone身份认证

    1.keystone介绍 keystone 是OpenStack的组件之一,用于为OpenStack家族中的其它组件成员提供统一的认证服务,包括身份验证.令牌的发放和校验.服务列表.用户权限的定义等等 ...