centos7 安装 postgres11

本文详细介绍了如何在CentOS7系统中安装PostgreSQL 11数据库,包括创建目录、下载源码、编译安装、初始化数据库、配置参数及启动服务等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

centos7 安装 postgres11

--创建安装目录

[root@localhost ~]# mkdir /dbgroup/pg11

[root@localhost ~]# chown -R postgres.postgres /dbgroup/pg11

--数据目录

mkdir /dbgroup/pg11/data

chown -R postgres.postgres /dbgroup/pg11/data

下载

wget https://ftp.postgresql.org/pub/snapshot/dev/postgresql-snapshot.tar.bz2  

解压

tar -jxvf postgresql-snapshot.tar.bz2   

cd postgresql-11devel  

vim ~/enpg11.sh

export PGHOME=/dbgroup/pg11

export PGPORT=6433

export PGDATA=/dbgroup/pg11/data

export LANG=en_US.UTF8

export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH

export DATE=`date +"%Y%m%d%H%M"`

export PATH=$PGHOME/bin:$PATH:.

export MANPATH=$PGHOME/share/man:$MANPATH

export PGUSER=postgres

export PGHOST='127.0.0.1'

export PGDATABASE='postgres'

alias rm='rm -i'

alias ll='ll -lh'

chmod +x ~/enpg11.sh

编译安装

./configure --prefix=/dbgroup/pg11 --with-pgport=6433 --with-perl  --with-python --with-openssl --with-pam --without-ldap --with-libxml --with-libxslt

安装 所有的插件

gmake world -j 32 && gmake install-world 

初始化

[postgres@localhost postgresql-11devel]$ initdb -D $PGDATA -E UTF8 --locale=C -U postgres -W

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 "C".

The default text search configuration will be set to "english".

Data page checksums are disabled.

Enter new superuser password: 

Enter it again: 

fixing permissions on existing directory /dbgroup/pg11/data ... ok

creating subdirectories ... ok

selecting default max_connections ... 100

selecting default shared_buffers ... 128MB

selecting dynamic shared memory implementation ... posix

creating configuration files ... ok

running bootstrap script ... ok

performing post-bootstrap initialization ... ok

syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections

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 /dbgroup/pg11/data -l logfile start

更改配置

cd $PGDATA

vim postgresql.conf 

监听IPV4的所有IP

listen_addresses='0.0.0.0'  

vim pg_hba.conf 

host    all             all             127.0.0.1/32            trust

host    all             all             0.0.0.0/0               md5 

[postgres@localhost data]$ pg_ctl -D $PGDATA -l logfile start

waiting for server to start.... done

server started

[postgres@localhost data]$ psql -h 127.0.0.1

psql (11devel)

Type "help" for help.

postgres=# select version();

                                                  version                                                   

------------------------------------------------------------------------------------------------------------

 PostgreSQL 11devel on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16), 64-bit

CentOS 7上使用yum安装PostgreSQL 12的步骤如下: 1. **导入PostgreSQL 12的仓库签名**: 首先,导入PostgreSQL的仓库签名,以确保软件包的安全性。 ```bash sudo rpm --import https://www.postgresql.org/media/keys/ACCC4CF8.asc ``` 2. **创建Yum仓库文件**: 创建一个新的Yum仓库文件,以便Yum可以找到PostgreSQL 12的软件包。 ```bash sudo vi /etc/yum.repos.d/pgdg.repo ``` 在文件中添加以下内容: ```ini [pgdg12] name=PostgreSQL 12 for RHEL/CentOS 7 - x86_64 baseurl=https://download.postgresql.org/pub/repos/yum/12/redhat/rhel-7-x86_64 enabled=1 gpgcheck=1 gpgkey=https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG ``` 3. **安装PostgreSQL 12**: 使用Yum安装PostgreSQL 12服务器和客户端。 ```bash sudo yum install postgresql12 postgresql12-server ``` 4. **初始化数据库**: 初始化数据库并启动PostgreSQL服务。 ```bash sudo /usr/pgsql-12 sudo systemctl start postgresql-12 ``` 5. **验证安装**: 验证PostgreSQL 12是否安装成功并正在运行。 ```bash sudo systemctl status postgresql-12 ``` 6. **配置防火墙**: 如果需要远程访问PostgreSQL,配置防火墙以允许访问端口5432。 ```bash sudo firewall-cmd --permanent --add-port=5432/tcp sudo firewall-cmd --reload ``` 通过以上步骤,你应该能够在CentOS 7上成功使用yum安装PostgreSQL 12。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值