hillpig的个人博客分享 http://blog.sciencenet.cn/u/hillpig 畅想ing,思考ing,前行ing Email:bluevaley@gmail.com

博文

PG9.1+pgpool-II3.1--之Load Balancing

已有 8768 次阅读 2012-3-1 10:37 |个人分类:postgresql|系统分类:科研笔记| Balancing

本教程是PostgreSQL Cluster系列教程的一部分,该系列包括:

  1. PostgreSQL9.1 PITR示例  (该教程主要阐述DBA如何基于WAL日志做备份恢复)

  2. PostgreSQL9.1 Warm-Standby ---之基于拷贝WAL文件的方法        (file-based log shipping)

  3. PostgreSQL9.1 Warm-Standby ---之基于流复制的方法 (streaming        replication)

  4. PostgreSQL9.1 Warm-Standby ---之基于同步复制的方法 (Synchronous Replication)

  5. PostgreSQL9.1 Hot-Standby ---之基于拷贝WAL文件的方法

  6. PostgreSQL9.1 Hot-Standby ---之基于流复制的方法

  7. PostgreSQL9.1 Hot-Standby ---之基于同步复制的方法

  8. PG9.1+pgpool-II3.1--之HA (Hot-Standby+Streaming Replication)

  9. PG9.1+pgpool-II3.1--之Load Balancing (when meeting large amounts of requests)

  10. PG9.1+pgpool-II3.1--之Parallel Query (when meeting large amounts of data)

  11. 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之间各自执行,若是则表明配置成功。


加我私人微信,交流技术。




https://blog.sciencenet.cn/blog-419883-542793.html

上一篇:PG9.1+pgpool-II3.1--之HA (Hot-Standby+Streaming Replication)
下一篇:PG9.1+pgpool-II3.1--之Parallel Query
收藏 IP: 223.72.72.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-23 23:20

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部