重庆思庄Oracle、Redhat认证学习论坛
标题: 基于 RHEL10 BETA版源码安装PG17.2 [打印本页]
作者: 郑全 时间: 2024-12-1 20:35
标题: 基于 RHEL10 BETA版源码安装PG17.2
RHEL10 现在还是BETA版本,根据红帽产品发布规律,未来在2025年5月份发布,PG17已经正式发布,而且已经到17.2版本,一直说安装来尝试一下,今天正好试一下,一直习惯了源码安装,本次也不例外。
具体步骤如下:
一、安装前准备1.1 关闭防火墙systemctl disablefirewalld
1.2关闭seliuxrhel9以上版本关闭SELINUX和9以前版本有点区别。使用以下命令即可
# grubby --update-kernel ALL --args selinux=0
# reboot
说明:
selinux 必须关闭,否则,使用systemd启动,会报:
dbserver (pg_ctl)[2994]:pg17.service: Unable to locate executable 'bin/pg_ctl': Permission denied
1.3 关闭透明大页# grubby --update-kernel ALL --argstransparent_hugepage=never
重启生效
1.4安装必要的包这里需要的包:
make
gcc
tar
readline and readline-devel
zlib
zlib-devel
ICU
libicu-devel
安装命令
yum -y install makegcc tar readline readline-devel zlib zlib-devel icu libicu-devel
1.5安装可选的包Perl
Python
Tcl
Gettext
OpenSSL
MIT, OpenLDAP, and/or PAM
LZ4 ,用于TOTAST,WAL压缩
Zstandard 1.4.0,用于 wal压缩
Flex and Bison 用于git
安装命令
yum -y install perlpython tcl gettext openssl mit openldap pam lz4 zstandard flex bison
1.6安装支持中文的包yum install glibc-common langpacks-zh_CN glibc-langpack-zhglibc-locale-source
1.7建立目录习惯了ORACLE的方式,按该习惯命名目录
# mkdir /u01/app/postgres/product/17.2/dbhome_1 -p
# mkdir /u01/app/postgres/pgdata -p
# mkdir /u01/setup/source -p
1.8创建用户groupadd postgres
useradd -g postgres postgres
echo "postgres" | passwd --stdin postgres
RHEL10 安全性要求比较高,对用户密码有长度,复杂度要求,如果你想回到RHEL9以前模式,可以修改 /etc/pam.d/system-auth ,在pam_pwquality.so 后面加上以前的要求即可,具体见下图。
1.9授权chown -R postgres:postgres /u01/app/postgres
chmod -R 775 /u01/app/postgres
chown -R postgres:postgres /u01/setup/source
二、安装PG2.1.下载安装文件到 /u01/setup/source# cd /u01/setup/source
2.2.解压su – postgres
tar xvf postgresql-17.2.tar.gz
2.3.Configurecd /u01/setup/source/postgresql-17.2
./configure --prefix=/u01/app/postgres/product/17.2/dbhome_1
2.4.编译make world -j 16 (含所有功能及文档)
2.5.安装 make install-world -j 162.6.配置环境变量cat >> ~/.bash_profile<<"EOF"
export PGPORT=2025 --马上到2025,提前迎接一下
export PGDATA=/u01/app/postgres/pgdata
export PGHOME=/u01/app/postgres/product/17.2/dbhome_1
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH:.
export PGHOST=$PGDATA
export PGUSER=postgres
export PGDATABASE=postgres
export PGCLIENTENCODING=GBK
EOF
2.7.创建数据库集群# su - postgres
$ source.bash_profile
$ initdb -D /u01/app/postgres/pgdata-E UTF8 --locale=zh_CN.UTF8 -U postgres
2.8.修改数据库参数cat >> $PGDATA/postgresql.conf<< "EOF"
listen_addresses = '*'
port=2025
unix_socket_directories='/u01/app/postgres/pgdata'
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
max_connections = 500
shared_buffers = 2GB
EOF
cat >> $PGDATA/pg_hba.conf<< "EOF"
# TYPE DATABASE USER ADDRESS METHOD
host all all 0.0.0.0/0 md5
EOF
2.9启停PGsu - postgres
pg_ctl start
pg_ctl status
pg_ctl stop
2.10验证
三、完善PG相关3.1.配置PG自动启动服务cat > /etc/systemd/system/pg17.service<<"EOF"
[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
Environment=PGPORT=2025
Environment=PGDATA=/u01/app/postgres/pgdata
OOMScoreAdjust=-1000
ExecStart=/u01/app/postgres/product/17.2/dbhome_1/bin/pg_ctlstart -D ${PGDATA} -s -o "-p ${PGPORT}" -w -t 300
ExecStop=/u01/app/postgres/product/17.2/dbhome_1/bin/pg_ctlstop -D ${PGDATA} -s -m fast
ExecReload=/u01/app/postgres/product/17.2/dbhome_1/bin/pg_ctlreload -D ${PGDATA} -s
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0
[Install]
WantedBy=multi-user.target
EOF
--配置生效
# systemctldaemon-reload
# systemctl enable pg17
# systemctl start pg17
# systemctl status pg17
3.2.设置内核参数cat > /etc/sysctl.conf <<EOF
vm.swappiness=10 --交换内存使用设置
vm.zone_reclaim_mode=0
fs.aio-max-nr = 1048576
fs.file-max = 6815744
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
kernel.shmmax = 8589934592
kernel.shmall = 2097152
kernel.shmmni = 4096
kernel.sem = 250 32000 250 128
EOF
3.3.设置资源限制cat >>/etc/security/limits.conf <<"EOF"
* soft nofile 131072
* hard nofile 131072
* soft nproc 131072
* hard nproc 131072
* soft core unlimited
* hard core unlimited
* soft memlock unlimited
* hard memlock unlimited
EOF
到此,数据库安装完成.
欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/) |
Powered by Discuz! X3.2 |