Cenos7环境PostgreSQ16.0离线安装部署

Cenos7环境PostgreSQ16.0离线安装部署

一、简介

1、访问官网

https://www.postgresql.org/

2、下载

https://ftp.postgresql.org/pub/source/v16.0/postgresql-16.0.tar.gz

二、环境准备

1、机器

centos7 x86

2、部署用户

  • 添加用户
sudo useradd postgres
  • 设置用户密码
sudo passwd postgres
  • 设置root权限
sudo vim /etc/sudoers

3、依赖下载

sudo yum -y install readline-devel
sudo yum -y install zlib-devel

4、通过ftp将下载的postgresql安装包放在指定的目录,并解压。解压后的目录为/opt/software/postgresql-16.0

tar -xvf ./postgresql-16.0.tar.gz

5、部署目录

  • 创建部署目录
mkdir /opt/postgresql-16.0
  • 创建数据目录
mkdir /opt/postgresql-16.0/data

-创建日志文件

touch /opt/postgresql-16.0/pgsql.log

三、安装步骤

1、进入解压后的目录

cd /opt/software/postgresql-16.0

2、指定安装到/opt/postgresql-16.0目录

./configure --prefix=/opt/postgresql-16.0 --without-icu

3、编译并安装

make && make install

4、检查是否安装成功

cd /opt/postgresql-16.0/
sh ./bin/pg_config

出现如下配置信息

BINDIR = /opt/postgresql-16.0/bin
DOCDIR = /opt/postgresql-16.0/share/doc
HTMLDIR = /opt/postgresql-16.0/share/doc
INCLUDEDIR = /opt/postgresql-16.0/include
PKGINCLUDEDIR = /opt/postgresql-16.0/include
INCLUDEDIR-SERVER = /opt/postgresql-16.0/include/server
LIBDIR = /opt/postgresql-16.0/lib
PKGLIBDIR = /opt/postgresql-16.0/lib
LOCALEDIR = /opt/postgresql-16.0/share/locale
MANDIR = /opt/postgresql-16.0/share/man
SHAREDIR = /opt/postgresql-16.0/share
SYSCONFDIR = /opt/postgresql-16.0/etc
PGXS = /opt/postgresql-16.0/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = ‘–prefix=/opt/postgresql-16.0’ ‘–without-icu’
CC = gcc -std=gnu99
CPPFLAGS = -D_GNU_SOURCE
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2
CFLAGS_SL = -fPIC
LDFLAGS = -Wl,–as-needed -Wl,-rpath,‘/opt/postgresql-16.0/lib’,–enable-new-dtags
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -lz -lreadline -lpthread -lrt -ldl -lm
VERSION = PostgreSQL 16.0

5、数据库初始化

./bin/initdb -D /opt/postgresql-16.0/data/

显示如下内容:

The files belonging to this database system will be owned by user “postgres”.
This user must also own the server process.

The database cluster will be initialized with locale “en_US.UTF-8”.
The default database encoding has accordingly been set to “UTF8”.
The default text search configuration will be set to “english”.

Data page checksums are disabled.

fixing permissions on existing directory /opt/postgresql-16.0/data … ok
creating subdirectories … ok
selecting dynamic shared memory implementation … posix
selecting default max_connections … 100
selecting default shared_buffers … 128MB
selecting default time zone … Asia/Shanghai
creating configuration files … ok
running bootstrap script … ok
performing post-bootstrap initialization … ok
syncing data to disk … ok

initdb: warning: enabling “trust” authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

pg_ctl -D /opt/postgresql-16.0/data/ -l logfile start

6、启动postgresql,并指定数据目录和日志文件

cd /opt/postgresql-16.0/bin
  • 启动postgresql
[postgres@hadoop3 bin]$ ./pg_ctl -D /opt/postgresql-16.0/data/ -l /opt/postgresql-16.0/pgsql.log start
waiting for server to start.... done
server started

  • 停止postgresql
[postgres@hadoop3 bin]$ ./pg_ctl -D /opt/postgresql-16.0/data/ -l /opt/postgresql-16.0/pgsql.log stop
waiting for server to shut down.... done
server stopped
  • 查看postgresql状态
[postgres@hadoop3 bin]$ ./pg_ctl -D /opt/postgresql-16.0/data/ -l /opt/postgresql-16.0/pgsql.log status
pg_ctl: server is running (PID: 6868)
/opt/postgresql-16.0/bin/postgres "-D" "/opt/postgresql-16.0/data"

7、查看进程

[postgres@hadoop3 bin]$ ps -aux | grep postgres
root      5781  0.0  0.0 241332  4628 pts/1    S    17:07   0:00 sudo su - postgres
root      5782  0.0  0.0 191884  2348 pts/1    S    17:07   0:00 su - postgres
postgres  5783  0.0  0.0 116052  2628 pts/1    S+   17:07   0:00 -bash
root      6012  0.0  0.0 241332  4632 pts/2    S    17:10   0:00 sudo su postgres
root      6013  0.0  0.0 191880  2348 pts/2    S    17:10   0:00 su postgres
postgres  6014  0.0  0.0 116060  2664 pts/2    S    17:10   0:00 bash
postgres  6868  0.0  0.1 276432 13508 ?        Ss   17:27   0:00 /opt/postgresql-16.0/bin/postgres -D /opt/postgresql-16.0/data
postgres  6869  0.0  0.0 276564  1136 ?        Ss   17:27   0:00 postgres: checkpointer 
postgres  6870  0.0  0.0 276588  2188 ?        Ss   17:27   0:00 postgres: background writer 
postgres  6872  0.0  0.0 276432  5092 ?        Ss   17:27   0:00 postgres: walwriter 
postgres  6873  0.0  0.0 278028  2152 ?        Ss   17:27   0:00 postgres: autovacuum launcher 
postgres  6874  0.0  0.0 278012  1904 ?        Ss   17:27   0:00 postgres: logical replication launcher 
postgres  7066  0.0  0.0 155476  1884 pts/2    R+   17:30   0:00 ps -aux
postgres  7067  0.0  0.0 112812   980 pts/2    S+   17:30   0:00 grep --color=auto postgres

8、配置远程连接

  • 修改pg_hba.conf
vim /opt/postgresql-16.0/data/pg_hba.conf

加上末尾一行

host    all             all             0.0.0.0/0               md5

效果如下:

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust
host    all             all             0.0.0.0/0               md5
  • 修改postgresql.conf
vim /opt/postgresql-16.0/data/postgresql.conf

将第60行的#listen_addresses = 'localhost'改为listen_addresses = '*'

修改之前

60 #listen_addresses = ‘localhost’ # what IP address(es) to listen on;

修改之后

listen_addresses = ‘*’ # what IP address(es) to listen on;

四、使用postgresql

  • 第一次进入postgresql
/opt/postgresql-16.0/bin/psql
  • postgresql用户设置密码(这个密码得设置,默认为空)
postgres=# \password postgres
Enter new password for user "postgres": 
Enter it again: 
  • 重置postgresql密码(这个好像未用到)
alter user postgres with encrypted password 'postgres123";
  • 创建用户pgdba
create user pgdba with encrypted password 'pgdba';
  • 修改pgdba用户吃的角色
alter role pgdba createrole superuser;
  • 创建数据库mytest
create database mytest;
  • 授予pgdba用户操作mytest数据库的权限
grant all privileges on database mytest to pgdba;
  • 配置环境变量
vim ~/.bashrc

写入如下内容

export POSTGRESQL_HOME=/opt/postgresql-16.0
export PATH=$POSTGRESQL_HOME/bin:$PATH

新打开一个会话,查看效果

which psql
  • 修改密码后需要使用
psql -U postgres -h localhost -d postgres -p 5432

-U是用户,-h是host的ip,-d是数据库名称,-p是端口号

五、系统配置

1、postgresql数据库的开机启动脚本在源安装包的postgresql-16.0/contrib/start-scripts目录下

/opt/software/postgresql-16.0/contrib/start-scripts/linux

2、将Linux文件复制到/etc/init.d目录下,并且将其重名为postgresql

sudo cp /opt/software/postgresql-16.0/contrib/start-scripts/linux /etc/init.d/postgresql

3、进入/etc/init.d目录下,修改postgresql文件

sudo vim /etc/init.d/postgresql

修改之前:

# Installation prefix
prefix=/usr/local/pgsql

# Data directory
PGDATA="/usr/local/pgsql/data"

# Who to run postgres as, usually "postgres".  (NOT "root")
PGUSER=postgres

# Where to keep a log file
PGLOG="$PGDATA/serverlog"

修改之后:

# Installation prefix
prefix=/opt/postgresql-16.0

# Data directory
PGDATA="/opt/postgresql-16.0/data"

# Who to run postgres as, usually "postgres".  (NOT "root")
PGUSER=postgres

# Where to keep a log file
PGLOG="/opt/postgresql-16.0/pgsql.log"

4、添加到开机启动

sudo chmod a+x /etc/init.d/postgresql
sudo chkconfig --add /etc/init.d/postgresql

/etc/init.d目录下放启动脚本与sudo systemctl enable postgresql是两种不同的方式,二选一。

  • 25
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
CentOS 7 是一种免费的开源操作系统,而 OpenSSH 是一个用于加密远程登录和文件传输的工具。在没有网络连接的情况下,我们可以通过离线安装安装 CentOS 7 上的 OpenSSH 9.3。 以下是离线安装的步骤: 1. 首先,您需要从官方网站下载 CentOS 7 的安装介质镜像文件。您可以选择下载 ISO 文件并将其刻录到光盘上,或者创建一个可引导的 USB 驱动器。 2. 在启动计算机时,选择从光盘或 USB 驱动器启动。这将进入 CentOS 7 的安装程序。 3. 在 CentOS 7 安装程序启动后,按照屏幕上的指示选择适当的语言和键盘布局。 4. 在安装程序的主菜单上,选择“Install CentOS 7”。 5. 然后,按照安装程序的指示进行必要的设置,例如选择适当的时区、设置密码等等。 6. 当您达到“软件选择”屏幕时,选择“最小安装”选项。这将只安装 CentOS 7 的最小功能集,您可以在安装后手动添加其他软件包。 7. 完成软件选择后,继续进行安装,直到安装完成。 8. 一旦安装完成,使用 root 用户或具有管理员权限的用户登录到系统。 9. 打开命令终端,使用以下命令安装 OpenSSH 9.3: ``` sudo yum install openssh-server ``` 该命令将从 CentOS 7 的安装媒体中安装 OpenSSH 9.3 软件包。 10. 安装完成后,使用以下命令启动 OpenSSH 服务: ``` sudo systemctl start sshd ``` 现在,您已成功在离线的情况下安装 CentOS 7 上的 OpenSSH 9.3。您可以使用 SSH 客户端连接到该服务器来进行远程登录和文件传输。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值