Pgcluster 1.7 安装手顺

| |
[不指定 2008/05/26 13:21 | by zeus ]
这几天一直接触postgres,想做集群。
简单做了一下,效果还不错。步骤如下。

pgcluster
--主要介绍
http://www.pgcluster.org/
http://pgcluster.projects.postgresql.org/

--下载
--http://pgfoundry.org/frs/?group_id=1000072
--选择最新版本下载
pgcluster-1.7.0rc7.tar.bz2

--配置4台linux机器分别如下
ip                        hostname
192.168.0.1   loadbalancer
192.168.0.11    cluster_1
192.168.0.12    cluster_2
192.168.0.21    replicate_upper

--在4台linux机器上用root帐号分别设置hosts
vi /etc/hosts
#
# load balancer
#
192.168.0.1      loadbalancer
#
# Cluster DBs
#
192.168.0.11     cluster_1
192.168.0.12     cluster_2
#
# replication server
#
192.168.0.21     replicate_upper

--将下载的文件pgcluster-1.7.0rc7.tar.bz2放到4台机器的/tmp目录下用root帐号进行安装,4台机器一样
cd /tmp
tar xvfj pgcluster-1.7.0rc7.tar.bz2
cd pgcluster-1.7.0rc7
./configure
gmake
gmake install


--创建用户
/usr/sbin/adduser postgres
mkdir -p /usr/local/pgsql/data
chown -R postgres.postgres /usr/local/pgsql
su - postgres
--设置环境变量
vi .bash_profile
export LD_LIBRARY_PATH=/usr/local/pgsql/lib
PATH=/usr/local/pgsql/bin:$PATH
export PATH
MANPATH=/usr/local/pgsql/man:$MANPATH
export MANPATH
PGDATA=/usr/local/pgsql/data
export PGDATA
source .bash_profile
--创建数据库集群
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data


--设置loadbalancer server
su - postgres
cd /usr/local/pgsql/share
cp pglb.conf.sample pglb.conf
vi pglb.conf
#============================================================
#          Load Balance Server configuration file
#-------------------------------------------------------------
# file: pglb.conf
#-------------------------------------------------------------
# This file controls:
#       o which hosts are db cluster server
#       o which port  use connect to db cluster server
#       o how many connections are allowed on each DB server
#============================================================
#-------------------------------------------------------------
# set cluster DB server information
#               o Host_Name :           Hostname of Cluster
#                                       Please write a host name by FQDN or IP address.
#               o Port :                Connection port for postmaster
#               o Max_Connection :      Maximum number of connections to postmaster
#-------------------------------------------------------------
<Cluster_Server_Info>
   <Host_Name>                cluster_1                            </Host_Name>
   <Port>                     5432                    </Port>
   <Max_Connect>              32                      </Max_Connect>
</Cluster_Server_Info>
<Cluster_Server_Info>
   <Host_Name>                cluster_2                         </Host_Name>
   <Port>                     5432                    </Port>
   <Max_Connect>              32                      </Max_Connect>
</Cluster_Server_Info>
#<Cluster_Server_Info>
#    <Host_Name>                post3.pgcluster.org     </Host_Name>
#    <Port>                     5432                    </Port>
#    <Max_Connect>              32                      </Max_Connect>
#</Cluster_Server_Info>
#-------------------------------------------------------------
# set Load Balance server information
#               o Host_Name :           The host name of this load balance server
#                                       Please write a host name by FQDN or IP address.
#               o Backend_Socket_Dir :  Unix domain socket path for the backend
#               o Receive_Port          Connection port from client
#               o Recovery_Port :       Connection port for recovery process
#               o Max_Cluster_Num :     Maximum number of cluster DB servers
#               o Use_Connection_Pooling : Use connection pool [yes/no]
#               o Lifecheck_Timeout :   Timeout of the lifecheck response
#               o Lifecheck_Interval :  Interval time of the lifecheck
#                               (range 1s - 1h)
#                               10s   -- 10 seconds
#                               10min -- 10 minutes
#                               1h    -- 1 hours
#-------------------------------------------------------------
<Host_Name>                     loadbalancer                                  </Host_Name>
<Backend_Socket_Dir>            /tmp                            </Backend_Socket_Dir>
<Receive_Port>                  5432                            </Receive_Port>
<Recovery_Port>         6001                            </Recovery_Port>
<Max_Cluster_Num>               128                             </Max_Cluster_Num>
<Use_Connection_Pooling>        no                              </Use_Connection_Pooling>
<LifeCheck_Timeout>             3s                              </LifeCheck_Timeout>
<LifeCheck_Interval>            15s                             </LifeCheck_Interval>
#-------------------------------------------------------------
# A setup of a log files
#
#               o File_Name :   Log file name with full path
#               o File_Size :   Maximum size of each log files
#                               Please specify in a number and unit(K or M)
#                                10   -- 10 Byte
#                                10K  -- 10 KByte
#                                10M  -- 10 MByte
#               o Rotate :      Rotation times
#                               If specified 0, old versions are removed.
#-------------------------------------------------------------
<Log_File_Info>
       <File_Name>             /tmp/pglb.log   </File_Name>
       <File_Size>             1M              </File_Size>
       <Rotate>                3               </Rotate>
</Log_File_Info>



--设置cluster db,两台的设置差不多只是主机名不同
su - postgres
cd /usr/local/pgsql/data
vi postgresql.conf
# - Connection Settings -

listen_addresses = '*'          # what IP address(es) to listen on;
                                       # comma-separated list of addresses;
                                       # defaults to 'localhost', '*' = all
                                       # (change requires restart)
port = 5432                             # (change requires restart)
max_connections = 100                   # (change requires restart)



vi pg_hba.conf
# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# "local" is for Unix domain socket connections only
local   all         all                               trust
# IPv4 local connections:
host    all         all         127.0.0.1/32          trust
host    all         all         192.168.0.0/24        trust
# IPv6 local connections:
host    all         all         ::1/128               trust

vi cluster.conf
#============================================================
#          Cluster DB Server configuration file
#------------------------------------------------------------
# file: cluster.conf
#------------------------------------------------------------
# This file controls:
#       o which hosts & port are replication server
#       o which port use for replication request to replication server
#       o which command use for recovery function
#============================================================
#------------------------------------------------------------
# set Replication Server information
#               o Host_Name :           hostname
#               o Port :                Connection port for postmaster
#               o Recovery_Port :       Connection port for recovery process
#------------------------------------------------------------
<Replicate_Server_Info>
       <Host_Name>             replicate_upper                 </Host_Name>
       <Port>                  8001                            </Port>
       <Recovery_Port>         8101                            </Recovery_Port>
</Replicate_Server_Info>
#<Replicate_Server_Info>
#       <Host_Name>             replicate2.pgcluster.org        </Host_Name>
#       <Port>                  8002                            </Port>
#       <Recovery_Port>         8102                            </Recovery_Port>
#</Replicate_Server_Info>
#<Replicate_Server_Info>
#       <Host_Name>             replicate3.pgcluster.org        </Host_Name>
#       <Port>                  8003                            </Port>
#       <Recovery_Port>         8103                            </Recovery_Port>
#</Replicate_Server_Info>
#-------------------------------------------------------------
# set Cluster DB Server information
#               o Host_Name :           Host name which connect with replication server
#               o Recovery_Port :       Connection port for recovery
#               o Rsync_Path :          Path of rsync command
#               o Rsync_Option :        File transfer option for rsync
#               o Rsync_Compress :      Use compression option for rsync
#                                       [yes/no]. default : yes
#               o Pg_Dump_Path :        Path of pg_dump
#               o When_Stand_Alone :    When all replication servers fell,
#                                       you can set up two kinds of permission,
#                                       "real_only" or "read_write".
#               o Replication_Timeout : Timeout of each replication request
#               o Lifecheck_Timeout :   Timeout of the lifecheck response
#               o Lifecheck_Interval :  Interval time of the lifecheck
#                               (range 1s - 1h)
#                               10s   -- 10 seconds
#                               10min -- 10 minutes
#                               1h    -- 1 hours
#-------------------------------------------------------------
<Host_Name>                     cluster_1               </Host_Name>
<Recovery_Port>         7001                            </Recovery_Port>
<Rsync_Path>                    /usr/bin/rsync                  </Rsync_Path>
<Rsync_Option>                  ssh -1                          </Rsync_Option>
<Rsync_Compress>                yes                             </Rsync_Compress>
<Pg_Dump_Path>                  /usr/local/pgsql/bin/pg_dump    </Pg_Dump_Path>
<When_Stand_Alone>              read_only                       </When_Stand_Alone>
<Replication_Timeout>           1 min                           </Replication_Timeout>
<LifeCheck_Timeout>             3s                              </LifeCheck_Timeout>
<LifeCheck_Interval>            11s                             </LifeCheck_Interval>
#-------------------------------------------------------------
# set partitional replicate control information
#     set DB name and Table name to stop reprication
#       o DB_Name :             DB name
#       o Table_Name :  Table name
#-------------------------------------------------------------
#<Not_Replicate_Info>
#       <DB_Name>               test_db         </DB_Name>
#       <Table_Name>            log_table       </Table_Name>
#</Not_Replicate_Info>

--注意上面的<Host_Name>部分.不同的机器需要设置相对应主机名


--设置replicate server
su - postgres
cd /usr/local/pgsql/share
cp pgreplicate.conf.sample pgreplicate.conf
vi pgreplicate.conf
#=============================================================
#  PGReplicate configuration file
#-------------------------------------------------------------
# file: pgreplicate.conf
#-------------------------------------------------------------
# This file controls:
#       o which hosts & port are cluster server
#       o which port use for replication request from cluster server
#=============================================================
#
#-------------------------------------------------------------
# A setup of Cluster DB(s)
#
#               o Host_Name :           The host name of Cluster DB.
#                                       Please write a host name by FQDN.
#                                       DO NOT write IP address.
#               o Port :                The connection port with postmaster.
#               o Recovery_Port :       The connection port at the time of
#                                       a recovery sequence.
#-------------------------------------------------------------
<Cluster_Server_Info>
   <Host_Name>                 cluster_1                       </Host_Name>
   <Port>                      5432                            </Port>
   <Recovery_Port>             7001                            </Recovery_Port>
</Cluster_Server_Info>
<Cluster_Server_Info>
   <Host_Name>                 cluster_2                       </Host_Name>
   <Port>                      5432                            </Port>
   <Recovery_Port>             7001                            </Recovery_Port>
</Cluster_Server_Info>
#<Cluster_Server_Info>
#    <Host_Name>                cluster3.pgcluster.org          </Host_Name>
#    <Port>                     5432                            </Port>
#    <Recovery_Port>            7001                            </Recovery_Port>
#</Cluster_Server_Info>
#
#-------------------------------------------------------------
# A setup of Load Balance Server
#
#               o Host_Name :           The host name of a load balance server.
#                                       Please write a host name by FQDN or IP address.
#               o Recovery_Port :       The connection port at the time of
#                                       a recovery sequence .
#-------------------------------------------------------------
<LoadBalance_Server_Info>
       <Host_Name>             loadbalancer                    </Host_Name>
       <Recovery_Port>         6001                            </Recovery_Port>
</LoadBalance_Server_Info>
#
#------------------------------------------------------------
# A setup of the cascade connection between replication servers.
# When you do not use RLOG recovery, you can skip this setup
#
#               o Host_Name :   The host name of the upper replication server.
#                               Please write a host name by FQDN or IP address.
#               o Port :        The connection port with postmaster.
#               o Recovery_Port : The connection port at the time of
#                                 a recovery sequence .
#------------------------------------------------------------
#<Replicate_Server_Info>
#       <Host_Name>             upper_replicate.pgcluster.org   </Host_Name>
#       <Port>                  8002                            </Port>
#       <Recovery_Port>         8102                            </Recovery_Port>
#</Replicate_Server_Info>
#
#-------------------------------------------------------------
# A setup of a replication server
#
#               o Host_Name :           The host name of the this replication server.
#                                       Please write a host name by FQDN or IP address.
#               o Replicate_Port :      Connection port for replication
#               o Recovery_Port :       Connection port for recovery
#               o RLOG_Port :           Connection port for replication log
#               o Response_mode :       Timing which returns a response
#                                       normal   -- return result of DB which received the query
#                                       reliable -- return result after waiting for response of
#                               all Cluster DBs.
#               o Use_Replication_Log : Use replication log
#                                       [yes/no]. default : no
#               o Replication_Timeout : Timeout of each replication response
#               o Lifecheck_Timeout :   Timeout of the lifecheck response
#               o Lifecheck_Interval :  Interval time of the lifecheck
#                                       (range 1s - 1h)
#                                       10s   -- 10 seconds
#                                       10min -- 10 minutes
#                                       1h    -- 1 hours
#-------------------------------------------------------------
<Host_Name>                     replicate_upper         </Host_Name>
<Replication_Port>              8001                            </Replication_Port>
<Recovery_Port>         8101                            </Recovery_Port>
<RLOG_Port>                     8301                            </RLOG_Port>
<Response_Mode>         normal                          </Response_Mode>
<Use_Replication_Log>           no                              </Use_Replication_Log>
<Replication_Timeout>           1min                            </Replication_Timeout>
<LifeCheck_Timeout>             3s                              </LifeCheck_Timeout>
<LifeCheck_Interval>            15s                             </LifeCheck_Interval>
#-------------------------------------------------------------
# A setup of a log files
#
#               o File_Name :   Log file name with full path
#               o File_Size :   Maximum size of each log files
#                               Please specify in a number and unit(K or M)
#                                 10  -- 10 Byte
#                                 10K -- 10 KByte
#                                 10M -- 10 MByte
#               o Rotate :      Rotation times
#                               If specified 0, old versions are removed.
#-------------------------------------------------------------
<Log_File_Info>
       <File_Name>             /tmp/pgreplicate.log    </File_Name>
       <File_Size>             1M                      </File_Size>
       <Rotate>                3                       </Rotate>
</Log_File_Info>


--启动replicate server
/usr/local/pgsql/bin/pgreplicate -D /usr/local/pgsql/share
--/usr/local/pgsql/bin/pgreplicate -D /usr/local/pgsql/share stop

--启动cluster db server
/usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data -o "-U"
--/usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data

--启动loadbalancer server
/usr/local/pgsql/bin/pglb -D /usr/local/pgsql/share
--/usr/local/pgsql/bin/pglb -D /usr/local/pgsql/share stop


--最后测试一下是否成功
su - postgres
pgsql -h 192.168.0.11
create table demo (id int);
insert into demo values(1);
insert into demo values(2);
insert into demo values(3);
select * from demo;
\q
pgsql -h 192.168.0.12
select * from demo;
\q
数据库相关 | 评论(1) | 引用(0) | 阅读(831)
机票 Email Homepage
2008/07/19 00:00
友情链接:国际机票
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
昵称   密码   游客无需密码
网址   电邮   [注册]
               

验证码 不区分大小写