PostgreSQL 安装部署

文章目录

    • 一、PostgreSQL部署方式
      • 1.Yum方式部署
      • 2.RPM方式部署
      • 3.源码方式部署
      • 4.二进制方式部署
      • 5.Docker方式部署
    • 二、PostgreSQL部署
      • 1.Yum方式部署
        • 1.1.部署数据库
        • 1.2.连接数据库
      • 2.RPM方式部署
        • 2.1.部署数据库
        • 2.2.连接数据库
      • 3.源码方式部署
        • 3.1.准备工作
        • 3.2.编译安装
        • 3.3.配置数据库
        • 3.4.连接数据库
      • 4.二进制方式部署
        • 4.1.准备工作
        • 4.2.配置数据库
        • 4.3.连接数据库
      • 5.Docker方式部署
        • 5.1.部署数据库

  • 开源中间件
# PostgreSQL

https://iothub.org.cn/docs/middleware/
https://iothub.org.cn/docs/middleware/postgresql/postgres-deploy/

一、PostgreSQL部署方式

1.Yum方式部署

# 下载安装包,本文以二进制包方式安装

# 下载地址:
https://www.postgresql.org/download/

# CentOS安装参考
https://www.postgresql.org/download/linux/redhat/

在这里插入图片描述
在这里插入图片描述

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
 
sudo yum install -y postgresql11-server
 
sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
 
sudo systemctl enable postgresql-11
 
sudo systemctl start postgresql-11

2.RPM方式部署

# 下载地址: 
https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/
 
 
#或者直接执行wget下载
wget https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7.2-x86_64/postgresql11-11.4-1PGDG.rhel7.x86_64.rpm
 
wget https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7.2-x86_64/postgresql11-libs-11.4-1PGDG.rhel7.x86_64.rpm
 
wget https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7.2-x86_64/postgresql11-server-11.4-1PGDG.rhel7.x86_64.rpm

3.源码方式部署

# 获取官方源码包
准备装11.7版本,选择其他版本进入下面的第一个地址后退选择目的版本即可
 
# 安装官方教学
https://www.postgresql.org/docs/11/install-getsource.html
 
# 源码包
https://www.postgresql.org/ftp/source/
 
# 11.7:连接可能随着官方的更新而失效
https://ftp.postgresql.org/pub/source/v11.7/postgresql-11.7.tar.gz
 
https://www.postgresql.org/ftp/source/ 
https://www.postgresql.org/docs/11/install-getsource.html 
https://www.postgresql.org/download/ 

4.二进制方式部署

# 下载二进制包
pgsql有很多类型的包,对于不同linux发行版都有对应的编译好的包,安装很方便,另外如果对于通用的linux平台可以编译源码安装或者安装官方编译好的二进制包,源码包的安装仅仅比二进制安装多出一个编译步骤,其余的都一样,所以这里使用安装方式是安装编译好的二进制包


# pgsql官网地址
https://www.postgresql.org/
进入后点击download就来到下载页,这里点击Linux下面的Other Linux选项,然后点击下方的tar.gz archive下载二进制归档

在这里插入图片描述

然后就来到最终的pgsql下载页了,地址为:
https://www.enterprisedb.com/download-postgresql-binaries
 

https://www.postgresql.org/
https://www.postgresql.org/download/
https://www.enterprisedb.com/download-postgresql-binaries 
 
注意:官网没有11以后的linux版本

5.Docker方式部署

https://hub.docker.com/_/postgres


$ docker run -d \
	--name some-postgres \
	-e POSTGRES_PASSWORD=mysecretpassword \
	-e PGDATA=/var/lib/postgresql/data/pgdata \
	-v /custom/mount:/var/lib/postgresql/data \
	postgres

二、PostgreSQL部署

1.Yum方式部署

1.1.部署数据库
1.安装yum源
# yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
 
2.安装postgresql
# yum install -y postgresql11-server
 
3.数据库初始化
# /usr/pgsql-11/bin/postgresql-11-setup initdb
 
4.修改配置文件
# cd /var/lib/pgsql/11/data/

在这里插入图片描述

# 修改配置文件
vim /var/lib/pgsql/11/data/postgresql.conf
 
# 修改为如下:
listen_addresses = '*'
port = 5432 

在这里插入图片描述

# 修改配置文件
vim /var/lib/pgsql/11/data/pg_hba.conf
 
# 修改为如下:
host    all             all             0.0.0.0/0               md5
 
# 或
host    all             all             all                          md5

在这里插入图片描述

# 说明:
TYPE:pg的连接方式,local:本地unix套接字,host:tcp/ip连接
DATABASE:指定数据库
USER:指定数据库用户
ADDRESS:ip地址,可以定义某台主机或某个网段,32代表检查整个ip地址,相当于固定的ip,24代表只检查前三位,最后一位是0~255之间的任何一个
METHOD:认证方式,常用的有ident,md5,password,trust,reject。
    md5是常用的密码认证方式。
    password是以明文密码传送给数据库,建议不要在生产环境中使用。
               trust是只要知道数据库用户名就能登录,建议不要在生产环境中使用。
               reject是拒绝认证。
 
 
5.postgresql 安装目录授权 
# chown postgres:root -R /usr/pgsql-11/ 
 
6.启动服务 
# systemctl start postgresql-11 
 
# 服务自启动
# systemctl enable postgresql-11

#查看端口
# netstat -lntp
# netstat -nat

在这里插入图片描述

1.2.连接数据库
1.切换用户,设置数据库密码 
 
# su - postgres
$ psql -U postgres
# ALTER USER postgres with encrypted password 'postgres';

在这里插入图片描述

退出: \q
列出所有库 \l
列出所有用户 \du
列出库下所有表\d

在这里插入图片描述

2.RPM方式部署

2.1.部署数据库
1.下载RPM包
下载地址: https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/
 
#或者直接执行wget下载 
wget https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7.2-x86_64/postgresql11-11.4-1PGDG.rhel7.x86_64.rpm
 
wget https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7.2-x86_64/postgresql11-libs-11.4-1PGDG.rhel7.x86_64.rpm
 
wget https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7.2-x86_64/postgresql11-server-11.4-1PGDG.rhel7.x86_64.rpm
 
 
2.安装
先安装相应依赖
# yum install -y libicu systemd-sysv 
 
安装rpm包,需要按照这个顺序安装,卸载就反序卸载
# rpm -ivh postgresql11-libs-11.4-1PGDG.rhel7.x86_64.rpm
# rpm -ivh postgresql11-11.4-1PGDG.rhel7.x86_64.rpm
# rpm -ivh postgresql11-server-11.4-1PGDG.rhel7.x86_64.rpm
 
卸载
rpm -e postgresql11-server-11.4-1PGDG.rhel7.x86_64
rpm -e postgresql11-11.4-1PGDG.rhel7.x86_64
rpm -e postgresql11-libs-11.4-1PGDG.rhel7.x86_64
rm -rf /usr/pgsql-11/
rm -rf /var/lib/pgsql/ 
 
3.数据库初始化
# /usr/pgsql-11/bin/postgresql-11-setup initdb 
 
4.修改配置文件
# cd /var/lib/pgsql/11/data/

在这里插入图片描述

# 修改配置文件
vim /var/lib/pgsql/11/data/postgresql.conf
 
# 修改为如下:
listen_addresses = '*'
port = 5432 

在这里插入图片描述

# 修改配置文件
vim /var/lib/pgsql/11/data/pg_hba.conf
 
# 修改为如下:
host    all             all             0.0.0.0/0               md5
 
# 或
host    all             all             all                          md5

在这里插入图片描述

# 说明:
TYPE:pg的连接方式,local:本地unix套接字,host:tcp/ip连接
DATABASE:指定数据库
USER:指定数据库用户
ADDRESS:ip地址,可以定义某台主机或某个网段,32代表检查整个ip地址,相当于固定的ip,24代表只检查前三位,最后一位是0~255之间的任何一个
METHOD:认证方式,常用的有ident,md5,password,trust,reject。
    md5是常用的密码认证方式。
    password是以明文密码传送给数据库,建议不要在生产环境中使用。
               trust是只要知道数据库用户名就能登录,建议不要在生产环境中使用。
               reject是拒绝认证。
 
 
5.postgresql 安装目录授权  
# chown postgres:root -R /usr/pgsql-11/ 
 
6.启动服务 
# systemctl start postgresql-11 
 
服务自启动
# systemctl enable postgresql-11

查看端口
# netstat -lntp
# netstat -nat

在这里插入图片描述

2.2.连接数据库
1.切换用户,设置数据库密码 
 
# su - postgres
$ psql -U postgres
# ALTER USER postgres with encrypted password 'postgres';

在这里插入图片描述

退出: \q
列出所有库 \l
列出所有用户 \du
列出库下所有表\d

在这里插入图片描述

3.源码方式部署

3.1.准备工作
1.1.安装gcc编辑器
# gcc --version 
 
1.2.安装make
# make --version
 
1.3.安装readline
# yum install readline
# yum -y install -y readline-devel
 
1.4.安装zlib-devel
# yum install zlib
# yum install zlib-devel
 
1.5.下载postgresql源码
postgresql的官方网站下载:
https://www.postgresql.org/
3.2.编译安装
2.1.解压下载的压缩包
# cd /root
# tar -xzvf postgresql-11.0.tar.gz
 
创建postgresql的安装目录
# mkdir -p /home/app/postgresql/data 
 
2.2.生成makefile
# cd postgresql-11.0
# ./configure --prefix=/home/app/postgresql
 
2.3.编译安装
# make && make install
  
2.4.安装工具集
# cd /home/software/postgresql-11.0/contrib
# make && make install
3.3.配置数据库
3.1.创建postgres用户:
# groupadd postgres
# useradd -g postgres postgres
 
3.2.修改data目录的用户为postgres
chown -R postgres:postgres /home/app/postgresql/data
 
3.3.修改环境变量
# su postgres
$ vim /home/postgres/.bash_profile
 
添加环境变量:
    export PGHOME=/home/app/postgresql
    export PGDATA=/home/app/postgresql/data
    export PATH=$PGHOME/bin:$PATH
    export MANPATH=$PGHOME/share/man:$MANPATH
    export LANG=en_US.utf8
    export DATE=`date +"%Y-%m-%d %H:%M:%S"`
    export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
    alias rm='rm  -i'
    alias ll='ls -lh'
然后使环境变量立即生效,否则initdb命令会找不到:
 
$ source /home/postgres/.bash_profile
 
3.4.初始化数据库
$ initdb -D /home/app/postgresql/data/
Success. You can now start the database server using:
 
    pg_ctl -D /home/app/postgresql/data/ -l logfile start
 
3.5.修改配置文件
# cd /home/app/postgresql/data/

在这里插入图片描述

修改配置文件
vim /home/app/postgresql/data/postgresql.conf
 
# 修改为如下:
listen_addresses = '*'
port = 5432 

在这里插入图片描述

# 修改配置文件
vim /home/app/postgresql/data/pg_hba.conf
 
# 修改为如下:
host    all             all             0.0.0.0/0               md5
 
# 或
host    all             all             all                          md5

在这里插入图片描述

3.6.启动数据库
$ su postgres
$ cd /home/postgres
$ pg_ctl -D /home/app/postgresql/data/ -l logfile start
 
    cd /home/postgres  //logfile需要在postgres的用户目录下创建
    pg_ctl -D /home/app/postgresql/data/ -l logfile start
 
 
查看端口
# netstat -lntp
# netstat -nat

在这里插入图片描述

3.7.添加postgresql至服务(未验证)
    cd /home/software/postgresql-11.4/contrib/start-scripts
    chmod a+x linux.
    cp linux /etc/init.d/postgresql
此时就可以使用 /etc/init.d/postgresql stop 来停止postgresql
也可以使用:service postgresql start 来启动postgresql
修改postgresql脚本中prefix和PGDATA的内容
chkconfig --add postgresql //设置服务开机启动
3.4.连接数据库

参考 1.2.连接数据库

4.二进制方式部署

4.1.准备工作
1.下载软件
# wget https://get.enterprisedb.com/postgresql/postgresql-10.12-1-linux-x64-binaries.tar.gz
 
2.创建postgres用户
# groupadd postgres
# useradd -g postgres postgres
 
3.创建postgresql的安装目录
# mkdir -p /home/app
 
进入下载目录解压
# tar -xzvf postgresql-10.12-1-linux-x64-binaries.tar.gz -C /home/app
 
创建data目录:
# mkdir -p /home/app/pgsql/data
# mkdir -p /home/app/pgsql/log
 
授权:
# cd /home/app/pgsql
# chown -R postgres.postgres pgsql
4.2.配置数据库
1.初始化数据库
切换用户 postgres,并执行初始化操作
# su postgres
 
# cd /home/app/pgsql/bin
 
$ ./initdb -E utf8 -D /home/app/pgsql/data
Success. You can now start the database server using:
 
    ./pg_ctl -D /home/app/pgsql/data -l logfile start
 
 
2.配置环境变量
~/.bash_profile 添加如下内容
注:这个文件目录是在当前用户(postgres)的根目录下,即/home/{User}/
 
[postgres@iZ2ze72jggg737pb9vp1g6Z data]$ vim ~/.bash_profile
 
PATH=/home/app/pgsql/bin:$PATH
export PATH
 
配置文件生效
$ source ~/.bash_profile
 
修改后的配置文件
# .bash_profile
 
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
 
# User specific environment and startup programs
 
PATH=$PATH:$HOME/.local/bin:$HOME/bin
 
PATH=/home/app/pgsql/bin:$PATH
 
export PATH
 
 
3.修改配置文件
# cd /home/app/postgresql/data/

在这里插入图片描述

# 修改配置文件
vim /home/app/postgresql/data/postgresql.conf
 
# 修改为如下:
listen_addresses = '*'
port = 5432 

在这里插入图片描述

修改配置文件
vim /home/app/postgresql/data/pg_hba.conf
 
# 修改为如下:
host    all             all             0.0.0.0/0               md5
 
或
host    all             all             all                          md5

在这里插入图片描述

4.启动数据库
$ cd /home/app/pgsql/bin
$ ./pg_ctl -D /home/app/pgsql/data -l logfile start
 
查看端口
# netstat -lntp
# netstat -nat
4.3.连接数据库

参考 1.2.连接数据库

5.Docker方式部署

5.1.部署数据库
1.创建目录
# mkdir -p /data/psql
 
2.运行容器
docker run -d --network host --name pg12 --restart=always \
-e LANG="C.UTF-8" \
-e 'TZ=Asia/Shanghai' \
-e "POSTGRES_DB=postgres" \
-e "POSTGRES_USER=postgres" \
-e "POSTGRES_PASSWORD=postgres" \
-v /data/psql:/var/lib/postgresql/data \
postgres:12
 
3.进入容器
# docker exec -it pg12 /bin/sh
 
切换用户
# su - postgres
$ psql 
# \l
  • 开源中间件
# PostgreSQL

https://iothub.org.cn/docs/middleware/
https://iothub.org.cn/docs/middleware/postgresql/postgres-deploy/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/435841.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Android视角看鸿蒙第一课(工程目录)

Android视角看鸿蒙第一课(工程目录) 导读 鸿蒙马上就来了,这个工作很有可能落到Android开发的头上,既是机遇也是挑战,希望能跟上时代的浪潮,迫不得已开始学习鸿蒙开发,顺带分享记录下 我的学…

新书速览|PyTorch语音识别实战(人工智能技术丛书)

实战语音唤醒、音频特征抽取、语音情绪分类、Whisper语音转换、鸟叫多标签分类、多模态语音文字转换 01 本书内容 《PyTorch语音识别实战》使用PyTorch 2.0作为语音识别的基本框架,循序渐进地引导读者从搭建环境开始,逐步深入到语音识别基本理论、算法以…

解决QMYSQL driver not loaded问题

前言 之前都是在Qt5.51上开发,连接mysql数据库一直没有问题,换到5.15.2后一直报错 一查才发现\5.15.2\msvc2019_64\plugins\sqldrivers目录下没有qsqlmysql了,5.5.1是有的,5.15.2是要自己编译的。。。 下载源码 安装qt的时候没…

阿里云游戏访问与下载加速解决方案

随着全球化的发展,越来越多的企业开始将业务扩展到海外市场。然而,海外市场的挑战也是显而易见的。例如在游戏企业进军海外市场的过程中,网络延迟是一个常见的问题。由于地理位置的限制,海外用户登录访问游戏和游玩时,…

阿里云服务器Ngnix配置SSL证书开启HTTPS访问

文章目录 前言一、SSL证书是什么?二、如何获取免费SSL证书三、Ngnix配置SSL证书总结 前言 很多童鞋的网站默认访问都是通过80端口的Http服务进行访问,往往都会提示不安全,很多人以为Https有多么高大上,实际不然,他只是…

虚拟机时间同步主机

1.查看是否设置同步 2.查看时区 date -R 0800 表示时区东八区 明显不对 执行指令: tzselect ;找到亚洲-中国-北京 3.覆盖一下文件 复制文件到 /etc/localtime 目录下:#sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 4.重现查…

html css 导航栏 2

鼠标划过会向上移动改变颜色 html文件 <!DOCTYPE html> <html><head><meta charset"UTF-8"><title>导航栏</title><link rel"stylesheet" href"css/dhl1.css" /></head><body><div …

MongoDB系列之索引

索引 一、创建1、普通索引2、唯一索引3、复合索引二、查看三、删除四、执行计划explain五、TTL索引存在一张articles集合 一、创建 1、普通索引 db.articles.ensureIndex({name:1}) // 普通索引,1代表升序,-1代表倒序_id是默认索引 2、唯一索引 db.articles.ensureInde…

【JavaEE】_Spring MVC 项目单个及多个参数传参

目录 1. 传递单个参数 1.1 关于参数名的问题 2. 传递多个参数 2.1 关于参数顺序的问题 2.2 关于基本类型与包装类的问题 1. 传递单个参数 现创建Spring MVC项目&#xff0c;.java文件内容如下&#xff1a; package com.example.demo.controller;import org.springframewo…

NFTScan :什么是 ERC-404?深入解读 NFT 协议的未来

上月初&#xff0c;ERC-404 成为最首要热门的话题&#xff0c;ERC-404 是由 Pandora 团队在 2 月初为创作者和开发者等开源的实验性代币标准&#xff0c;其混合 ERC-20 / ERC-721 实现&#xff0c;具有原生流动性和碎片化等特点。伴随着早期的发展&#xff0c;越来越多参与者开…

Qt 类的前置声明和头文件包含

1. 在头文件中引入另一个类经常有两种写法 1&#xff09;前置声明 2&#xff09;头文件包含 #ifndef FRMCOUPLE2_H #define FRMCOUPLE2_H#include <QWidget> //头文件包含namespace Ui { class frmcouple2; }//前置声明&#xff1a;QPushButton frmchkeyboard…

QT----云服务器部署Mysql,Navicat连接1698 -Access denied for user ‘root‘@‘‘

阿里云有活动&#xff0c;白嫖了一年的新加坡轻量级服务器&#xff0c;有点卡&#xff0c;有时候要开梯子 白嫖300元优惠券 目录 1 安装启动Mysql服务2 更改连接权限2.1 Navicat连接报错1698 -Access denied for user root 3 qt连接云服务器数据库 1 安装启动Mysql服务 我使用…

Go-zero中分布式事务的实现(DTM分布式事务管理器,在一个APi中如何调用两个不同服务的rpc层,并保证两个不同服务之间的业务逻辑同时成功)

涉及到的相关技术 1.DTM分布式事务管理器,解决跨数据库、跨服务、跨语言栈更新数据的一致性问题。 2.SAGA事务模式,SAGA事务模式是DTM中常用的一种模式,简单易上手.(当然还有其它更多的事务模式,这里采用的SAGA只不过是其中一种较为简单的方法) 3.Go-zero框架,ETCD服务注册... …

虾皮、lazada店铺运营攻略,如何搭建高效、稳定的自养号测评系统

随着电子商务的蓬勃发展&#xff0c;越来越多的人选择在虾皮这样的电商平台上开设店铺&#xff0c;以实现创业梦想。但如何在众多店铺中脱颖而出&#xff0c;成为消费者的首选?本文将为您详细解答“怎么样做好虾皮店铺”&#xff0c;并提供一些实用的运营建议。 一、怎么样做…

Java工作需求后端代码--实现树形结构

加油&#xff0c;新时代打工人&#xff01; 前端页面 带树形结构的表格 最近在新项目上加班加点&#xff0c;下面是个实现树形结构的数据表格。 需求&#xff1a; 在前端页面表格中展示成树形结构的数据。 技术&#xff1a; 后端&#xff1a;Java、Mybatis-Plus、HuTool树形的…

b站小土堆pytorch学习记录—— P18-P22 神经网络+小实战

文章目录 一、卷积层 P181.卷积操作2.代码 二、池化层 P191.池化层简单介绍2.代码&#xff08;1&#xff09;池化操作中数字的变化&#xff08;2&#xff09;池化操作对图片的影响 三、非线性激活 P201.简要介绍2.代码 四、线性层及其他层介绍 P211.线性层2.代码 五、搭建小实战…

docker安装和使用kafka

1. 启动zookeeper Kafka依赖zookeeper, 首先安装zookeeper -p&#xff1a;设置映射端口&#xff08;默认2181&#xff09; docker run --name zookeeper \--network app-tier \-e ALLOW_ANONYMOUS_LOGINyes \--restartalways \-d bitnami/zookeeper:latest2. 启动kafka docker…

实验七 综合实验

一&#xff0e; 下载并成功运行Anaconda,jupyter book ,spyder 输入检验(print (“hello”)) 二&#xff0e; 在jupyter prompt中安装库&#xff1a; 找到anaconda 的Scripts库&#xff0c;并复制路径以备后面安装命令 D:\Program Files\anaconda3\Scripts 进入prompt命令…

网络原理初识

一、IP地址 概念 IP 地址主要用于标识网络主机、其他网络设备&#xff08;如路由器&#xff09;的网络地址。简单说&#xff0c; IP 地址用于定位主机 的网络地址 。 就像我们发送快递一样&#xff0c;需要知道对方的收货地址&#xff0c;快递员才能将包裹送到目的地。 二、…

搭建的svn 1.14.1,拉取代码时候没输入账户密码就报错 auth failed

这边在ubuntu里面搭的svn server&#xff0c;但是拉代码的是否一直报错 auth faield&#xff0c;一开始以为是有auth cache&#xff0c;去设置里面清楚了&#xff0c;windows 里面也清楚了&#xff0c;但是还是报错 问题原因 一直排查才发现&#xff0c;我新增用户的时候&…
最新文章