暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

安装单机版PG数据库

2203

1.安装概述

操作系统版本:Readhat7.6

PostgreSQL版本:PostgreSQL13

注:文档中的命令以#号开头表示使用root用户执行,以$符号开头表示使用postgres用户执行。

2.系统设置

2.1. 关闭防火墙和selinux

# systemctl disable firewalld.service # systemctl stop firewalld.service # setenforce 0 # sed -i '/^SELINUX=/c'SELINUX=disabled /etc/selinux/config

2.2. 修改/etc/hosts

# vi /etc/hosts 192.168.2.154 hostname01

2.3. 安装软件依赖包

# yum -y install readline readline-devel zlib zlib-devel gettext gettext-devel openssl openssl-devel pam pam-devel libxml2 libxml2-devel libxslt libxslt-devel perl perl-devel tcl-devel uuid-devel gcc gcc-c++ make flex bison perl-ExtUtils

2.4. 内核参数调整

# vi /etc/sysctl.conf ##--文件尾追加: fs.file-max = 76724200 kernel.sem = 10000 10240000 10000 1024 kernel.shmmni = 4096 kernel.shmall = 253702 kernel.shmmax = 1039163392 net.ipv4.ip_local_port_range = 9000 65500 net.core.rmem_default = 262144 net.core.wmem_default = 262144 net.core.rmem_max = 4194304 net.core.wmem_max = 1048576 fs.aio-max-nr = 40960000 vm.dirty_ratio=20 vm.dirty_background_ratio=3 vm.dirty_writeback_centisecs=100 vm.dirty_expire_centisecs=500 vm.swappiness=10 vm.min_free_kbytes=524288 vm.swappiness=0 vm.overcommit_memory=2 vm.overcommit_ratio=75 net.ipv4.ip_local_port_range = 10000 65535 生效配置: # sysctl -p

2.5. 用户limits设置

# vi /etc/security/limits.conf ##--文件尾追加: postgres soft nofile 1048576 postgres hard nofile 1048576 postgres soft nproc 131072 postgres hard nproc 131072 postgres soft stack 10240 postgres hard stack 32768 postgres soft core 6291456 postgres hard core 6291456 postgres soft memlock -1 postgres hard memlock -1

2.6. 创建用户和组

# groupadd dba -g 3000 # useradd postgres --gid 3000 --uid 3000 --create-home # echo "PostgreSQL123()"|passwd postgres --stdin

3. 源码方式安装PostgreSQL

3.1. 编译安装

3.1.1. 下载文件并解压

# su - postgres $ cd /soft $ wget https://ftp.postgresql.org/pub/source/v13.3/postgresql-13.3.tar.gz $ tar -zxvf postgresql-13.3.tar.gz

3.1.2. 编译

$ cd postgresql-13.3/ $ ./configure --prefix=/opt/pg13 --with-openssl --with-includes=/usr/include/openssl --with-pgport=6000

3.1.3. 安装

$ gmake world $ gmake install-world

3.2. 初始化数据库集簇

$ /opt/pgsql/bin/initdb -D /opt/data6000 -X /opt/wal6000 -E UTF8 -U postgres -W

3.3. 修改数据库参数

$ vi /opt/data6000/postgresql.conf ##--文件尾追加: cluster_name='pg_6000' listen_addresses = '0.0.0.0' port = 6000

3.4. 配置环境变量(非必须)

$ vi ~/.bashrc ##--文件尾追加: export PGPORT=6000 export PGUSER=postgres export PGHOME=/opt/pgsql export PGDATA=/opt/data6000 export PGHOST=/opt/data6000 export PATH=$PGHOME/bin:$PATH 生效环境变量 source ~/.bashrc

3.5. 修改pg_hba.conf文件

允许所有ip以用户名密码方式登录数据库

$ vi /opt/data6000/pg_hba.conf ##--文件尾追加: host all postgres 0.0.0.0/0 reject host all all 0.0.0.0/0 scram-sha-256

3.6. 启动数据库

$ pg_ctl -D /opt/data6000 start -l $PGDATA/log/startup.log
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论