狂飙Linux平台,PostgreSQL16部署大全

2024-03-12 08:44

本文主要是介绍狂飙Linux平台,PostgreSQL16部署大全,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

📢📢📢📣📣📣
哈喽!大家好,我是【IT邦德】,江湖人称jeames007,10余年DBA及大数据工作经验
一位上进心十足的【大数据领域博主】!😜😜😜
中国DBA联盟(ACDU)成员,目前服务于工业互联网
擅长主流Oracle、MySQL、PG、高斯及Greenplum运维开发,备份恢复,安装迁移,性能优化、故障应急处理等。
✨ 如果有对【数据库】感兴趣的【小可爱】,欢迎关注【IT邦德】💞💞💞
❤️❤️❤️感谢各位大可爱小可爱!❤️❤️❤️

文章目录

    • 📣 1.源码安装
      • ✨ 1.1 源码包下载
      • ✨ 1.2 创建用户
      • ✨ 1.3 创建目录
      • ✨ 1.4 本地yum源配置
      • ✨ 1.5 操作系统参数设置
      • ✨ 1.6 编译安装
      • ✨ 1.7 配置环境变量
      • ✨ 1.8 初始化DB
      • ✨ 1.9 配置DB参数
      • ✨ 1.10 数据库启动
    • 📣 2.RPM离线安装PG
      • ✨ 2.1 RPM包下载
      • ✨ 2.2 环境变量配置
      • ✨ 2.3 数据库初始化
      • ✨ 2.4 配置DB参数
    • 📣 3.YUM在线安装
      • ✨ 3.1 安装依赖包
      • ✨ 3.2 配置YUM源
      • ✨ 3.3 确认版本
      • ✨ 3.4 安装PG
      • ✨ 3.5 初始化PG
      • ✨ 3.6 DB登陆
      • ✨ 3.7 配置文件修改
    • 4.总结


PostgreSQL16的部署方式可以基于Linux,也可以在Window上部署,作为目前最火的关系型数据库,安装部署是第一步,本文详细介绍了PostgreSQL16基于Linux8操作系统的3种部署方式,并附带了避坑指南,希望带领大家开启PG的学习之路

官方文档指南
https://www.postgresql.org/docs/

📣 1.源码安装

✨ 1.1 源码包下载

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

在这里插入图片描述

✨ 1.2 创建用户

[root@rhel8 ~]# groupadd -g 60000 postgres
[root@rhel8 ~]# useradd -u 60000 -g postgres postgres
[root@rhel8 ~]# echo “postgres” | passwd --stdin postgres

在这里插入图片描述

✨ 1.3 创建目录

[root@rhel8 ~]# mkdir -p /pgccc/{pgdata,archive,scripts,backup,pgsql-16,soft}
[root@rhel8 ~]# chown -R postgres:postgres /pgccc
[root@rhel8 ~]# chmod -R 775 /pgccc

✨ 1.4 本地yum源配置

1.创建挂载路径
[root@rhel8 ~]# mkdir -p /mnt/cdrom2.挂载系统镜像光盘到指定目录
#因为光盘的格式通常是iso9660,意思是/dev/sr0挂载在/mnt/cdrom目录上
[root@rhel8 ~]# mount -t iso9660 /dev/sr0 /mnt/cdrom
mount: /mnt/cdrom: WARNING: device write-protected, mounted read-only.3.修改yum源配置文件
编辑rhel8-local.repo文件
[root@rhel8 ~]# cd /etc/yum.repos.d
[root@rhel8 yum.repos.d]# vi rhel8-local.repo
[localREPO]
name=localhost8
baseurl=file:///mnt/cdrom/BaseOS
enable=1
gpgcheck=0[localREPO_APP]
name=localhost8_app
baseurl=file:///mnt/cdrom/AppStream
enable=1
gpgcheck=04.配置好后重建本地缓存
yum clean all 
yum makecache 
yum repolist安装依赖包
yum install -y openssl openssl-devel pam pam-devel libxml2 libxml2-devel \
libxslt libxslt-devel perl perl-devel python-devel perl-ExtUtils-Embed \
readline readline-devel bzip2 zlib zlib-devel \
gettext gettext-devel bison flex gcc gcc-c++ \
boost-devel gmp* mpfr* libevent* libpython3.6myum install libicu-devel -y
yum install zlib-devel -y

✨ 1.5 操作系统参数设置

--关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld--关闭安全服务
临时关闭:
setenforce 0永久关闭:
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config查看是否成功关闭:
getenforce
cat /etc/selinux/config--资源限制
vi /etc/security/limits.conf
soft    nofile   65535
hard    nofile   65535
soft    nproc   65535
hard    nproc   65535

✨ 1.6 编译安装

[root@rhel8 ~]# cp /opt/postgresql-16.2.tar.gz /pgccc/soft
[root@rhel8 ~]# chown -R postgres:postgres /pgccc/soft
[root@rhel8 ~]# chmod -R 775 /pgccc/soft

[root@rhel8 ~]# su - postgres
[postgres@rhel8 ~]$ cd /pgccc/soft/
[postgres@rhel8 soft]$ tar zxvf postgresql-16.2.tar.gz

–配置预编译
[postgres@rhel8 postgresql-16.2]$ ./configure --prefix=/pgccc/pgsql-16 --without-readline

在这里插入图片描述

–编译及安装
[postgres@rhel8 postgresql-16.2]$ make -j 4 && make install
#编译及安装正常,则输出结尾如下

在这里插入图片描述

✨ 1.7 配置环境变量

cat >> ~/.bash_profile <<"EOF"
export LANG=en_US.UTF-8
export PS1="[\u@\h \W]\$ "
export PGPORT=5432
export PGDATA=/pgccc/pgdata
export PGHOME=/pgccc/pgsql-16
export PATH=$PGHOME/bin:$PATH:.
export PGUSER=postgres
export PGDATABASE=postgres
EOF[postgres@rhel8 ]$ source  /.bash_profile

✨ 1.8 初始化DB

[root@rhel8 ~]# su - postgres
[postgres@rhel8 ~]# /pgccc/pgsql-16/bin/initdb -D /pgccc/pgdata -E UTF8
–locale=en_US.utf8 -U postgres

在这里插入图片描述

[postgres@rhel8 ~]$ pg_ctl -D /pgccc/pgdata -l logfile start

在这里插入图片描述

✨ 1.9 配置DB参数

两个参数文件:

cat >> /pgccc/pgdata/postgresql.conf <<"EOF"
listen_addresses = '*'
port=5432
#unix_socket_directories='/pgccc/pgdata'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
EOFcat > /pgccc/pgdata/pg_hba.conf << EOF
# TYPE  DATABASE    USER    ADDRESS       METHOD
local     all       all                    trust
host      all       all   127.0.0.1/32     trust
host      all       all    0.0.0.0/0      md5
host   replication  all    0.0.0.0/0      md5
local  replication  all                    trust
EOF

✨ 1.10 数据库启动

[root@rhel8 ~]# su - postgres
[postgres@rhel8 ~]$ pg_ctl restart
[postgres@rhel8 ~]$ pg_ctl status
[postgres@rhel8 ~]$ netstat -anp | grep 5432
[postgres@rhel8 ~]$ cd /pgccc/pgdata/pg_log --日志文件

在这里插入图片描述

📣 2.RPM离线安装PG

✨ 2.1 RPM包下载

https://ftp.postgresql.org/pub/repos/yum/16/redhat/rhel-8.1-x86_64/

数据库lib库
postgresql16-libs-16.2-1PGDG.rhel8.x86_64.rpm
客户端安装包
postgresql16-16.2-1PGDG.rhel8.x86_64.rpm
数据库主程序
postgresql16-server-16.2-1PGDG.rhel8.x86_64.rpm

下载libzstd依赖包,高于1.4.0版本
https://rpmfind.net/linux/rpm2html/search.php

rpm -ivh libzstd-1.4.4-1.el8.x86_64.rpm
rpm -ivh postgresql16-libs-16.2-1PGDG.rhel8.x86_64.rpm
rpm -ivh postgresql16-16.2-1PGDG.rhel8.x86_64.rpm
rpm -ivh postgresql16-server-16.2-1PGDG.rhel8.x86_64.rpm

在这里插入图片描述

✨ 2.2 环境变量配置

[root@rhel8 ~]# su - postgrescat >> ~/.bash_profile <<"EOF"
export LANG=en_US.UTF-8
export PS1="[\u@\h \W]\$ "
export PGPORT=5432
export PGDATA=/pgccc/pgdata
export PGHOME=/usr/pgsql-16
export PATH=$PGHOME/bin:$PATH:.
export PGUSER=postgres
export PGDATABASE=postgres
EOF[postgres@rhel8 ]$ source  ~/.bash_profile 

✨ 2.3 数据库初始化

mkdir -p /pgccc/{pgdata,archive,scripts,backup,pgsql-16,soft}
chown -R postgres:postgres /pgccc
chmod -R 775 /pgccc

su - postgres
/usr/pgsql-16/bin/initdb -U postgres -E utf8 -D /pgccc/pgdata

在这里插入图片描述

✨ 2.4 配置DB参数

两个参数文件:
/pgccc/pgdata/postgresql.conf
/pgccc/pgdata/pg_hba.conf

cat >> /pgccc/pgdata/postgresql.conf <<"EOF"
listen_addresses = '*'
port=5432
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
EOFcat > /pgccc/pgdata/pg_hba.conf << EOF
# TYPE  DATABASE    USER    ADDRESS       METHOD
local     all       all                    trust
host      all       all   127.0.0.1/32     trust
host      all       all    0.0.0.0/0      md5
host   replication  all    0.0.0.0/0      md5
local  replication  all                    trust
EOF

#启动
[root@rhel8 ~]# su - postgres
[postgres@rhel8 ~]$ pg_ctl restart
[postgres@rhel8 ~]$ pg_ctl status
[postgres@rhel8 ~]$ netstat -anp | grep 5432
[postgres@rhel8 ~]$ cd /pgccc/pgdata/pg_log --日志文件

在这里插入图片描述

📣 3.YUM在线安装

✨ 3.1 安装依赖包

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo

yum install -y cmake make gcc zlib gcc-c++ perl readline readline-devel
yum install -y zlib-devel perl python36 tcl openssl ncurses-devel openldap pam
yum install -y zlib libicu

✨ 3.2 配置YUM源

sudo dnf install -y \
https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

✨ 3.3 确认版本

dnf update
yum repolist all | grep pgdg
yum repolist enabled | grep pgdg

在这里插入图片描述

✨ 3.4 安装PG

离线安装
rpm -ivh libzstd-1.4.4-1.el8.x86_64.rpm
yum install -y postgresql16 postgresql16-server
#环境变量
–root下操作
echo “export PATH=/usr/pgsql-16/bin:$PATH” >> /etc/profile

✨ 3.5 初始化PG

/usr/pgsql-16/bin/postgresql-16-setup initdb
systemctl enable postgresql-16
systemctl start postgresql-16
systemctl status postgresql-16

在这里插入图片描述

✨ 3.6 DB登陆

su - postgres
[postgres@rhel8 ~]$ psql
postgres=# \l

在这里插入图片描述

✨ 3.7 配置文件修改

cat >> /var/lib/pgsql/16/data/postgresql.conf <<"EOF"
listen_addresses = '*'
port=5432
#unix_socket_directories='/var/lib/pgsql/16/data'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
EOF##黑名单配置
cat << EOF > /var/lib/pgsql/16/data/pg_hba.conf
# TYPE  DATABASE    USER    ADDRESS       METHOD
local     all       all                    trust
host      all       all   127.0.0.1/32     trust
host      all       all    0.0.0.0/0      md5
host   replication  all    0.0.0.0/0      md5
local  replication  all                    trust
EOF

systemctl restart postgresql-16 --重启
systemctl status postgresql-16 --查看状态

4.总结

安装部署是关键,只有环境才能更好的训练,以上内容我已经在B站制作了详细视频

B站直播间:
https://www.bilibili.com/video/BV1yj421Z7iJ

这篇关于狂飙Linux平台,PostgreSQL16部署大全的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


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

相关文章

Web技术与Nginx网站环境部署教程

《Web技术与Nginx网站环境部署教程》:本文主要介绍Web技术与Nginx网站环境部署教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、Web基础1.域名系统DNS2.Hosts文件3.DNS4.域名注册二.网页与html1.网页概述2.HTML概述3.

linux服务之NIS账户管理服务方式

《linux服务之NIS账户管理服务方式》:本文主要介绍linux服务之NIS账户管理服务方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、所需要的软件二、服务器配置1、安装 NIS 服务2、设定 NIS 的域名 (NIS domain name)3、修改主

Linux实现简易版Shell的代码详解

《Linux实现简易版Shell的代码详解》本篇文章,我们将一起踏上一段有趣的旅程,仿照CentOS–Bash的工作流程,实现一个功能虽然简单,但足以让你深刻理解Shell工作原理的迷你Sh... 目录一、程序流程分析二、代码实现1. 打印命令行提示符2. 获取用户输入的命令行3. 命令行解析4. 执行命令

Nginx使用Keepalived部署web集群(高可用高性能负载均衡)实战案例

《Nginx使用Keepalived部署web集群(高可用高性能负载均衡)实战案例》本文介绍Nginx+Keepalived实现Web集群高可用负载均衡的部署与测试,涵盖架构设计、环境配置、健康检查、... 目录前言一、架构设计二、环境准备三、案例部署配置 前端 Keepalived配置 前端 Nginx

ubuntu如何部署Dify以及安装Docker? Dify安装部署指南

《ubuntu如何部署Dify以及安装Docker?Dify安装部署指南》Dify是一个开源的大模型应用开发平台,允许用户快速构建和部署基于大语言模型的应用,ubuntu如何部署Dify呢?详细请... Dify是个不错的开源LLM应用开发平台,提供从 Agent 构建到 AI workflow 编排、RA

ubuntu16.04如何部署dify? 在Linux上安装部署Dify的技巧

《ubuntu16.04如何部署dify?在Linux上安装部署Dify的技巧》随着云计算和容器技术的快速发展,Docker已经成为现代软件开发和部署的重要工具之一,Dify作为一款优秀的云原生应用... Dify 是一个基于 docker 的工作流管理工具,旨在简化机器学习和数据科学领域的多步骤工作流。它

Nginx部署React项目时重定向循环问题的解决方案

《Nginx部署React项目时重定向循环问题的解决方案》Nginx在处理React项目请求时出现重定向循环,通常是由于`try_files`配置错误或`root`路径配置不当导致的,本文给大家详细介... 目录问题原因1. try_files 配置错误2. root 路径错误解决方法1. 检查 try_f

Linux高并发场景下的网络参数调优实战指南

《Linux高并发场景下的网络参数调优实战指南》在高并发网络服务场景中,Linux内核的默认网络参数往往无法满足需求,导致性能瓶颈、连接超时甚至服务崩溃,本文基于真实案例分析,从参数解读、问题诊断到优... 目录一、问题背景:当并发连接遇上性能瓶颈1.1 案例环境1.2 初始参数分析二、深度诊断:连接状态与

Linux系统调试之ltrace工具使用与调试过程

《Linux系统调试之ltrace工具使用与调试过程》:本文主要介绍Linux系统调试之ltrace工具使用与调试过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、ltrace 定义与作用二、ltrace 工作原理1. 劫持进程的 PLT/GOT 表2. 重定

Linux区分SSD和机械硬盘的方法总结

《Linux区分SSD和机械硬盘的方法总结》在Linux系统管理中,了解存储设备的类型和特性是至关重要的,不同的存储介质(如固态硬盘SSD和机械硬盘HDD)在性能、可靠性和适用场景上有着显著差异,本文... 目录一、lsblk 命令简介基本用法二、识别磁盘类型的关键参数:ROTA查询 ROTA 参数ROTA