PostgresqlHA高可用安装配置Word文档下载推荐.docx
《PostgresqlHA高可用安装配置Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《PostgresqlHA高可用安装配置Word文档下载推荐.docx(28页珍藏版)》请在冰豆网上搜索。
#chown–Rpostgres:
potgres/opt/soft
把此目录及子目录的所属人和所属组全换成postgres
3.2.关闭防火墙
#chkconfigiptablesoff
#serviceiptablesstop
3.3.关闭SElinux
修改SELinux配置文件
#vim/etc/sysconfig/selinux
把SELINUX=enforcing修改为SELINUX=disabled
3.4.配置hosts文件
在hosts文件中增加以下容
#vim/etc/hosts
192.168.1.231pgpool-node01
192.168.1.232pgpool-node02
3.5.创建postgres用户并设置密码
安装之前要先检查系统中是否有postgres系统账号
#cat/etc/passwd|greppostgres
如果没有postgres账号,需要新增postgres账号
#groupadd-g26postgres
#useradd-d/var/lib/pgsql-gpostgres-u26postgres
给postgres配置密码
#passwdpostgres
3.6.主备节点时钟同步
#/usr/sbin/ntpdateasia.pool.ntp.org&
&
/sbin/hwclock–systohc
asia.pool.ntp.org为网络时间
通过ntpdate命令获取网络时间并且将其作为硬件时间
3.7.配置sysctl
sysctl.conf(配置系统信息,系统变量,主要用来优化系统)
/etc/sysctl.conf这个目录主要是配置一些系统信息,而且它的容全部是对应于/proc/sys/这个目录的子目录及文件
#vi/etc/sysctl.conf
kernel.shmmni=4096
kernel.sem=5010064128000501001280
fs.file-max=7672460
net.ipv4.ip_local_port_range=900065000
net.core.rmem_default=1048576
net.core.rmem_max=4194304
net.core.wmem_default=262144
net.core.wmem_max=1048576
net.ipv4.tcp_tw_recycle=1
net.ipv4.tcp_max_syn_backlog=4096
dev_max_backlog=10000
vm.overcommit_memory=0
net.ipv4.ip_conntrack_max=655360
fs.aio-max-nr=1048576
net.ipv4.tcp_timestamps=0
●使文件修改生效
#sysctl–p
3.8.limit资源分配
#vi/etc/security/limits.conf
*softnofile131072
*hardnofile131072
*softnproc131072
*hardnproc131072
*softcoreunlimited
*hardcoreunlimited
*softmemlock50000000
*hardmemlock50000000
4.postgreSQL流复制环境安装配置
4.1.配置SSH免登陆
Onmaster:
#su–postgres
$ssh-keygen-trsa–P'
'
$ssh-copy-id-i~/.ssh/id_rsa.pubpostgres192.168.1.232
$sshpostgresnode2
Onstandby:
$ssh-keygen-trsa-P'
$ssh-copy-id-i~/.ssh/id_rsa.pubpostgres192.168.1.231
$sshpostgresnode1
4.2.安装依赖包
使用yum自动安装以下软件
#yum-yinstallreadline-develzlibzlib-developensslopenssl-develpam-devellibxml2-devellibxslt-develpython-develtcl-develgccperl-ExtUtils-Embed
或者是手动安装以下软件
gcc
libxml2-devel
libxslt-devel
openssl-devel
pam-devel
python-devel
readline-devel
tcl-devel
zlib-devel
cloog-ppl
cpp
keyutils-libs-devel
krb5-devel
libcom_err-devel
libgcrypt-devel
libgpg-error-devel
libselinux-devel
libsepol-devel
mpfr
ncurses-devel
ppl
tcl
4.3.解压和安装
#su-postgres
$cd/opt/soft/
$tar-zxvfpostgresql-9.3.5.tar.gz
$cdpostgresql-9.3.5
$./configure--prefix=/opt/pgsql/--with-pgport=5432--with-perl--with-tcl--with-python--with-openssl--with-pam--without-ldap--with-libxml--with-libxslt--with-blocksize=8
$gmake
$gmakeinstall
4.4.设置环境变量
●编辑环境变量配置文件,增加以下容
$vim~/.bash_profile
exportPGPORT=5432
exportPGDATA=/opt/pgdata
exportPGHOME=/opt/pgsql
exportPATH=.:
$PGHOME/bin:
$PATH
●使环境变量配置立即生效
$source~/.bash_profile
4.5.初始化数据库(master)
初始化数据库
$initdb-D$PGDATA
4.6.修改配置文件(master)
主配置文件postgresql.conf参数调整(master)
找到以下参数容,调整参数值
$cd$PGDATA
$vimpostgresql.conf
listen_addresses='
*'
port=5432
max_connections=500
wal_level=hot_standby
archive_mode=on
archive_command='
/bin/date'
max_wal_senders=6
hot_standby=on
访问控制文件pg_hba.conf配置(master)
增加以下访问控制容
$vimpg_hba.conf
hostallall192.168.1.231/32trust
hostallall192.168.1.232/32trust
hostreplicationreplica192.168.1.232/32trust
hostreplicationreplica192.168.1.231/32trust
标志文件recovery.done配置(master)
新增一个recovery.done文件
$touch/opt/pgdata/recovery.done
$chmod777recovery.done
在文件中输入以下容
$vim/opt/pgdata/recovery.done
standby_mode=on
recovery_target_timeline='
latest'
primary_conninfo='
host=192.168.1.232port=5432user=replicapassword=replica'
trigger_file='
/opt/pgdata/trigger_file'
4.7.启动主库服务(master)
$pg_ctl-D$PGDATA-l$PGDATA/logfilerestart
或$pg_ctl–D$PGDTArestart
Pg_ctl–D$PGDATAstart>
>
/opt/pgdata/logfile2>
1$&
4.8.配置流复制用户(master)
●创建流复制用户
$psql-Upostgres
postgres#CREATEROLEreplicaloginreplicationencryptedpassword'
replica'
;
4.9.备库实例生成(standby)
从主库复制实例到备库
$pg_basebackup-D$PGDATA-Fp-Xs-v-P-hnode1-Ureplica
修改备库标识文件
$mv/opt/pgdata/recovery.done/opt/pgdata/recovery.conf
$vim/opt/pgdata/recovery.conf
recovery_target_timeline=’latest’
primary_conninfo=‘host=192.168.1.231port=5432user=replica’
trigger_file=‘/opt/pgdata/trigger_file’
4.10.启动备库服务(standby)
$chown-Rpostgres:
postgres
/opt/pgdata
$chmod0700/opt/pgdata
$pg_ctl–D$PGDATA-l$PGDATA/logfilestart
4.11.检查运行情况
●查看备库进程
ps–ef|greppostgres
●查看主库进程
4.12.测试
OnMaster:
$psql-Upostgres
postgres=#createtabletest(idint,namevarchar(10));
postgres=#selecttable_namefrominformation_schema.tableswheretable_schema='
public'
table_name
------------
test
(1row)
OnStandby:
table_name
新增的数据已经传输过去,并且standby端的会话是只读的。
5.pgpool-II安装配置
5.1.安装
解压和安装(master/standby)
$mkdir/opt/pgpool
$tarzxvfpgpool-II-3.4.3.tar.gz
$cdpgpool-II-3.4.3
$./configure--prefix=/opt/pgpool--with-pgsql=/opt/pgsql--with-openssl
$make
$makeinstall
安装相关函数(master)
●安装pgpool-regclass,pgpool-recovery函数
[postgresnode1~]$cd/opt/soft/pgpool-II-3.4.3/src/sql/pgpool-regclass
[postgresnode1pgpool-regclass]$make
[postgresnode1pgpool-regclass]$makeinstall
[postgresnode1pgpool-regclass]$psql-fpgpool-regclass.sqltemplate1
[postgresnode1pgpool-regclass]$cd../pgpool-recovery
[postgresnode1pgpool-recovery]$make
[postgresnode1pgpool-recovery]$makeinstall
[postgresnode1pgpool-recovery]$psql-fpgpool-recovery.sqltemplate1
●安装完以后/opt/pgsql/share/extension/目录下应该有如下文件
pgpool_recovery--1.1.sql
pgpool_recovery.control
pgpool-recovery.sql
pgpool_regclass--1.0.sql
pgpool_regclass.control
pgpool-regclass.sql
备注:
备节点不需要创建pgpool_regclass,pgpool_recovery)
●查看新增加的函数
[postgresnode1~]$psql-Upostgrestemplate1
template1=#\df
5.2.配置环境变量(master/standby)
$vim/etc/profile
exportPGPOOL=/opt/pgpool
$PGPOOL/bin:
使环境变量立即生效
$source/etc/profile
5.3.配置ifconfig,arping执行权限(master/standby)
●配置sudo权限
#vim/etc/sudoers
postgresALL=(ALL)NOPASSWD:
/sbin/ifconfig
/sbin/ifup
/sbin/ifdown
/sbin/arping
●配置s权限
#chmodu+s/sbin/ifconfig
#chmodu+s/usr/sbin/arping
5.4.###开启日志(master/standby)###
●在日志/etc/rsyslog.conf加入以下行
#vim/etc/rsyslog.conf
local0.*/var/log/pgpool/pgpool.log
●重启rsyslog服务
#/etc/init.d/rsyslogrestart
●pgpool.conf配置以下行
#vim/opt/pgpool/etc/pgpool.conf
log_destination=’syslog’
5.5.主库修改配置文件(master)
主配置文件pgpool.conf参数调整
[postgresnode1~]$cd/opt/pgpool/etc
[postgresnode1etc]$cppgpool.conf.samplepgpool.conf
[postgresnode1etc]$vimpgpool.conf
主节点的pgpool.conf(配置文件中的用户名和配置能用postgres用户就用postgres用户,尽量减少用户)
#CONNECTIONS
#-pgpoolConnectionSettings-
port=9999
socket_dir='
/opt/pgpool'
#-pgpoolCommunicationManagerConnectionSettings–
pcp_listen_addresses='
pcp_port=9898
pcp_socket_dir='
#-BackendConnectionSettings-
backend_hostname0='
node1'
##配置数据节点node1
backend_data_directory0='
/opt/pgdata'
backend_hostname1='
node2'
##配置数据节点node2
backend_port1=5432
backend_weight1=1
backend_data_directory1='
backend_flag1='
ALLOW_TO_FAILOVER'
#-Authentication-
enable_pool_hba=on
pool_passwd='
pool_passwd'
authentication_timeout=60
#-Wheretolog-
log_destination='
syslog'
#-Whattolog-
log_connections=on
log_hostname=on
log_statement=on
log_per_node_statement=off
log_standby_delay='
none'
#FILELOCATIONS
pid_file_name='
/opt/pgpool/pgpool.pid'
logdir='
/var/log/pgpool'
#CONNECTIONPOOLING
connection_cache=on
reset_query_list='
ABORT;
DISCARDALL'
#LOADBALANCINGMODE
load_balance_mode=on
ignore_leading_white_space=on
white_function_list='
'
black_function_list='
nextval,setval,nextval,setval'
#MASTER/SLAVEMODE
master_slave_mode=on#设置流复制模式
master_slave_sub_mode='
stream'
#设置流复制模式
#-Streaming-
sr_check_period=5
sr_check_user='
sr_check_password='
delay_threshold=16000
#-Specialcommands-
follow_master_command='
parallel_mode=off
pgpool2_hostname='
system_db_hostname='
localhost'
system_db_port=5432
system_db_dbname='
pgpool'
system_db_schema='
pgpool_catalog'
system_db_user='
system_db_password='
#HEALTHCHECK
health_check_period=5
health_check_timeout=20
health_check_user='
health_check_password='
health_check_max_retries=3
health_check_retry_delay=1
#FAILOVERANDFAILBACK
failover_command='
/opt/pgpool/failover_stream.sh%d%H/opt/pgdata/trigger_file'
#WATCHDOG
use_watchdog=on
#-WatchdogcommunicationSettings-
wd_hostname='
#-VirtualIPcontrolSetting–
delegate_IP='
192.168.1.233'
代理的IP地址
#-LifecheckSetting-
wd_interv