日期:2014-05-16  浏览次数:20495 次

pgpool_II配置2(复制模式)

?

先设置复制模式的配置。?它其实已经帮你弄了样本了,改下名字。

?

?

?

cp $prefix/etc/pgpool.conf.sample-replication $prefix/etc/pgpool.conf

?

?

然后配置node,所谓的节点。有这几个属性:

?

backend_hostname
指出连接到 PostgreSQL 后台程序的地址。它用于 pgpool-II 与服务器通信。如果你改变了这个值,需要重新加载 pgpool.conf 以使变动生效
对于 TCP/IP 通信,本参数可以是一个主机名或者IP地址。如果它是从斜线开始的,它指出是通过 UNIX 域套接字通信,而不是 TCP/IP 协议;它
backend_host 为空,则它的默认行为是通过 /tmp 中的 UNIX 域套接字连接。
可以通过在本参数名的末尾添加一个数字来指定多个后台程序(例如backend_hostname0)。这个数 字对应为“数据库节点 ID”,是从 0 开始的正整
序将被叫做“主数据库”。当定义了多个后台程序时,即使主数据库当机后依然能继续(某些模式下不行)。在这种情况下,存活的最小的数据库 节
如果你只计划使用一台 PostgreSQL 服务器,可以通过 backend_hostname0 指定。
可以通过配置本参数后重新加载配置文件添加新的节点。但是,对已有的值无法更新,所以这种情况下你必须重启 pgpool-II。
backend_port
指定后台程序的端口号。可以通过在本参数名的末尾添加一个数字来指定多个后台程序(例如backend_port0)。如果你只计划使用一台 Postgre
可以通过配置本参数后重新加载配置文件添加新的后台端口。但是,对已有的值无法更新,所以这种情况下你必须重启 pgpool-II。
backend_weight
指定后台程序的负载均衡权重。可以通过在本参数名的末尾添加一个数字来指定多个后台程序(例如backend_weight0)。如果你只计划使用一台
指定。
在原始模式中,请将本值设置为 1。
可以通过配置本参数后重新加载配置文件添加新的负载均衡权重。但是,对已有的值无法更新,所以这种情况下你必须重启 pgpool-II。
在 pgpool-II 2 2 6/2 3 或者更新的版本中
你可以通过重新加载配置文件来改变本值
但这只对新连接的客户会话生效
这在主备模式中可以避
在 pgpool II 2.2.6/2.3 或者更新的版本中,你可以通过重新加载配置文件来改变本值。但这只对新连接的客户会话生效。这在主备模式中可以避
点上。
backend_data_directory
指定后台的数据库实例的目录。可以通过在本参数名的末尾添加一个数字来指定多个后台程序(例如backend_data_directory0)。如果你不打算使
可以通过配置本参数后重新加载配置文件添加新的后台的数据库实例目录。但是,对已有的值无法更新,所以这种情况下你必须重启 pgpool-II。
backend_flag
控制大量的后台程序的行为。可以通过在本参数名的末尾添加一个数字来指定多个后台程序(例如backend_flag0)
当前支持以下的内容。多个标志可以通过“|”来分隔。
ALLOW_TO_FAILOVER
允许故障切换或者从后台程序断开。本值为默认值。指定本值后,不能同时指定 DISALLOW_TO_FAILOVER 。
DISALLOW_TO_FAILOVER
不允许故障切换或者从后台程序断开。本值在你使用 HA(高可用性)软件例如 Heartbeat 或者 Packmaker 来保护后台程序时非常有用
DISALLOW _TO_FAILOVER 。

?

?节点可以设很多个,貌似没有限制。

?

?

接着要设置各个节点上的PostgreSql的datadir下的pg_hba.conf文件。如下:

?

?

# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
host    all             all             172.29.0.41/32          trust

?

?其中trust设置成md5应该也可行。

?

?

接着应该配置结束了,启动pgpool。

?

1.5. Starting/Stopping pgpool-II

To fire up pgpool-II, execute the following command on a terminal.

$ pgpool
The above command, however, prints no log messages because pgpool detaches the terminal. If you want to show pgpool log messages, you pass -n option to pgpool command. pgpool-II is executed as non-daemon process, and the terminal will not be detached.

$ pgpool -n &
The log messages are printed on the terminal, so the recommended options to use are like the following.

$ pgpool -n -d > /tmp/pgpool.log 2>&1 &
-d option enables debug messages to be generated.

The above command keeps appending log messages to /tmp/pgpool.log. If you need to rotate log files, pass the logs to a external command which have log rotation function. For example, you can use rotatelogs coming with Apache2:

$ pgpool -n 2>&1 | /usr/local/apache2/bin/rotatelogs \
  -l -f /var/log/pgpool/pgpool.log.%A 86400 &
This will generate a log file named "pgpool.log.Thursday" everyday then rotate it 00:00 at midnight. Rotatelogs adds log to a file if it already exists. To delete old log files before rotation, you could use cron:
55 23 * * * /usr/bin/find /var/log/pgpool -type f -mtime +5 -exec /bin/rm -f '{}' \;
Please note that rotaelogs may exist as /usr/sbin/rotatelogs2 in some distributions. -f option generates a log file as soon as rotatelogs starts and is available apache2 2.2.9 or greater.
Also cronolog helps you.

$ pgpool -n 2>&1 | /usr/sbin/cronolog \
  --hardlink=/var/log/pgsql/pgpool.log \
  '/var/log/pgsql/%Y-%m-%d-pgpool.log' &
To stop pgpool-II process, execute the following command.

$ pgpool stop
If any client is still connected, pgpool-II waits for them to disconnect, and then terminate itself. Execute the following comma