前言
自我感觉10.8和10.3安装一样的方式,没有太大区别
一、下载POSTGRESQL源码安装包及主机配置
https://www.postgresql.org/ftp/source/v10.8/
postgresql-10.8.tar.gz
虚拟机环境
node1 192.168.159.4
node2 192.168.159.5
操作系统为redhat7.6
数据库为postgresql10.8
两个节点均配置/etc/hosts
vi /etc/hosts
node1 192.168.159.4
node2 192.168.159.5
二、编译安装
(1)创建postgres用户
useradd -m -r -s /bin/bash -u 5432 postgres
(2)安装相关依赖包
yum install gettext gcc make perl python perl-ExtUtils-Embed readline-devel zlib-devel openssl-devel libxml2-devel cmake gcc-c++ libxslt-devel openldap-devel pam-devel python-devel cyrus-sasl-devel libgcrypt-devel libgpg-error-devel libstdc++-devel
(3)配置POSTGRES
上传解压安装包
cd /opt/
tar -zxvf postgresql-10.8.tar.gz
cd /opt/ postgresql-10.8
./configure --prefix=/opt/postgresql-10.8 --with-segsize=8 --with-wal-segsize=64 --with-wal-blocksize=16 --with-blocksize=16 --with-libedit-preferred --with-perl --with-python --with-openssl --with-libxml --with-libxslt --enable-thread-safety --enable-nls=zh_CN
最后几行出现以下黄色输出即配置正确,否则根据报错提示继续安装依赖包
checking thread safety of required library functions... yes
checking whether gcc supports -Wl,--as-needed... yes
configure: using compiler=gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
configure: using CFLAGS=-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -pg -DLINUX_PROFILE -O2
configure: using CPPFLAGS= -D_GNU_SOURCE -I/usr/include/libxml2
configure: using LDFLAGS= -Wl,--as-needed
configure: creating ./config.status
config.status: creating GNUmakefile
config.status: creating src/Makefile.global
config.status: creating src/include/pg_config.h
config.status: creating src/include/pg_config_ext.h
config.status: creating src/interfaces/ecpg/include/ecpg_config.h
config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s
config.status: linking src/backend/port/dynloader/linux.c to src/backend/port/dynloader.c
config.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.c
config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
config.status: linking src/backend/port/dynloader/linux.h to src/include/dynloader.h
config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port
或者马上输入echo $?得到输出是0就可以了
(4)编译
make && make install
最后几行出现以下黄色输出即配置正确
make[2]: 离开目录“/opt/postgresql-10.8/src/test/perl”
/usr/bin/mkdir -p '/opt/postgresql-10.8/lib/pgxs/src'
/usr/bin/install -c -m 644 Makefile.global '/opt/postgresql-10.8/lib/pgxs/src/Makefile.global'
/usr/bin/install -c -m 644 Makefile.port '/opt/postgresql-10.8/lib/pgxs/src/Makefile.port'
/usr/bin/install -c -m 644 ./Makefile.shlib '/opt/postgresql-10.8/lib/pgxs/src/Makefile.shlib'
/usr/bin/install -c -m 644 ./nls-global.mk '/opt/postgresql-10.8/lib/pgxs/src/nls-global.mk'
make[1]: 离开目录“/opt/postgresql-10.8/src”
make -C config install
make[1]: 进入目录“/opt/postgresql-10.8/config”
/usr/bin/mkdir -p '/opt/postgresql-10.8/lib/pgxs/config'
/usr/bin/install -c -m 755 ./install-sh '/opt/postgresql-10.8/lib/pgxs/config/install-sh'
/usr/bin/install -c -m 755 ./missing '/opt/postgresql-10.8/lib/pgxs/config/missing'
make[1]: 离开目录“/opt/postgresql-10.8/config”
PostgreSQL installation complete.
或者马上输入echo $?得到输出是0就可以了
(5)安装
make world && make install -world
最后几行出现以下黄色输出即配置正确
/usr/bin/mkdir -p '/opt/postgresql-10.8/lib/pgxs/src'
/usr/bin/install -c -m 644 Makefile.global '/opt/postgresql-10.8/lib/pgxs/src/Makefile.global'
/usr/bin/install -c -m 644 Makefile.port '/opt/postgresql-10.8/lib/pgxs/src/Makefile.port'
/usr/bin/install -c -m 644 ./Makefile.shlib '/opt/postgresql-10.8/lib/pgxs/src/Makefile.shlib'
/usr/bin/install -c -m 644 ./nls-global.mk '/opt/postgresql-10.8/lib/pgxs/src/nls-global.mk'
make[1]: 离开目录“/opt/postgresql-10.8/src”
make -C config install
make[1]: 进入目录“/opt/postgresql-10.8/config”
/usr/bin/mkdir -p '/opt/postgresql-10.8/lib/pgxs/config'
/usr/bin/install -c -m 755 ./install-sh '/opt/postgresql-10.8/lib/pgxs/config/install-sh'
/usr/bin/install -c -m 755 ./missing '/opt/postgresql-10.8/lib/pgxs/config/missing'
make[1]: 离开目录“/opt/postgresql-10.8/config”
PostgreSQL installation complete.
make: 离开目录“/opt/postgresql-10.8”
或者马上输入echo $?得到输出是0就可以了
(6)创建相关目录及配置环境变量
su - postgres
vi .bash_profile (删除原来的所有,以下黄色部分直接复制粘贴)
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
# postgres
#PostgreSQL端口
PGPORT=5432
#PostgreSQL数据目录
PGDATA=/home/postgresql10.8/pg/pgdata
export PGPORT PGDATA
#所使用的语言
export LANG=zh_CN.utf8
#PostgreSQL 安装目录
export PGHOME= /home/postgresql10.8/pg/pgdata
#PostgreSQL 连接库文件
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export DATE=`date +"%Y%m%d%H%M"`
#将PostgreSQL的命令行添加到 PATH 环境变量
export PATH=$PGHOME/bin:$PATH
#PostgreSQL的 man 手册
export MANPATH=$PGHOME/share/man:$MANPATH
#PostgreSQL的默认用户
export PGUSER=postgres
#PostgreSQL默认主机地址
export PGHOST=127.0.0.1
#默认的数据库名
export PGDATABASE=postgres
#定义日志存放目录
PGLOG="$PGDATA/serverlog"
source .bash_profile
(7)初始化数据库
#执行数据库初始化脚本
root用户登录
警告:为本地连接启动了 "trust" 认证.
你可以通过编辑 pg_hba.conf 更改或你下次
行 initdb 时使用 -A或者--auth-local和--auth-host选项.
Success. You can now start the database server using:
启动数据库
su - postgres
/opt/postgresql-10.8/bin/pg_ctl -D '/home/postgresql10.8/pg/pgdata/' -l logfile start
(8)相关命令拷贝
root用户
三、postgresql主从搭建
1、主库配置
su - postgres
host replication replica 192.168.159.0/24 md5
host all replica 192.168.159.0/24 md5
host all all 192.168.159.0/24 md5
host all all 0.0.0.0/0 md5
(3)主库配置文件修改以下几项,其他不变
vi /home/postgresql10.8/pg/pgdata/ postgresql.conf
listen_addresses = '*'
wal_level = hot_standby #热备模式
max_wal_senders= 10 #可以设置最多几个流复制链接,差不多有几个从,就设置多少
wal_keep_segments = 100 #重要配置
wal_send_timeout = 60s
max_connections = 3000 #从库的 max_connections要大于主库
archive_mode = on #允许归档
archive_command = 'cp %p /home/postgresql10.8/pg/archivedir /%f' #根据实际情况设置
checkpoint_timeout = 30min
max_wal_size = 2GB
min_wal_size = 1GB
mkdir /home/postgresql10.8/pg/archivedir
vi /home/postgresql10.8/pg/pgdata / postgresql.conf
listen_addresses ='*'
(5) 启动备库
/opt/postgresql-10.8/bin/pg_ctl -D '/home/postgresql10.8/pg/pgdata/' -l logfile start
cd /data/pg/
注意一个问题,生产库要注意时区问题
找到配置文件postgresql.conf
其中参数
timezone = 'PRC'
PRC代表是上海时区
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28371090/viewspace-2645631/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28371090/viewspace-2645631/