首页 > 代码库 > Slony-I双机备份

Slony-I双机备份

测试环境:postgresql 9.3.5,slony-I2.2.3(application stack builder提供)以下参考网上教程亲自测试总结

-----------------------------------------------------------------------------------------------------------------------

主机:192.168.19.1    从机:192.168.19.2

(主从机)数据库名称:postgres,用户名:postgres,密码:admin

-----------------------------------------------------确保通讯----------------------------------------------------------

1.关闭主机和从机的防火墙(或者打通5432端口,允许通过防火墙)

2.修改主从机pg_hba.conf文件,这两步都是确保通讯正常

# IPv4 local connections:host    all             all             127.0.0.1/32            md5host    all             all             192.168.19.0/24         trust//new add line

-----------------------------------------------------配置从机----------------------------------------------------------

1.在从机上安装slony-I2.2.3

2.进入%PG%/bin 运行命令slon -regservice,注册slony-I服务,这时在任务管理器中的服务一列可见此项。

3.在从机上bin下加入配置文件slony_slave.conf,进入%PG%/bin 运行命令slon -addengine slony_slave.conf

#集群名称cluster_name = Cluster #连接从服务器的信息conn_info = dbname=postgres host=192.168.19.2 user=postgres password=admin

4.在任务管理器中的服务一列开启slony-I服务。

-----------------------------------------------------配置主机----------------------------------------------------------

前四步与从机一样。

1.在主机上安装slony-I2.2.3

2.进入%PG%/bin 运行命令slon -regservice,注册slony-I服务,这时在任务管理器中的服务一列可见此项。

3.在主机上bin下加入配置文件slony_master.conf,进入%PG%/bin 运行命令slon -addengine slony_master.conf

#集群名称cluster_name = Cluster #连接主服务器的信息conn_info = dbname=postgres host=192.168.19.1 user=postgres password=admin

4.在任务管理器中的服务一列开启slony-I服务。

5.在主机上bin下加入配置文件master.script,进入%PG%/bin 运行命令slonik master.script

cluster name = Cluster; #指明要定义的Cluster名 node 1 admin conninfo = ‘dbname=postgres host=192.168.19.1 user=postgres password=admin‘; node 2 admin conninfo = ‘dbname=postgres host=192.168.19.2 user=postgres password=admin‘; init cluster(id = 1, comment = ‘Master Cluster‘); #初始化Cluster,ID从1开始store node ( id = 2, comment = ‘Slave Node‘, event node=1); #定义从库节点 #定义路由路径#主节点store path ( server=1, client=2, conninfo = ‘dbname=postgres host=192.168.19.1 user=postgres password=admin‘);store path ( server=2, client=1, conninfo = ‘dbname=postgres host=192.168.19.2 user=postgres password=admin‘);#添加事件监听#设置侦听事件和订阅方向,复制中角色,主节点是原始提供者,从节点是接受者store listen ( origin = 1, provider = 1, receiver = 2 );store listen ( origin = 2, provider = 2, receiver = 1 ); create set ( id = 1, origin = 1, comment = ‘Data Provider‘ ); #定义复制集, origin指明主库 set add table ( set id = 1, origin = 1, id = 1, fully qualified name = ‘public.Point‘, comment=‘Point Table‘ );#为复制集合中增加表, fully qualified name 指明了要复制的表名.SUBSCRIBE SET (ID = 1, PROVIDER = 1, RECEIVER = 2, FORWARD = YES);

-----------------------------------------------------配置完成----------------------------------------------------------

pgAdmin3下主机可以看到如图技术分享,从机也差不多这些东西。现在在主机上对point表做的任何改变,从机是也是跟着变的。

注意:主从机备份表的结构要一致,备份的表要有主键否则会出错。

 

Slony-I双机备份