一、安装Rocky Linux
略(VMware workstation 17.5虚拟机安装)
二、修改dnf阿里源:
[root@localhost etc]# MIRROR=mirrors.aliyun.com/rockylinux
[root@localhost etc]# sudo sed -i.bak -e "s|^mirrorlist=|#mirrorlist=|" -e "s|^#baseurl=|baseurl=|" -e "s|dl.rockylinux.org/\$contentdir|$MIRROR|" /etc/yum.repos.d/rocky-*.repo
[root@localhost etc]# sudo dnf makecache
Rocky Linux 9 - BaseOS 291 kB/s | 2.2 MB 00:07
Rocky Linux 9 - AppStream 653 kB/s | 7.9 MB 00:12
Rocky Linux 9 - Extras 3.2 kB/s | 15 kB 00:04
元数据缓存已建立。
三、安装第三方软件
root@localhost etc]# make -v
bash: make: 未找到命令...
安装软件包“make”以提供命令“make”? [N/y] y
* 正在队列中等待...
* 正在载入软件包列表。...
下列软件包必须安装:
make-1:4.3-8.el9.x86_64 A GNU tool which simplifies the build process for users
继续更改? [N/y] y
* 正在队列中等待...
* 正在等待认证...
* 正在队列中等待...
* 正在下载软件包...
* 正在请求数据...
* 正在测试更改...
* 正在安装软件包...
GNU Make 4.3
为 x86_64-redhat-linux-gnu 编译
Copyright (C) 1988-2020 Free Software Foundation, Inc.
许可证:GPLv3+:GNU 通用公共许可证第 3 版或更新版本<http://gnu.org/licenses/gpl.html>。
本软件是自由软件:您可以自由修改和重新发布它。
在法律允许的范围内没有其他保证。
[root@localhost etc]# gcc -v
bash: gcc: 未找到命令...
安装软件包“gcc”以提供命令“gcc”? [N/y] y
* 正在队列中等待...
* 正在载入软件包列表。...
下列软件包必须安装:
gcc-11.4.1-3.el9.x86_64 Various compilers (C, C++, Objective-C, ...)
glibc-devel-2.34-100.el9.x86_64 Object files for development using standard C libraries.
glibc-headers-2.34-100.el9.x86_64 Additional internal header files for glibc-devel.
kernel-headers-5.14.0-427.16.1.el9_4.x86_64 Header files for the Linux kernel for use by glibc
libxcrypt-devel-4.4.18-3.el9.x86_64 Development files for libxcrypt
继续更改? [N/y] y
* 正在队列中等待...
* 正在等待认证...
* 正在队列中等待...
* 正在下载软件包...
* 正在请求数据...
* 正在测试更改...
* 正在安装软件包...
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
目标:x86_64-redhat-linux
配置为:../configure --enable-bootstrap --enable-host-pie --enable-host-bind-now --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.rockylinux.org/ --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-plugin --enable-initfini-array --without-isl --enable-multilib --with-linker-hash-style=gnu --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_64=x86-64-v2 --with-arch_32=x86-64 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1
线程模型:posix
Supported LTO compression algorithms: zlib zstd
gcc 版本 11.4.1 20231218 (Red Hat 11.4.1-3) (GCC)
[root@localhost etc]# dnf -y install readline-devel zlib-devel
上次元数据过期检查:0:05:34 前,执行于 2024年05月29日 星期三 16时24分24秒。
依赖关系解决。
================================================================================
软件包 架构 版本 仓库 大小
================================================================================
安装:
readline-devel x86_64 8.1-4.el9 appstream 194 k
zlib-devel x86_64 1.2.11-40.el9 appstream 44 k
安装依赖关系:
ncurses-c++-libs x86_64 6.2-10.20210508.el9 appstream 36 k
ncurses-devel x86_64 6.2-10.20210508.el9 appstream 516 k
事务概要
================================================================================
安装 4 软件包
总下载:791 k
安装大小:1.7 M
下载软件包:
(1/4): ncurses-c++-libs-6.2-10.20210508.el9.x86 17 kB/s | 36 kB 00:02
(2/4): readline-devel-8.1-4.el9.x86_64.rpm 89 kB/s | 194 kB 00:02
(3/4): zlib-devel-1.2.11-40.el9.x86_64.rpm 927 kB/s | 44 kB 00:00
(4/4): ncurses-devel-6.2-10.20210508.el9.x86_64 226 kB/s | 516 kB 00:02
--------------------------------------------------------------------------------
总计 157 kB/s | 791 kB 00:05
Rocky Linux 9 - AppStream 1.7 MB/s | 1.7 kB 00:00
导入 GPG 公钥 0x350D275D:
Userid: "Rocky Enterprise Software Foundation - Release key 2022 <releng@rockylinux.org>"
指纹: 21CB 256A E16F C54C 6E65 2949 702D 426D 350D 275D
来自: /etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9
导入公钥成功
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : ncurses-c++-libs-6.2-10.20210508.el9.x86_64 1/4
安装 : ncurses-devel-6.2-10.20210508.el9.x86_64 2/4
安装 : readline-devel-8.1-4.el9.x86_64 3/4
安装 : zlib-devel-1.2.11-40.el9.x86_64 4/4
运行脚本: zlib-devel-1.2.11-40.el9.x86_64 4/4
验证 : ncurses-devel-6.2-10.20210508.el9.x86_64 1/4
验证 : ncurses-c++-libs-6.2-10.20210508.el9.x86_64 2/4
验证 : readline-devel-8.1-4.el9.x86_64 3/4
验证 : zlib-devel-1.2.11-40.el9.x86_64 4/4
已安装:
ncurses-c++-libs-6.2-10.20210508.el9.x86_64
ncurses-devel-6.2-10.20210508.el9.x86_64
readline-devel-8.1-4.el9.x86_64
zlib-devel-1.2.11-40.el9.x86_64
完毕!
[root@localhost etc]# dnf -y install libicu-devel
上次元数据过期检查:0:06:28 前,执行于 2024年05月29日 星期三 16时24分24秒。
依赖关系解决。
================================================================================
软件包 架构 版本 仓库 大小
================================================================================
安装:
libicu-devel x86_64 67.1-9.el9 appstream 830 k
事务概要
================================================================================
安装 1 软件包
总下载:830 k
安装大小:5.4 M
下载软件包:
libicu-devel-67.1-9.el9.x86_64.rpm 356 kB/s | 830 kB 00:02
--------------------------------------------------------------------------------
总计 162 kB/s | 830 kB 00:05
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
准备中 : 1/1
安装 : libicu-devel-67.1-9.el9.x86_64 1/1
运行脚本: libicu-devel-67.1-9.el9.x86_64 1/1
验证 : libicu-devel-67.1-9.el9.x86_64 1/1
已安装:
libicu-devel-67.1-9.el9.x86_64
完毕!
四、源码安装
1、创建postgres用户
groupadd postgres
useradd -g postgres postgres
passwd postgres
2、创建数据库软件安装路径及数据路径,同时到官网下载最新的源码包
mkdir -p /usr/local/pg16/data
chown postgres /usr/local/pg16/data
cd /usr/local/pg16
wget https://ftp.postgresql.org/pub/source/v16.3/postgresql-16.3.tar.gz
3、安装
tar -zxvf postgresql-16.3.tar.gz
cd postgresql-16.3
./configure --prefix=/usr/local/pg16
make world
make install-world
4、初始化数据库
[root@localhost postgresql-16.3]# su - postgres
[postgres@localhost ~]$
postgres@localhost ~]$ /usr/local/pg16/bin/initdb -D /usr/local/pg16/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 "zh_CN.UTF-8".
The default database encoding has accordingly been set to "UTF8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".
Data page checksums are disabled.
fixing permissions on existing directory /usr/local/pg16/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:
/usr/local/pg16/bin/pg_ctl -D /usr/local/pg16/data -l logfile start
[postgres@localhost ~]$
[postgres@localhost ~]$ /usr/local/pg16/bin/pg_ctl -D /usr/local/pg16/data -l logfile start
waiting for server to start.... done
server started
[postgres@localhost ~]$
5、修改管理员密码
[postgres@localhost ~]$ /usr/local/pg16/bin/psql
psql (16.3)
Type "help" for help.
postgres=# alter user postgres password 'postgres';
ALTER ROLE
6、修改环境变量
[postgres@localhost ~]$ vi ~/.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:/usr/local/pg16/bin
export PATH
PGDATA=/usr/local/pg16/data
export PGDATA
使其环境变量生效
source ~/.bash_profile
7、修改/usr/local/pg16/data/pg_hba.conf文件,针对IPV4地址的客户端机器,允许其通过任意IP地址,通过md5加密认证。
[postgres@localhost ~]$ vi /usr/local/pg16/data/pg_hba.conf
# IPv4 local connections:
host all all 127.0.0.1/32 trust
改为:
# IPv4 local connections:
host all all 0.0.0.0/0 md5
8、修改/usr/local/pg16/data/postgresql.conf文件
[postgres@localhost ~]$ vi /usr/local/pg16/data/postgresql.conf
修改#listen_addresses = ‘localhost’为listen_addresses = ‘*’
重启数据库使生效
postgres@localhost ~]$ pg_ctl restart -m fast
waiting for server to shut down.... done
server stopped
waiting for server to start....2024-05-29 18:59:26.812 CST [49379] LOG: starting PostgreSQL 16.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3), 64-bit
2024-05-29 18:59:26.813 CST [49379] LOG: listening on IPv4 address "0.0.0.0", port 5432
2024-05-29 18:59:26.813 CST [49379] LOG: listening on IPv6 address "::", port 5432
2024-05-29 18:59:26.815 CST [49379] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2024-05-29 18:59:26.818 CST [49382] LOG: database system was shut down at 2024-05-29 18:59:26 CST
2024-05-29 18:59:26.821 CST [49379] LOG: database system is ready to accept connections
done
server started
9、配置pg数据库开机自启动
vim /usr/lib/systemd/system/postgresql.service
[Unit]
Description=PostgreSQL 16 database server
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
# 以下路径需要根据实际安装路径进行修改
ExecStart=/usr/local/pg16/bin/pg_ctl start -D /usr/local/pg16/data
ExecStop=/usr/local/pg16/bin/pg_ctl stop -D /usr/local/pg16/data -s -m fast
ExecReload=/usr/local/pg16/bin/pg_ctl reload -D /usr/local/pg16/data
[Install]
WantedBy=multi-user.target
加载配置和启动
root@localhost system]# systemctl daemon-reload && systemctl enable postgresql
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /usr/lib/systemd/system/postgresql.service.
10、防火墙修改
[root@localhost ~]# sudo firewall-cmd --zone=public --add-port=5432/tcp --permanent
生效:
[root@localhost ~]# sudo firewall-cmd –reload
检查:
[root@localhost ~]# sudo firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens160
sources:
services: cockpit dhcpv6-client ssh
ports: 5432/tcp
protocols:
forward: yes
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
[root@localhost ~]#
11、下载pgadmin4工具
https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v8.6/windows/pgadmin4-8.6-x64.exe
客户机(192.168.44.1)无法访问数据库(192.168.44.129),处理:
vi /usr/local/pg16/data/pg_hba.conf
增加:
host all all 192.168.44.1/32 md5