DM7 使用dminit工具创建数据库

1 功能简介
dminit是DM数据库初始化工具。在安装DM的过程中,用户可以选择是否创建初始数据库。如果当时没有创建,那么在安装完成之后,可以利用创建数据库工具dminit来创建。

系统管理员可以利用dminit工具提供的各种参数,设置数据库存放路径、段页大小、是否对大小写敏感、以及是否使用UNICODE等,创建出满足用户需要的数据库。该工具位于安装目录的/bin目录下。

2 使用dminit
dminit工具需要从命令行启动。找到dminit所在安装目录/bin,输入dminit和参数后回车。参数在下一节详细介绍。
语法如下:
dminit KEYWORD=value { KEYWORD=value }
KEYWORD:dminit参数关键字。多个参数之间排列顺序无影响,参数之间使用空格间隔。value:参数取值。

dminit如果没有带参数,系统会引导用户进行设置。参数、等号和值之间不能有空格,例如PAGE_SIZE=16。HELP参数的后面不用添加“=”号。

例如,初始化一个数据库,放在/home/test/dmdbms目录下,数据页PAGE_SIZE大小为16K。

./dminit PATH=/home/test/dmdbms PAGE_SIZE=16 

如果创建成功,则屏幕显示如下:

initdb V7.1.5.22-Build(2015.11.17-62910trunc)
db version: 0x70009
create dm database success. 2015-12-21 15:46:27

此时在/home/test/dmdbms目录下会出现一个DAMENG文件夹,内容包含初始数据库DAMENG的相关文件和DM数据库启动所必须的配置文件dm.ini。

3 查看dminit参数
dminit使用较为灵活,参数较多。用户可使用“dminit HELP”快速查看各参数。

[dmdba@ora19c bin]$ ./dminit help
initdb V7.1.6.46-Build(2018.02.08-89107)ENT 
db version: 0x7000a
file dm.key not found, use default license!
License will expire on 2020-06-05
Format:  ./dminit         KEYWORD=value

Example: ./dminit         PATH=/public/dmdb/dmData PAGE_SIZE=16

Keyword                     Explanation(default value)
--------------------------------------------------------------------------------
INI_FILE                    dm.ini path
PATH                        database path
CTL_PATH                    control file path
LOG_PATH                    log file path
EXTENT_SIZE                 extent size of data file(16), optional value: 16,32, unit: PAGE
PAGE_SIZE                   page size(8), optional value: 4,8,16,32, unit: K
LOG_SIZE                    log file size(256), unit: M, range: 64M ~ 2G
CASE_SENSITIVE              whether case is sensitive(Y), optional value: Y/N or 1/0
CHARSET/UNICODE_FLAG        CHARSET(0), optional value:0[GB18030],1[UTF-8],2[EUC-KR]
LENGTH_IN_CHAR              whether LENGTH for VARCHAR is in characters(N), optional value: Y/N, 1/0
SYSDBA_PWD                  set SYSDBA password(SYSDBA), password length must between 9 and 48
SYSAUDITOR_PWD              set SYSAUDITOR password(SYSAUDITOR), password length must between 9 and 48
DB_NAME                     database name(DAMENG)
INSTANCE_NAME               instance name(DMSERVER)
PORT_NUM                    listener port(5236)
TIME_ZONE                   set time zone(+08:00)
PAGE_CHECK                  page check mode(0), optional value: 0/1/2
EXTERNAL_CIPHER_NAME        set default encrypt/decrypt algorithm
EXTERNAL_HASH_NAME          set default hash algorithm
EXTERNAL_CRYPTO_NAME        set crypto name to encrypt svr key
RLOG_ENC_FLAG               whether encrypt redo log(N), optional value: Y/N, 1/0
USBKEY_PIN                  set usbkey pin
ENCRYPT_NAME                set algorithm for encrypt the whole database
BLANK_PAD_MODE              set blank padding mode(0), optional value:0/1
SYSTEM_MIRROR_PATH          mirror path of system data file
MAIN_MIRROR_PATH            mirror path of main file
ROLL_MIRROR_PATH            mirror path of roll file
MAL_FLAG                    MAL_INI flag(0) in dm.ini
ARCH_FLAG                   ARCH_INI(0) flag in dm.ini
MPP_FLAG                    MPP_INI(0) flag in dm.ini
CONTROL                     control file path!
AUTO_OVERWRITE              whether overwrite all files with the same name(0) 0: no 1: part 2: all
USE_NEW_HASH                whether use new hash algorithm for string. (default 1)
DCP_MODE                    whether is DM CLUSTER PROXY mode(default 0)
DCP_PORT_NUM                in DCP mode, set dcp_port_num
ELOG_PATH                   set the path of log file recording the contents during initialization
HELP                        print help information

4 dminit初始化数据库
CONTROL参数是dminit工具的高级功能,用于初始化数据库时指定初始化配置文件。初始化配置文件是一个保存了各数据文件路径和大小设置、所有dminit工具的命令行参数设置等信息的文本,名称由用户自己选取,例如:dminit.ini 、abc.txt、dminit.ctl等。

dminit工具使用CONTROL参数,就不能再指定其他参数,CONTROL参数只能单独使用。

DM既支持初始化单机数据库,又支持初始化RAC集群的数据库。操作非常简单,只要在使用dminit工具创建数据库的时候,使用CONTROL参数指定初始化配置文件即可。

例如:初始化配置文件为dminit.ini。

./dminit CONTROL=/home/data/dminit.ini 

初始化配置文件(本章统一命名为dminit.ini)内容如何书写,单机和RAC环境下略有不同,下面分别详细介绍。

4.1 初始化单机数据库
DM支持初始化数据库到一个普通机器上或是一个共享存储上。本节以文件系统为例,初始化单机数据库。涉及路径和文件大小的参数配置。

例如,在文件系统上创建数据库。参数path、main、system、roll、ctl_path、log01、log02都指定了文件系统,单机配置文件(命名dminit.ini)书写如下:

[dmdba@ora19c dm7]$ cat dminit.ini
[jy] --实例名使用control配置文件指定实例不能使用instance_name参数
db_name = jy
path =/dm7/data
main = /dm7/data/jy/main.dbf
main_size = 256
system = /dm7/data/jy//system.dbf
system_size = 256
roll = /dm7/data/jy//roll.dbf
roll_size = 256
ctl_path = /dm7/data/jy/dm.ctl
log_path = /dm7/data/jy/log01.log
log_path = /dm7/data/jy/log02.log
log_size = 128
auto_overwrite = 2

初始化数据库
[dmdba@ora19c bin]$ ./dminit control=/dm7/dminit.ini
initdb V7.1.6.46-Build(2018.02.08-89107)ENT 
db version: 0x7000a
file dm.key not found, use default license!
License will expire on 2020-06-05

 log file path: /dm7/data/jy/log01.log


 log file path: /dm7/data/jy/log02.log

write to dir [/dm7/data/jy].
create dm database success. 2020-05-22 22:36:10


注册数据库服务
[root@ora19c root]# ./dm_service_installer.sh -t dmserver -p jy -i /dm7/data/jy/dm.ini -m open
ln -s '/usr/lib/systemd/system/DmServicejy.service' '/etc/systemd/system/multi-user.target.wants/DmServicejy.service'
Finished to create the service (DmServicejy)
[root@ora19c root]# systemctl start DmServicejy
[root@ora19c root]# ps -ef | grep dmserver
dmdba    31843     1 21 01:29 ?        00:00:05 /dm7/bin/dmserver /dm7/data/jy/dm.ini -noconsole
root     31901  3225  0 01:30 pts/2    00:00:00 grep --color=auto dmserver

连接数据库
[dmdba@ora19c ~]$ disql SYSDBA/SYSDBA@10.13.13.140:5236

Server[10.13.13.140:5236]:mode is normal, state is open
login used time: 10.975(ms)
disql V7.1.6.46-Build(2018.02.08-89107)ENT 
Connected to: DM 7.1.6.46
SQL> select * from v$version;

LINEID     BANNER                                                       
---------- -------------------------------------------------------------
1          DM Database Server x64 V7.1.6.46-Build(2018.02.08-89107)ENT  
2          DB Version: 0x7000a

used time: 3.827(ms). Execute id is 807.

4.2初始化RAC集群的数据库
DM RAC是一个单数据库、多实例的集群系统,数据库部署在共享存储上,供所有节点访问,具有高可用性、高性能、低成本等特性。DM支持在RAC环境下创建数据库。RAC的初始化库配置文件dminit.ini中涉及到的参数,是在单机dminit.ini基础上,增加了RAC节点信息。同时,把单机dminit.ini中node_instance参数去掉,log_size,log_path二个参数下放到每个RAC节点里。

准备dminit.ini 配置文件
在2个节点的/dm/dmdbms/data目录下创建 dminit.ini 配置文件,添加如下内容。 在2个节点都创建。

[dmdba@dmrac1 data]$ vi dminit.ini
db_name = rac
system_path = +DMDATA/data
system = +DMDATA/data/rac/system.dbf
system_size = 128
roll = +DMDATA/data/rac/roll.dbf
roll_size = 128
main = +DMDATA/data/rac/main.dbf
main_size = 128
ctl_path = +DMDATA/data/rac/dm.ctl
ctl_size = 8
log_size = 256
dcr_path = /dev/raw/raw1 #dcr 磁盘路径,目前不支持 asm,只能是裸设备
dcr_seqno = 0
auto_overwrite = 1

[RAC0] #inst_name 跟 dmdcr_cfg.ini 中 DB 类型 group 中 DCR_EP_NAME 对应
config_path = /dm7/data/rac0_config
port_num = 5236
mal_host = 10.10.10.161
mal_port = 9340
log_path = +DMLOG/log/rac0_log01.log
log_path = +DMLOG/log/rac0_log02.log

[RAC1] #inst_name 跟 dmdcr_cfg.ini 中 DB 类型 group 中 DCR_EP_NAME 对应
config_path = /dm7/data/rac1_config
port_num = 5236
mal_host = 10.10.10.162
mal_port = 9341
log_path = +DMLOG/log/rac1_log01.log
log_path = +DMLOG/log/rac1_log02.log


[dmdba@dmrac2 data]$ vi dminit.ini
db_name = rac
system_path = +DMDATA/data
system = +DMDATA/data/rac/system.dbf
system_size = 128
roll = +DMDATA/data/rac/roll.dbf
roll_size = 128
main = +DMDATA/data/rac/main.dbf
main_size = 128
ctl_path = +DMDATA/data/rac/dm.ctl
ctl_size = 8
log_size = 256
dcr_path = /dev/raw/raw1 #dcr 磁盘路径,目前不支持 asm,只能是裸设备
dcr_seqno = 0
auto_overwrite = 1

[RAC0] #inst_name 跟 dmdcr_cfg.ini 中 DB 类型 group 中 DCR_EP_NAME 对应
config_path = /dm7/data/rac0_config
port_num = 5236
mal_host = 10.10.10.161
mal_port = 9340
log_path = +DMLOG/log/rac0_log01.log
log_path = +DMLOG/log/rac0_log02.log

[RAC1] #inst_name 跟 dmdcr_cfg.ini 中 DB 类型 group 中 DCR_EP_NAME 对应
config_path = /dm7/data/rac1_config
port_num = 5236
mal_host = 10.10.10.162
mal_port = 9341
log_path = +DMLOG/log/rac1_log01.log
log_path = +DMLOG/log/rac1_log02.log

使用dminit初始化数据库
在任意节点启动 dminit 工具初始化数据库。dminit 执行完成后,会在 config_path 目录(/dm7/data/rac0_config 和/dm7/data/rac1_config)下生成配置文件 dm.ini 和 dmmal.ini。

[dmdba@dmrac1 data]$ dminit control=/dm7/data/dminit.ini
initdb V7.1.6.46-Build(2018.02.08-89107)ENT
db version: 0x7000a
file dm.key not found, use default license!
License will expire on 2020-05-08

 log file path: +DMLOG/log/rac0_log01.log


 log file path: +DMLOG/log/rac0_log02.log


 log file path: +DMLOG/log/rac1_log01.log


 log file path: +DMLOG/log/rac1_log02.log

write to dir [+DMDATA/data/rac].
create dm database success. 2020-04-24 16:39:03

将节点一的配置文件复制到节点二:

[dmdba@dmrac1 data]$ scp -r rac1_config 10.13.13.162:`pwd`
The authenticity of host '10.13.13.162 (10.13.13.162)' can't be established.
RSA key fingerprint is 89:fc:3e:e3:2d:27:94:07:0e:6b:fc:c5:e8:89:44:1f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.13.13.162' (RSA) to the list of known hosts.
dmdba@10.13.13.162's password:
sqllog.ini                                                                                                                                                                                                100%  479     0.5KB/s   00:00
dm.ini                                                                                                                                                                                                    100%   40KB  39.8KB/s   00:00
dmmal.ini                                                                                                                                                                                                 100%  204     0.2KB/s   00:00
[dmdba@dmrac1 data]$

启动数据库服务器
1、在2个节点分别注册DM 数据库服务:
节点一:

[root@dmrac1 init.d]# /dm7/script/root/dm_service_installer.sh -t dmserver -i /dm7/data/rac0_config/dm.ini -d /dm7/data/dmdcr.ini -p rac1
Move the service script file(/dm7/bin/DmServicerac1 to /etc/rc.d/init.d/DmServicerac1)
Finished to create the service (DmServicerac1)

节点二:
[root@dmrac2 ~]# /dm7/script/root/dm_service_installer.sh -t dmserver -i /dm7/data/rac1_config/dm.ini -d /dm7/data/dmdcr.ini -p rac2
Move the service script file(/dm7/bin/DmServicerac2 to /etc/rc.d/init.d/DmServicerac2)
Finished to create the service (DmServicerac2)

2、启动数据库

[root@dmrac1 init.d]# service DmServicerac1 start
Starting DmServicerac1: [ OK ]

[root@dmrac2 ~]# service DmServicerac2 start
Starting DmServicerac2: [ OK ]

手工启动命令如下,手工启动后窗口不能关闭,所以

./dmserver /dm7/data/rac0_config/dm.ini dcr_ini=/dm7/data/dmdcr.ini
./dmserver /dm7/data/rac1_config/dm.ini dcr_ini=/dm7/data/dmdcr.ini

连接数据库验证
1 配置服务名文件

[dmdba@dmrac1 ~]$ vi /etc/dm_svc.conf
TIME_ZONE=(480)
rac=(10.13.13.161:5236,10.13.13.162:5236)
SWITCH_TIME=(10000)
SWITCH_INTERVAL=(10)

TIME_ZONE=(480)
LANGUAGE=(en)

[dmdba@dmrac2 ~]$ vi /etc/dm_svc.conf
TIME_ZONE=(480)
rac=(10.13.13.161:5236,10.13.13.162:5236)
SWITCH_TIME=(10000)
SWITCH_INTERVAL=(10)

TIME_ZONE=(480)
LANGUAGE=(en)

2连接RAC集群

[dmdba@dmrac1 ~]$ disql SYSDBA/SYSDBA@rac

Server[10.13.13.161:5236]:mode is normal, state is open
login used time: 10.365(ms)
disql V7.1.6.46-Build(2018.02.08-89107)ENT
Connected to: DM 7.1.6.46
SQL> select instance_name from v$instance;

LINEID     INSTANCE_NAME
---------- -------------
1          RAC0

used time: 18.248(ms). Execute id is 807.
SQL> select * from v$rac_ep_info;

LINEID     EP_NAME EP_SEQNO    EP_GUID              EP_TIMESTAMP         EP_MODE EP_STATUS
---------- ------- ----------- -------------------- -------------------- ------- ---------
1          RAC0    0           2067076818           2067077298           MASTER  OK
2          RAC1    1           2067098084           2067098537           SLAVE   OK

used time: 2.741(ms). Execute id is 808.

DM7使用裸设备搭建DMRAC

一、操作环境
主机 IP地址(对外服务) IP地址(内部通信) 实例名 操作系统

dmrac1	10.18.13.165	         10.10.10.165	        rac0	Redhat 6.7
dmrac2	10.18.13.166	         10.10.10.166	        rac1	Redhat 6.7

共享存储

/dev/sdb1	/dev/raw/raw1	dcr disk	2G
/dev/sdb2	/dev/raw/raw2	voting disk	2G
/dev/sdb3	/dev/raw/raw3	data disk1	2G
/dev/sdb4	/dev/raw/raw4	data disk2	2G
/dev/sdb1	/dev/raw/raw5	data disk3	2G
/dev/sdb2	/dev/raw/raw6	data disk4	2G
/dev/sdb3	/dev/raw/raw7	log disk1	2G
/dev/sdb4	/dev/raw/raw8	log disk2	2G
/dev/sdb1	/dev/raw/raw9	log disk3	2G
/dev/sdb2	/dev/raw/raw10	log disk4	2G
/dev/sdb3	/dev/raw/raw11	log disk5	2G
/dev/sdb4	/dev/raw/raw12	log disk6	2G

二、操作系统配置
1、关闭防火墙和SELINUX

[root@cs ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: nat mangle filter [  OK  ]
iptables: Flushing firewall rules: [  OK  ]
iptables: Unloading modules: [  OK  ]
[root@cs ~]# chkconfig iptables off
[root@cs ~]# setenforce 0
[root@cs ~]# sed -i s:^SELINUX=.*$:SELINUX=disabled:g /etc/selinux/config

[root@cs ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: nat mangle filter [  OK  ]
iptables: Flushing firewall rules: [  OK  ]
iptables: Unloading modules: [  OK  ]
[root@cs ~]# chkconfig iptables off
[root@cs ~]# setenforce 0
[root@cs ~]# sed -i s:^SELINUX=.*$:SELINUX=disabled:g /etc/selinux/config

2、修改主机名

[root@cs ~]# hostname dm1
[root@cs ~]# sed -i s:^HOSTNAME=.*$:HOSTNAME=dm1:g /etc/sysconfig/network


[root@cs ~]# hostname dm2
[root@cs ~]# sed -i s:^HOSTNAME=.*$:HOSTNAME=dm2:g /etc/sysconfig/network

3、修改hosts文件
[root@cs ~]# echo "
> 10.18.13.165   dm1
> 10.18.13.166   dm2" >> /etc/hosts
[root@cs ~]#


[root@cs ~]# echo "
> 10.18.13.165   dm1
> 10.18.13.166   dm2" >> /etc/hosts
[root@cs ~]#

三、 安装达梦软件
安装操作详见Oracle Linux 7.1中安装达梦数据库DM7

四、绑定UDEV

[root@dm1 rules.d]# vi 99-dm-devices.rules
ACTION=="add", KERNEL=="sdb1", RUN+="/bin/raw /dev/raw/raw1 %N"
ACTION=="add", KERNEL=="sdb2", RUN+="/bin/raw /dev/raw/raw2 %N"
ACTION=="add", KERNEL=="sdb3", RUN+="/bin/raw /dev/raw/raw3 %N"
ACTION=="add", KERNEL=="sdb4", RUN+="/bin/raw /dev/raw/raw4 %N"

ACTION=="add", KERNEL=="sdc1", RUN+="/bin/raw /dev/raw/raw5 %N"
ACTION=="add", KERNEL=="sdc2", RUN+="/bin/raw /dev/raw/raw6 %N"
ACTION=="add", KERNEL=="sdc3", RUN+="/bin/raw /dev/raw/raw7 %N"
ACTION=="add", KERNEL=="sdc4", RUN+="/bin/raw /dev/raw/raw8 %N"

ACTION=="add", KERNEL=="sdd1", RUN+="/bin/raw /dev/raw/raw9 %N"
ACTION=="add", KERNEL=="sdd2", RUN+="/bin/raw /dev/raw/raw10 %N"
ACTION=="add", KERNEL=="sdd3", RUN+="/bin/raw /dev/raw/raw11 %N"
ACTION=="add", KERNEL=="sdd4", RUN+="/bin/raw /dev/raw/raw12 %N"



ACTION=="add", KERNEL=="raw[1-12]", OWNER="dmdba", GROUP="dinstall", MODE="660"


[root@dm1 rules.d]# start_udev
Starting udev: [  OK  ]
[root@dm1 rules.d]# ls -lrt /dev/raw/
total 0
crw-rw---- 1 root  disk     162,  0 May  7 16:28 rawctl
crw-rw---- 1 dmdba dinstall 162,  9 May  7 16:28 raw9
crw-rw---- 1 dmdba dinstall 162, 12 May  7 16:28 raw12
crw-rw---- 1 dmdba dinstall 162, 11 May  7 16:28 raw11
crw-rw---- 1 dmdba dinstall 162, 10 May  7 16:28 raw10
crw-rw---- 1 dmdba dinstall 162,  6 May  7 16:28 raw6
crw-rw---- 1 dmdba dinstall 162,  1 May  7 16:28 raw1
crw-rw---- 1 dmdba dinstall 162,  7 May  7 16:28 raw7
crw-rw---- 1 dmdba dinstall 162,  8 May  7 16:28 raw8
crw-rw---- 1 dmdba dinstall 162,  5 May  7 16:28 raw5
crw-rw---- 1 dmdba dinstall 162,  2 May  7 16:28 raw2
crw-rw---- 1 dmdba dinstall 162,  3 May  7 16:28 raw3
crw-rw---- 1 dmdba dinstall 162,  4 May  7 16:28 raw4



[root@dm2 /]# cd /etc/udev/rules.d/
[root@dm2 rules.d]# vi 99-dm-devices.rules
ACTION=="add", KERNEL=="sdb1", RUN+="/bin/raw /dev/raw/raw1 %N"
ACTION=="add", KERNEL=="sdb2", RUN+="/bin/raw /dev/raw/raw2 %N"
ACTION=="add", KERNEL=="sdb3", RUN+="/bin/raw /dev/raw/raw3 %N"
ACTION=="add", KERNEL=="sdb4", RUN+="/bin/raw /dev/raw/raw4 %N"

ACTION=="add", KERNEL=="sdc1", RUN+="/bin/raw /dev/raw/raw5 %N"
ACTION=="add", KERNEL=="sdc2", RUN+="/bin/raw /dev/raw/raw6 %N"
ACTION=="add", KERNEL=="sdc3", RUN+="/bin/raw /dev/raw/raw7 %N"
ACTION=="add", KERNEL=="sdc4", RUN+="/bin/raw /dev/raw/raw8 %N"

ACTION=="add", KERNEL=="sdd1", RUN+="/bin/raw /dev/raw/raw9 %N"
ACTION=="add", KERNEL=="sdd2", RUN+="/bin/raw /dev/raw/raw10 %N"
ACTION=="add", KERNEL=="sdd3", RUN+="/bin/raw /dev/raw/raw11 %N"
ACTION=="add", KERNEL=="sdd4", RUN+="/bin/raw /dev/raw/raw12 %N"



ACTION=="add", KERNEL=="raw[1-12]", OWNER="dmdba", GROUP="dinstall", MODE="660"

[root@dm2 rules.d]# start_udev
Starting udev: [  OK  ]
[root@dm2 rules.d]# ls -lrt /dev/raw/
total 0
crw-rw---- 1 root  disk     162,  0 May  7 16:28 rawctl
crw-rw---- 1 dmdba dinstall 162,  9 May  7 16:28 raw9
crw-rw---- 1 dmdba dinstall 162, 12 May  7 16:28 raw12
crw-rw---- 1 dmdba dinstall 162, 11 May  7 16:28 raw11
crw-rw---- 1 dmdba dinstall 162, 10 May  7 16:28 raw10
crw-rw---- 1 dmdba dinstall 162,  6 May  7 16:28 raw6
crw-rw---- 1 dmdba dinstall 162,  1 May  7 16:28 raw1
crw-rw---- 1 dmdba dinstall 162,  7 May  7 16:28 raw7
crw-rw---- 1 dmdba dinstall 162,  8 May  7 16:28 raw8
crw-rw---- 1 dmdba dinstall 162,  5 May  7 16:28 raw5
crw-rw---- 1 dmdba dinstall 162,  2 May  7 16:28 raw2
crw-rw---- 1 dmdba dinstall 162,  3 May  7 16:28 raw3
crw-rw---- 1 dmdba dinstall 162,  4 May  7 16:28 raw4

可以通过blockdev –getsize64 /dev/raw/raw1命令查看裸设备大小

[root@dm1 rules.d]# blockdev --getsize64 /dev/raw/raw1
2154991104


[root@dm2 ~]# blockdev --getsize64 /dev/raw/raw1
2154991104

六、配置dmdcr_cfg.ini文件
在2个节点的/dm7/data目录下创建配置文件dmdcr_cfg.ini,仅使用裸设备,不使用ASM文件系统,不需要配置ASM信息,仅配置CSS/DB信息。在文件中添加如下内容:

[dmdba@dm1 dm7]$ mkdir data
[dmdba@dm1 dm7]$ cd data
[dmdba@dm1 data]$ vi dmdcr_cfg.ini
DCR_N_GRP = 2
DCR_VTD_PATH = /dev/raw/raw2
DCR_OGUID = 63635

[GRP]
DCR_GRP_TYPE = CSS
DCR_GRP_NAME = GRP_CSS
DCR_GRP_N_EP = 2
DCR_GRP_DSKCHK_CNT = 60
[GRP_CSS]
DCR_EP_NAME = CSS0
DCR_EP_HOST = 10.10.10.165
DCR_EP_PORT = 9541
[GRP_CSS]
DCR_EP_NAME = CSS1
DCR_EP_HOST = 10.10.10.166
DCR_EP_PORT = 9542


[GRP]
DCR_GRP_TYPE = DB
DCR_GRP_NAME = GRP_RAC
DCR_GRP_N_EP = 2
DCR_GRP_DSKCHK_CNT = 60
[GRP_RAC]
DCR_EP_NAME = RAC0
DCR_EP_SEQNO = 0
DCR_EP_PORT = 5236
DCR_CHECK_PORT = 9741
[GRP_RAC]
DCR_EP_NAME = RAC1
DCR_EP_SEQNO = 1
DCR_EP_PORT = 5236
DCR_CHECK_PORT = 9742

[dmdba@dm2 dm7]$ mkdir data
[dmdba@dm2 dm7]$ cd data
[dmdba@dm2 data]$ vi dmdcr_cfg.ini
DCR_N_GRP = 2
DCR_VTD_PATH = /dev/raw/raw2
DCR_OGUID = 63635

[GRP]
DCR_GRP_TYPE = CSS
DCR_GRP_NAME = GRP_CSS
DCR_GRP_N_EP = 2
DCR_GRP_DSKCHK_CNT = 60
[GRP_CSS]
DCR_EP_NAME = CSS0
DCR_EP_HOST = 10.10.10.165
DCR_EP_PORT = 9541
[GRP_CSS]
DCR_EP_NAME = CSS1
DCR_EP_HOST = 10.10.10.166
DCR_EP_PORT = 9542


[GRP]
DCR_GRP_TYPE = DB
DCR_GRP_NAME = GRP_RAC
DCR_GRP_N_EP = 2
DCR_GRP_DSKCHK_CNT = 60
[GRP_RAC]
DCR_EP_NAME = RAC0
DCR_EP_SEQNO = 0
DCR_EP_PORT = 5236
DCR_CHECK_PORT = 9741
[GRP_RAC]
DCR_EP_NAME = RAC1
DCR_EP_SEQNO = 1
DCR_EP_PORT = 5236
DCR_CHECK_PORT = 9742

七、使用 DMASMCMD 工具初始化(任意一节点执行)

[dmdba@dm1 ~]$ dmasmcmd
DMASMCMD V7.1.6.46-Build(2018.02.08-89107)ENT
ASM>create dcrdisk '/dev/raw/raw1' 'dcr'
the ASM initialize dcrdisk /dev/raw/raw1 to name DMASMdcr
Used time: 1.459(ms).
ASM>create votedisk '/dev/raw/raw2' 'vote'
the ASM initialize votedisk /dev/raw/raw2 to name DMASMvote
Used time: 1.380(ms).
ASM>init dcrdisk '/dev/raw/raw1' from '/dm7/data/dmdcr_cfg.ini'
syntax error
asmcmd parse failed!
ASM>init dcrdisk '/dev/raw/raw1' from '/dm7/data/dmdcr_cfg.ini' identified by 'dameng123'
[Trace]DG 126 allocate 4 extents for file 0xfe000002.
Check dcr disk failed, please check and try again
Used time: 271.543(ms).
ASM>init dcrdisk '/dev/raw/raw1' from '/dm7/data/dmdcr_cfg.ini' identified by 'dameng123'
[Trace]DG 126 allocate 4 extents for file 0xfe000002.
Used time: 68.745(ms).
ASM>init votedisk '/dev/raw/raw2' from '/dm7/data/dmdcr_cfg.ini'
[Trace]DG 125 allocate 4 extents for file 0xfd000002.
Used time: 33.488(ms).

八、操作系统配置准备配置dminit.ini文件,存放在/dm7/data目录中

system_path = /dm7/data
db_name=rac
main = /dev/raw/raw3
main_size = 128
roll = /dev/raw/raw4
roll_size = 128
system = /dev/raw/raw5
system_size = 128
ctl_path = /dev/raw/raw6
ctl_size = 8
dcr_path=/dev/raw/raw1
dcr_seqno=0

[rac0]
config_path=/dm7/data/rac0_config
port_num = 5236
mal_host = 10.10.10.165
mal_port = 9340
log_size = 256
log_path = /dev/raw/raw7
log_path = /dev/raw/raw8
[rac1]
config_path=/dm7/data/rac1_config
port_num = 5236
mal_host = 10.10.10.166
mal_port = 9341
log_size = 256
log_path = /dev/raw/raw9
log_path = /dev/raw/raw10

九、准备dmdcr.ini 配置文件
dmdcr.ini 是 dmcss、dmasmsvr、dmasmtool 工具的输入参数。记录了当前节点序列号以及 DCR 磁盘路径。在2个节点的/dm/dmdbms/data目录下创建dmdcr.ini 配置文件,dmdcr_path 相同,dmasvrmal.ini 文件内容也相同,dmdcr_seqo 分别为 0 和 1。
节点 1:

[dmdba@dmrac1 data]$ vi dmdcr.ini
DMDCR_PATH = /dev/raw/raw1
DMDCR_SEQNO = 0

#ASM
DMDCR_ASM_RESTART_INTERVAL = 0
DMDCR_ASM_STARTUP_CMD = /dm7/bin/dmasmsvr dcr_ini=/dm7/data/dmdcr.ini

#DB
DMDCR_DB_RESTART_INTERVAL = 0
DMDCR_DB_STARTUP_CMD = /dm7/bin/dmserver path=/dm7/data/rac0_config/dm.ini dcr_ini=/dm7/data/dmdcr.ini

节点2:

[dmdba@dmrac2 data]$ vi dmdcr.ini
DMDCR_PATH = /dev/raw/raw1
DMDCR_SEQNO = 1

#ASM
DMDCR_ASM_RESTART_INTERVAL = 0
DMDCR_ASM_STARTUP_CMD = /dm7/bin/dmasmsvr dcr_ini=/dm7/data/dmdcr.ini

#DB
DMDCR_DB_RESTART_INTERVAL = 0
DMDCR_DB_STARTUP_CMD = /dm7/bin/dmserver path=/dm7/data/rac1_config/dm.ini dcr_ini=/dm7/data/dmdcr.ini

十、启动DMCSS 服务程序
1、注册 DMCSS服务
节点一:

[root@dm1 ~]# /dm7/script/root/dm_service_installer.sh -t dmcss -i /dm7/data/dmdcr.ini -p rac1
Move the service script file(/dm7/bin/DmCSSServicerac1 to /etc/rc.d/init.d/DmCSSServicerac1)
Finished to create the service (DmCSSServicerac1)

节点二:

[root@dm2 ~]# /dm7/script/root/dm_service_installer.sh -t dmcss -i /dm7/data/dmdcr.ini -p rac2
Move the service script file(/dm7/bin/DmCSSServicerac2 to /etc/rc.d/init.d/DmCSSServicerac2)
Finished to create the service (DmCSSServicerac2)

2、启动DMCSS 服务
节点一:

[root@dm1 ~]# service DmCSSServicerac1 start
Starting DmCSSServicerac1: [ OK ]

节点二:

[root@dm2 ~]# service DmCSSServicerac2 start
Starting DmCSSServicerac2: [ OK ]

十一、操作系统配置使用dminit初始化DB环境
在任意节点启动 dminit 工具初始化数据库。dminit 执行完成后,会在 config_path 目录(/dm7/data/rac0_config 和/dm7/data/rac1_config)下生成配置文件 dm.ini 和 dmmal.ini。

[dmdba@dm1 data]$ dminit control=/dm7/data/dminit.ini
initdb V7.1.6.46-Build(2018.02.08-89107)ENT
db version: 0x7000a
file dm.key not found, use default license!
License will expire in 14 day(s) on 2020-05-21

 log file path: /dev/raw/raw7


 log file path: /dev/raw/raw8


 log file path: /dev/raw/raw9


 log file path: /dev/raw/raw10

FILE "/dev/raw/raw5" has already existed
FILE "/dev/raw/raw4" has already existed
FILE "/dev/raw/raw3" has already existed
FILE "/dev/raw/raw6" has already existed
FILE "/dev/raw/raw7" has already existed
FILE "/dev/raw/raw8" has already existed
FILE "/dev/raw/raw9" has already existed
FILE "/dev/raw/raw10" has already existed
File "/dev/raw/raw5" has already existed,
whether overwrite(y/n, 1/0): y
File "/dev/raw/raw4" has already existed,
whether overwrite(y/n, 1/0): y
File "/dev/raw/raw3" has already existed,
whether overwrite(y/n, 1/0): y
File "/dev/raw/raw6" has already existed,
whether overwrite(y/n, 1/0): y
File "/dev/raw/raw7" has already existed,
whether overwrite(y/n, 1/0): y
File "/dev/raw/raw8" has already existed,
whether overwrite(y/n, 1/0): y
File "/dev/raw/raw9" has already existed,
whether overwrite(y/n, 1/0): y
File "/dev/raw/raw10" has already existed,
whether overwrite(y/n, 1/0): y
write to dir [/dm7/data/rac].
create dm database success. 2020-05-07 16:41:52

将节点一的配置文件复制到节点二:

[dmdba@dm1 data]$ scp -r rac1_config 10.18.13.166:`pwd`
The authenticity of host '10.18.13.166 (10.18.13.166)' can't be established.
RSA key fingerprint is 89:fc:3e:e3:2d:27:94:07:0e:6b:fc:c5:e8:89:44:1f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.18.13.166' (RSA) to the list of known hosts.
dmdba@10.18.13.166's password:
sqllog.ini                                                                                                                                                                                                100%  479     0.5KB/s   00:00
dm.ini                                                                                                                                                                                                    100%   40KB  39.8KB/s   00:00
dmmal.ini                                                                                                                                                                                                 100%  204     0.2KB/s   00:00
[dmdba@dm1 data]$

一定要将节点一/dm7/data/目录中生成的rac目录复制到节点二的/dm7/data目录中,否则在节点二中启动数据库时会出现以下错误,原因就是因为使用裸设备时生成的rac目录及其文件不是存储在共享存储中可以让集群节点都能访问。

Starting DmServicerac2: [ FAILED ]
file dm.key not found, use default license!
Read ini warning, default dm.ctl backup path [/dm7/data/rac/ctl_bak] does not exist.
Read ini error, name:SYSTEM_PATH, value:/dm7/data/rac
dmserver startup failed, code = -803 [Invalid ini config value]

将节点一/dm7/data/目录中生成的rac目录复制到节点二的/dm7/data目录

[dmdba@dm1 data]$ scp -r rac 10.18.13.166:`pwd`
dmdba@10.18.13.166's password:
dm_20200507164149_942994.ctl                                                                                                                                                                              100% 6144     6.0KB/s   00:00
TEMP0.DBF                                                                                                                                                                                                 100%   10MB  10.0MB/s   00:00
dm_service.prikey                                                                                                                                                                                         100%  633     0.6KB/s   00:00

十二、启动数据库服务器
1、在2个节点分别注册DM 数据库服务:
节点一:

[root@dm1 ~]# /dm7/script/root/dm_service_installer.sh -t dmserver -i /dm7/data/rac0_config/dm.ini -d /dm7/data/dmdcr.ini -p rac1
Move the service script file(/dm7/bin/DmServicerac1 to /etc/rc.d/init.d/DmServicerac1)
Finished to create the service (DmServicerac1)

节点二:

[root@dm2 ~]# /dm7/script/root/dm_service_installer.sh -t dmserver -i /dm7/data/rac1_config/dm.ini -d /dm7/data/dmdcr.ini -p rac2
Move the service script file(/dm7/bin/DmServicerac2 to /etc/rc.d/init.d/DmServicerac2)
Finished to create the service (DmServicerac2)

2、启动数据库

[root@dm1 ~]# service DmServicerac1 start
Starting DmServicerac1: [ OK ]

[root@dm2 ~]# service DmServicerac2 start
Starting DmServicerac2: [ OK ]

手工启动命令如下,手工启动后窗口不能关闭,所以

./dmserver /dm7/data/rac0_config/dm.ini dcr_ini=/dm7/data/dmdcr.ini
./dmserver /dm7/data/rac1_config/dm.ini dcr_ini=/dm7/data/dmdcr.ini

十三、操作系统配置连接数据库验证
13.1配置服务名文件

[dmdba@dm1 data]$ vi /etc/dm_svc.conf
rac=(10.18.13.165:5236,10.18.13.166:5236)
SWITCH_TIME=(10000)
SWITCH_INTERVAL=(10)

TIME_ZONE=(480)
LANGUAGE=(en)

[dmdba@dm2 rac]$ vi /etc/dm_svc.conf
TIME_ZONE=(480)
rac=(10.18.13.165:5236,10.18.13.166:5236)
SWITCH_TIME=(10000)
SWITCH_INTERVAL=(10)

TIME_ZONE=(480)
LANGUAGE=(en)

13.2 连接RAC集群
节点一:

[dmdba@dm1 data]$ disql SYSDBA/SYSDBA@rac

Server[10.18.13.166:5236]:mode is normal, state is open
login used time: 9.596(ms)
disql V7.1.6.46-Build(2018.02.08-89107)ENT
Connected to: DM 7.1.6.46
SQL> select instance_name from v$instance;

LINEID     INSTANCE_NAME
---------- -------------
1          RAC1

used time: 5.020(ms). Execute id is 2.
SQL> select * from v$rac_ep_info;

LINEID     EP_NAME EP_SEQNO    EP_GUID              EP_TIMESTAMP         EP_MODE EP_STATUS
---------- ------- ----------- -------------------- -------------------- ------- ---------
1          RAC0    0           2982624975           2982625916           MASTER  OK
2          RAC1    1           2983098335           2983098713           SLAVE   OK

used time: 7.731(ms). Execute id is 3.

节点二:

SQL> select instance_name from v$instance;

LINEID     INSTANCE_NAME
---------- -------------
1          RAC1

used time: 117.515(ms). Execute id is 1.
SQL> select * from v$rac_ep_info;

LINEID     EP_NAME EP_SEQNO    EP_GUID              EP_TIMESTAMP         EP_MODE EP_STATUS
---------- ------- ----------- -------------------- -------------------- ------- ---------
1          RAC0    0           2982624975           2982632228           MASTER  OK
2          RAC1    1           2983098335           2983105025           SLAVE   OK

used time: 4.439(ms). Execute id is 4.

13.3测试故障重连

[dmdba@dm2 rac]$ disql SYSDBA/SYSDBA@rac

Server[10.18.13.166:5236]:mode is normal, state is open
login used time: 6.728(ms)
disql V7.1.6.46-Build(2018.02.08-89107)ENT
Connected to: DM 7.1.6.46
SQL> select instance_name from v$instance;

LINEID     INSTANCE_NAME
---------- -------------
1          RAC1

used time: 117.515(ms). Execute id is 1.
SQL> select * from v$rac_ep_info;

LINEID     EP_NAME EP_SEQNO    EP_GUID              EP_TIMESTAMP         EP_MODE EP_STATUS
---------- ------- ----------- -------------------- -------------------- ------- ---------
1          RAC0    0           2982624975           2982632228           MASTER  OK
2          RAC1    1           2983098335           2983105025           SLAVE   OK

used time: 4.439(ms). Execute id is 4.

#此时连接的rac1,我们kill 进程:

[root@dm2 ~]# ps -ef | grep dm.ini
dmdba     6231     1  0 17:25 pts/2    00:00:44 /dm7/bin/dmserver /dm7/data/rac1_config/dm.ini DCR_INI=/dm7/data/dmdcr.ini -noconsole
root     10844  5237  0 19:20 pts/2    00:00:00 grep dm.ini
[root@dm2 ~]# kill -9 6231

#在查询,故障重连成功:

SQL> select instance_name from v$instance;
[-70065]:Connection exception, switch the current connection sucessful.
[-70065]:Connection exception, switch the current connection sucessful.

Server[10.18.13.165:5236]:mode is normal, state is open
SQL> select instance_name from v$instance;

LINEID     INSTANCE_NAME
---------- -------------
1          RAC0

used time: 9.443(ms). Execute id is 807.

SQL> select * from v$rac_ep_info;

LINEID     EP_NAME EP_SEQNO    EP_GUID              EP_TIMESTAMP         EP_MODE EP_STATUS
---------- ------- ----------- -------------------- -------------------- ------- ---------
1          RAC0    0           2982624975           2982632568           MASTER  OK
2          RAC1    1           2983098335           2983105240           SLAVE   ERROR

used time: 3.184(ms). Execute id is 808.

可以看到连接的实例从rac1变为了rac0

DM7使用DMASM安装DMRAC

一.环境准备
主机 IP地址(对外服务) IP地址(内部通信) 实例名 操作系统
dmrac1 10.18.13.161 10.10.10.161 rac0 Redhat 6.7
dmrac2 10.18.13.162 10.10.10.162 rac1 Redhat 6.7

共享存储
/dev/sdb /dev/raw/raw1 dcr disk 2G
/dev/sdc /dev/raw/raw2 voting disk 2G
/dev/sdd /dev/raw/raw3 log disk 10G
/dev/sde /dev/raw/raw4 data disk1 10G
/dev/sdf /dev/raw/raw5 data disk2 10G

二、操作系统配置

1、关闭防火墙和SELINUX

[root@cs ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: nat mangle filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@cs ~]# chkconfig iptables off
[root@cs ~]# setenforce 0
[root@cs ~]# sed -i s:^SELINUX=.*$:SELINUX=disabled:g /etc/selinux/config

[root@cs ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: nat mangle filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@cs ~]# chkconfig iptables off
[root@cs ~]# setenforce 0
[root@cs ~]# sed -i s:^SELINUX=.*$:SELINUX=disabled:g /etc/selinux/config

2、修改主机名

[root@cs ~]# hostname dmrac1
[root@cs ~]# hostname dmrac2
[root@cs ~]# sed -i s:^HOSTNAME=.*$:HOSTNAME=dmrac1:g /etc/sysconfig/network
[root@cs ~]# sed -i s:^HOSTNAME=.*$:HOSTNAME=dmrac2:g /etc/sysconfig/network

3、修改hosts文件

[root@cs ~]# echo "
> 10.18.13.161 dmrac1
> 10.18.13.162 dmrac2" >> /etc/hosts

[root@cs ~]# echo "
> 10.18.13.161 dmrac1
> 10.18.13.162 dmrac2" >> /etc/hosts

三、 安装达梦软件
为了减少对操作系统的影响,用户不应该以root系统用户来安装和运行DM。用户可以在安装之前为DM创建一个专用的系统用户。具体操作详见Oracle Linux 7.1中安装达梦数据库DM7

四、绑定UDEV

[root@dmrac1 rules.d]# vi 99-dm-devices.rules
ACTION=="add", KERNEL=="sdb", RUN+="/bin/raw /dev/raw/raw1 %N"
ACTION=="add", KERNEL=="sdc", RUN+="/bin/raw /dev/raw/raw2 %N"
ACTION=="add", KERNEL=="sdd", RUN+="/bin/raw /dev/raw/raw3 %N"
ACTION=="add", KERNEL=="sde", RUN+="/bin/raw /dev/raw/raw4 %N"
ACTION=="add", KERNEL=="sdf", RUN+="/bin/raw /dev/raw/raw5 %N"


ACTION=="add", KERNEL=="raw[1-5]", OWNER="dmdba", GROUP="dinstall", MODE="660"
~
[root@dmrac1 rules.d]# start_udev
Starting udev: [ OK ]
[root@dmrac1 rules.d]# ls -lrt /dev/raw/
total 0
crw-rw----. 1 root disk 162, 0 Apr 24 14:08 rawctl
crw-rw----. 1 dmdba dinstall 162, 2 Apr 24 14:08 raw2
crw-rw----. 1 dmdba dinstall 162, 1 Apr 24 14:08 raw1
crw-rw----. 1 dmdba dinstall 162, 4 Apr 24 14:08 raw4
crw-rw----. 1 dmdba dinstall 162, 3 Apr 24 14:08 raw3
crw-rw----. 1 dmdba dinstall 162, 5 Apr 24 14:08 raw5


[root@dmrac2 rules.d]# vi 99-dm-devices.rules
ACTION=="add", KERNEL=="sdb", RUN+="/bin/raw /dev/raw/raw1 %N"
ACTION=="add", KERNEL=="sdc", RUN+="/bin/raw /dev/raw/raw2 %N"
ACTION=="add", KERNEL=="sdd", RUN+="/bin/raw /dev/raw/raw3 %N"
ACTION=="add", KERNEL=="sde", RUN+="/bin/raw /dev/raw/raw4 %N"
ACTION=="add", KERNEL=="sdf", RUN+="/bin/raw /dev/raw/raw5 %N"


ACTION=="add", KERNEL=="raw[1-5]", OWNER="dmdba", GROUP="dinstall", MODE="660"
~
[root@dmrac2 rules.d]# start_udev
Starting udev: [ OK ]
[root@dmrac2 rules.d]# ls -lrt /dev/raw/
total 0
crw-rw----. 1 root disk 162, 0 Apr 24 14:08 rawctl
crw-rw----. 1 dmdba dinstall 162, 2 Apr 24 14:08 raw2
crw-rw----. 1 dmdba dinstall 162, 1 Apr 24 14:08 raw1
crw-rw----. 1 dmdba dinstall 162, 4 Apr 24 14:08 raw4
crw-rw----. 1 dmdba dinstall 162, 3 Apr 24 14:08 raw3
crw-rw----. 1 dmdba dinstall 162, 5 Apr 24 14:08 raw5

可以通过blockdev –getsize64 /dev/raw/raw1命令查看裸设备大小

[root@dmrac1 rules.d]# blockdev --getsize64 /dev/raw/raw1
2147483648
[root@dmrac1 rules.d]# blockdev --getsize64 /dev/raw/raw2
2147483648
[root@dmrac1 rules.d]# blockdev --getsize64 /dev/raw/raw3
10737418240
[root@dmrac1 rules.d]# blockdev --getsize64 /dev/raw/raw4
10737418240
[root@dmrac1 rules.d]# blockdev --getsize64 /dev/raw/raw5
10737418240

[root@dmrac2 rules.d]# blockdev --getsize64 /dev/raw/raw1
2147483648
[root@dmrac2 rules.d]# blockdev --getsize64 /dev/raw/raw2
2147483648
[root@dmrac2 rules.d]# blockdev --getsize64 /dev/raw/raw3
10737418240
[root@dmrac2 rules.d]# blockdev --getsize64 /dev/raw/raw4
10737418240
[root@dmrac2 rules.d]# blockdev --getsize64 /dev/raw/raw5
10737418240

六、配置dmdcr_cfg.ini文件
在2个节点的/dm7/data目录下创建配置文件dmdcr_cfg.ini,在文件中添加如下内容:

[root@dmrac1 /]# su - dmdba
[dmdba@dmrac1 ~]$ mkdir /dm7/data
[dmdba@dmrac1 ~]$cd /dm7/data
[dmdba@dmrac1 data]$ cat dmdcr_cfg.ini
DCR_N_GRP = 3
DCR_VTD_PATH = /dev/raw/raw2
DCR_OGUID = 63635

[GRP]
DCR_GRP_TYPE = CSS
DCR_GRP_NAME = GRP_CSS
DCR_GRP_N_EP = 2
DCR_GRP_DSKCHK_CNT = 60
[GRP_CSS]
DCR_EP_NAME = CSS0
DCR_EP_HOST = 10.10.10.161
DCR_EP_PORT = 9541
[GRP_CSS]
DCR_EP_NAME = CSS1
DCR_EP_HOST = 10.10.10.162
DCR_EP_PORT = 9542

[GRP]
DCR_GRP_TYPE = ASM
DCR_GRP_NAME = GRP_ASM
DCR_GRP_N_EP = 2
DCR_GRP_DSKCHK_CNT = 60
[GRP_ASM]
DCR_EP_NAME = ASM0
DCR_EP_SHM_KEY = 93360
DCR_EP_SHM_SIZE = 10
DCR_EP_HOST = 10.18.13.161
DCR_EP_PORT = 9641
DCR_EP_ASM_LOAD_PATH = /dev/raw
[GRP_ASM]
DCR_EP_NAME = ASM1
DCR_EP_SHM_KEY = 93361
DCR_EP_SHM_SIZE = 10
DCR_EP_HOST = 10.18.13.162
DCR_EP_PORT = 9642
DCR_EP_ASM_LOAD_PATH = /dev/raw

[GRP]
DCR_GRP_TYPE = DB
DCR_GRP_NAME = GRP_RAC
DCR_GRP_N_EP = 2
DCR_GRP_DSKCHK_CNT = 60
[GRP_RAC]
DCR_EP_NAME = RAC0
DCR_EP_SEQNO = 0
DCR_EP_PORT = 5236
DCR_CHECK_PORT = 9741
[GRP_RAC]
DCR_EP_NAME = RAC1
DCR_EP_SEQNO = 1
DCR_EP_PORT = 5236
DCR_CHECK_PORT = 9742


[root@dmrac2 /]# su - dmdba
[dmdba@dmrac2 ~]$ mkdir /dm7/data
[dmdba@dmrac2 ~]$cd /dm7/data
[dmdba@dmrac2 data]$ cat dmdcr_cfg.ini
DCR_N_GRP = 3
DCR_VTD_PATH = /dev/raw/raw2
DCR_OGUID = 63635

[GRP]
DCR_GRP_TYPE = CSS
DCR_GRP_NAME = GRP_CSS
DCR_GRP_N_EP = 2
DCR_GRP_DSKCHK_CNT = 60
[GRP_CSS]
DCR_EP_NAME = CSS0
DCR_EP_HOST = 10.10.10.161
DCR_EP_PORT = 9541
[GRP_CSS]
DCR_EP_NAME = CSS1
DCR_EP_HOST = 10.10.10.162
DCR_EP_PORT = 9542

[GRP]
DCR_GRP_TYPE = ASM
DCR_GRP_NAME = GRP_ASM
DCR_GRP_N_EP = 2
DCR_GRP_DSKCHK_CNT = 60
[GRP_ASM]
DCR_EP_NAME = ASM0
DCR_EP_SHM_KEY = 93360
DCR_EP_SHM_SIZE = 10
DCR_EP_HOST = 10.18.13.161
DCR_EP_PORT = 9641
DCR_EP_ASM_LOAD_PATH = /dev/raw
[GRP_ASM]
DCR_EP_NAME = ASM1
DCR_EP_SHM_KEY = 93361
DCR_EP_SHM_SIZE = 10
DCR_EP_HOST = 10.18.13.162
DCR_EP_PORT = 9642
DCR_EP_ASM_LOAD_PATH = /dev/raw

[GRP]
DCR_GRP_TYPE = DB
DCR_GRP_NAME = GRP_RAC
DCR_GRP_N_EP = 2
DCR_GRP_DSKCHK_CNT = 60
[GRP_RAC]
DCR_EP_NAME = RAC0
DCR_EP_SEQNO = 0
DCR_EP_PORT = 5236
DCR_CHECK_PORT = 9741
[GRP_RAC]
DCR_EP_NAME = RAC1
DCR_EP_SEQNO = 1
DCR_EP_PORT = 5236
DCR_CHECK_PORT = 9742

七、使用 DMASMCMD 工具初始化(任意一节点执行)

[dmdba@dmrac1 data]$ dmasmcmd
DMASMCMD V7.1.6.46-Build(2018.02.08-89107)ENT
ASM>create dcrdisk '/dev/raw/raw1' 'dcr'
the ASM initialize dcrdisk /dev/raw/raw1 to name DMASMdcr
Used time: 9.322(ms).
ASM>create votedisk '/dev/raw/raw2' 'vote'
the ASM initialize votedisk /dev/raw/raw2 to name DMASMvote
Used time: 6.251(ms).
ASM>create asmdisk '/dev/raw/raw3' 'LOG0'
the ASM initialize asmdisk /dev/raw/raw3 to name DMASMLOG0
Used time: 8.825(ms).
ASM>create asmdisk '/dev/raw/raw4' 'DATA0'
the ASM initialize asmdisk /dev/raw/raw4 to name DMASMDATA0
Used time: 6.145(ms).
ASM>init dcrdisk '/dev/raw/raw1' from '/dm7/data/dmdcr_cfg.ini' identified by 'dameng123'
[Trace]DG 126 allocate 4 extents for file 0xfe000002.
Check dcr disk failed, please check and try again
Used time: 84.489(ms).提示检查dcr磁盘失败请再次执行
ASM>init dcrdisk '/dev/raw/raw1' from '/dm7/data/dmdcr_cfg.ini' identified by 'dameng123'
[Trace]DG 126 allocate 4 extents for file 0xfe000002.
Used time: 00:00:06.078.
ASM>init votedisk '/dev/raw/raw2' from '/dm7/data/dmdcr_cfg.ini'
[Trace]DG 125 allocate 4 extents for file 0xfd000002.
Used time: 36.305(ms).

八、准备DMASM 的 MAL 配置文件
在2个节点的/dm7/data目录下创建 DMASM 的 MAL 配置文件(命名为 dmasvrmal.ini),使用 DMASM 的所有节点都要配置,内容完全一样。

[dmdba@dmrac1 data]$ vi dmasvrmal.ini
[MAL_INST1]
MAL_INST_NAME = ASM0
MAL_HOST = 10.10.10.161
MAL_PORT = 7236

[MAL_INST2]
MAL_INST_NAME = ASM1
MAL_HOST = 10.10.10.162
MAL_PORT = 7237
[dmdba@dmrac2 data]$ vi dmasvrmal.ini
[MAL_INST1]
MAL_INST_NAME = ASM0
MAL_HOST = 10.10.10.161
MAL_PORT = 7236

[MAL_INST2]
MAL_INST_NAME = ASM1
MAL_HOST = 10.10.10.162
MAL_PORT = 7237
~

九、准备dmdcr.ini 配置文件
dmdcr.ini 是 dmcss、dmasmsvr、dmasmtool 工具的输入参数。记录了当前节点序列号以及 DCR 磁盘路径。
在2个节点的/dm/dmdbms/data目录下创建dmdcr.ini 配置文件,dmdcr_path 相同,dmasvrmal.ini 文件内容也相同,dmdcr_seqo 分别为 0 和 1。
节点 1:

[dmdba@dmrac1 data]$ vi dmdcr.ini
DMDCR_PATH = /dev/raw/raw1
DMDCR_MAL_PATH =/dm7/data/dmasvrmal.ini
DMDCR_SEQNO = 0

#ASM
DMDCR_ASM_RESTART_INTERVAL = 0
DMDCR_ASM_STARTUP_CMD = /dm7/bin/dmasmsvr dcr_ini=/dm7/data/dmdcr.ini

#DB
DMDCR_DB_RESTART_INTERVAL = 0
DMDCR_DB_STARTUP_CMD = /dm7/bin/dmserver path=/dm7/data/rac0_config/dm.ini dcr_ini=/dm7/data/dmdcr.ini

节点2:

[dmdba@dmrac2 data]$ vi dmdcr.ini
DMDCR_PATH = /dev/raw/raw1
DMDCR_MAL_PATH =/dm7/data/dmasvrmal.ini
DMDCR_SEQNO = 1

#ASM
DMDCR_ASM_RESTART_INTERVAL = 0
DMDCR_ASM_STARTUP_CMD = /dm7/bin/dmasmsvr dcr_ini=/dm7/data/dmdcr.ini

#DB
DMDCR_DB_RESTART_INTERVAL = 0
DMDCR_DB_STARTUP_CMD = /dm7/bin/dmserver path=/dm7/data/rac1_config/dm.ini dcr_ini=/dm7/data/dmdcr.ini

十、启动DMCSS、DMASM 服务程序
1、注册 DMCSS和DMASM服务
节点一:

[root@dmrac1 ~]# /dm7/script/root/dm_service_installer.sh -t dmcss -i /dm7/data/dmdcr.ini -p rac1
Move the service script file(/dm7/bin/DmCSSServicerac1 to /etc/rc.d/init.d/DmCSSServicerac1)
Finished to create the service (DmCSSServicerac1)
[root@dmrac1 ~]# /dm7/script/root/dm_service_installer.sh -t dmasmsvr -i /dm7/data/dmdcr.ini -p rac1
Move the service script file(/dm7/bin/DmASMSvrServicerac1 to /etc/rc.d/init.d/DmASMSvrServicerac1)
Finished to create the service (DmASMSvrServicerac1)
[root@dmrac1 ~]#

节点二:

[root@dmrac2 ~]# /dm7/script/root/dm_service_installer.sh -t dmcss -i /dm7/data/dmdcr.ini -p rac2
Move the service script file(/dm7/bin/DmCSSServicerac2 to /etc/rc.d/init.d/DmCSSServicerac2)
Finished to create the service (DmCSSServicerac2)
[root@dmrac2 ~]# /dm7/script/root/dm_service_installer.sh -t dmasmsvr -i /dm7/data/dmdcr.ini -p rac2
Move the service script file(/dm7/bin/DmASMSvrServicerac2 to /etc/rc.d/init.d/DmASMSvrServicerac2)
Finished to create the service (DmASMSvrServicerac2)

2、启动DMCSS和DMASM服务
节点一:

[root@dmrac1 init.d]# service DmCSSServicerac1 start
Starting DmCSSServicerac1: [ OK ]
[root@dmrac1 init.d]# service DmASMSvrServicerac1 start
Starting DmASMSvrServicerac1: [ OK ]

节点二:

[root@dmrac2 init.d]# service DmCSSServicerac2 start
Starting DmCSSServicerac2: [ OK ]
[root@dmrac2 init.d]# service DmASMSvrServicerac2 start
Starting DmASMSvrServicerac2: [ OK ]

十一、创建DMASM磁盘组
在任意节点使用 dmasmtool 工具创建 DMASM 磁盘组。

[dmdba@dmrac1 ~]$ dmasmtool DCR_INI=/dm7/data/dmdcr.ini
DMASMTOOL V7.1.6.46-Build(2018.02.08-89107)ENT
ASM>create diskgroup 'DMLOG' asmdisk '/dev/raw/raw3'
Used time: 00:00:06.363.
ASM>create diskgroup 'DMDATA' asmdisk '/dev/raw/raw4'
Used time: 00:00:06.504.

十二、准备dminit.ini 配置文件
在2个节点的/dm/dmdbms/data目录下创建 dminit.ini 配置文件,添加如下内容。 在2个节点都创建。

[dmdba@dmrac1 data]$ vi dminit.ini
db_name = rac
system_path = +DMDATA/data
system = +DMDATA/data/rac/system.dbf
system_size = 128
roll = +DMDATA/data/rac/roll.dbf
roll_size = 128
main = +DMDATA/data/rac/main.dbf
main_size = 128
ctl_path = +DMDATA/data/rac/dm.ctl
ctl_size = 8
log_size = 256
dcr_path = /dev/raw/raw1 #dcr 磁盘路径,目前不支持 asm,只能是裸设备
dcr_seqno = 0
auto_overwrite = 1

[RAC0] #inst_name 跟 dmdcr_cfg.ini 中 DB 类型 group 中 DCR_EP_NAME 对应
config_path = /dm7/data/rac0_config
port_num = 5236
mal_host = 10.10.10.161
mal_port = 9340
log_path = +DMLOG/log/rac0_log01.log
log_path = +DMLOG/log/rac0_log02.log

[RAC1] #inst_name 跟 dmdcr_cfg.ini 中 DB 类型 group 中 DCR_EP_NAME 对应
config_path = /dm7/data/rac1_config
port_num = 5236
mal_host = 10.10.10.162
mal_port = 9341
log_path = +DMLOG/log/rac1_log01.log
log_path = +DMLOG/log/rac1_log02.log


[dmdba@dmrac2 data]$ vi dminit.ini
db_name = rac
system_path = +DMDATA/data
system = +DMDATA/data/rac/system.dbf
system_size = 128
roll = +DMDATA/data/rac/roll.dbf
roll_size = 128
main = +DMDATA/data/rac/main.dbf
main_size = 128
ctl_path = +DMDATA/data/rac/dm.ctl
ctl_size = 8
log_size = 256
dcr_path = /dev/raw/raw1 #dcr 磁盘路径,目前不支持 asm,只能是裸设备
dcr_seqno = 0
auto_overwrite = 1

[RAC0] #inst_name 跟 dmdcr_cfg.ini 中 DB 类型 group 中 DCR_EP_NAME 对应
config_path = /dm7/data/rac0_config
port_num = 5236
mal_host = 10.10.10.161
mal_port = 9340
log_path = +DMLOG/log/rac0_log01.log
log_path = +DMLOG/log/rac0_log02.log

[RAC1] #inst_name 跟 dmdcr_cfg.ini 中 DB 类型 group 中 DCR_EP_NAME 对应
config_path = /dm7/data/rac1_config
port_num = 5236
mal_host = 10.10.10.162
mal_port = 9341
log_path = +DMLOG/log/rac1_log01.log
log_path = +DMLOG/log/rac1_log02.log

十三、使用dminit初始化数据库
在任意节点启动 dminit 工具初始化数据库。dminit 执行完成后,会在 config_path 目录(/dm7/data/rac0_config 和/dm7/data/rac1_config)下生成配置文件 dm.ini 和 dmmal.ini。

[dmdba@dmrac1 data]$ dminit control=/dm7/data/dminit.ini
initdb V7.1.6.46-Build(2018.02.08-89107)ENT
db version: 0x7000a
file dm.key not found, use default license!
License will expire on 2020-05-08

log file path: +DMLOG/log/rac0_log01.log


log file path: +DMLOG/log/rac0_log02.log


log file path: +DMLOG/log/rac1_log01.log


log file path: +DMLOG/log/rac1_log02.log

write to dir [+DMDATA/data/rac].
create dm database success. 2020-04-24 16:39:03

将节点一的配置文件复制到节点二:

[dmdba@dmrac1 data]$ scp -r rac1_config 10.18.13.162:`pwd`
The authenticity of host '10.18.13.162 (10.18.13.162)' can't be established.
RSA key fingerprint is 89:fc:3e:e3:2d:27:94:07:0e:6b:fc:c5:e8:89:44:1f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.18.13.162' (RSA) to the list of known hosts.
dmdba@10.18.13.162's password:
sqllog.ini 100% 479 0.5KB/s 00:00
dm.ini 100% 40KB 39.8KB/s 00:00
dmmal.ini 100% 204 0.2KB/s 00:00
[dmdba@dmrac1 data]$

十四、启动数据库服务器
1、在2个节点分别注册DM 数据库服务:
节点一:

[root@dmrac1 init.d]# /dm7/script/root/dm_service_installer.sh -t dmserver -i /dm7/data/rac0_config/dm.ini -d /dm7/data/dmdcr.ini -p rac1
Move the service script file(/dm7/bin/DmServicerac1 to /etc/rc.d/init.d/DmServicerac1)
Finished to create the service (DmServicerac1)

节点二:

[root@dmrac2 ~]# /dm7/script/root/dm_service_installer.sh -t dmserver -i /dm7/data/rac1_config/dm.ini -d /dm7/data/dmdcr.ini -p rac2
Move the service script file(/dm7/bin/DmServicerac2 to /etc/rc.d/init.d/DmServicerac2)
Finished to create the service (DmServicerac2)

2、启动数据库

[root@dmrac1 init.d]# service DmServicerac1 start
Starting DmServicerac1: [ OK ]

[root@dmrac2 ~]# service DmServicerac2 start
Starting DmServicerac2: [ OK ]

手工启动命令如下,手工启动后窗口不能关闭,所以

./dmserver /dm7/data/rac0_config/dm.ini dcr_ini=/dm7/data/dmdcr.ini
./dmserver /dm7/data/rac1_config/dm.ini dcr_ini=/dm7/data/dmdcr.ini

15 连接数据库验证
15.1 配置服务名文件

[dmdba@dmrac1 ~]$ vi /etc/dm_svc.conf
TIME_ZONE=(480)
rac=(10.18.13.161:5236,10.18.13.162:5236)
SWITCH_TIME=(10000)
SWITCH_INTERVAL=(10)

TIME_ZONE=(480)
LANGUAGE=(en)

[dmdba@dmrac2 ~]$ vi /etc/dm_svc.conf
TIME_ZONE=(480)
rac=(10.18.13.161:5236,10.18.13.162:5236)
SWITCH_TIME=(10000)
SWITCH_INTERVAL=(10)

TIME_ZONE=(480)
LANGUAGE=(en)

15.2 连接RAC集群
节点一:

[dmdba@dmrac1 ~]$ disql SYSDBA/SYSDBA@rac

Server[10.18.13.161:5236]:mode is normal, state is open
login used time: 10.365(ms)
disql V7.1.6.46-Build(2018.02.08-89107)ENT
Connected to: DM 7.1.6.46
SQL> select instance_name from v$instance;

LINEID INSTANCE_NAME
———- ————-
1 RAC0

used time: 18.248(ms). Execute id is 807.
SQL> select * from v$rac_ep_info;

LINEID EP_NAME EP_SEQNO EP_GUID EP_TIMESTAMP EP_MODE EP_STATUS
———- ——- ———– ——————– ——————– ——- ———
1 RAC0 0 2067076818 2067077298 MASTER OK
2 RAC1 1 2067098084 2067098537 SLAVE OK

used time: 2.741(ms). Execute id is 808.

节点二:

[dmdba@dmrac2 ~]$ disql SYSDBA/SYSDBA@rac

Server[10.18.13.162:5236]:mode is normal, state is open
login used time: 16.835(ms)
disql V7.1.6.46-Build(2018.02.08-89107)ENT
Connected to: DM 7.1.6.46
SQL> select instance_name from v$instance;

LINEID INSTANCE_NAME
---------- -------------
1 RAC1

used time: 106.703(ms). Execute id is 1.
SQL> select * from v$rac_ep_info;

LINEID EP_NAME EP_SEQNO EP_GUID EP_TIMESTAMP EP_MODE EP_STATUS
---------- ------- ----------- -------------------- -------------------- ------- ---------
1 RAC0 0 2067076818 2067077305 MASTER OK
2 RAC1 1 2067098084 2067098544 SLAVE OK

used time: 7.358(ms). Execute id is 2.

DMRAC缓存交换

缓存交换
根据目前的硬件发展状况来看,网络的传输速度比磁盘的读、写速度更快,因此,DMRAC集群引入了缓存交换(Buffer Swap)技术,节点间的数据页尽可能通过网络传递,避免通过磁盘的写入、再读出方式在节点间传递数据,从而减少数据库的IO等待时间,提升系统的响应速度。

缓存交换的实现基础是GBS/LBS服务,在GBS/LBS中维护了Buffer数据页的相关信息。包括:1. 闩的封锁权限(LATCH);2. 哪些站点访问过此数据页(Access MAP);3. 最新数据保存在哪一个节点(Fresh EP)中;4. 以及最新数据页的LSN值(Fresh LSN)等信息。这些信息作为LBS封锁、GBS授权和GBS权限回收请求的附加信息进行传递,因此并不会带来额外的通讯开销。

下面,以两节点DMRAC集群(EP0/EP1)访问数据页P1为例子。初始页P1位于共享存储上,P1的GBS控制结构位于节点EP1上。初始页P1还没有被任何一个节点访问过,初始页P1的LSN为10000。通过几种常见场景分析,逐步深入,解析缓存交换的原理。
场景1
节点EP0访问数据页P1。
1. 节点EP0的本地LBS向EP1的GBS请求数据页P1的S LATCH权限
2. 节点EP1的GBS修改P1控制结构,记录访问节点EP0的封锁模式为S LATCH(数据分布节点为EP0),并响应EP0的LBS请求
3. 节点EP0的LBS获得GBS授权后,记录获得的授权模式是S_LATCH,P1数据不在其他节点的Buffer中,发起本地IO请求,从磁盘读取数据。
IO完成后,修改LBS控制结构,记录数据页上的LSN信息

场景2
节点EP1访问数据页P1。
1. 节点EP1本地LBS向EP1的GBS请求数据页P1的S LATCH权限
2. 节点EP1的GBS修改控制结构,记录访问节点EP1的封锁模式为S LATCH(数据分布节点为EP0/EP1),并响应EP1的LBS请求
3. 节点EP1的LBS获得GBS授权后,记录获得的授权模式是S LATCH,根据数据分布情况,EP1向EP0发起P1的读请求,通过内部网络从EP0获取
数据,而不是重新从磁盘读取P1数据

场景3
节点EP0修改数据页P1。
1. 节点EP0本地LBS向EP1的GBS请求数据页P1的X LATCH权限(附加LSN信息)
2. 节点EP1的GBS修改控制结构的LSN值,从EP1的LBS回收P1的权限
3. 修改访问节点EP0的封锁模式为S + X LATCH,并响应EP0的LBS请求
4. 节点EP0的LBS获得GBS授权后,记录获得的授权模式是S + X LATCH
5. 节点EP0修改数据页P1,LSN修改为11000
这个过程中,只有全局Latch请求,数据页并没有在节点间传递。

修改之后,数据页P1的LSN修改为11000。如下所示:

场景4
节点EP1修改数据页P1。
1.节点EP1本地LBS向EP1的GBS请求数据页P1的X LATCH权限
2.节点EP1的GBS发现P1被EP0以S + X方式封锁,向EP0发起回收P1权限的请求
3.节点EP0释放P1的全局LATCH,响应GBS,并且在响应消息中附加了最新的PAGE LSN值
4.节点EP1的GBS收到EP0的响应后,修改GBS控制结构,记录最新数据保存在EP0,最新的LSN值信息,记录EP0获得的授权模式是S + X LATCH
(此时,数据分布节点仍然是EP0/EP1),并授权EP1的LBS
5.节点EP1的LBS收到授权信息后,记录获得的授权模式是S + X LATCH,并根据数据分布情况,向节点EP0发起数据页P1的读请求
6.节点EP1修改数据页P1,LSN修改为12000

修改之后,数据页P1的LSN修改为12000。如下所示:

这个过程中,数据页P1的最新数据从EP0传递到了EP1,但并没有产生磁盘IO。

达梦7异构(DM-Oracle) DBLINK

使用DM数据库,创建一个连接到IP地址为10.10.10.180机器上的oracle数据库的外部链接。可以通过三种方式创建:一网络服务名tsn_name;二连接描述符description;三/< 服务名>。

(一) 通过网络服务名创建
首先介绍Oracle网络服务名的配置方法。网络服务名配置成功才能创建DBLINK
安装Oracle客户端挺费时间的,而且大部分功能都用不到,Oracle官方给出了简易客户端,直接解压就可以使用,下载地址:http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
下面来看安装步骤:
1、下载安装包,我这里把所有的都下载下来了

 [root@dmks soft]# ls -lrt
总用量 2293896
drwxr-xr-x. 19 1000 1000       4096 4月  20 2010 unixODBC-2.3.0
drwxrwxr-x.  5  502  502       4096 1月  27 2017 client
-rw-r--r--.  1  502  502 1258314437 3月   2 2017 linuxx64_12201_client.zip
-rw-r--r--.  1 root root  493170688 3月  19 2018 dm7_setup_neokylin6_64_20180209.iso
-rw-r--r--.  1 root root  488814959 3月   4 15:19 DM_linux64.zip
drwxr-xr-x.  2 root root       4096 3月   6 19:47 dm_soft
-rw-r--r--.  1 root root    1804749 3月  11 17:20 unixODBC-2.3.0.tar.gz
-rw-r--r--.  1 root root     904309 3月  21 18:38 instantclient-sqlplus-linux.x64-12.2.0.1.0.zip
-rw-r--r--.  1 root root   68965195 3月  21 18:42 instantclient-basic-linux.x64-12.2.0.1.0.zip
-rw-r--r--.  1 root root     674743 3月  21 18:45 instantclient-sdk-linux.x64-12.2.0.1.0.zip
-rw-r--r--.  1 root root    1572942 3月  21 22:51 instantclient-jdbc-linux.x64-12.2.0.1.0.zip
-rw-r--r--.  1 root root     634023 3月  21 22:51 instantclient-odbc-linux.x64-12.2.0.1.0-2.zip
-rw-r--r--.  1 root root   32917466 3月  21 22:51 instantclient-basiclite-linux.x64-12.2.0.1.0.zip
-rw-r--r--.  1 root root    1132671 3月  21 22:52 instantclient-tools-linux.x64-12.2.0.1.0.zip

2、unzip解压
解压出来一个目录instantclient_12_2

[root@dmks soft]# unzip instantclient-sqlplus-linux.x64-12.2.0.1.0.zip
Archive:  instantclient-sqlplus-linux.x64-12.2.0.1.0.zip
  inflating: instantclient_12_2/glogin.sql
  inflating: instantclient_12_2/libsqlplusic.so
  inflating: instantclient_12_2/libsqlplus.so
  inflating: instantclient_12_2/sqlplus
  inflating: instantclient_12_2/SQLPLUS_README
[root@dmks soft]# unzip instantclient-basic-linux.x64-12.2.0.1.0.zip
Archive:  instantclient-basic-linux.x64-12.2.0.1.0.zip
  inflating: instantclient_12_2/adrci
  inflating: instantclient_12_2/BASIC_README
  inflating: instantclient_12_2/genezi
  inflating: instantclient_12_2/libclntshcore.so.12.1
  inflating: instantclient_12_2/libclntsh.so.12.1
  inflating: instantclient_12_2/libipc1.so
  inflating: instantclient_12_2/libmql1.so
  inflating: instantclient_12_2/libnnz12.so
  inflating: instantclient_12_2/libocci.so.12.1
  inflating: instantclient_12_2/libociei.so
  inflating: instantclient_12_2/libocijdbc12.so
  inflating: instantclient_12_2/libons.so
  inflating: instantclient_12_2/liboramysql12.so
  inflating: instantclient_12_2/ojdbc8.jar
  inflating: instantclient_12_2/uidrvci
  inflating: instantclient_12_2/xstreams.jar
[root@dmks soft]# unzip instantclient-sdk-linux.x64-12.2.0.1.0.zip
Archive:  instantclient-sdk-linux.x64-12.2.0.1.0.zip
   creating: instantclient_12_2/sdk/
  inflating: instantclient_12_2/sdk/ott
 extracting: instantclient_12_2/sdk/ottclasses.zip
  inflating: instantclient_12_2/sdk/SDK_README
   creating: instantclient_12_2/sdk/demo/
  inflating: instantclient_12_2/sdk/demo/setuporamysql.sh
  inflating: instantclient_12_2/sdk/demo/occiobj.typ
  inflating: instantclient_12_2/sdk/demo/occidml.cpp
  inflating: instantclient_12_2/sdk/demo/occidemo.sql
  inflating: instantclient_12_2/sdk/demo/occiobj.cpp
  inflating: instantclient_12_2/sdk/demo/occidemod.sql
  inflating: instantclient_12_2/sdk/demo/oraaccess.xml
  inflating: instantclient_12_2/sdk/demo/demo.mk
  inflating: instantclient_12_2/sdk/demo/cdemo81.c
   creating: instantclient_12_2/sdk/include/
  inflating: instantclient_12_2/sdk/include/occiControl.h
  inflating: instantclient_12_2/sdk/include/oro.h
  inflating: instantclient_12_2/sdk/include/ociapr.h
  inflating: instantclient_12_2/sdk/include/occiCommon.h
  inflating: instantclient_12_2/sdk/include/occiData.h
  inflating: instantclient_12_2/sdk/include/oci8dp.h
  inflating: instantclient_12_2/sdk/include/ociextp.h
  inflating: instantclient_12_2/sdk/include/orl.h
  inflating: instantclient_12_2/sdk/include/nzt.h
  inflating: instantclient_12_2/sdk/include/ldap.h
  inflating: instantclient_12_2/sdk/include/occi.h
  inflating: instantclient_12_2/sdk/include/ociap.h
  inflating: instantclient_12_2/sdk/include/odci.h
  inflating: instantclient_12_2/sdk/include/ocixstream.h
  inflating: instantclient_12_2/sdk/include/nzerror.h
  inflating: instantclient_12_2/sdk/include/oci1.h
  inflating: instantclient_12_2/sdk/include/ori.h
  inflating: instantclient_12_2/sdk/include/ocixmldb.h
  inflating: instantclient_12_2/sdk/include/ocidem.h
  inflating: instantclient_12_2/sdk/include/occiAQ.h
  inflating: instantclient_12_2/sdk/include/ocidef.h
  inflating: instantclient_12_2/sdk/include/occiObjects.h
  inflating: instantclient_12_2/sdk/include/oci.h
  inflating: instantclient_12_2/sdk/include/oratypes.h
  inflating: instantclient_12_2/sdk/include/orid.h
  inflating: instantclient_12_2/sdk/include/xa.h
  inflating: instantclient_12_2/sdk/include/ocikpr.h
  inflating: instantclient_12_2/sdk/include/ocidfn.h
  inflating: instantclient_12_2/sdk/include/ort.h
   creating: instantclient_12_2/sdk/admin/
  inflating: instantclient_12_2/sdk/admin/oraaccess.xsd
[root@dmks soft]# unzip instantclient-jdbc-linux.x64-12.2.0.1.0.zip
Archive:  instantclient-jdbc-linux.x64-12.2.0.1.0.zip
  inflating: instantclient_12_2/JDBC_README
  inflating: instantclient_12_2/libheteroxa12.so
  inflating: instantclient_12_2/orai18n.jar
  inflating: instantclient_12_2/orai18n-mapping.jar
[root@dmks soft]# unzip instantclient-odbc-linux.x64-12.2.0.1.0-2.zip
Archive:  instantclient-odbc-linux.x64-12.2.0.1.0-2.zip
   creating: instantclient_12_2/help/
   creating: instantclient_12_2/help/ja/
  inflating: instantclient_12_2/help/ja/blafdoc.css
  inflating: instantclient_12_2/help/ja/oracle.gif
   creating: instantclient_12_2/help/ja/img_text/
  inflating: instantclient_12_2/help/ja/img_text/setup_ssmig.htm
  inflating: instantclient_12_2/help/ja/img_text/setup_work.htm
  inflating: instantclient_12_2/help/ja/img_text/odbcmodel.htm
  inflating: instantclient_12_2/help/ja/img_text/setup_app.htm
  inflating: instantclient_12_2/help/ja/img_text/setup_ora.htm
  inflating: instantclient_12_2/help/ja/img_text/odbcdrvarch.htm
  inflating: instantclient_12_2/help/ja/toc.htm
  inflating: instantclient_12_2/help/ja/map.xml
   creating: instantclient_12_2/help/ja/META-INF/
  inflating: instantclient_12_2/help/ja/META-INF/MANIFEST.MF
   creating: instantclient_12_2/help/ja/img/
  inflating: instantclient_12_2/help/ja/img/setup_app.gif
  inflating: instantclient_12_2/help/ja/img/odbcmodel.gif
  inflating: instantclient_12_2/help/ja/img/setup_ora.gif
  inflating: instantclient_12_2/help/ja/img/odbcdrvarch.gif
  inflating: instantclient_12_2/help/ja/img/setup_ssmig.gif
  inflating: instantclient_12_2/help/ja/img/setup_work.gif
  inflating: instantclient_12_2/help/ja/cpyr.htm
  inflating: instantclient_12_2/help/ja/sqora.htm
   creating: instantclient_12_2/help/us/
  inflating: instantclient_12_2/help/us/blafdoc.css
  inflating: instantclient_12_2/help/us/oracle.gif
   creating: instantclient_12_2/help/us/img_text/
  inflating: instantclient_12_2/help/us/img_text/setup_ssmig.htm
  inflating: instantclient_12_2/help/us/img_text/setup_work.htm
  inflating: instantclient_12_2/help/us/img_text/odbcmodel.htm
  inflating: instantclient_12_2/help/us/img_text/setup_app.htm
  inflating: instantclient_12_2/help/us/img_text/setup_ora.htm
  inflating: instantclient_12_2/help/us/img_text/odbcdrvarch.htm
  inflating: instantclient_12_2/help/us/toc.htm
  inflating: instantclient_12_2/help/us/map.xml
   creating: instantclient_12_2/help/us/META-INF/
  inflating: instantclient_12_2/help/us/META-INF/MANIFEST.MF
   creating: instantclient_12_2/help/us/img/
  inflating: instantclient_12_2/help/us/img/setup_app.gif
  inflating: instantclient_12_2/help/us/img/odbcmodel.gif
  inflating: instantclient_12_2/help/us/img/setup_ora.gif
  inflating: instantclient_12_2/help/us/img/odbcdrvarch.gif
  inflating: instantclient_12_2/help/us/img/setup_ssmig.gif
  inflating: instantclient_12_2/help/us/img/setup_work.gif
  inflating: instantclient_12_2/help/us/cpyr.htm
  inflating: instantclient_12_2/help/us/sqora.htm
  inflating: instantclient_12_2/libsqora.so.12.1
  inflating: instantclient_12_2/ODBC_IC_Readme_Unix.html
  inflating: instantclient_12_2/odbc_update_ini.sh
[root@dmks soft]# unzip instantclient-basiclite-linux.x64-12.2.0.1.0.zip
Archive:  instantclient-basiclite-linux.x64-12.2.0.1.0.zip
replace instantclient_12_2/adrci? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
  inflating: instantclient_12_2/adrci
  inflating: instantclient_12_2/BASIC_LITE_README
  inflating: instantclient_12_2/genezi
  inflating: instantclient_12_2/libclntshcore.so.12.1
  inflating: instantclient_12_2/libclntsh.so.12.1
  inflating: instantclient_12_2/libipc1.so
  inflating: instantclient_12_2/libmql1.so
  inflating: instantclient_12_2/libnnz12.so
  inflating: instantclient_12_2/libocci.so.12.1
  inflating: instantclient_12_2/libociicus.so
  inflating: instantclient_12_2/libocijdbc12.so
  inflating: instantclient_12_2/libons.so
  inflating: instantclient_12_2/liboramysql12.so
  inflating: instantclient_12_2/ojdbc8.jar
  inflating: instantclient_12_2/uidrvci
  inflating: instantclient_12_2/xstreams.jar
[root@dmks soft]# unzip instantclient-tools-linux.x64-12.2.0.1.0.zip
Archive:  instantclient-tools-linux.x64-12.2.0.1.0.zip
  inflating: instantclient_12_2/exp
  inflating: instantclient_12_2/expdp
  inflating: instantclient_12_2/imp
  inflating: instantclient_12_2/impdp
  inflating: instantclient_12_2/libnfsodm12.so
  inflating: instantclient_12_2/sqlldr
  inflating: instantclient_12_2/TOOLS_README
  inflating: instantclient_12_2/wrc

3、配置环境变量

export ORACLE_HOME=/soft/instantclient_12_2
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
export PATH=$ORACLE_HOME:$PATH

4、配置tns

[root@dmks instantclient_12_2]# mkdir -p network/admin
[root@dmks instantclient_12_2]# cd  network/admin/

[root@dmks admin]# vi tnsnames.ora
shardcat =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.10.180)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = shardcat)
    )
  )

5、测试sqlplus,成功

[root@dmks admin]# sqlplus jy/xxzx7817600@shardcat

SQL*Plus: Release 12.2.0.1.0 Production on Sat Mar 21 23:07:41 2020

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Last Successful login time: Sun Mar 22 2020 01:36:51 +08:00

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL>

拷贝动态库文件

[root@dmks instantclient_12_2]# cp  *so*  /dm_home/dmdbms/bin/

[root@dmks instantclient_12_2]# cd  /dm_home/dmdbms/bin/
[root@dmks bin]# chown -R dmdba:dinstall *so*  //一定要将动态库文件修改为dmdba用户所有
[root@dmks bin]# chmod -R 777 /dm_home/dmdbms/bin/

创建DBlink
网络服务名配置成功后,就可以使用网络服务名shardcat或网络连接描述符创建DBLINK.

SQL> create or replace public link link3 connect 'oracle' with system identified by "xxzx7817600" using 'shardcat';
executed successfully
used time: 27.431(ms). Execute id is 8.
SQL> select * from v$version@link3;

LINEID     BANNER                                                                       CON_ID
---------- ---------------------------------------------------------------------------- ------
1          Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
2          PL/SQL Release 12.2.0.1.0 - Production                                       0
3          CORE 12.2.0.1.0 Production                                                   0
4          TNS for Linux: Version 12.2.0.1.0 - Production                               0
5          NLSRTL Version 12.2.0.1.0 - Production                                       0

used time: 66.846(ms). Execute id is 9.

(二) 通过连接描述符创建

SQL> create or replace public link link4 connect 'oracle' with system identified by "xxzx7817600" using '(description =
2   (address_list = (address = (protocol = tcp)(host = 10.10.10.180)(port = 1521)))
3   (connect_data = (service_name = shardcat)))';
executed successfully
used time: 19.074(ms). Execute id is 10.
SQL> select * from v$version@link4;

LINEID     BANNER                                                                       CON_ID
---------- ---------------------------------------------------------------------------- ------
1          Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
2          PL/SQL Release 12.2.0.1.0 - Production                                       0
3          CORE 12.2.0.1.0 Production                                                   0
4          TNS for Linux: Version 12.2.0.1.0 - Production                               0
5          NLSRTL Version 12.2.0.1.0 - Production                                       0

used time: 140.930(ms). Execute id is 12.

(三) 通过/< 服务名>创建

SQL> create or replace public link link5 connect 'oracle' with system identified by "xxzx7817600" using '10.10.10.180/shardcat';
executed successfully
used time: 17.347(ms). Execute id is 13.
SQL> select * from v$version@link5;

LINEID     BANNER                                                                       CON_ID
---------- ---------------------------------------------------------------------------- ------
1          Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
2          PL/SQL Release 12.2.0.1.0 - Production                                       0
3          CORE 12.2.0.1.0 Production                                                   0
4          TNS for Linux: Version 12.2.0.1.0 - Production                               0
5          NLSRTL Version 12.2.0.1.0 - Production                                       0


used time: 92.869(ms). Execute id is 14.
SQL> select * from jy.t1@link3;

LINEID     T_ID T_NAME
---------- ---- -------
1          9    m_YYL
2          1    m_A
3          2    m_B
4          3    m_C
5          4    m_D
6          5    m_E
7          6    m_F
8          7    m_JYHY
9          8    m_JYYYL

9 rows got

used time: 10.891(ms). Execute id is 15.
SQL> insert into jy.t1@link3 values(9,'m_wy');
affect rows 1

used time: 33.658(ms). Execute id is 16.
SQL> commit;
executed successfully
used time: 20.563(ms). Execute id is 17.

SQL> select * from jy.t1;

      T_ID T_NAME
---------- ----------------------------------------
         9 m_wy
         9 m_YYL
         1 m_A
         2 m_B
         3 m_C
         4 m_D
         5 m_E
         6 m_F
         7 m_JYHY
         8 m_JYYYL

10 rows selected.

删除外部链接
删除一个外部链接。
语法格式
DROP [PUBLIC] LINK [< 模式名>.]< 外部链接名>;
参数
1.< 模式名> 指明被操作的外部链接属于哪个模式,缺省为当前模式;
2.< 外部链接名> 指明被操作的外部链接的名称。

语句功能
删除一个外部链接。
使用说明
只有链接对象的创建者和DBA拥有该对象的删除权限。

举例说明
删除外部链接LINK1。
DROP LINK LINK1;

使用外部链接通过外部链接,可以对远程服务器的对象进行查询或进行增删改操作,可以调用远程的过程。使用外部链接进行查询或增删改的语法格式与普通格式基本一致,唯一的区别在于指定外部链接表时需要使用如下格式作为表或视图的引用:
[TABLENAME | VIEWNAME] [LINK | @] 链接名

举例说明 使用外部链接查询LINK1上的远程表进行查询
SELECT * FROM SYSOBJECTS LINK LINK1; 或对远程表进行插入数据:
INSERT INTO T1@LINK1 VALUES(1,2,3);
也可以查询本地表或其他链接的表对远程表进行操作,如
UPDATE T1@LINK1 SET C1 = C1+1 WHERE C2 NOT IN (SELECT ID FROM LOCAL_TABLE);
DELETE FROM T1@LINK1 WHERE C1 IN (SELECT ID FROM T2@LINK2);

使用外部链接,可以调用远程的存储过程,但是不支持调用远程的函数,使用中有以下约束:
(1)参数数据类型为SQL类型,不允许为DMSQL程序类型;
(2)参数数据类型不允许为复合类型。
其使用方式为:
[CALL] [< 模式名>.][< 包名>.]< 过程名> [@] < 外部链接名>(< 参数列>);

使用限制
外部链接的使用有以下限制:
1. DM-DM的同构外部链接不支持MPP环境,DM与异构数据库的外部链接支持MPP环境;
2. 增删改不支持INTO语句;
3. 不支持使用游标进行增删改操作;
4. DBLINK理论上不支持LOB类型列的操作,但支持简单的增删改语句中使用常量来对LOB类型列进行操作。
另外,DM连接异构数据库的外部链接还有如下使用限制:
1. 数据类型以DM为基础,不支持DM没有的数据类型;
2. 语法以DM的语法为标准,不支持DM不兼容的语法;
3. 主键更新,如果是涉及到多个服务器的语句,不能保证更新操作一定成功。

Proudly powered by WordPress | Indrajeet by Sus Hill.