|||
本教程是PostgreSQL Cluster系列教程的一部分,该系列包括:
PostgreSQL9.1 PITR示例 (该教程主要阐述DBA如何基于WAL日志做备份恢复)
PostgreSQL9.1 Warm-Standby ---之基于拷贝WAL文件的方法 (file-based log shipping)
PostgreSQL9.1 Warm-Standby ---之基于流复制的方法 (streaming replication)
PostgreSQL9.1 Warm-Standby ---之基于同步复制的方法 (Synchronous Replication)
PG9.1+pgpool-II3.1--之Load Balancing (when meeting large amounts of requests)
PG9.1+pgpool-II3.1--之Parallel Query (when meeting large amounts of data)
PostgreSQL9.1 HA --- 之Slony
其实依据上一篇文章PG9.1+pgpool-II3.1--之HA (Hot-Standby+Streaming Replication)(只读的hot-standby要是能用promote命令来提升为master接受read和write,则该文有效,否则还是建议用warm-standby,我没在warm-standby上试,但是希望有朋友后续写写),我们稍作修改就可以设置Load Blancing的集群了。pgpool-II负责在前面调度,后面的master和n个hot-standby做具体的工作,简单来讲,写的SQL语句由pgpool-II自动识别发给master,只读的发给n个standby。做研究的可以琢磨琢磨,要是你怎么实现?或许哪个学生可以从这里深入下去,写一篇论文,因为你必须判断哪些语句要给master,哪些给standby,当语句复杂时可能就不容易。
为了简化该教程,我们只说针对PG9.1+pgpool-II3.1--之HA (Hot-Standby+Streaming Replication做哪些修改。
1. 安装pgpool-II3.1.2和pgpoolAdmin3.1.1 (相同)
2.千辛万苦我们把pgpool-II和pgpoolAdmin安装上了,接下来我们就得把Master和Standby的数据库安装上(相同)
3.然后进入激动人心的HA的配置了(修改)
接着修改/usr/local/etc/pgpool.conf:
listen_addresses = '*'
backend_hostname0 = 'localhost'
backend_port0 = 6432
backend_weight0 = 1
backend_data_directory0 = '/home/postgres/db/master/pgsql/data'
backend_flag0= 'ALLOW_TO_FAILOVER'
backend_hostname1 = 'localhost'
backend_port1 = 7432
backend_weight1 = 1
backend_data_directory1 = '/home/postgres/db/standby/pgsql/data'
backend_flag1= 'ALLOW_TO_FAILOVER'
pid_file_name = '/home/postgres/pgpool/pgpool.pid'
logdir = '/home/postgres/pgpool'
#增加项
load_balance_mode = on
ignore_leading_white_space = on
white_function_list = ''
black_function_list = 'currval,lastval,nextval,setval'
master_slave_mode = on
master_slave_sub_mode = 'stream'
health_check_user = 'apache'
health_check_password = ''
failover_command = '/usr/local/etc/failover.sh %d "%h" %p %D %m %M "%H" %P'
failback_command = '/bin/rm -f /home/postgres/var/log/pgpool/trigger/'
recovery_user = 'postgres'
recovery_password = 'postgres'
recovery_1st_stage_command = 'basebackup.sh'
recovery_2nd_stage_command = ''
4.检验(修改)
在master和standby的postgresql.conf中设置:
log_statement = 'all'
依次启动master,standby,pgpool,apache:
/home/postgres/db/master/pgsql/bin/postmaster -D /home/postgres/db/master/pgsql/data
/home/postgres/db/standby/pgsql/bin/postmaster -D /home/postgres/db/standby/pgsql/data
pgpool -n &
sh /home/postgres/website/apache-tomcat-7.0.16/bin/startup.sh
然后开启两个客户端:
psql -p 9999 mydb;
mydb=# select count(*) from foo;
分别执行,看看是不是在master和standby之间各自执行,若是则表明配置成功。
加我私人微信,交流技术。
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-11-24 13:08
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社