注册
单机在线改主备
专栏/技术分享/ 文章详情 /

单机在线改主备

M4x7 2025/08/29 11 0 0
摘要

目前版本(2025 年第一季度版本 - 8.1.4.80)已经支持单机在线转变为主备集群。

1 环境规划

1.1 机器信息

机器 硬件类型 版本信息 备注
主机 IP 192.168.40.134/135 ip a
CPU x86_64 11th Gen Intel® Core™ i5-11300H @ 3.10GHz lscpu
内存 2.8Gi 2.0Gi可用 free -h
存储 34G 可用 df -h fdisk -l
操作系统 Kylin Linux Advanced Server V10 (Sword) hostnamectl
达梦数据库 dm8_20250423_x86_kylin10_64

1.2 端口规划

实例名 DM01 DM02
MAL_HOST 192.168.40.134 192.168.40.135
MAL_PORT 61141 61142
MAL_INST_HOST 192.168.40.134 192.168.40.135
MAL_INST_PORT 5236 5236
MAL_DW_PORT 52141 52142
MAL_INST_DW_PORT 33141 33142

2 主机

2.1 开启本地归档

select * from  v$dm_arch_ini where ARCH_IS_VALID='Y';

若没有配置,则开启

ALTER DATABASE MOUNT;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE ADD ARCHIVELOG 'DEST = /opt/dmdbms/data/DM01/arch, TYPE = local,FILE_SIZE = 1024, SPACE_LIMIT = 204800';
ALTER DATABASE OPEN;

2.2 对主库进行备份

在业务低峰操作

BACKUP DATABASE FULL BACKUPSET 'FULL_BAK_20250815' COMPRESSED LEVEL 1 PARALLEL 4;

2.3 在线添加dmmal

CALL SF_MAL_INST_ADD_APPLY('MAL_INST','DM01','192.168.40.134',61141,'192.168.40.134',5236,52141,0,33141);
CALL SF_MAL_INST_ADD_APPLY('MAL_INST1','DM02','192.168.40.135',61142,'192.168.40.135',5236,52142,0,33142);
CALL SP_SET_PARA_VALUE(1,'MAL_INI',1);

2.4 添加realtime归档

ALTER DATABASE ADD ARCHIVELOG 'TYPE=REALTIME,DEST=DM02';

2.5 主库新增dmwatcher

创建 dmwatcher.ini 文件

[DM01]  #注意组
DW_TYPE = GLOBAL
DW_MODE = AUTO
DW_ERROR_TIME = 10
INST_RECOVER_TIME = 60
INST_ERROR_TIME = 10
INST_OGUID = 20250815
INST_INI = /opt/dmdbms/data/DM01/dm.ini               # 注意路径
INST_AUTO_RESTART = 1
INST_STARTUP_CMD = /opt/dmdbms/bin/dmserver
RLOG_SEND_THRESHOLD = 0
RLOG_APPLY_THRESHOLD = 0

修改主库oguid 以及数据库状态

./disql SYSDBA/'"Dameng@123"'

alter database primary force;
sp_set_oguid(20250815);        # 注意oguid

3 备机

3.0 查询主机参数

SELECT BANNER FROM V$VERSION;


SELECT '数据库版本', CAST((select build_version from v$instance) AS VARCHAR(100))
UNION ALL
SELECT '授权类型', CAST((select server_type from v$license) AS VARCHAR(100))
UNION ALL
SELECT '文件序列号', CAST((SELECT SERIES_NO FROM V$LICENSE) AS VARCHAR(100))
UNION ALL
SELECT '服务器颁布类型', CAST((SELECT SERVER_SERIES FROM V$LICENSE) AS VARCHAR(100))
UNION ALL
SELECT '有效日期', CAST((SELECT EXPIRED_DATE FROM V$LICENSE) AS VARCHAR(100))
UNION ALL
SELECT '用户名称', 
  CAST((SELECT AUTHORIZED_CUSTOMER FROM V$LICENSE) AS VARCHAR(100))
UNION ALL
SELECT '授权用户数', 
  CAST((SELECT AUTHORIZED_USER_NUMBER FROM V$LICENSE) AS VARCHAR(100))
UNION ALL
SELECT '服务器版本号', 
  CAST((SELECT SVR_VERSION FROM V$INSTANCE) AS VARCHAR(100))
UNION ALL
SELECT '服务器启动时间', 
  CAST((SELECT START_TIME FROM V$INSTANCE) AS VARCHAR(100))
UNION ALL
SELECT '页大小', 
  CAST((SELECT PAGE()) AS VARCHAR(100))
UNION ALL
SELECT '簇大小', 
  CAST((SELECT SF_GET_EXTENT_SIZE()) AS VARCHAR(100))
UNION ALL
SELECT '大小写敏感', 
  CAST((SELECT CASE_SENSITIVE()) AS VARCHAR(100))
UNION ALL
SELECT '字符集', 
  CAST((SELECT UNICODE()) AS VARCHAR(100))
UNION ALL
SELECT '库状态', 
  CAST((SELECT STATUS$ FROM V$INSTANCE) AS VARCHAR(100))
UNION ALL
SELECT '当前节点的模式', 
  CAST((SELECT MODE$ FROM V$INSTANCE) AS VARCHAR(100));

3.1 新建备库实例并还原

./dminit db_name=DM02 instance_name=DM02 page_size=32 extent_size=32 case_sensitive=1 charset=0 SYSDBA_PWD=Dameng@123 SYSAUDITOR_PWD=Dameng@123  path=/opt/dmdbms/data/

主机:
scp -r /opt/dmdbms/data/DM01/bak/FULL_BAK_20250815 dmdba@192.168.40.135:/opt/dmdbms/data/DM02/bak/

备机:
./dmrman CTLSTMT="RESTORE DATABASE '/opt/dmdbms/data/DM02/dm.ini' FROM BACKUPSET '/opt/dmdbms/data/DM02/bak/FULL_BAK_20250815'"
./dmrman CTLSTMT="RECOVER DATABASE '/opt/dmdbms/data/DM02/dm.ini' FROM BACKUPSET '/opt/dmdbms/data/DM02/bak/FULL_BAK_20250815'"
./dmrman CTLSTMT="RECOVER DATABASE '/opt/dmdbms/data/DM02/dm.ini' UPDATE DB_MAGIC"

3.2 备库修改配置文件

从主库传输dmmal.ini、dmarch.ini、dmwatcher.ini到备库

dm.ini 修改 MAL_INI = 1 ARCH_INI = 1

dmmal.ini 无需修改

dmarch.ini 修改 ARCH_DEST 和 ARCH_DEST

dmwatcher.ini 修改 INST_INI 路径

示例:

dmmal.ini

MAL_CHECK_INTERVAL     = 30
MAL_COMBIN_BUF_SIZE    = 0
MAL_SEND_THRESHOLD = 2048
MAL_CONN_FAIL_INTERVAL = 10
MAL_LOGIN_TIMEOUT      = 15
MAL_BUF_SIZE           = 100
MAL_SYS_BUF_SIZE       = 0
MAL_VPOOL_SIZE         = 128
MAL_COMPRESS_LEVEL     = 0
MAL_TEMP_PATH          =

[MAL_INST]
    MAL_INST_NAME    = DM01
    MAL_HOST         = 192.168.40.134
    MAL_PORT         = 61141
    MAL_INST_HOST    = 192.168.40.134
    MAL_INST_PORT    = 5236
    MAL_DW_PORT      = 52141
    MAL_LINK_MAGIC   = 0
    MAL_INST_DW_PORT = 33141

[MAL_INST1]
    MAL_INST_NAME    = DM02
    MAL_HOST         = 192.168.40.135
    MAL_PORT         = 61142
    MAL_INST_HOST    = 192.168.40.135
    MAL_INST_PORT    = 5236
    MAL_DW_PORT      = 52142
    MAL_LINK_MAGIC   = 0
    MAL_INST_DW_PORT = 33142

dmarch.ini

        ARCH_WAIT_APPLY      = 0

[ARCHIVE_LOCAL1]
        ARCH_TYPE            = LOCAL
        ARCH_DEST            = /opt/dmdbms/data/DM02/arch
        ARCH_FILE_SIZE       = 2048
        ARCH_SPACE_LIMIT     = 102400
        ARCH_FLUSH_BUF_SIZE  = 2
        ARCH_HANG_FLAG       = 1
[ARCHIVE_REALTIME1]
        ARCH_TYPE            = REALTIME
        ARCH_DEST            = DM01             # 注意主库名称

        WAIT_APPLY           = 0
        ARCH_FAILOVER        = 0

dmwatcher.ini

[DM01]
DW_TYPE = GLOBAL
DW_MODE = AUTO
DW_ERROR_TIME = 10
INST_RECOVER_TIME = 60
INST_ERROR_TIME = 10
INST_OGUID = 20250815
INST_INI = /opt/dmdbms/data/DM02/dm.ini
INST_AUTO_RESTART = 1
INST_STARTUP_CMD = /opt/dmdbms/bin/dmserver
RLOG_SEND_THRESHOLD = 0
RLOG_APPLY_THRESHOLD = 0

3.3 使用mount状态启动新实例

/opt/dmdbms/bin/dmserver /opt/dmdbms/data/DM02/dm.ini mount

3.4 修改oguid以及数据库状态

./disql SYSDBA/'"Dameng@123"'

alter database standby;
sp_set_oguid(20250815);

4 验证

4.1 启动新旧实例的 dmwatcher

./dmwatcher /opt/dmdbms/data/DM01/dmwatcher.ini

./dmwatcher /opt/dmdbms/data/DM02/dmwatcher.ini

4.2 监视器

vi /opt/dmdbms/data/DM02/dmmonitor.ini

MON_LOG_PATH = /opt/dmdbms/bin/log
MON_LOG_INTERVAL = 60
MON_LOG_FILE_SIZE = 32
MON_LOG_SPACE_LIMIT = 2048
MON_DW_CONFIRM             = 0  #0:非确认(故障手切) 1:确认(故障自切)

[DM01]
MON_INST_OGUID = 20250815
MON_DW_IP = 192.168.40.134:52141
MON_DW_IP = 192.168.40.135:52142

/opt/dmdbms/bin/dmmonitor /opt/dmdbms/data/DM02/dmmonitor_manual.ini

LNVluraTBYHwWahAo3hB4tiv5DwE4Q90tvyEW4mbB3o.png

评论
后发表回复

作者

文章

阅读量

获赞

扫一扫
联系客服