centos7 离线源码安装 postgresql9.6.6

摘要:
部署服务器时,数据库服务器位于LAN环境中,没有公共访问权限。尽管可以通过ssh操作,但基本的yum安装无法实现安装应用程序软件时的目的。
部署服务器时,数据库服务器是在局域网环境下,不对外公开访问,虽然能够通过ssh操作但是在安装应用软件时基本的yum安装并不能达到目的。也许可以下载rpm进行yum,但也许会死于依赖.
案例环境
下载postgresql源码并解压
新增postgres用户及用户组
编译
安装
配置权限路径
初始化数据库
启动数据库

案例环境

  • 一台可以公网访问的阿里云ECS -- A
  • 一台无公网访问的阿里云ECS -- B

下载postgresql源码并解压

A上下载

1 [root@iZuf------------kZ resource]#wget https://ftp.postgresql.org/pub/source/v9.6.6/postgresql-9.6.6.tar.gz
2 --2017-12-05 13:24:04--  https://ftp.postgresql.org/pub/source/v9.6.6/postgresql-9.6.6.tar.gz
3 Resolving ftp.postgresql.org (ftp.postgresql.org)… 217.196.149.55, 174.143.35.246, 87.238.57.227, …
4 Connecting to ftp.postgresql.org (ftp.postgresql.org)|217.196.149.55|:443… connected.
5 HTTP request sent, awaiting response… 200OK
6 Length: 25709021 (25M) [application/x-gzip]
7 Saving to: ‘postgresql-9.6.6.tar.gz’
8 
9 100%[=============================================================================================================================================>] 25,709,021  4.31MB/s  in 6.3s  
10 
11 2017-12-05 13:24:13 (3.92 MB/s) - ‘postgresql-9.6.6.tar.gz’ saved [25709021/25709021]
12 
13 [root@iZuf------------kZ resource]#ls
14 postgresql-9.6.6.tar.gz
15 [root@iZuf------------kZ resource]#tar zxvf postgresql-9.6.6.tar.gz 
16 [root@iZuf------------kZ resource]#ls
17 postgresql-9.6.6  postgresql-9.6.6.tar.gz
  • 将下载文件发送到B上
1 [root@iZuf------------kZ resource]#scp postgresql-9.6.6.tar.gz root@ip地址:路径

新增postgres用户及用户组

1 [root@iZuf------------kZ resource]#groupadd postgres
2 [root@iZuf------------kZ resource]#useradd postgres -g postgres
一般需要环境如下,可提前准备,也可以根据编译提示信息补安装
1 [root@iZuf------------kZ postgresql-9.6.6]#yum -y install wget gcc readline-devel zlib-devel make

编译

1 [root@iZuf------------kZ postgresql-9.6.6]#ls
2 aclocal.m4  config  configure  configure.in  contrib  COPYRIGHT  doc  GNUmakefile.inHISTORY  INSTALL  Makefile  README  src
3 [root@iZuf------------kZ postgresql-9.6.6]#./configure --prefix=/usr/local/pgsql
如果出现编译错误则需关注报错信息 ,如下 缺少 readline-devel  zlib
1 configure: error: readline library not found
2 If you have readline already installed, see config.log fordetails on the
3 failure.  It is possible the compiler isn't looking inthe proper directory.
4 Use --without-readline to disable readline support.
5 [root@iZuf------------kZ postgresql-9.6.6]# 
6 7 configure: error: zlib library not found
8 If you have zlib already installed, see config.log fordetails on the
9 failure.  It is possible the compiler isn't looking inthe proper directory.
10 Use --without-zlib to disable zlib support.
11 [root@iZuf------------kZ postgresql-9.6.6]# 
12 [root@iZuf------------kZ postgresql-9.6.6]#yum -y install gcc gcc-c++ readline-devel zlib-devel make

如下提示为本次编译成功

1 configure: using CPPFLAGS= -D_GNU_SOURCE 
2 configure: using LDFLAGS=  -Wl,--as-needed
3 configure: creating ./config.status
4 config.status: creating GNUmakefile
5 config.status: creating src/Makefile.global
6 config.status: creating src/include/pg_config.h
7 config.status: creating src/include/pg_config_ext.h
8 config.status: creating src/interfaces/ecpg/include/ecpg_config.h
9 config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s
10 config.status: linking src/backend/port/dynloader/linux.c to src/backend/port/dynloader.c
11 config.status: linking src/backend/port/sysv_sema.c to src/backend/port/pg_sema.c
12 config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
13 config.status: linking src/backend/port/dynloader/linux.h to src/include/dynloader.h
14 config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
15 config.status: linking src/makefiles/Makefile.linux to src/Makefile.port
16 [root@iZuf------------kZ postgresql-9.6.6]#ls

安装

  • make && make install
[root@iZuf------------kZ postgresql-9.6.6]# make && make install

最终提示PostgreSQL installation complete.表示安装成功

  • 扩展安装 contrib make && make install
1 [root@iZuf------------kZ postgresql-9.6.6]#ls
2 aclocal.m4  config  config.log  config.status  configure  configure.in  contrib  COPYRIGHT  doc  GNUmakefile  GNUmakefile.inHISTORY  INSTALL  Makefile  README  src
3 [root@iZuf------------kZ postgresql-9.6.6]#cd contrib/
4 [root@iZuf------------kZ contrib]#ls
5 adminpack    btree_gist        dblink        fuzzystrmatch    intarray        Makefile        pgcrypto        pg_stat_statements  README  start-scripts  tsm_system_rows  xml2
6 auth_delay    chkpass            dict_int      hstore          isn            oid2name        pg_freespacemap  pgstattuple        seg      tablefunc      tsm_system_time
7 auto_explain  citext            dict_xsyn      hstore_plperl    lo              pageinspect    pg_prewarm      pg_trgm            sepgsql  tcn            unaccent
8 bloom        contrib-global.mk  earthdistance  hstore_plpython  ltree          passwordcheck  pgrowlocks      pg_visibility      spi      test_decoding  uuid-ossp
9 btree_gin    cube              file_fdw      intagg          ltree_plpython  pg_buffercache  pg_standby      postgres_fdw        sslinfo  tsearch2      vacuumlo
10 [root@iZuf------------kZ contrib]#make && make install

配置权限路径

  • 数据库路径
1 [root@iZuf------------kZ ~]#chown -R postgres:postgres /usr/local/psql
  • 数据data目录
1 [root@iZuf------------kZ ~]#mkdir -p /usr/local/psql/data
2 [root@iZuf------------kZ ~]#chown postgres:postgres /usr/local/psql/data

初始化数据库

  • initdb
1 [postgres@iZuf------------kZ bin]$ ./initdb --encoding=UTF-8 -D /usr/local/pgsql/data/
2 The files belonging to this database system will be owned by user "postgres".
3 This user must also own the server process.
4 
5 The database cluster will be initialized with locale "en_US.UTF-8".
6 The default text search configuration will be set to "english".
7 
8 Data page checksums are disabled.
9 
10 fixing permissions on existing directory /usr/local/pgsql/data … ok
11 creating subdirectories … ok
12 selecting default max_connections … 100
13 selecting defaultshared_buffers … 128MB
14 selecting dynamic shared memory implementation … posix
15 creating configuration files … ok
16 running bootstrap script … ok
17 performing post-bootstrap initialization … ok
18 syncing data to disk … ok
19 
20 WARNING: enabling "trust" authentication forlocal connections
21 You can change this by editing pg_hba.conf or using the option -A, or
22 --auth-local and --auth-host, the next time you run initdb.
23 
24 Success. You can now start the database server using:
25 
26     ./pg_ctl -D /usr/local/pgsql/data/ -l logfile start
27 
28 [postgres@iZuf------------kZ bin]$ 
  • 配置环境变量 在/etc/profile追加配置,注意注意退出postgres用户
1 [postgres@iZuf------------kZ bin]$exit
2 exit
3 [root@iZuf------------kZ pgsql]#vim /etc/profile
4 [root@iZuf------------kZ pgsql]#tail -n 2 /etc/profile
5 #postresql-9.6.6
6 export PATH=$PATH:/usr/local/pgsql/bin
7 [root@iZuf------------kZ pgsql]#source /etc/profile
8 [root@iZuf------------kZ pgsql]# 

启动数据库

1 [postgres@iZuf------------kZ bin]$ ./pg_ctl -D /usr/local/pgsql/data/ -l logfile start
2 server starting
3 [postgres@iZuf------------kZ bin]$psql
4 psql (9.6.6)
5 Type "help" forhelp.
6 
7 postgres=#\l
8 List of databases
9   Name    |  Owner  | Encoding |  Collate  |    Ctype    |Access privileges  
10 -----------+----------+----------+-------------+-------------+-----------------------
11 postgres  | postgres | UTF8    | en_US.UTF-8 | en_US.UTF-8 | 
12 template0 | postgres | UTF8    | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
13           |          |          |            |            | postgres=CTc/postgres
14 template1 | postgres | UTF8    | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
15           |          |          |            |            | postgres=CTc/postgres
16 (3 rows)
执行psql报错,这个漏掉了配置环境变量或环境变量没有生效
1 [postgres@iZuf------------kZ bin]$psql
2 bash: psql: command not found

至此 postgresql安装完成。

来自为知笔记(Wiz)

免责声明:文章转载自《centos7 离线源码安装 postgresql9.6.6》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Infiniband 网络性能测试Cesium项目实战(5)-城市各类POI数据制作、加工、展示下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

详解SpringBoot应用跨域访问解决方案

一、什么是跨域访问 说到跨域访问,必须先解释一个名词:同源策略。所谓同源策略就是在浏览器端出于安全考量,向服务端发起请求必须满足:协议相同、Host(ip)相同、端口相同的条件,否则访问将被禁止,该访问也就被称为跨域访问。虽然跨域访问被禁止之后,可以在一定程度上提高了应用的安全性,但也为开发带来了一定的麻烦。比如:我们开发一个前后端分离的易用,页面及js部...

web.config中httpRunTime的属性

配置httpRuntime也可以让FileUpload上传更大的文件,不过设置太大了会因用户将大量文件传递到该服务器而导致的拒绝服务攻击(属性有说明) <httpRuntime> <httpRuntime useFullyQualifiedRedirectUrl="true|false"              maxRequestLe...

【转】 Linux内核升级指南

【转】 Linux内核升级指南 转自:http://blog.csdn.net/xyang81/article/details/7522032 一、升级背景 前 段时间公司有个项目用到了短信收发的业务,采购了两台16口的Wavecom USB短信猫设备,服务器操作系统是ReadHat5.4,内核2.6.18,插上设备后,操作系统无法自动识别该设备,原因是没...

Redis布隆过滤器

一、布隆过滤器使用场景 比如有如下几个需求: ①、原本有10亿个号码,现在又来了10万个号码,要快速准确判断这10万个号码是否在10亿个号码库中? 解决办法一:将10亿个号码存入数据库中,进行数据库查询,准确性有了,但是速度会比较慢。 解决办法二:将10亿号码放入内存中,比如Redis缓存中,这里我们算一下占用内存大小:10亿*8字节=8GB,通过内存查询...

HPE 交换机基础配置

1、交换机命名(config)# hostname POE-SW2、vlan创建及端口划分1)端口加入vlan,两种方式(config)# vlan 2(vlan-2)# untagged ethernet 1,3,5-10 /把这些端口加入vlan 2(config)# vlan 3 untagged Ethernet 1,3,5-10 /另外一种端口加...

《Python》hashlib模块、configparser模块、logging模块

一、hashlib模块     Python的hashlib模块中提供了常见的摘要算法,如md5,sha1等等。     摘要算法又称哈希算法、散列算法。它通过一个函数,把任意长度的数据转换为一个长度固定的字符串(通常用16进制的字符串表示)。     不同的字符串通过这个算法计算出的密文总是不同的,相同的算法,相同的字符串,获得的结果总是相同的(不同的语...