CentOS7.4系统下Postgres12版本数据库编译安装分享

操作系统:CentOS7.4
编译安装的步骤主要分三部分:

  • 安装依赖包
  • 编译安装
  • 设置环境变量设置

- 安装依赖包

rpm -ivh perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake --nodeps --force

- 安装postgres

tar -zxf postgresql-12.3.tar.gz
cd postgresql-12.3
 ./configure --prefix=/data/postgresql >> ${dir}/install.log
make && make install  >> ${dir}/install.log
chown postgres.postgres /data/ -R

- 设置环境变量

vim /home/postgres/.bash_profile
export PG_HOME=/data/postgres/
export PATH=$PG_PATH:$PG_HOME/bin:$PG_HOME/bin
export PG_PORT=5432

-启动数据库

#初始化数据库
[postgres@docker-master-79100 ~]$ initdb -D /data/postgresql/data
#启动数据库 
[postgres@docker-master-79100 ~]$ pg_ctl -D /data/postgresql/data start
pg_ctl: another server might be running; trying to start server anyway
waiting for server to start....2020-08-02 01:05:11.011 CST [2653] LOG:  starting PostgreSQL 12.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16), 64-bit
2020-08-02 01:05:11.012 CST [2653] LOG:  listening on IPv6 address "::1", port 5432
2020-08-02 01:05:11.012 CST [2653] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2020-08-02 01:05:11.015 CST [2653] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2020-08-02 01:05:11.041 CST [2654] LOG:  database system was interrupted; last known up at 2020-08-01 23:35:12 CST
2020-08-02 01:05:11.049 CST [2654] LOG:  database system was not properly shut down; automatic recovery in progress
2020-08-02 01:05:11.051 CST [2654] LOG:  redo starts at 0/163AEE8
2020-08-02 01:05:11.051 CST [2654] LOG:  invalid record length at 0/163AFD0: wanted 24, got 0
2020-08-02 01:05:11.051 CST [2654] LOG:  redo done at 0/163AF98
2020-08-02 01:05:11.069 CST [2653] LOG:  database system is ready to accept connections
 done
server started
[postgres@docker-master-79100 ~]$ pg_ctl -D /data/postgresql/data status
pg_ctl: server is running (PID: 2653)
/home/postgres/bin/postgres "-D" "/data/postgresql/data"

为了方便使用,将12版本的数据库安装包打了一个一键化安装的tar包

已将一键化安装包上传至下载论坛:

CentOS7.4系统下一键安装postgresql-12.3版本数据库

安装时注意:
1、输入目录最后不用加 / (斜杠)
2、第一个数据入的是安装目录(home)
3、第二个数据入的是数据存放目录(data)

一键安装展示:

[root@docker-slave-79101 ~]# fdisk -l

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d02a2

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048   209715199   104344576   8e  Linux LVM

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-root: 104.7 GB, 104698216448 bytes, 204488704 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@docker-slave-79101 ~]# mkfs.ext
mkfs.ext2  mkfs.ext3  mkfs.ext4  
[root@docker-slave-79101 ~]# mkfs.ext4 /dev/sdb 
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2153775104
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

[root@docker-slave-79101 ~]# mkdir /PG/12
mkdir: cannot create directory ‘/PG/12’: No such file or directory
[root@docker-slave-79101 ~]# mkdir /PG/12 -p
[root@docker-slave-79101 ~]# ll
total 48820
-rw-------. 1 root root     1831 Jul 16 16:54 anaconda-ks.cfg
-rw-r--r--. 1 root root   650922 Aug  1 07:19 openjdk-14.0.2_linux-x64_bin.tar.gz
-rw-r--r--. 1 root root 49334565 Aug  2 06:37 Postgres-12.3v.tar.gz
[root@docker-slave-79101 ~]# blkid 
/dev/sda1: UUID="0ee2726f-ccdb-4b0b-912c-d9ed82296330" TYPE="ext4" 
/dev/sda2: UUID="X7flOH-knTA-lGf4-rek7-SZo9-GtS5-9jAGsy" TYPE="LVM2_member" 
/dev/sdb: UUID="5f31e110-f3c2-42ca-84cf-82619d0788eb" TYPE="ext4" 
/dev/mapper/centos-root: UUID="05eda9d9-d1c8-45bf-99e9-750b099ae98f" TYPE="xfs" 
/dev/mapper/centos-swap: UUID="e36a8cde-a21b-43bf-bb29-7b12b5fcc7e6" TYPE="swap" 
[root@docker-slave-79101 ~]# clear
[root@docker-slave-79101 ~]# 
[root@docker-slave-79101 ~]# 
[root@docker-slave-79101 ~]# mkdir /PG/12 -p
[root@docker-slave-79101 ~]# mkfs.ext4 /dev/sdb 
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2153775104
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

[root@docker-slave-79101 ~]# mount /dev/sdb /PG/12/
[root@docker-slave-79101 ~]# umount -l /PG/12/
[root@docker-slave-79101 ~]# mount /dev/sdb /PG/12/
[root@docker-slave-79101 ~]# 
[root@docker-slave-79101 ~]# 
[root@docker-slave-79101 ~]# rz
-bash: rz: command not found
[root@docker-slave-79101 ~]# yum install lrz* -y
Loaded plugins: fastestmirror, langpacks
base                                                                                                                                                                    | 3.6 kB  00:00:00     
centos-ansible-27                                                                                                                                                       | 3.0 kB  00:00:00     
centos-ansible-28                                                                                                                                                       | 3.0 kB  00:00:00     
centos-ansible-29                                                                                                                                                       | 3.0 kB  00:00:00     
centos-ansible26                                                                                                                                                        | 2.9 kB  00:00:00     
extras                                                                                                                                                                  | 2.9 kB  00:00:00     
updates                                                                                                                                                                 | 2.9 kB  00:00:00     
(1/2): centos-ansible-29/7/x86_64/primary_db                                                                                                                            |  16 kB  00:00:00     
(2/2): updates/7/x86_64/primary_db                                                                                                                                      | 3.7 MB  00:00:03     
Determining fastest mirrors
 * base: mirrors.cn99.com
 * centos-ansible-27: mirrors.163.com
 * centos-ansible-28: mirrors.163.com
 * centos-ansible-29: mirrors.163.com
 * centos-ansible26: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package lrzsz.x86_64 0:0.12.20-36.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================
 Package                                    Arch                                        Version                                                Repository                                 Size
===============================================================================================================================================================================================
Installing:
 lrzsz                                      x86_64                                      0.12.20-36.el7                                         base                                       78 k

Transaction Summary
===============================================================================================================================================================================================
Install  1 Package

Total download size: 78 k
Installed size: 181 k
Downloading packages:
lrzsz-0.12.20-36.el7.x86_64.rpm                                                                                                                                         |  78 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : lrzsz-0.12.20-36.el7.x86_64                                                                                                                                                 1/1 
  Verifying  : lrzsz-0.12.20-36.el7.x86_64                                                                                                                                                 1/1 

Installed:
  lrzsz.x86_64 0:0.12.20-36.el7                                                                                                                                                                

Complete!
[root@docker-slave-79101 ~]# rz

[root@docker-slave-79101 ~]# rz                                                                                                                                  [root@docker-slave-79101 ~]# 
[root@docker-slave-79101 ~]# 
[root@docker-slave-79101 ~]# tar -zxvf Postgres-12.3
Postgres-12.3-v1-20200802.tar.gz  Postgres-12.3v.tar.gz             
[root@docker-slave-79101 ~]# tar -zxvf Postgres-12.3-v1-20200802.tar.gz 
Postgres-12.3-v1-20200802/
Postgres-12.3-v1-20200802/postgres_rpm/
Postgres-12.3-v1-20200802/postgres_rpm/cmake-2.8.12.2-2.el7.x86_64.rpm
Postgres-12.3-v1-20200802/postgres_rpm/gcc-c++-4.8.5-39.el7.x86_64.rpm
Postgres-12.3-v1-20200802/postgres_rpm/libxml2-devel-2.9.1-6.el7.4.i686.rpm
Postgres-12.3-v1-20200802/postgres_rpm/libxml2-devel-2.9.1-6.el7.4.x86_64.rpm
Postgres-12.3-v1-20200802/postgres_rpm/libxslt-devel-1.1.28-5.el7.i686.rpm
Postgres-12.3-v1-20200802/postgres_rpm/libxslt-devel-1.1.28-5.el7.x86_64.rpm
Postgres-12.3-v1-20200802/postgres_rpm/openldap-devel-2.4.44-21.el7_6.i686.rpm
Postgres-12.3-v1-20200802/postgres_rpm/openldap-devel-2.4.44-21.el7_6.x86_64.rpm
Postgres-12.3-v1-20200802/postgres_rpm/openssl-devel-1.0.2k-19.el7.i686.rpm
Postgres-12.3-v1-20200802/postgres_rpm/openssl-devel-1.0.2k-19.el7.x86_64.rpm
Postgres-12.3-v1-20200802/postgres_rpm/pam-devel-1.1.8-23.el7.i686.rpm
Postgres-12.3-v1-20200802/postgres_rpm/pam-devel-1.1.8-23.el7.x86_64.rpm
Postgres-12.3-v1-20200802/postgres_rpm/perl-ExtUtils-Embed-1.30-295.el7.noarch.rpm
Postgres-12.3-v1-20200802/postgres_rpm/python-devel-2.7.5-88.el7.x86_64.rpm
Postgres-12.3-v1-20200802/postgres_rpm/zlib-devel-1.2.7-18.el7.i686.rpm
Postgres-12.3-v1-20200802/postgres_rpm/readline-devel-6.2-11.el7.x86_64.rpm
Postgres-12.3-v1-20200802/postgres_rpm/readline-devel-6.2-11.el7.i686.rpm
Postgres-12.3-v1-20200802/postgres_rpm/zlib-devel-1.2.7-18.el7.x86_64.rpm
Postgres-12.3-v1-20200802/postgresql-12.3.tar.gz
Postgres-12.3-v1-20200802/test.sh
Postgres-12.3-v1-20200802/readme.txt
Postgres-12.3-v1-20200802/setenv
Postgres-12.3-v1-20200802/install.sh
[root@docker-slave-79101 ~]# cd Postgres-12.3-v1-20200802/
[root@docker-slave-79101 Postgres-12.3-v1-20200802]# cat readme.txt 
#postgresql的版本
version=12.3
安装:
tar -zxvf Postgres-12.3v-20200801.tar.gz
cd Postgres-12.3v-20200801
sh install.sh
#根据提示输入安装目录
初始化数据库:
su - postgres -c "initdb -D /data/pgsql/data "
启动(加入/etc/rc.local下实现开机启动)su - postgres -c "pg_ctl -D /data/pgsql/data start"
停止数据库
su - postgres -c "pg_ctl -D /data/pgsql/data stop"
查看数据库是否运行
su - postgres -c "pg_ctl -D /data/pgsql/data status"

#该安装没有进行数据库的优化,要根据个人需求进行优化
[root@docker-slave-79101 Postgres-12.3-v1-20200802]# sh install.sh 
输入安装目录:
        eg: /opt/postgres
        /opt/postgres
/opt/postgres
输入安装目录:
        eg: /data/12
        /PG/12
/PG/12
postgres 用户不存在,现在增加
 现在安装以下依赖包 
cmake-2.8.12.2-2.el7.x86_64.rpm		libxslt-devel-1.1.28-5.el7.x86_64.rpm	   pam-devel-1.1.8-23.el7.i686.rpm		readline-devel-6.2-11.el7.x86_64.rpm
gcc-c++-4.8.5-39.el7.x86_64.rpm		openldap-devel-2.4.44-21.el7_6.i686.rpm    pam-devel-1.1.8-23.el7.x86_64.rpm		zlib-devel-1.2.7-18.el7.i686.rpm
libxml2-devel-2.9.1-6.el7.4.i686.rpm	openldap-devel-2.4.44-21.el7_6.x86_64.rpm  perl-ExtUtils-Embed-1.30-295.el7.noarch.rpm	zlib-devel-1.2.7-18.el7.x86_64.rpm
libxml2-devel-2.9.1-6.el7.4.x86_64.rpm	openssl-devel-1.0.2k-19.el7.i686.rpm	   python-devel-2.7.5-88.el7.x86_64.rpm
libxslt-devel-1.1.28-5.el7.i686.rpm	openssl-devel-1.0.2k-19.el7.x86_64.rpm	   readline-devel-6.2-11.el7.i686.rpm
 依赖包安装完成 !!! 
设置环境变量完成
# .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

#export #PATH
export PG_HOME=/opt/postgres
export PG_DATA=/PG/12
export PATH=$PATH:$PG_HOME/bin:$PG_HOME/bin
export PG_PORT=5432
======================开始安装数据库================================ 

安装成功提示:
在这里插入图片描述

附录几个问题解决截图:
1.编码格式是英文
export LANG=“en_US.UTF-8”编码是英文

2.数据库没启动
在这里插入图片描述

postgresql数据安装分享到这里,后续继续更新,欢迎转载和交流~~

©️2020 CSDN 皮肤主题: 黑客帝国 设计师:上身试试 返回首页