达梦DM8数据守护主备集群搭建

DM8守护集群 (类似于Oracle的DataGuard) 但是通过搭建过程 感觉 部署十分方便,搭建难度小于oracle的 DataGuard

其原理也是 操作系统平台,达梦版本相同的数据库 通过主库传输 归档日志到备库,备库通过实时应用主库的归档日志,使主库和备份 数据实时同步

并且,备库可以对外提供查询服务。

搭建的过程如下:

 

#####修改主机名 (两台机器都做)

hostnamectl set-hostname dmdbserver2

 

###修改操作系统限制 (两台机器都做)
cat >> /etc/security/limits.conf << EOF
dmdba soft nproc 16384
dmdba hard nproc 16384
dmdba soft nofile 65536
dmdba hard nofile 65536
EOF

####关闭防火墙 (两台机器都做)
systemctl stop firewalld
systemctl disable firewalld
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

 

 

####挂载DM光盘: (两台机器都做)

mount -o loop dm8_20220701_x86_rh6_64_ent_8.1.2.128.iso /mnt

 

######################## 配置 YUM (两台机器都做)

/dev/sr0 3.7G 3.7G 0 100% /run/media/root/RHEL-7.1 Server.x86_64


umount /run/media/root/RHEL-7.6\ Server.x86_64/
mount /dev/cdrom /media -o loop

cd /etc/yum.repos.d


vi rhel7.repo ----------------或者--------------- local.repo

[local]
baseurl=file:///media
name=this is a local repo
enabled=1
gpgcheck=0


yum clean all;
yum list all;

 


###安装依赖包
yum install *glibc* -y
yum install *libXp* -y
yum install *libXt* -y
yum install *libXtst* -y

 

 

 

 

#### 下一步 修改 主库 dmdw1 的dm.ini文件

vi /dmdata/dmdw/dm.ini


MAL_INI = 1 ## 0 变为 1
ARCH_INI = 1 ## 0 变为 1


ALTER_MODE_STATUS = 0 #Whether to permit database user to alter database mode and status by SQLs, 1: yes, 0: no
ENABLE_OFFLINE_TS = 2 #Whether tablespace can be offline

#### 新建文件 vi /dmdata/dmdw/dmmal.ini


MAL_CHECK_INTERVAL = 5 #MAL链路检测时间间隔
MAL_CONN_FAIL_INTERVAL = 5 #判定MAL链路断开的时间
[MAL_INST1]
MAL_INST_NAME = dmdw1 #实例名,和dm.ini中的INSTANCE_NAME一致
MAL_HOST = 10.10.10.150 #MAL系统监听TCP连接的IP地址 心跳地址
MAL_PORT = 61141 #MAL系统监听TCP连接的端口
MAL_INST_HOST = 192.168.115.150 #实例的对外服务IP地址
MAL_INST_PORT = 5236 #实例的对外服务端口,和dm.ini中的PORT_NUM一致
MAL_DW_PORT = 52141 #实例本地的守护进程监听TCP连接的端口
MAL_INST_DW_PORT = 33141 #实例监听守护进程TCP连接的端口
[MAL_INST2]
MAL_INST_NAME = dmdw2 #### 需要修改
MAL_HOST = 10.10.10.160
MAL_PORT = 61142
MAL_INST_HOST = 192.168.115.160
MAL_INST_PORT = 5236
MAL_DW_PORT = 52142
MAL_INST_DW_PORT = 33142

 


######## 新建立和 配置 vi /dmdata/dmdw/dmarch.ini

su - dmdba
mkdir -p /dmdata/arch


[ARCHIVE_REALTIME]
ARCH_TYPE = REALTIME #实时归档类型
ARCH_DEST = dmdw2 #实时归档目标实例名
[ARCHIVE_LOCAL1]
ARCH_TYPE = LOCAL #本地归档类型
ARCH_DEST = /dmdata/arch #本地归档文件存放路径
ARCH_FILE_SIZE = 128 #单位Mb,本地单个归档文件最大值
ARCH_SPACE_LIMIT = 0 #单位Mb,0表示无限制,范围1024~4294967294M

######## 新建立和 配置 vi /dmdata/dmdw/dmwatcher.ini

修改dmwatcher.ini配置守护进程,配置为全局守护类型,使用自动切换模式。

[GRP1]
DW_TYPE = GLOBAL #全局守护类型
DW_MODE = AUTO #自动切换模式
DW_ERROR_TIME = 10 #远程守护进程故障认定时间
INST_RECOVER_TIME = 60 #主库守护进程启动恢复的间隔时间
INST_ERROR_TIME = 10 #本地实例故障认定时间
INST_OGUID = 453331 #守护系统唯一OGUID值
INST_INI = /dmdata/dmdw/dm.ini #dm.ini配置文件路径
INST_AUTO_RESTART = 1 #打开实例的自动启动功能
INST_STARTUP_CMD = /dm/dmdbms/bin/dmserver #命令行方式启动
RLOG_SEND_THRESHOLD = 0 #指定主库发送日志到备库的时间阀值,默认关闭
RLOG_APPLY_THRESHOLD = 0 #指定备库重演日志的时间阀值,默认关闭

 

 

 

主库脱机备份:


cd /dm/dmdbms/bin
./dmrman

 

### 一号机 dmdw1 上执行脱机备份
### 备份出来的 dbfull 是个目录

backup database '/dmdata/dmdw/dm.ini' full backupset '/dmdata/dbfullbackup';

##把脱机备份集拷贝到2号机 dmdw2

scp -rp dbfullbackup/ 192.168.115.138:/dmdata/.

 


### 在2号机器dmdw2进行还原


cd /dm/dmdbms/bin
./dmrman

restore database '/dmdata/dmdw/dm.ini' from backupset '/dmdata/dbfullbackup';

recover database '/dmdata/dmdw/dm.ini' from backupset '/dmdata/dbfullbackup';

recover database '/dmdata/dmdw/dm.ini' update db_magic;

 

 

 


#### 启动 主库 dmdw1 到 mount状态 设置 OGUID

cd /dm/dmdbms/bin
./dmserver /dmdata/dmdw/dm.ini mount


SP_SET_PARA_VALUE(1, 'ALTER_MODE_STATUS', 1);
sp_set_oguid(453331);
SP_SET_PARA_VALUE(1, 'ALTER_MODE_STATUS', 0);


alter database primary;

 


#### 启动 主库 dmdw2 到 mount状态 设置 OGUID


cd /dm/dmdbms/bin
./dmserver /dmdata/dmdw/dm.ini mount


SP_SET_PARA_VALUE(1, 'ALTER_MODE_STATUS', 1);
sp_set_oguid(453331);
SP_SET_PARA_VALUE(1, 'ALTER_MODE_STATUS', 0);


alter database standby;

 

 

 

#######主库启动守护进程

/dm/dmdbms/bin/dmwatcher /dmdata/dmdw/dmwatcher.ini

 


#######备库启动守护进程

/dm/dmdbms/bin/dmwatcher /dmdata/dmdw/dmwatcher.ini

 

 

######## 注册守护进程为服务的形式

su - root

cd /dm/dmdbms/script/root
./dm_service_installer.sh -t dmwatcher -watcher_ini /dmdata/dmdw/dmwatcher.ini -p dmdw1

su - root
cd /dm/dmdbms/script/root
./dm_service_installer.sh -t dmwatcher -watcher_ini /dmdata/dmdw/dmwatcher.ini -p dmdw2

 


######## 注册 监视器 服务的形式

su - root

vi /dmdata/dmdw/dmmonitor.ini

cd /dm/dmdbms/script/root
./dm_service_installer.sh -t dmmonitor -monitor_ini /dmdata/dmmonitor.ini -p dmdw150160

 

 

7、启动监视器

/dm/dmdbms/bin/dmmonitor /dmdata/dmmonitor_0.ini


/dm/dmdbms/bin/dmmonitor /dmdata/dmmonitor.ini


MON_DW_CONFIRM = 1 #确认监视器模式
MON_LOG_PATH = /dmdata/log #监视器日志文件存放路径
MON_LOG_INTERVAL = 60 #每隔60s定时记录系统信息到日志文件
MON_LOG_FILE_SIZE = 32 #每个日志文件最大32
MON_LOG_SPACE_LIMIT = 0 #不限定日志文件总占用空间
[GRP1]
MON_INST_OGUID = 453331 #组GRP1的唯一OGUID值

#以下配置为监视器到组GRP1的守护进程的连接信息,以―IP:PORT‖的形式配置
#IP对应dmmal.ini中的MAL_HOST,PORT对应dmmal.ini中的MAL_DW_PORT
MON_DW_IP = 192.168.115.150:52141
MON_DW_IP = 192.168.115.160:52142

 


其他命令:

监视器里输入:

show global info

show arch send info DMDW2
show apply stat DMDW2


#### 5 s 自动刷新显示
show i 5

stop dmwatcher grp1
startup dmwatcher grp1


#### 停止 组里所有的数据库
stop group grp1

startup group grp1


### 停止单库

login

detach database dmdw2
stop database dmdw2
startup database dmdw2

attach database dmdw2


###查看 系统运行状态
tip

 


切换命令 :
正常切换 switchover

login
choose switchover grp1

switchover grp1.dmdw2

switchover grp1.dmdw1

choose takeover grp1

check recover dmdw2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


#=============================================================================================#
#------------------------------------FOR GLOBAL COMMAND---------------------------------------#
1.help --show help information
2.exit --exit dmmonitor
3.show version --show self dmmonitor version
4.show global info --show global database information of all groups
5.show database [group_name.]db_name --show detail database information of specified database
6.show [group_name] --show detail database information of specified group, if not specified, it will show all groups
7.show i[nterval] n --auto show database information in console every n seconds
8.q --cancel 'auto show' in console
9.list [[group_name.]db_name] --list configuration of specified dmwatcher, if not specified, it will show all dmwatchers
10.show open info [group_name.]db_name --show open history of specified database
11.show arch send info [group_name.]db_name --show source database arch send info to specified database(include recover time info)
12.show apply stat [group_name.]db_name --show specified database apply stat
13.show monitor [group_name[.]] [db_name] --show all dmmonitor connection info of specified dmwatcher

14 show state --show state of all monitors which are in the same monitor group with current monitor

15.tip --show system currently working status

16.login --login dmmonitor
17.logout --logout dmmonitor

18.get takeover time --get how much time will delay before standby instance will do takeover

---Type q/Q <return> to quit, or <return> to continue---

#=============================================================================================#
#------------------------------------FOR GROUP COMMAND----------------------------------------#
19.startup dmwatcher [group_name] --startup watching specified group
20.stop dmwatcher [group_name] --stop watching specified group
21.startup group [group_name] --startup all databases of specified group
22.stop group [group_name] --exit all databases of specified group
23.kill group [group_name] --kill all active databases of specified group

24.choose switchover [group_name] --choose databases which can do switchover
25.choose takeover [group_name] --choose databases which can do takeover
26.choose takeover force [group_name] --choose databases which can do takeover force

27.set group [group_name] auto restart on --set all instances of specified group auto restart on
28.set group [group_name] auto restart off --set all instances of specified group auto restart off

29.set group [group_name] para_name para_value --set all dmwatchers of specified group configuration(set both ini file and value in memory)
--if group_name not specified, it will notify all groups to execute
--para_name: specified parameter name, para_value: specified parameter value
--can set parameters: DW_ERROR_TIME/INST_RECOVER_TIME/INST_ERROR_TIME/INST_AUTO_RESTART/
INST_SERVICE_IP_CHECK/RLOG_SEND_THRESHOLD/RLOG_APPLY_THRESHOLD

30.set group [group_name] recover time time_value --set all standby database of specified group recover time with time_value(time_value is an integer: 3~86400(s))(only set value in dmwatcher memory)
--if group_name not specified, it will notify all groups to execute

31.set group [group_name] arch invalid --set all standby databases of specified group arch status invalid
--if group_name not specified, it will notify all groups to execute

32.clear group [group_name] arch send info --clear source database recent arch send info to all standby databases of specified group(notify source database to execute)
--if group_name not specified, it will notify all groups to execute

33.clear group [group_name] apply stat --clear all standby databases of specified group recent arch apply stat(notify all standby databases to execute)
--if group_name not specified, it will notify all groups to execute

---Type q/Q <return> to quit, or <return> to continue---

#=============================================================================================#
#------------------------------------FOR DATABASE COMMAND-------------------------------------#
34.check recover [group_name.]db_name --check specified database of specified group can be auto recovered or not
35.check open [group_name.]db_name --check specified database of specified group can be auto opened or not

36.open database [group_name.]db_name --open specified database of specified group
37.switchover [group_name[.]] [db_name] --switchover specified database of specified group as primary database
38.takeover [group_name[.]] [db_name] --use specified database of specified group to takeover as primary database
39.takeover force [group_name[.]] [db_name] --use specified database of specified group to takeover as primary database forcefully

40.set database [group_name.]db_name recover time time_value --set specified database of specified group recover time with time_value(time_value is an integer: 3~86400(s))(only set in dmwatcher memory)
41.set database [group_name.]db_name arch invalid --set specified database of specified group arch status invalid

42.detach database [group_name.]db_name --detach specified standby database from specified group
43.attach database [group_name.]db_name --attach specified standby database to specified group

44.startup dmwatcher database [group_name.]db_name --startup watching specified database
45.stop dmwatcher database [group_name.]db_name --stop watching specified database

46.startup database [group_name.]db_name --startup specified database of specified group
47.stop database [group_name.]db_name --stop specified database of specified group
48.kill database [group_name.]db_name --kill specified database of specified group

49.clear database [group_name.]db_name arch send info --clear primary database recent arch send info to specified standby database(notify primary database to execute)
50.clear database [group_name.]db_name apply stat --clear specified standby database recent arch apply stat(notify standby database to execute)
51.set database [group_name.]db_name until time time_val --set specified database of specified group archive send until time with time_val
52.cancel database [group_name.]db_name until time --cancel specified database of specified group archive send until time

---Type q/Q <return> to quit, or <return> to continue---

#=============================================================================================#
#------------------------------------FOR MPP COMMAND------------------------------------------#
53.show mpp --show mpp site info
54.startup dmwatcher all --startup watching all groups
55.stop dmwatcher all --stop watching all groups
56.startup group all --startup all database of all groups
57.stop group all --exit all database of all groups
58.kill group all --kill active database of all groups

59.check mppctl --check all active primary databases' dmmpp.ctl files are same or not
60.recover mppctl --recover all active primary databases' dmmpp.ctl files to be same

#=============================================================================================#

 

 

达梦社区地址:https://eco.dameng.com

 

posted @ 2022-09-10 19:45  stone469  阅读(439)  评论(1编辑  收藏  举报