环境
3台服务器,分布式部署如下:
安装部署
(注:以下部署流程中所设计的IP、端口、HOME/DATA等路径需根据实际环境进行替换,此处仅为举例说明)
1. 使用LightDB安装包安装分布式多机单实例模式,安装完成后形成1CN 2DN环境,每个服务器上运行一个实例(具体部署步骤可根据LightDB安装手册进行操作
http://www.light-pg.com/docs/LightDB_Install_Manual/current/install.html#id3
http://www.light-pg.com/docs/LightDB_Install_Manual/current/install.html#id30)
2. 分别修改三个实例配置文件$LTDATA/lightdb.conf中的shared_preload_libraries,添加ltcluster(注:需添加在canopy之后)
shared_preload_libraries='canopy,ltcluster,lt_stat_statements,lt_stat_activity,lt_prewarm,lt_cron,lt_hint_plan,lt_show_plans'
修改后重启数据库;
3. 在CN节点库中执行以下三条SQL:
create extension ltcluster;
create role ltcluster superuser password 'ltcluster' login;
create database ltcluster owner ltcluster;
分别在两个DN节点库中执行以下一条SQL:
create database ltcluster owner ltcluster;
4. 在DN1节点的$LTHOME/etc/ltcluster下创建ltcluster.conf配置文件,内容如下(以下IP、端口、路径均针对DN1节点数据库,此处仅作举例):
node_id=1295432
node_name='192168111295432'
conninfo='host=192.168.11.129 port=5432 user=ltcluster dbname=ltcluster connect_timeout=2'
data_directory='$LTDATA'
pg_bindir='$LTHOME/bin'
failover='automatic'
promote_command='$LTHOME/bin/ltcluster standby promote -f $LTHOME/etc/ltcluster/ltcluster.conf'
follow_command='$LTHOME/bin/ltcluster standby follow -f $LTHOME/etc/ltcluster/ltcluster.conf --upstream-node-id=%n'
restore_command='cp $LTHOME/archive/%f %p'
monitoring_history=true #(Enable monitoring parameters)
monitor_interval_secs=2 #(Define monitoring data interval write time parameter)
connection_check_type='ping'
reconnect_attempts=3 #(before failover,Number of attempts to reconnect to primary before failover(default 6))
reconnect_interval=5
standby_disconnect_on_failover =true
failover_validation_command='$LTHOME/etc/ltcluster/ltcluster_failover.sh "$LTHOME" "$LTDATA"'
log_level=INFO
log_facility=STDERR
log_file=’$LTHOME/etc/ltcluster/ltcluster.log'
shutdown_check_timeout=1800
use_replication_slots=true
check_lightdb_command='$LTHOME/etc/ltcluster/check_lightdb.sh'
check_lightdb_interval=10
5. DN1节点上执行以下两条命令:
ltcluster primary register -f $LTHOME/etc/ltcluster/ltcluster.conf –F
ltclusterd -d -f $LTHOME/etc/ltcluster/ltcluster.conf -p $LTHOME/etc/ltcluster/ltcluster.pid
此时DN1主已注册添加完成;
6. 在DN2节点服务器上使用LightDB安装包安装一个单机版数据库并创建实例,这里端口以5435为例,该实例作为DN1主的备节点;
7. 修改该实例配置文件$LTDATA/lightdb.conf中的shared_preload_libraries,添加ltcluster:
shared_preload_libraries='ltcluster,lt_stat_statements,lt_stat_activity,lt_prewarm,lt_cron,lt_hint_plan,lt_show_plans'
修改后重启数据库;
8. 在DN2 5435库中执行以下三条SQL:
create extension ltcluster;
create role ltcluster superuser password 'ltcluster' login;
create database ltcluster owner ltcluster;
9. 停止DN2 5435实例,在DN2 5435的$LTHOME/etc/ltcluster下创建ltcluster.conf配置文件,内容如下(以下IP、端口、路径均针对为DN2 5435单机版数据库,此处仅作举例):
node_id=1305435
node_name='192168111305435'
conninfo='host=192.168.11.130 port=5435 user=ltcluster dbname=ltcluster connect_timeout=2'
data_directory='$LTDATA'
pg_bindir='$LTHOME/bin'
failover='automatic'
promote_command='$LTHOME/bin/ltcluster standby promote -f $LTHOME/etc/ltcluster/ltcluster.conf'
follow_command='$LTHOME/bin/ltcluster standby follow -f $LTHOME/etc/ltcluster/ltcluster.conf --upstream-node-id=%n'
restore_command='cp $LTHOME/archive/%f %p'
monitoring_history=true #(Enable monitoring parameters)
monitor_interval_secs=2 #(Define monitoring data interval write time parameter)
connection_check_type='ping'
reconnect_attempts=3 #(before failover,Number of attempts to reconnect to primary before failover(default 6))
reconnect_interval=5
standby_disconnect_on_failover =true
failover_validation_command='$LTHOME/etc/ltcluster/ltcluster_failover.sh "$LTHOME" "$LTDATA"'
log_level=INFO
log_facility=STDERR
log_file=’$LTHOME/etc/ltcluster/ltcluster.log'
shutdown_check_timeout=1800
use_replication_slots=true
check_lightdb_command='$LTHOME/etc/ltcluster/check_lightdb.sh'
check_lightdb_interval=10
10. DN2 5435备机克隆
ltcluster -h $DN1_PRIMARY_IP -p $DN1_PRIMARY_PORT -U ltcluster –d ltcluster -f $DN2_5435_HOME/etc/ltcluster/ltcluster.conf standby clone –F
(克隆时间根据DN1 主库大小时间不定)
克隆完成后修改DN2 5435的DATA/lightdb.conf,将port改为5435
port=5435
启动DN2 5435数据库;
11. DN2 5435注册为从节点
ltcluster standby register -f $LTHOME/etc/ltcluster/ltcluster.conf –F
ltclusterd -d -f $LTHOME/etc/ltcluster/ltcluster.conf -p $LTHOME/etc/ltcluster/ltcluster.pid
此时DN1主-DN2备高可用已完成;
12. 可使用以下命令查看DN的主备状态:
ltcluster –f $LTHOME/etc/ltcluster/ltcluster.conf cluster show
ltcluster –f $LTHOME/etc/ltcluster/ltcluster.conf service status
13. DN2主-DN1备环境搭建与上述的DN1主-DN2备操作步骤相同,此处不再赘述。
标签:LightDB,5435,LTHOME,ltcluster,etc,conf,DN2,1CN2DN,分布式 From: https://www.cnblogs.com/xxl-cr7/p/17084745.html