达梦数据的主备集群搭建

数据准备
查看主备库的数据库版本一致
主库版本
[dmdba@redhat tool]$ ./disql SYSDBA/123456789@localhost:5237
SQL> CONN SYSDBA/[email protected]:5237
Server[192.168.64.130:5237]:mode is normal, state is open
login used time: 79.375(ms)
SQL> select * from v$version;
LINEID BANNER


1 DM Database Server 64 V8
2 DB Version: 0x7000a
used time: 17.466(ms). Execute id is 1012.
备库版本
[dmdba@redhat tool]$ ./disql SYSDBA/123456789@LOCALHOST:5237
disql V8
SQL> CONN SYSDBA/[email protected]:5237
服务器[192.168.64.129:5237]:处于普通打开状态
登录使用时间: 73.510(毫秒)
SQL> SELECT * FROM V$VERSION;

行号 BANNER


1 DM Database Server 64 V8
2 DB Version: 0x7000a
已用时间: 92.678(毫秒). 执行号:4.

在主机上创建数据库:[dmdba@redhat bin]$ ./dminit PATH=/opt/dmdbms/data PAGE_SIZE=16 DB_NAME=TEST INSTANCE_NAME=TEST

方法一:备份数据库
直接采用复制文件的方式将主库复制到备库上,查询两个库的永久魔数
root@redhat tool]# ./disql SYSDBA/123456789@localhost:2537
disql V8
SQL> conn SYSDBA/[email protected]:2537
[-70028]:Create SOCKET connection failure.
SQL> conn SYSDBA/[email protected]:2537
[-70028]:Create SOCKET connection failure.
SQL> conn SYSDBA/[email protected]:5237

Server[192.168.64.130:5237]:mode is normal, state is open
login used time: 15.940(ms)
SQL> select file_lsn,cur_lsn from v$rlog;

LINEID FILE_LSN CUR_LSN


1 53046 53046

used time: 34.189(ms). Execute id is 28.
SQL>
[root@redhat ~]# cd /opt/dmdbms/tool
[root@redhat tool]# ./disql SYSDBA/123456789@localhost:2537
disql V8
SQL> conn SYSDBA/[email protected]:5237

服务器[192.168.64.129:5237]:处于普通打开状态
登录使用时间: 76.909(毫秒)
SQL> select file_lsn,cur_lsn from v$rlog;

行号 FILE_LSN CUR_LSN


1 58213 58213

已用时间: 132.136(毫秒). 执行号:21.
SQL>
发现永久函数不一致,所以要换别的方式备份数据库

方法二:备份数据库
使用命令的方式备份数据库
首先查询主库的永久模数和lsn
[dmdba@redhat init.d]$ cd /opt/dmdbms/bin
[dmdba@redhat bin]$ ./disql SYSDBA/SYSDBA@localhost:5236

Server[localhost:5236]:mode is normal, state is open
login used time: 22.629(ms)
disql V8
SQL> select file_lsn.cur_lsn from v r l o g ; s e l e c t f i l e l s n . c u r l s n f r o m v rlog; select file_lsn.cur_lsn from v rlog;selectfilelsn.curlsnfromvrlog;
[-2207]:Error in line: 1
Member access ["V R L O G " . F I L E L S N . C U R L S N ] u n r e s o l v e d . u s e d t i m e : 5.116 ( m s ) . E x e c u t e i d i s 0. S Q L > S E L E C T F I L E L S N , C U R L S N F R O M V RLOG".FILE_LSN.CUR_LSN] unresolved. used time: 5.116(ms). Execute id is 0. SQL> SELECT FILE_LSN,CUR_LSN FROM V RLOG".FILELSN.CURLSN]unresolved.usedtime:5.116(ms).Executeidis0.SQL>SELECTFILELSN,CURLSNFROMVRLOG;

LINEID FILE_LSN CUR_LSN


1 44065 44065

used time: 14.983(ms). Execute id is 4.
SQL> SELECT PERMANENT_MAGIC;

LINEID PERMANENT_MAGIC


1 1490129029

used time: 22.214(ms). Execute id is 5.

查看DMAP服务是否开启,并且将数据库实例的服务关闭
[dmdba@redhat init.d]$ ps -ef|grep dmser
dmdba 9178 8488 0 16:02 pts/0 00:00:00 grep dmser
[dmdba@redhat init.d]$ ps -ef|grep dmap
dmdba 1896 1 0 11:05 ? 00:00:54 /opt/dmdbms/bin/dmap
dmdba 9182 8488 0 16:03 pts/0 00:00:00 grep dmap

将数据库实例TEST1进行备份
[dmdba@redhat bin]$ ./dmrman
dmrman V8
RMAN> BACKUP DATABASE ‘/opt/dmdbms/data/TEST1/dm.ini’ full backupset ‘/opt/dmdbms/data/dmbak1/testfull’;

将备份好的文件dbbak1传到备库的服务器上,在备库上创建一个文件夹TEST1,将主库TEST1的dm.ini和dm.ctl文件传到备库的服务器上的TEST1目录下。
在备库执行还原命令,还原数据库。
[dmdba@redhat bin]$ ./dmrman
dmrman V8
RMAN> RESTORE DATABASE ‘/opt/dmdbms/data/TEST1/dm.ini’ FROM BACKUPSET ‘/opt/dmdbms/data/dmbak1/testfull’;
RMAN> RECOVER DATABASE ‘/opt/dmdbms/data/TEST1/dm.ini’ FROM BACKUPSET ‘/opt/dmdbms/data/dmbak1/testfull’;
RMAN> RECOVER DATABASE ‘/opt/dmdbms/data/TEST1/dm.ini’ update DB_MAGIC;
备份执行完之后,以mount方式启动主备机器
[dmdba@redhat bin]$ ./dmserver …/data/TEST/dm.ini mount
使用disql命令查询备库的永久魔数和lsn号:
[dmdba@redhat bin]$ ./disql SYSDBA/SYSDBA@localhost:5236

Server[localhost:5236]:mode is normal, state is mount
login used time: 47.429(ms)
disql V8
SQL> select PERMANENT_MAGIC;

LINEID PERMANENT_MAGIC


1 231139257

used time: 106.582(ms). Execute id is 1.
[dmdba@redhat bin]$ ./disql SYSDBA/SYSDBA@localhost:5236

服务器[localhost:5236]:处于普通配置状态
登录使用时间: 36.881(毫秒)
disql V8
SQL> select PERMANENT_MAGIC;

行号 PERMANENT_MAGIC


1 231139257

已用时间: 175.549(毫秒). 执行号:1.
SQL> SELECT FILE_LSN,CUR_LSN FROM V$RLOG;

行号 FILE_LSN CUR_LSN


1 38159 38159

已用时间: 14.000(毫秒). 执行号:2.
SQL> EXIT;
实验证明方法二的备份还原方式可以保证主备库的lsn号和永久模数一致。
在整个配置过程中主备库的状态都是mount状态,切不可改成其他的状态
配置主备库
主库的配置
dm.ini的配置
INSTANCE_NAME = GRP1_RT_01
PORT_NUM = 32141 #数据库实例监听端口
DW_PORT = 33141 #守护环境下,监听守护进程连接端口
DW_ERROR_TIME = 60 #接收守护进程消息超时时间
ALTER_MODE_STATUS = 1 #不允许手工方式修改实例模式/状态
ENABLE_OFFLINE_TS = 2 #不允许备库OFFLINE表空间
MAL_INI = 1 #打开MAL系统
ARCH_INI = 1 #打开归档配置
RLOG_SEND_APPLY_MON = 64 #统计最近 64 次的日志重演信息

dmmal.ini的配置
MAL_CHECK_INTERVAL =5
MAL_CONN_FAIL_INTERVAL =5
[MAL_INST1]
MAL_INST_NAME = GRP1_RT_01
MAL_HOST = 192.168.64.133
MAL_PORT = 61141
MAL_INST_HOST = 192.168.64.131
MAL_INST_PORT = 32141
MAL_DW_PORT = 52141
MAL_INST_DW_PORT = 33141

[MAL_INST2]
MAL_INST_NAME = GRP1_RT_02
MAL_HOST = 192.168.64.129
MAL_PORT = 61142
MAL_INST_HOST = 192.168.64.132
MAL_INST_PORT = 32142
MAL_DW_PORT = 52142
MAL_INST_DW_PORT = 33142

dmarch.ini的配置
[ARCHIVE_REALTIME]
ARCH_TYPE = REALTIME
ARCH_DEST = GRP1_RT_02
[ARCHIVE_LOCAL1]
ARCH_TYPE = LOCAL
ARCH_DEST = /opt/dmdbms/data/TEST/arch
ARCH_FILE_SIZE = 128
ARCH_SPACE_LIMIT = 0
dmwatcher.ini的配置
[GRP1]
DW_TYPE = GLOBAL
DW_MODE = AUTO
DW_ERROR_TIME = 10
INST_RECOVER_TIME = 60
INST_ERROR_TIME = 10
INST_OGUID = 453331
INST_INI = /opt/dmdbms/data/TEST/dm.ini
INST_AUTO_RESTART = 1
INST_STARTUP_CMD = /opt/dmdbms/bin/dmserver
RLOG_SEND_THRESHOLD = 0
RLOG_APPLY_THRESHOLD = 0

使主库数据库以mount状态开启
./dmserver /opt/dmdbms/data/TEST/dm.ini mount
进入disql修改主库模式为primary:
Alter database primary;
查看主库的模式和状态
[dmdba@redhat bin]$ ./disql SYSDBA/SYSDBA@localhost:32141

服务器[localhost:32142]:处于备库配置状态
登录使用时间: 20.382(毫秒)
disql V8
SQL> select mode$ from v$instance;

LINEID MODE$


1 PRIMARY

used time: 7.597(ms). Execute id is 2.
SQL> select status$ from v$instance;

LINEID STATUS$


1 MOUNT

used time: 5.485(ms). Execute id is 3.
SQL>
备库的配置
dm.ini的配置
INSTANCE_NAME = GRP1_RT_02
PORT_NUM = 32142 #数据库实例监听端口
DW_INACTIVE_INTERVAL = 60 #接收守护进程消息超时时间
ALTER_MODE_STATUS = 0 #不允许手工方式修改实例模式/状态/OGUID
ENABLE_OFFLINE_TS = 2 #不允许备库 OFFLINE 表空间
MAL_INI = 1 #打开 MAL 系统
ARCH_INI = 1 #打开归档配置
RLOG_SEND_APPLY_MON = 64 #统计最近 64 次的日志重演信息

dmmal.ini的配置
MAL_CHECK_INTERVAL = 5
MAL_CONN_FAIL_INTERVAL = 5
[MAL_INST1]
MAL_INST_NAME = GRP1_RT_01
MAL_HOST = 192.168.64.133
MAL_PORT = 61141
MAL_INST_HOST = 192.168.64.131
MAL_INST_PORT = 32141
MAL_DW_PORT = 52141
MAL_INST_DW_PORT = 33141
[MAL_INST2]
MAL_INST_NAME = GRP1_RT_02
MAL_HOST = 192.168.64.129
MAL_PORT = 61142
MAL_INST_HOST = 192.168.64.132
MAL_INST_PORT = 32142
MAL_DW_PORT = 52142
MAL_INST_DW_PORT = 33142

dmarch.ini的配置
[ARCHIVE_REALTIME]
ARCH_TYPE = REALTIME
ARCH_DEST = GRP1_RT_01
[ARCHIVE_LOCAL1]
ARCH_TYPE = LOCAL
ARCH_DEST = /opt/dmdbms/data/TEST/arch
ARCH_FILE_SIZE = 128
ARCH_SPACE_LIMIT = 0
dmwatcher.ini的配置
[GRP1]
DW_TYPE = GLOBAL
DW_MODE = AUTO
DW_ERROR_TIME = 10
INST_RECOVER_TIME = 60
INST_ERROR_TIME = 10
INST_OGUID = 453331
INST_INI = /opt/dmdbms/data/TEST/dm.ini
INST_AUTO_RESTART = 1
INST_STARTUP_CMD = /opt/dmdbms/bin/dmserver
RLOG_SEND_THRESHOLD = 0
RLOG_APPLY_THRESHOLD = 0

使备库数据库以mount状态开启
./dmserver /opt/dmdbms/data/TEST/dm.ini mount
进入disql修改主库模式为primary:
Alter database standby;
查看备库的模式和状态
[dmdba@redhat bin]$ ./disql SYSDBA/SYSDBA@localhost:32142

服务器[localhost:32142]:处于备库配置状态
登录使用时间: 20.382(毫秒)
disql V8
SQL> select status$ from v$instance;

行号 STATUS$


1 MOUNT

已用时间: 13.516(毫秒). 执行号:5.
SQL> select mode$ from v$instance;

行号 MODE$


1 STANDBY

配置监视器
[dmdba@redhat TEST]$ vi dmmonitor.ini
我的监视器是配置在备库上的
MON_DW_CONFIRM = 1
MON_LOG_PATH = /opt/dmdbms/data/log
MON_LOG_INTERVAL = 60
MON_LOG_FILE_SIZE = 32
MON_LOG_SPACE_LIMIT = 0
[GRP1]
MON_INST_OGUID = 453331
MON_DW_IP = 192.168.64.133:52141
MON_DW_IP = 192.168.64.129:52142
关闭主备库的防火墙,记住一定要在root用户下关闭防火墙
[root@redhat init.d]# service iptables stop 这是临时关闭
[root@redhat init.d]# service iptables status最好是永久关闭
开启主备库的守护进程
[dmdba@redhat bin]$ ./dmwatcher …/data/TEST/dmwatcher.i
[dmdba@redhat bin]$ ./dmwatcher …/data/TEST/dmwatcher.ini
开启监控
[dmdba@redhat bin]$./dmmonitor /opt/dmdbms/data/TEST/dmmonitor.ini
达梦数据的主备集群搭建_第1张图片

你可能感兴趣的:(达梦数据的主备集群搭建)