1 准备环境

修改yum源

mkdir -p /etc/yum.bak
mv /etc/yum.repos.d/* /etc/yum.bak/ &&\
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo &&\
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo &&\
yum clean all &&\
yum makecache

安装基础安装包
yum install -y readline-devel zlib-devel make gcc

创建组和用户

groupadd postgres
useradd -g postgres -G postgres -d /home/postgresql postgres

将安装包放在/opt 路径中并解压
tar xf /opt/postgresql-12.0.tar.gz -C /home/postgresql/postgresql-12.0

2 编译安装

编译

cd /home/postgresql/postgresql-12.0
./configure --prefix=/usr/share/postgresql-12
make && make install

配置环境变量

echo 'export PGHOME=/usr/share/postgresql-12/
export PGDATA=/data/pgsql-12
export PATH=$PGHOME/bin:$PATH
export LANG=en_US.utf8
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH'>>/etc/profile
source /etc/profile

3 初始化数据

创建数据目录并授权

mkdir -p /data/pgsql-12
chown -R postgres:postgres /data/pgsql-12
chown -R postgres:postgres /usr/share/postgresql-12

初始化

su - postgres
initdb -E utf8 -D $PGDATA

4 配置数据库

切换到root下操作

配置连接方式

echo -e "listen_addresses = '*'\nmax_connections = 100">>/data/pgsql-12/postgresql.conf

配置连接网段
echo 'host all all 0.0.0.0 md5'>>/data/pgsql-12/pg_hba.conf

pg配置文件认证方法

认证方法(authentication method)
trust 无条件地允许联接,这个方法允许任何可以与PostgreSQL 数据库联接的用户以他们期望的任意 PostgreSQL 数据库用户身份进行联接,而不需要口令。
reject 联接无条件拒绝,常用于从一个组中"过滤"某些主机。
md5 要求客户端提供一个 MD5 加密的口令进行认证,这个方法是允许加密口令存储在pg_shadow里的唯一的一个方法。
password 和"md5"一样,但是口令是以明文形式在网络上传递的,我们不应该在不安全的网络上使用这个方式。
gss 使用GSSAPI认证用户,这只适用于 TCP/IP 连接。
sspi 使用SSPI认证用户,这只适用于 Windows 连接。
peer 获取客户端的操作系统的用户名并判断他是否匹配请求的数据库名,这只适用于本地连接。
ldap 使用LDAP服务进行验证。
radius 使用RADIUS服务进行验证。
cert 使用SSL服务进行验证。
pam 使用操作系统提供的可插入的认证模块服务 (Pluggable Authentication Modules)(PAM)来认证。

修改配置启动脚本

启动pg_ctl -D /data/pgsql-12/ -l logfile start
cp /home/postgresql/postgresql-12.0/contrib/start-scripts/linux /etc/init.d/postgresql-12
chmod 777 /etc/init.d/postgresql-12
sed -i '/prefix=/s#prefix=.*#prefix=/usr/share/postgresql-12#' /etc/init.d/postgresql-12
sed -i 's#PGDATA=.*#PGDATA=/data/pgsql-12#' /etc/init.d/postgresql-12

设置开机自启动

chmod 777 /etc/rc.d/rc/local
echo '/etc/init.d/postgresql-12 stop
/etc/init.d/postgresql-12 start'>>/etc/rc.d/rc/local

启动检查

/etc/init.d/postgresql-12 start
ps -ef|grep post

修改密码
alter user postgres with password '123456';

5 编译可选参数

[root@ab416a5bed3f postgresql-10.0]# ./configure --help
`configure' configures PostgreSQL 10.0 to adapt to many kinds of systems. Usage: ./configure [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print `checking ...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or `..'] Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local/pgsql]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX] By default, `make install` will install all the files in
/usr/local/pgsql/bin, /usr/local/pgsql/lib' etc. You can specify
an installation prefix other than `/usr/local/pgsql' using --prefix',
for instance `--prefix=$HOME'. For better control, use the options below. Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc/postgresql]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR] System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD] Optional Features:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--disable-integer-datetimes
obsolete option, no longer supported
--enable-nls[=LANGUAGES]
enable Native Language Support
--disable-rpath do not embed shared library search path in
executables
--disable-spinlocks do not use spinlocks
--disable-atomics do not use atomic operations
--disable-strong-random do not use a strong random number source
--enable-debug build with debugging symbols (-g)
--enable-profiling build with profiling enabled
--enable-coverage build with coverage testing instrumentation
--enable-dtrace build with DTrace support
--enable-tap-tests enable TAP tests (requires Perl and IPC::Run)
--enable-depend turn on automatic dependency tracking
--enable-cassert enable assertion checks (for debugging)
--disable-thread-safety disable thread-safety in client libraries
--disable-largefile omit support for large files
--disable-float4-byval disable float4 passed by value
--disable-float8-byval disable float8 passed by value Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-extra-version=STRING
append STRING to version
--with-template=NAME override operating system template
--with-includes=DIRS look for additional header files in DIRS
--with-libraries=DIRS look for additional libraries in DIRS
--with-libs=DIRS alternative spelling of --with-libraries
--with-pgport=PORTNUM set default port number [5432]
--with-blocksize=BLOCKSIZE
set table block size in kB [8]
--with-segsize=SEGSIZE set table segment size in GB [1]
--with-wal-blocksize=BLOCKSIZE
set WAL block size in kB [8]
--with-wal-segsize=SEGSIZE
set WAL segment size in MB [16]
--with-CC=CMD set compiler (deprecated)
--with-icu build with ICU support
--with-tcl build Tcl modules (PL/Tcl)
--with-tclconfig=DIR tclConfig.sh is in DIR
--with-perl build Perl modules (PL/Perl)
--with-python build Python modules (PL/Python)
--with-gssapi build with GSSAPI support
--with-krb-srvnam=NAME default service principal name in Kerberos (GSSAPI)
[postgres]
--with-pam build with PAM support
--with-bsd-auth build with BSD Authentication support
--with-ldap build with LDAP support
--with-bonjour build with Bonjour support
--with-openssl build with OpenSSL support
--with-selinux build with SELinux support
--with-systemd build with systemd support
--without-readline do not use GNU Readline nor BSD Libedit for editing
--with-libedit-preferred
prefer BSD Libedit over GNU Readline
--with-uuid=LIB build contrib/uuid-ossp using LIB (bsd,e2fs,ossp)
--with-ossp-uuid obsolete spelling of --with-uuid=ossp
--with-libxml build with XML support
--with-libxslt use XSLT support when building contrib/xml2
--with-system-tzdata=DIR
use system time zone data in DIR
--without-zlib do not use Zlib
--with-gnu-ld assume the C compiler uses GNU ld [default=no] Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
LIBS libraries to pass to the linker, e.g. -l<library>
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
CPP C preprocessor
PKG_CONFIG path to pkg-config utility
PKG_CONFIG_PATH
directories to add to pkg-config's search path
PKG_CONFIG_LIBDIR
path overriding pkg-config's built-in search path
ICU_CFLAGS C compiler flags for ICU, overriding pkg-config
ICU_LIBS linker flags for ICU, overriding pkg-config
LDFLAGS_EX extra linker flags for linking executables only
LDFLAGS_SL extra linker flags for linking shared libraries only Use these variables to override the choices made by ’configure or to help
it to find libraries and programs with nonstandard names/locations. Report bugs to <pgsql-bugs@postgresql.org>.

6报错解决

6.1 configure: error: readline library not found

缺少readline-devel包

解决:
方法1 安装readline-devel包
yum install readline-devel -y
方法2 编译时加上--without-readline关闭该选项

6.2 解决外网无法访问

修改data目录下的pg_hba.conf,添加如下配置

host    all             all             0.0.0.0/0              trust

6.3 修改登陆密码

用客户端软件在空密码的情况下登陆后执行

ALTER USER postgres WITH PASSWORD 'new pwd';

并修改6.2的trust为md5开启认证模式

转自:https://www.cnblogs.com/wzstudy/p/11793814.html

postgresql-12编译安装的更多相关文章

  1. rehat7.X下postgresql 11编译安装

    文档目录结构: 一.准备 操作系统版本:rehat7.6 Postgresql:11.2 软件安装目录:/pgsql11/basedir 数据文件存放目录:/pgsql11data/ 11.2的下载地 ...

  2. PostgreSQL 12 YUM安装

    目录 1.创建postgres用户 2.查看操作系统版本 3.配置yum源(对应CentOS 6) 4.安装客户端包 5.安装服务器端包 6.初始化数据库和设置自启动服务 7.postgres用户的b ...

  3. PostgreSQL(一) 编译安装运行

    原创,如转发需注明出处. 多年没写博客,一直用的个人笔记软件,最近准备阅读PostgreSQL源码,故记录.(这两年PostgreSQL数据库在某些环境下是比较火的,原因想必大家都清楚.) Postg ...

  4. Ubuntu 12 编译安装 PHP 5.4 及 问题汇总

    参考先前的文章:Ubuntu 14 编译安装 PHP 5.4.45 + Nginx 1.4.7 + MySQL 5.6.26 笔记 安装过程: ############################ ...

  5. postgresql编译安装与调试(二)

    接前文postgresql编译安装与调试(一),继续说说postgresql的编译安装与调试. 上一篇已经详细说明了如何在Linux系统上编译安装postgresql,这次我们在此基础上简单讲讲如何在 ...

  6. Ubuntu下编译安装postgreSQL 10.5

    Ubuntu下编译安装postgreSQL 10.5 ubuntu 16.04 LTS系统postgreSQL 10.5 安装包准备 1.从PostgreSQL官网下载PostgreSQL的安装包 安 ...

  7. Linux环境PostgreSQL源码编译安装

    Linux环境PostgreSQL源码编译安装 Linux版本: Red Hat 6.4 PostgreSQL版本: postgresql-9.3.2.tar.gz 数据存放目录: /var/post ...

  8. CentOS7 源码安装 PostgreSQL 12

    PostgreSQL 12 源码安装 Table of Contents 1. 下载 2. 准备环境 3. 编译安装 4. 设置环境变量 5. 初始化数据库 6. 配置参数文件 6.1. postgr ...

  9. 对<< ubuntu 12.04编译安装linux-3.6.10内核笔记>>的修正

    前题: 在前几个月的时候,写了一篇笔记,说的是kernel compile的事情,当时经验不足,虽说编译过了,但有些地方写的有错误--因为当时的理解是有错误的.今天一一更正,记录如下: 前文笔记链接: ...

  10. 编译安装 Nginx1.12.1

    本文描述Nginx 的源码编译安装过程 ############## 一.安装OpenSSL ###################### 下载地址 https://www.openssl.org/s ...

随机推荐

  1. 面试 HTTP和HTML 浏览器

    HTTP和HTML 浏览器 #说一下http和https #参考回答: https的SSL加密是在传输层实现的. (1)http和https的基本概念 http: 超文本传输协议,是互联网上应用最为广 ...

  2. MySQL(二):快速理解MySQL数据库索引

    索引 基本概念:索引是在存储引擎层实现的,而不是在服务器层实现的,所以不同存储引擎具有不同的索引类型和实现. 数据结构 Tree 指的是 Balance Tree,也就是平衡树.平衡树是一颗查找树,并 ...

  3. vulstudy靶机搭建(kali)

    安装 安装docker apt-get install docker.io //# 安装docker pip install docker-compose //# 安装docker-compose g ...

  4. SpringBoot2 整合OAuth2组件,模拟第三方授权访问

    本文源码:GitHub·点这里 || GitEE·点这里 一.模式描述 授权服务 验证第三方服务的身份,验证邮箱用户的身份,记录和管理认证Token,为资源服务器提供Token校验.场景:第三方网站借 ...

  5. Erlang那些事儿第2回之我是模块(module),一文件一模块

    前几篇文章会写得比较基础,但是既然要写一系列的文章,还是得从基础开始写.我刚学Erlang碰到最大的问题是,想网上搜索下语法,结果却是寥寥无几,而且介绍得不是很系统,对我了解一些细节是有影响的,正好我 ...

  6. Python爬取热搜存入数据库并且还能定时发送邮件!!!

    一.前言 微博热搜榜每天都会更新一些新鲜事,但是自己处于各种原因,肯定不能时刻关注着微博,为了与时代接轨,接受最新资讯,就寻思着用Python写个定时爬取微博热搜的并且发送QQ邮件的程序,这样每天可以 ...

  7. C# 生成6位短信验证码

    1 private string VerifyCode() 2 { 3 Random random = new Random(); 4 return random.Next(100000, 99999 ...

  8. H3C路由器配置——静态路由

    一.网络畅通条件及排错思路 1.网络畅通的条件 网络畅通的条件:数据包能去能回,也是我们排除网络故障的理论依据. 2.网络不畅通示列 ①.目标主机不可达 原因分析:可能是数据包没有到达目的地,在中途就 ...

  9. 什么是可变参数?如何创建不可变集合?Steam三类方法是什么?获取流方法特点?流中间方法特点?终结流方法特点?

    ==知识梳理== ==重难点梳理== ==今日目标== 1.能够了解什么是可变参数 2.能够了解如何去创建不可变集合 3.能够掌握Stream流的使用 ==知识点== 1.可变参数 2.Stream流 ...

  10. datagrid 根据指定参数重新加载数据

    $('#statisticalRecordList').datagrid('reload',{ start_date:$('#dd1').datebox('getValue'), end_date: ...