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
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
相关文章推荐
- 10分钟搞定Windows环境下hadoop安装和配置
- 轻松八步搞定Cacti配置安装(原创视频)
- postgresql+slony-i安装配置主从
- 30分钟搞定EBS套件安装及配置
- 轻松八步搞定Cacti配置安装(原创视频)
- 六步搞定Linux Oracle 11gR2 配置安装
- Linux系统指定目录下安装配置Mysql 5.7.15步骤图文详解,只需5分钟搞定
- [转]PostgreSQL数据库同步Slony-I的安装和配置
- windows服务,安装、启动、停止,配置,一个批处理文件搞定
- 【转】让你10分钟搞定Mac--最简单快速的虚拟安装
- 10分钟搞定linux编辑器vim的配置
- PostgreSQL和Slony-I的安装和配置
- 搞定VCS4.0 For Oracle RAC安装配置
- 6步搞定基于Ubuntu Linux的Hadoop的安装与配置
- 让你10分钟搞定Mac--最简单快速的虚拟安装
- 10分钟快速入门Redis,从安装到启动配置
- 轻松八步搞定Cacti配置安装(原创视频)
- 关于ROS安装快而简洁的办法~适合初学者或无开发经验者“10分钟”即可搞定
- Linux下安装openldap 启动及配置一站式搞定
- postgresql+slony-i安装配置主从