博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
centos7 离线源码安装 postgresql-9.6.6
阅读量:4569 次
发布时间:2019-06-08

本文共 7735 字,大约阅读时间需要 25 分钟。

 
部署服务器时,数据库服务器是在局域网环境下,不对外公开访问,虽然能够通过ssh操作但是在安装应用软件时基本的yum安装并不能达到目的。也许可以下载rpm进行yum,但也许会死于依赖.

案例环境

  • 一台可以公网访问的阿里云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… 200 OK 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]# ls14 postgresql-9.6.6.tar.gz15 [root@iZuf------------kZ resource]# tar zxvf postgresql-9.6.6.tar.gz 16 [root@iZuf------------kZ resource]# ls17 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 postgres2 [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]# ls2 aclocal.m4  config  configure  configure.in  contrib  COPYRIGHT  doc  GNUmakefile.in  HISTORY  INSTALL  Makefile  README  src3 [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 for details on the 3 failure.  It is possible the compiler isn't looking in the 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 for details on the 9 failure.  It is possible the compiler isn't looking in the 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.s10 config.status: linking src/backend/port/dynloader/linux.c to src/backend/port/dynloader.c11 config.status: linking src/backend/port/sysv_sema.c to src/backend/port/pg_sema.c12 config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c13 config.status: linking src/backend/port/dynloader/linux.h to src/include/dynloader.h14 config.status: linking src/include/port/linux.h to src/include/pg_config_os.h15 config.status: linking src/makefiles/Makefile.linux to src/Makefile.port16 [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.in  HISTORY  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      vacuumlo10 [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/data2 [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 … ok11 creating subdirectories … ok12 selecting default max_connections … 10013 selecting default shared_buffers … 128MB14 selecting dynamic shared memory implementation … posix15 creating configuration files … ok16 running bootstrap script … ok17 performing post-bootstrap initialization … ok18 syncing data to disk … ok19 20 WARNING: enabling "trust" authentication for local connections21 You can change this by editing pg_hba.conf or using the option -A, or22 --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 start27 28 [postgres@iZuf------------kZ bin]$

 

 
  • 配置环境变量 在/etc/profile追加配置,注意注意退出postgres用户
1 [postgres@iZuf------------kZ bin]$ exit2 exit3 [root@iZuf------------kZ pgsql]# vim /etc/profile4 [root@iZuf------------kZ pgsql]# tail -n 2 /etc/profile5 #postresql-9.6.66 export PATH=$PATH:/usr/local/pgsql/bin7 [root@iZuf------------kZ pgsql]# source /etc/profile8 [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" for help. 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/postgres14 template1 | postgres | UTF8    | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +15           |          |          |            |            | postgres=CTc/postgres16 (3 rows)

 

执行psql报错,这个漏掉了配置环境变量或环境变量没有生效
1 [postgres@iZuf------------kZ bin]$ psql2 bash: psql: command not found

 

至此 postgresql安装完成。

 
 
 
 

)

转载于:https://www.cnblogs.com/wangdaozhi/p/7987848.html

你可能感兴趣的文章
多线程/多进程+QProgressBar实现进度条
查看>>
多任务(进程)案例----- 拷贝文件夹
查看>>
Kotlin的快速入门
查看>>
底层原理
查看>>
21. Merge Two Sorted Lists
查看>>
创建数组
查看>>
dict使用
查看>>
ASP.NET MVC的帮助类HtmlHelper和UrlHelper
查看>>
02_ListActive中响应事件 并LogCat输出
查看>>
doubleclick adx note
查看>>
Celery框架
查看>>
[c#]asp.net开发微信公众平台(4)关注事件、用户记录、回复文本消息
查看>>
[转载,感觉写的非常详细]DUBBO配置方式详解
查看>>
Android在Eclipse上的环境配置
查看>>
面向对象(五)
查看>>
android平台下使用点九PNG技术
查看>>
Python学习3,列表
查看>>
最长回文子串
查看>>
JAVA基础-JDBC(一)
查看>>
js中for和while运行速度比较
查看>>