PostgreSQL数据库安装部署

news/2024/7/9 21:57:17 标签: 数据库, postgresql

PostgreSQL官网
https://www.postgresql.org/
PostgreSQL下载地址
http://www.postgresql.org/ftp/source/

一.安装所需要的依赖包

yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake

二.上传并解压缩jar包

[root@node1 module]# tar -zxvf postgresql-11.1.tar.gz -C /opt/module
[root@node1 module]# cd postgresql-11.1/
[root@node1 postgresql-11.1]# ls
aclocal.m4  config.log     configure     contrib    doc          GNUmakefile.in  INSTALL   README
config      config.status  configure.in  COPYRIGHT  GNUmakefile  HISTORY         Makefile  src

postgresql_16">三.开始编译postgresql源码

[root@node1 postgresql-11.1]# ./configure --prefix=/pgsql/postgresql
[root@node1 postgresql-11.1]# make
[root@node1 postgresql-11.1]# make install

postgresql_22">四.创建启动postgresql的用户

#创建用户组postgres
[root@node1 postgresql-11.1]# groupadd postgres
#创建用户postgres
[root@node1 postgresql-11.1]# useradd -g postgres postgres
#创建用户密码
[root@node1 postgresql-11.1]# passwd postgres
#查看用户
[root@node1 postgresql-11.1]# id postgres
uid=1002(postgres) gid=1002(postgres)=1002(postgres)

postgresql_34">五.创建postgresql数据库的数据目录并修改文件所有者

[root@node1 postgresql-11.1]# cd /pgsql/postgresql
[root@node1 postgresql]# mkdir data
[root@node1 postgresql]# chown postgres:postgres data
[root@node1 postgresql]# ls
bin  data  include  lib  share

六.配置环境变量

[root@node1 postgres]# cd /home/postgres/
[root@node1 postgres]# ls -al
总用量 24
drwx------  2 postgres postgres  120 120 12:02 .
drwxr-xr-x. 6 root     root       59 120 11:39 ..
-rw-------  1 postgres postgres 1123 120 12:16 .bash_history
-rw-r--r--  1 postgres postgres   18 1125 2021 .bash_logout
-rw-r--r--  1 postgres postgres  301 120 11:44 .bash_profile
-rw-r--r--  1 postgres postgres  231 1125 2021 .bashrc
[root@node1 postgres]# vim .bash_profile

添加以下内容到文件末尾

export PGHOME=/pgsql/postgresql
export PGDATA=/pgsql/postgresql/data
PATH=$PATH:$HOME/bin:$PGHOME/bin

使环境变量生效

[root@node1 postgres]# source .bash_profile

七.切换用户postgres并初始化数据库

[root@node1 postgres]# su - postgres
[postgres@node1 ~]$ initdb
...........
Success. You can now start the database server using:
 
    pg_ctl -D /pgsql/postgresql/data -l logfile start

可以看到 /pgsql/postgresql/data已经有文件了

[postgres@node1 data]$ cd /pgsql/postgresql/data
[postgres@node1 data]$ ls
base          pg_dynshmem    pg_multixact  pg_snapshots  pg_tblspc    pg_xact               postmaster.pid
global        pg_hba.conf    pg_notify     pg_stat       pg_twophase  postgresql.auto.conf  serverlog
logfile       pg_ident.conf  pg_replslot   pg_stat_tmp   PG_VERSION   postgresql.conf
pg_commit_ts  pg_logical     pg_serial     pg_subtrans   pg_wal       postmaster.opts

八.配置PostgreSQL服务

1.postgresql.conf 配置PostgreSQL数据库服务器的相应的参数

[postgres@node1 data]$ vim postgresql.conf
listen_addresses = '*'                  # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
#port = 5432                            # (change requires restart)

2.pg_hba.conf 配置对数据库的访问权限。

[postgres@node1 data]$ vim pg_hba.conf

找到最下面这一行 ,添加上配置,这样局域网的人才能访问

# IPv4 local connections:
host    all             all             0.0.0.0/0                  trust
host    all             all             127.0.0.1/32               trust

postgresql_105">九.启动postgresql

[postgres@node1 ~]$ pg_ctl -D /pgsql/postgresql/data -l logfile start
waiting for server to start.... done
server started

进入postgresql

[postgres@node1 ~]$ psql
psql (11.1)
Type "help" for help.

postgres=# 

如果报错进不去,指定ip,用户,端口号

[postgres@node1 ~]$ psql -h node1 -U postgres -p 5432

至此大功告成,安装配置成功

postgresql_124">10.设置postgresql的开机启动

1.在解压安装目录下找到启动脚本

[root@node1 start-scripts]# pwd
/opt/module/postgresql-11.1/contrib/start-scripts
[root@node1 start-scripts]# ll
总用量 8
-rw-r--r-- 1 linux linux 1467 117 2018 freebsd
-rw-r--r-- 1 linux linux 3552 117 2018 linux
drwxrwxr-x 2 linux linux   84 117 2018 macos

2.拷贝linux文件到init.d目录下

[root@node1 start-scripts]# cp linux /etc/init.d/postgresqld

3.修改配置文件

[root@node1 start-scripts]# cd /etc/init.d/
[root@node1 init.d]# vim postgresqld
# Installation prefix   (pgsql主目录)
prefix=/home/postgres/pgsql

# Data directory                     (pg data目录)
PGDATA="/home/postgres/pgsql/data"

# Who to run the postmaster as, usually "postgres".  (NOT "root")  (pg用户)
PGUSER=postgres

# Where to keep a log file              (pg日志文件)
PGLOG="/home/postgres/pgsql/logs/serverlog"

4.修改文件的可执行权

[root@node1 init.d]# chmod 755 /etc/init.d/postgresqld

5.注册脚本

[root@node1 init.d]# chkconfig postgresqld on
[root@node1 init.d]# chkconfig --list
postgresqld    	0:off	1:off	2:on	3:on	4:on	5:on	6:off

6.查看服务状态

[root@node1 init.d]# systemctl status postgresqld
● postgresqld.service - SYSV: PostgreSQL RDBMS
   Loaded: loaded (/etc/rc.d/init.d/postgresqld; bad; vendor preset: disabled)
   Active: inactive (dead) since 六 2024-01-20 18:11:13 CST; 18min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1614 ExecStop=/etc/rc.d/init.d/postgresqld stop (code=exited, status=0/SUCCESS)
  Process: 1015 ExecStart=/etc/rc.d/init.d/postgresqld start (code=exited, status=0/SUCCESS)

7.启动postgresql

[root@node1 init.d]# ./postgresqld start
Starting PostgreSQL: ok
[root@node1 init.d]# ./postgresqld stop
Stopping PostgreSQL: ok
[root@node1 init.d]# systemctl status postgresqld
● postgresqld.service - SYSV: PostgreSQL RDBMS
   Loaded: loaded (/etc/rc.d/init.d/postgresqld; bad; vendor preset: disabled)
   Active: active (exited) since 六 2024-01-20 18:31:50 CST; 1min 24s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1614 ExecStop=/etc/rc.d/init.d/postgresqld stop (code=exited, status=0/SUCCESS)
  Process: 1817 ExecStart=/etc/rc.d/init.d/postgresqld start (code=exited, status=0/SUCCESS)

http://www.niftyadmin.cn/n/5338449.html

相关文章

基于深度学习的细胞感染性识别与判定

基于深度学习的细胞感染性识别与判定 基于深度学习的细胞感染性识别与判定引言项目背景项目意义项目实施数据采集与预处理模型选择与训练模型评估与优化 结果与展望结论 基于深度学习的细胞感染性识别与判定 引言 随着深度学习技术的不断发展,其在医学图像处理领域…

【js】js 异步机制详解 Generator / Async / Promise

三种语法功能放在一起,是因为他们都有相似特点: 维护某种状态在未来恢复状态并执行 本文重点回答以下几个问题: 为什么 Generator 和 Async 函数的 代码执行流 都可以简化成树形结构?async 函数为什么返回一个 promise&#xf…

C#,入门教程(21)——命名空间(namespace)与程序结构的基础知识

上一篇: C#,入门教程(20)——列表(List)的基础知识https://blog.csdn.net/beijinghorn/article/details/124094382 编写软件(大软件称为系统)与盖大楼一个道理。 假设咱们现在需要盖一座名为“天梯大厦”的…

vue3+vite:封装Svg组件

前言 在项目开发过程中,以svg图片引入时,会遇到当hover态时图片颜色修改的场景,我们可能需要去引入另一张不同颜色的svg图片,或者用css方式修改,为了方便这种情况,需要封装svg组件来自定义宽高和颜色&…

CentOS Linux操作系统源码安装最新Redis版本,使用JSON数据类型踩入新坑

最近有空查阅了redis官网,发现redis数据类型不止Strings、Lists、Sets、Hashes、Sorted sets,还多了几种,决定先试用下JSON数据类型 1、安装Redis软件 JSON数据类型,对Redis版本有要求,需要大于4.0版本。下图是华为云…

GPT应用_PrivateGPT

项目地址:https://github.com/imartinez/privateGPT 1 功能 1.1 整体功能,想解决什么问题 搭建完整的 RAG 系统,与 FastGPT 相比,界面比较简单。但是底层支持比较丰富,可用于知识库的完全本地部署,包含大…

Flutter开发进阶之使用Socket实现主机服务

Flutter开发进阶之使用Socket实现主机服务 在Flutter开发实践中,有一些业务是需要主从机合作搭配的服务,其中一些重要的数据和功能是交由主机进行存储和管理,从机再通过UDP和TCP与主机通讯去获得权限,一般在同一个局域网内的多端…

回调地狱与解决方案

什么是回调地狱? 简单理解就是回调函数嵌套回调 示例: setTimeout(() > {console.log(1);setTimeout(() > {console.log(2);setTimeout(() > {console.log(3);}, 1000);}, 2000)}, 3000)如上代码所示,回调函数嵌套回调,就…