postgresql-12編譯安裝
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關閉該選項
參考文檔