您的位置:首页 > 其它

10分钟搞定,slony的安装和配置

2013-08-23 12:17 796 查看
最近要配置Postgres的数据复制功能(replication)

Replication 分为2类:synchronization 和 asynchronization

在Postgres的最新版本里,已经自带了synchronization replication功能

同样Postgres也支持asynchronization的复制

而我们今天要说的是,使用slony,第三方软件来做异步复制

http://www.postgresql.org/docs/9.2/static/high-availability.html

在上面这个链接,能够得到详情

安装与配置slony
1,编译源代码和安装 (conf_slon.sh)

#!/bin/bash

#install slon

cd /tmp/rpms/64bit/postgresql/slony

tar zxvf slony1-2.1.3.tar.gz ./

cd /tmp/rpms/64bit/postgresql/slony/slony1-2.1.3

./configure --with-pgconfigdir=/usr/pgsql-9.2/bin/--with-perltools

make clean

make

sudo make install

sudo mkdir /etc/slon

2,编写slony启动配置文件 (slon.conf)

新建一个文件叫slon.conf,内容如下:

# cluster_name名字随便取

cluster_name='BOA_4'

#host,dbname,user一定要填写正确,并且还有对应的访问权限

conn_info='host=* dbname=* user=*'

#进程ID号的存放文件,主要用于重启时用到

pid_file='/var/log/boa/slon_pid.file'

把这个文件拷贝到这个目录下,稍后的配置里将用到这个文件

sudo cp slon.conf /etc/slon/

3,配置master,slave的节点 (configure_slony.sh)

##############################

#!/bin/sh

SLONIK=/usr/pgsql-9.2/bin/slonik #slony的安装路径

CLUSTERNAME=BOA_4 #名字要和slon.conf的一致

REPLICATIONUSER=* # 能够访问数据库的用户名

MASTERDBNAME=* # 主数据库的名字

SLAVEDBNAME=* # 从数据库的名字

MASTERHOST=* # 主数据库的名字

SLAVEHOST=* # 从数据库的名字

$SLONIK <<_EOF_

cluster name = $CLUSTERNAME;

node 1 admin conninfo = 'dbname=$MASTERDBNAMEhost=$MASTERHOST user=$REPLICATIONUSER';

node 2 admin conninfo = 'dbname=$SLAVEDBNAME host=$SLAVEHOSTuser=$REPLICATIONUSER';

init cluster(id=1,comment='Master Node');

#创建set

create set (id=1,origin=1,comment='All pgbench tables');

#创需要同步的表的名字,这些表一定要在数据库中真实存在的

set add table (set id=1,origin=1,id=1,fully qualifiedname='public.pgbench_accounts',comment='accounts table');

set add table (set id=1,origin=1,id=2,fully qualifiedname='public.pgbench_branches',comment='branches table');

set add table (set id=1,origin=1,id=3,fully qualifiedname='public.pgbench_tellers',comment='tellers table');

set add table (set id=1,origin=1,id=4,fully qualifiedname='public.pgbench_history',comment='history table');

store node (id=2,comment='Slave node',event node=1);

store path (server=1,client=2,conninfo='dbname=$MASTERDBNAMEhost=$MASTERHOST user=$REPLICATIONUSER');

store path (server=2,client=1,conninfo='dbname=$SLAVEDBNAMEhost=$SLAVEHOST user=$REPLICATIONUSER');

node 1 admin conninfo = 'dbname=$MASTERDBNAMEhost=$MASTERHOST user=$REPLICATIONUSER';

node 2 admin conninfo = 'dbname=$SLAVEDBNAME host=$SLAVEHOSTuser=$REPLICATIONUSER';

subscribe set (id=1,provider=1,receiver=2,forward=no);

_EOF_

########################

4,启动slony(start_slon.sh)

需要在主从两台机器上都启动slony

启动脚本为start_slon.sh,该脚本可以在源代码下找到,修改属性如下:

SLON_BIN_PATH=/usr/pgsql-9.2/bin

SLON_LOG=/var/log/boa/slon.log

SLON_CONF=/etc/slon/slon.conf #在步骤2里,我们配置了该文件

拷贝该文件到/etc/init.d/下

启动方式:/etc/init.d/start_slon.sh[start|stop|status]

可以从该链接下载到相关的sh脚本和slony源代码
http://download.csdn.net/detail/alajl/5998271
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: