RMAN 으로 Raw device 백업 복구하기

테스트 1 : Raw device 상태의 데이터파일을 RMAN 의 backupset 으로 백업 받은 후 정상적으로 복구 되는지 확인


Step 1. 현재상태 확인


[oracle@localhost ~]$ sqlplus / as sysdba


SQL*Plus: Release 10.2.0.5.0 - Production on Wed Feb 1 11:05:19 2012

Copyright (c) 1982, 2010, Oracle. All Rights Reserved.

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> !vi dd.sql


set line 200

col tablespace_name for a10

col file_name for a45

select tablespace_name,bytes/1024/1024 MB,file_name from dba_data_files

/

:wq!


SQL> @dd <- Data file 상태 확인


TABLESPACE MB FILE_NAME

------------------- ---------- ---------------------------------------------

USERS 5 /dev/raw/raw4

SYSAUX 250 /dev/raw/raw2

UNDOTBS1 30 /dev/raw/raw3

SYSTEM 440 /dev/raw/raw1

EXAMPLE 100 /dev/raw/raw5


SQL> !vi log.sql <- Redo log file 상태 확인


set line 200

col group# for 999

col member for a20

col mb for 999

col seq# for 999

col archived for a4

col status for a8

select a.group#,a.member,b.bytes/1024/1024 MB,b.sequence# "SEQ#" ,b.archived,b.status

from v$logfile a, v$log b

where a.group#=b.group#

order by 1,2

/

:wq!


SQL> @log


GROUP# MEMBER MB SEQ# ARCH STATUS

---------- -------------------- ------ ------- ---------- -----------

1 /dev/raw/raw10 50 4 NO CURRENT

1 /dev/raw/raw9 50 4 NO CURRENT

2 /dev/raw/raw11 50 2 YES INACTIVE

2 /dev/raw/raw12 50 2 YES INACTIVE

3 /dev/raw/raw13 50 3 YES INACTIVE

3 /dev/raw/raw14 50 3 YES INACTIVE

6 rows selected.


SQL> select name from v$controlfile;


NAME

---------------------------------

/dev/raw/raw6

/dev/raw/raw7

/dev/raw/raw8


SQL> archive log list;

Database log mode Archive Mode

Automatic archival Enabled

Archive destination /data/arc2

Oldest online log sequence 2

Next log sequence to archive 4

Current log sequence 4


Step 2. RMAN 을 사용하여 전체 백업(백업경로는 /data/backup/rman/ 으로 하겠습니다)


[oracle@localhost ~]$ rman target /


Recovery Manager: Release 10.2.0.5.0 - Production on Wed Feb 1 10:47:50 2012

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

connected to target database: TESTDB (DBID=2557423915)


RMAN> backup as compressed backupset

2> format '/data/backup/rman/%U_%T'

3> database;

Starting backup at 01-FEB-12

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=144 devtype=DISK

channel ORA_DISK_1: starting compressed full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00001 name=/dev/raw/raw1

input datafile fno=00003 name=/dev/raw/raw2

input datafile fno=00005 name=/dev/raw/raw5

input datafile fno=00002 name=/dev/raw/raw3

input datafile fno=00004 name=/dev/raw/raw4

channel ORA_DISK_1: starting piece 1 at 01-FEB-12

channel ORA_DISK_1: finished piece 1 at 01-FEB-12

piece handle=/data/backup/rman/01n27hl4_1_1_20120201 tag=TAG20120201T104907

comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:36

channel ORA_DISK_1: starting compressed full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

including current control file in backupset

including current SPFILE in backupset

channel ORA_DISK_1: starting piece 1 at 01-FEB-12

channel ORA_DISK_1: finished piece 1 at 01-FEB-12

piece handle=/data/backup/rman/02n27hm8_1_1_20120201 tag=TAG20120201T104907

comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03

Finished backup at 01-FEB-12


[oracle@localhost ~]$ ls -lSh /data/backup/rman/

합계 112M

-rw-r----- 1 oracle dba 111M 2월 1 10:49 01n27hl4_1_1_20120201 <- 전체 backupset

-rw-r----- 1 oracle dba 1.1M 2월 1 10:49 02n27hm8_1_1_20120201 <- controlfile backupset


Step 3. 테스트용 테이블 scott.gogak 테이블 생성 후 장애 발생시킴


[oracle@localhost ~]$ sqlplus scott/tiger


SQL*Plus: Release 10.2.0.5.0 - Production on Wed Feb 1 11:14:21 2012

Copyright (c) 1982, 2010, Oracle. All Rights Reserved.

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> create table gogak (no number, name varchar2(10)) tablespace users;

Table created.


SQL> insert into gogak values (1,'AAA');

1 row created.


SQL> insert into gogak values (2,'BBB');

1 row created.


SQL> commit;

Commit complete.


SQL> select * from gogak;


NO NAME

---------- ----------

1 AAA

2 BBB


SQL> conn / as sysdba

Connected.


SQL> @dd


TABLESPACE MB FILE_NAME

---------------- ---------- ---------------------------------------------

USERS 5 /dev/raw/raw4 <- 이 파일에 장애 발생시킴

SYSAUX 250 /dev/raw/raw2

UNDOTBS1 30 /dev/raw/raw3

SYSTEM 440 /dev/raw/raw1

EXAMPLE 100 /dev/raw/raw5


SQL> !dd if=/dev/zero of=/dev/raw/raw4 bs=8k

dd: writing `/dev/raw/raw4': 장치에 남은 공간이 없음

12801+0개의 레코드를 입력하였습니다

12800+0개의 레코드를 출력하였습니다


SQL> alter tablespace users offline immediate;

Tablespace altered.


SQL> alter tablespace users online;

alter tablespace users online

*

ERROR at line 1:

ORA-01122: database file 4 failed verification check

ORA-01110: data file 4: '/dev/raw/raw4'

ORA-01210: data file header is media corrupt


SQL> select * from scott.gogak;

select * from scott.gogak

*

ERROR at line 1:

ORA-00376: file 4 cannot be read at this time

ORA-01110: data file 4: '/dev/raw/raw4'


Step 4. RMAN 으로 해당 장애 복구하기


[oracle@localhost ~]$ rman target /


Recovery Manager: Release 10.2.0.5.0 - Production on Wed Feb 1 11:19:20 2012

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

connected to target database: TESTDB (DBID=2557423915)

RMAN> run {

2> sql "alter tablespace users offline immediate";

3> restore tablespace users;

4> recover tablespace users;

5> sql "alter tablespace users online";

6> }

sql statement: alter tablespace users offline immediate

Starting restore at 01-FEB-12

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00004 to /dev/raw/raw4

channel ORA_DISK_1: reading from backup piece /data/backup/rman/01n27hl4_1_1_20120201

channel ORA_DISK_1: restored backup piece 1

piece handle=/data/backup/rman/01n27hl4_1_1_20120201 tag=TAG20120201T104907

channel ORA_DISK_1: restore complete, elapsed time: 00:00:02

Finished restore at 01-FEB-12

Starting recover at 01-FEB-12

using channel ORA_DISK_1

starting media recovery

media recovery complete, elapsed time: 00:00:01

Finished recover at 01-FEB-12

sql statement: alter tablespace users online


RMAN> exit

Recovery Manager complete.


[oracle@localhost ~]$ sqlplus scott/tiger


SQL*Plus: Release 10.2.0.5.0 - Production on Wed Feb 1 11:21:53 2012

Copyright (c) 1982, 2010, Oracle. All Rights Reserved.

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> select * from gogak;


NO NAME

---------- ----------

1 AAA

2 BBB


위에서 테스트 해 본 바와 같이 Raw device 도 RMAN 으로 백업 및 복구가 가능합니다.



테스트 2. Raw device 상태의 데이터 파일을 backupset 으로 증분 백업 가능한지와 복구 가능한지 테스트



Step 1. 현재 상태 확인


[oracle@localhost ~]$ sqlplus / as sysdba


SQL*Plus: Release 10.2.0.5.0 - Production on Wed Feb 1 11:24:25 2012

Copyright (c) 1982, 2010, Oracle. All Rights Reserved.

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> @dd


TABLESPACE MB FILE_NAME

----------------- ---------- ---------------------------------------------

USERS 5 /dev/raw/raw4

SYSAUX 250 /dev/raw/raw2

UNDOTBS1 30 /dev/raw/raw3

SYSTEM 440 /dev/raw/raw1

EXAMPLE 100 /dev/raw/raw5


SQL> @log


GROUP# MEMBER MB SEQ# ARCH STATUS

----------- ---------------------- ------- --------- ---------- -------------

1 /dev/raw/raw10 50 4 NO CURRENT

1 /dev/raw/raw9 50 4 NO CURRENT

2 /dev/raw/raw11 50 2 YES INACTIVE

2 /dev/raw/raw12 50 2 YES INACTIVE

3 /dev/raw/raw13 50 3 YES INACTIVE

3 /dev/raw/raw14 50 3 YES INACTIVE


SQL> select name from v$controlfile;


NAME

----------------------------------------

/dev/raw/raw6

/dev/raw/raw7

/dev/raw/raw8

6 rows selected.



Step 2. RMAN 을 사용하여 증분 백업을 여러 차례 수행합니다.


[oracle@localhost ~]$ rman target /


Recovery Manager: Release 10.2.0.5.0 - Production on Wed Feb 1 11:28:05 2012

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

connected to target database: TESTDB (DBID=2557423915)


RMAN> backup as compressed backupset

2> incremental level 0

3> format '/data/backup/rman/%U_%T'

4> database;

Starting backup at 01-FEB-12

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=145 devtype=DISK

channel ORA_DISK_1: starting compressed full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00001 name=/dev/raw/raw1

input datafile fno=00003 name=/dev/raw/raw2

input datafile fno=00005 name=/dev/raw/raw5

input datafile fno=00002 name=/dev/raw/raw3

input datafile fno=00004 name=/dev/raw/raw4

channel ORA_DISK_1: starting piece 1 at 01-FEB-12

channel ORA_DISK_1: finished piece 1 at 01-FEB-12

piece handle=/data/backup/rman/03n27jur_1_1_20120201 tag=TAG20120201T112827

comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35

channel ORA_DISK_1: starting compressed full datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

including current control file in backupset

including current SPFILE in backupset

channel ORA_DISK_1: starting piece 1 at 01-FEB-12

channel ORA_DISK_1: finished piece 1 at 01-FEB-12

piece handle=/data/backup/rman/04n27jvu_1_1_20120201 tag=TAG20120201T112827

comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03

Finished backup at 01-FEB-12

-- 다른 터미널에서 데이터 변경을 위해 테이블 생성하고 데이터 입력합니다.


SQL> create table scott.gogak2 (no number,name varchar2(10)) tablespace users;

Table created.


SQL> insert into scott.gogak2 values (1,'CCC');

1 row created.


SQL> insert into scott.gogak2 values (2,'DDD');

1 row created.


SQL> commit;

Commit complete.


-- RMAN 터미널에서 증분 백업을 수행합니다.

RMAN> backup as compressed backupset

2> incremental level 2

3> format '/data/backup/rman/%U_%T'

4> tablespace users;

Starting backup at 01-FEB-12

using channel ORA_DISK_1

channel ORA_DISK_1: starting compressed incremental level 2 datafile backupset

channel ORA_DISK_1: specifying datafile(s) in backupset

input datafile fno=00004 name=/dev/raw/raw4

channel ORA_DISK_1: starting piece 1 at 01-FEB-12

channel ORA_DISK_1: finished piece 1 at 01-FEB-12

piece handle=/data/backup/rman/05n27knu_1_1_20120201 tag=TAG20120201T114150

comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 01-FEB-12



Step 3. 장애를 발생 시킵니다


SQL> @dd


TABLESPACE MB FILE_NAME

---------------- ------- ---------------------------------------------

USERS 5 /dev/raw/raw4

SYSAUX 250 /dev/raw/raw2

UNDOTBS1 30 /dev/raw/raw3

SYSTEM 440 /dev/raw/raw1

EXAMPLE 100 /dev/raw/raw5


SQL> !dd if=/dev/zero of=/dev/raw/raw4 bs=8k <- 장애를 발생시킵니다

dd: writing `/dev/raw/raw4': 장치에 남은 공간이 없음

12801+0개의 레코드를 입력하였습니다

12800+0개의 레코드를 출력하였습니다


SQL> alter tablespace users offline immediate;

Tablespace altered.


SQL> alter tablespace users online;

alter tablespace users online

*

ERROR at line 1:

ORA-01122: database file 4 failed verification check

ORA-01110: data file 4: '/dev/raw/raw4'

ORA-01210: data file header is media corrupt


SQL> select * from scott.gogak2;

select * from scott.gogak2

*

ERROR at line 1:

ORA-00376: file 4 cannot be read at this time

ORA-01110: data file 4: '/dev/raw/raw4'



Step 4. RMAN 으로 복구 후 확인합니다.


RMAN> run {

2> restore tablespace users;

3> recover tablespace users;

4> sql "alter tablespace users online" ;

5> }

Starting restore at 01-FEB-12

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backupset restore

channel ORA_DISK_1: specifying datafile(s) to restore from backup set

restoring datafile 00004 to /dev/raw/raw4

channel ORA_DISK_1: reading from backup piece /data/backup/rman/05n27knu_1_1_20120201

channel ORA_DISK_1: restored backup piece 1

piece handle=/data/backup/rman/05n27knu_1_1_20120201 tag=TAG20120201T114150

channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

Finished restore at 01-FEB-12

Starting recover at 01-FEB-12

using channel ORA_DISK_1

starting media recovery

media recovery complete, elapsed time: 00:00:01

Finished recover at 01-FEB-12

sql statement: alter tablespace users online


SQL> select * from scott.gogak2;


NO NAME

---------- ----------

1 CCC

2 DDD



테스트 3. RMAN 으로 Raw device 상태의 데이터 파일을 Raw device 형태로 백업 받은 후 복구 가능한지 테스트



Step 1. 현재 상태 확인


RMAN> report schema;

Report of database schema

List of Permanent Datafiles

===========================

File Size(MB) Tablespace RB segs Datafile Name

---- -------- -------------------- ------- ------------------------

1 440 SYSTEM *** /dev/raw/raw1

2 30 UNDOTBS1 *** /dev/raw/raw3

3 250 SYSAUX *** /dev/raw/raw2

4 5 USERS *** /dev/raw/raw4

5 100 EXAMPLE *** /dev/raw/raw5

List of Temporary Files

=======================

File Size(MB) Tablespace Maxsize(MB) Tempfile Name

---- -------- -------------------- ----------- --------------------

1 20 TEMP 100 /dev/raw/raw15


Step 2. RMAN 으로 Raw device 파일 백업 수행


RMAN> copy

2> datafile 1 to '/data/backup/rman/system' ,

3> datafile 2 to '/data/backup/rman/undotbs1' ,

4> datafile 3 to '/data/backup/rman/sysaux' ,

5> datafile 4 to '/data/backup/rman/users' ,

6> datafile 5 to '/data/backup/rman/example' ;

Starting backup at 01-FEB-12

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

input datafile fno=00001 name=/dev/raw/raw1

output filename=/data/backup/rman/system tag=TAG20120201T115814 recid=9

stamp=774100724

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:35

channel ORA_DISK_1: starting datafile copy

input datafile fno=00003 name=/dev/raw/raw2

output filename=/data/backup/rman/sysaux tag=TAG20120201T115814 recid=10

stamp=774100744

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:16

channel ORA_DISK_1: starting datafile copy

input datafile fno=00005 name=/dev/raw/raw5

output filename=/data/backup/rman/example tag=TAG20120201T115814 recid=11

stamp=774100749

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07

channel ORA_DISK_1: starting datafile copy

input datafile fno=00002 name=/dev/raw/raw3

output filename=/data/backup/rman/undotbs1 tag=TAG20120201T115814 recid=12

stamp=774100754

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03

channel ORA_DISK_1: starting datafile copy

input datafile fno=00004 name=/dev/raw/raw4

output filename=/data/backup/rman/users tag=TAG20120201T115814 recid=13

stamp=774100756

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01

Finished backup at 01-FEB-12

-- 다른 창에서 백업 파일을 확인합니다


[oracle@localhost rman]$ pwd

/data/backup/rman


[oracle@localhost rman]$ ls –lSh

-rw-r----- 1 oracle dba 441M 2?? 1 11:58 system

-rw-r----- 1 oracle dba 251M 2?? 1 11:59 sysaux

-rw-r----- 1 oracle dba 101M 2?? 1 11:59 example

-rw-r----- 1 oracle dba 31M 2?? 1 11:59 undotbs1

-rw-r----- 1 oracle dba 5.1M 2?? 1 11:59 users


Step 3. 테스트용 테이블 scott.gogak3 을 생성 후 장애를 발생시킵니다.


SQL> create table scott.gogak3 (no number, name varchar2(10))

2 tablespace users;

Table created.


SQL> insert into scott.gogak3 values (1,'EEE');

1 row created.


SQL> insert into scott.gogak3 values (2,'FFF');

1 row created.


SQL> commit;

Commit complete.


SQL> select * from scott.gogak3;


NO NAME

---------- ----------

1 EEE

2 FFF


SQL> @dd


TABLESPACE MB FILE_NAME

---------------- -------- ---------------------------------------------

USERS 5 /dev/raw/raw4

SYSAUX 250 /dev/raw/raw2

UNDOTBS1 30 /dev/raw/raw3

SYSTEM 440 /dev/raw/raw1

EXAMPLE 100 /dev/raw/raw5

SQL> !dd if=/dev/zero of=/dev/raw/raw4 bs=8k

dd: writing `/dev/raw/raw4': 장치에 남은 공간이 없음

12801+0개의 레코드를 입력하였습니다

12800+0개의 레코드를 출력하였습니다


SQL> alter tablespace users offline immediate;

Tablespace altered.


SQL> alter tablespace users online;

alter tablespace users online

*

ERROR at line 1:

ORA-01122: database file 4 failed verification check

ORA-01110: data file 4: '/dev/raw/raw4'

ORA-01210: data file header is media corrupt


SQL> select * from scott.gogak3;

select * from scott.gogak3

*

ERROR at line 1:

ORA-00376: file 4 cannot be read at this time

ORA-01110: data file 4: '/dev/raw/raw4'


Step 4. RMAN 으로 파일을 복원 한 후 복구합니다.


RMAN> restore tablespace users;

Starting restore at 01-FEB-12

using channel ORA_DISK_1

channel ORA_DISK_1: restoring datafile 00004

input datafile copy recid=13 stamp=774100756 filename=/data/backup/rman/users

destination for restore of datafile 00004: /dev/raw/raw4

channel ORA_DISK_1: copied datafile copy of datafile 00004

output filename=/dev/raw/raw4 recid=14 stamp=774101682

Finished restore at 01-FEB-12

위에서 진하게 표시된 부분을 보면 RMAN 에서 자동으로 copy 된 raw device 를 찾아서

복원하는 것을 알 수 있습니다.


RMAN> recover tablespace users;

Starting recover at 01-FEB-12

using channel ORA_DISK_1

starting media recovery

media recovery complete, elapsed time: 00:00:00

Finished recover at 01-FEB-12


-- sqlplus 창에서 데이터가 복구되었는지 확인합니다.


SQL> alter tablespace users online;

Tablespace altered.


SQL> select * from scott.gogak3;

NO NAME

---------- ----------

1 EEE

2 FFF


정상적으로 복구가 된 것을 알 수 있습니다.

위에서 살펴본 바와 같이 Raw Device 로 구성된 database 도 RMAN 으로 동일하게 관리할 수 있습니다.

Oracle 18c 설치 Single

오라클 18c가 릴리즈 되었는데 설치 방법이 약간 바뀌었다.


18c는 2018.08.21 기준, 리눅스와 솔라리스 버전만 릴리즈 되었다.



해당 예제는 리눅스 7버전에 설치를 진행 한다.



리눅스 7의 Oracle 설치를 위한 기본 설치 패키지



Server with GUI

Hardware Monitoring Utilities

Large Systems Performance

Network file system client

Performance Tools

Compatibility Libraries

Development Tools


# vi /etc/hosts


# yum update -y




자동 셋업


# yum install -y install oracle-database-preinstall-18c




수동 셋업


# vi /etc/sysctl.conf


fs.file-max = 6815744

kernel.sem = 250 32000 100 128

kernel.shmmni = 4096

kernel.shmall = 1073741824

kernel.shmmax = 4398046511104

kernel.panic_on_oops = 1

net.core.rmem_default = 262144

net.core.rmem_max = 4194304

net.core.wmem_default = 262144

net.core.wmem_max = 1048576

net.ipv4.conf.all.rp_filter = 2

net.ipv4.conf.default.rp_filter = 2

fs.aio-max-nr = 1048576

net.ipv4.ip_local_port_range = 9000 65500



# vi /etc/security/limits.d/oracle-database-preinstall-18c.conf


oracle   soft   nofile    1024

oracle   hard   nofile    65536

oracle   soft   nproc    16384

oracle   hard   nproc    16384

oracle   soft   stack    10240

oracle   hard   stack    32768

oracle   hard   memlock    134217728

oracle   soft   memlock    134217728



패키지 설치 목록


# OL6 and OL7 (RHEL6 and RHEL7)

yum install -y bc    

yum install -y binutils

yum install -y compat-libcap1

yum install -y compat-libstdc++-33

yum install -y compat-libstdc++-33.i686

yum install -y elfutils-libelf.i686

yum install -y elfutils-libelf

yum install -y elfutils-libelf-devel.i686

yum install -y elfutils-libelf-devel

yum install -y fontconfig-devel

yum install -y glibc.i686

yum install -y glibc

yum install -y glibc-devel.i686

yum install -y glibc-devel

yum install -y ksh

yum install -y libaio.i686

yum install -y libaio

yum install -y libaio-devel.i686

yum install -y libaio-devel

yum install -y libX11.i686

yum install -y libX11

yum install -y libXau.i686

yum install -y libXau

yum install -y libXi.i686

yum install -y libXi

yum install -y libXtst.i686

yum install -y libXtst

yum install -y libgcc.i686

yum install -y libgcc

yum install -y librdmacm-devel

yum install -y libstdc++.i686

yum install -y libstdc++

yum install -y libstdc++-devel.i686

yum install -y libstdc++-devel

yum install -y libxcb.i686

yum install -y libxcb

yum install -y make

yum install -y nfs-utils

yum install -y net-tools

yum install -y python

yum install -y python-configshell

yum install -y python-rtslib

yum install -y python-six

yum install -y smartmontools

yum install -y sysstat

yum install -y targetcli

yum install -y unixODBC



그룹 및 유저 추가


# groupadd -g 54321 oinstall

# groupadd -g 54322 dba

# groupadd -g 54323 oper


# useradd -u 54321 -g oinstall -G dba,oper oracle




추가 세팅



SELinux 설정


# vi /etc/selinux/config


SELINUX=permissive


# setenforce Permissive

※ 리눅스 7 버전은 SELinux 설정 후 재구동 필요없음.



방화벽 Off


# systemctl stop firewalld

# systemctl disable firewalld



디렉토리 생성


# mkdir -p /u01/app/oracle/product/18.0.0/dbhome_1

# mkdir -p /u02/oradata

# chown -R oracle:oinstall /u01 /u02

# chmod -R 775 /u01 /u02


* u01 - 엔진

* u02 - 데이터



프로파일 설정


기존의 방식대로 해도 되고, 

아래는 18c 부터 오라클이 제공하는 방식을 설명한다.


$ mkdir /home/oracle/scripts


$ touch /home/oracle/scripts/setEnv.sh


$ cat > /home/oracle/scripts/setEnv.sh <<EOF

# Oracle Settings

export TMP=/tmp

export TMPDIR=\$TMP


export ORACLE_HOSTNAME=ol7-183.localdomain

export ORACLE_UNQNAME=cdb1

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOME=\$ORACLE_BASE/product/18.0.0/dbhome_1

export ORA_INVENTORY=/u01/app/oraInvenotry

export ORACLE_SID=cdb1

export PDB_NAME=pdb1

export DATA_DIR=/u02/data


export PATH=/usr/sbin:/usr/local/bin:\$PATH

export PATH=\$ORACLE_HOME/bin:\$PATH


export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib

export CLASSPATH=\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib

EOF


$ echo ". /home/oracle/scripts/setEnv.sh" >> /home/oracle/.bash_profile



시작, 종료 스크립트 작성


$ touch /home/oracle/scripts/start_all.sh

$ touch /home/oracle/scripts/stop_all.sh


$ cat > /home/oracle/scripts/start_all.sh <<EOF

#!/bin/bash

. /home/oracle/scripts/setEnv.sh


export ORAENV_ASK=NO

. oraenv

export ORAENV_ASK=YES


dbstart \$ORACLE_HOME

EOF



$ cat > /home/oracle/scripts/stop_all.sh <<EOF

#!/bin/bash

. /home/oracle/scripts/setEnv.sh


export ORAENV_ASK=NO

. oraenv

export ORAENV_ASK=YES


dbshut \$ORACLE_HOME

EOF



$ chown -R oracle.oinstall /home/oracle/scripts

$ chmod u+x /home/oracle/scripts/*.sh


설치 완료후에 /etc/oratab에 넣어주고, 오라클 유저로 시작/종료 할 수 있다.


~/scripts/start_all.sh

~/scripts/stop_all.sh



엔진 설치


Oracle 홈페이지에서 LINUX.X64_180000_db_home.zip 파일을 받을 수 있다.


해당 파일을 반드시 /u01/app/oracle/product/18.0.0/dbhome_1 폴더로 옮겨서 압축을 푼다.


$ cd /u01/app/oracle/product/18.0.0/dbhome_1



X매니저 나 Gnome 환경에서 GUI 방식으로 설치 한다.


$ ./runInstaller




엔진 설치 완료


DBCA는 12c와 동일하다.

오라클에서 ODBC를 이용한 MySQL으로 DB LINK 설정

오라클에서 ODBC를 이용한 MySQL으로 DB LINK 설정



테스트 환경



오라클 DB 서버


Oracle Linux 6.9

Oracle 11gR2 - 11.2.0.4

ODBC Driver 8.0.11 (홈페이지에서 받아서 설치, https://dev.mysql.com/downloads/connector/odbc/)

캐릭터셋 - KO16MSWIN949

ip - 192.168.0.55



MySQL DB 서버


CentOS 7.2

MySQL 5.7 (yum 설치)

Oracle Gateway 11gR2 - 11.2.0.4

캐릭터셋 - euckr

ip - 192.168.0.44

Database - MYSQL



오라클 서버에서 설정


버전에 맞는 ODBC 드라이버를 받아서 yum으로 설치하면 /etc/odbc.ini, /etc/odbcinst.ini 파일이 보인다.


vi로 odbcinst.ini 열어보면


[MySQL ODBC 8.0 Unicode Driver]

Driver = /usr/lib64/libmyodbc8w.so

UsageCount = 1


[MySQL ODBC 8.0 ANSI Driver]

Driver = /usr/lib64/libmyodbc8a.so

UsageCount = 1


이 것이 MySQL 연결에 사용될 드라이버 인데, 주의할점은 각 DB의 캐릭터 셋에 맞춰 드라이버를 설정해줘야 한다.

UTF8를 사용할 것이라면 Unicode 드라이버를, EUCKR을 사용할 것 이라면 ANSI를 선택해야 한다.



# vi /etc/odbc.ini


[MYSQL]

Driver = /usr/lib64/libmyodbc8a.so

trace = off

port = 3306

server = 192.168.0.44

database = MYSQL

option = 2

user = DEMO

password = PASSWORD

charset = euckr



$ vi tnsnames.ora


MYSQL =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = tcp)(HOST = 192.168.0.44)(PORT = 1521))

      (CONNECT_DATA = (SID = MYSQL))

      (HS = OK)

  )



$ isql -v MYSQL 

+---------------------------------------+

| Connected!                            |

|                                       |

| sql-statement                         |

| help [tablename]                      |

| quit                                  |

|                                       |

+---------------------------------------+

SQL>


이렇게 나오면 일단 MySQL DB로 원격접속이 되는것이다.


※ 사전에 MySQL 서버의 방화벽을 내린다거나, MySQL 계정에 원격접속 가능한 권한을 줘야 한다.




MySQL 서버에서의 설정


MySQL은 기호에 맞게 설치하면 되고, 오라클 Gateway를 설치한다. 오라클 GUI 설치 할때와 같은 환경으로 맞춰서 설치한다.


# groupadd oinstall

# groupadd dba

# useradd -g oinstall -G dba oracle

# su - oracle



$ vi .bash_profile


export ODBCINI=/etc/odbc.ini

export ORACLE_HOME=/oracle/product/11.2.0/tg_1

export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:/usr/lib64:/lib

export PATH=$ORACLE_HOME/bin:$PATH


GUI에서 gateway를 설치할때 


ODBC 부분을 체크 해서 설치 해준다. (해당 스샷은 설치 후 캡처를 위해 다시 창을 띄운거라 reinstall 이라고 나옴)


Gateway 설치 후 HS 파라미터를 설정해야 한다.


$ cd $ORACLE_HOME/hs/admin



$ vi initMYSQL.ora (initXXXX.ora)    <-- [아래 HS_FDS_CONNECT_INFO = XXXX 의 XXXX 부분과 동일 하게 설정]


# This is a sample agent init file that contains the HS parameters that are

# needed for the Database Gateway for ODBC


#

# HS init parameters

#

HS_FDS_CONNECT_INFO = MYSQL      <-- [해당부분은 접속 하고자하는 MySQL DB 명 입력]

HS_FDS_SHAREABLE_NAME = /usr/lib64/libmyodbc8a.so      <-- [사용하고자 하는 ODBC 드라이버]

HS_FDS_TRACE_LEVEL = OFF                <--[접속은 되는데 결과값이 안나온다면 255 로 설정해 trace 확인]

HS_FDS_SUPPORT_STATISTICS = FALSE

HS_LANGUAGE=AMERICAN_AMERICA.KO16MSWIN949     <--[Oracle 서버쪽 DB의 캐릭터셋]

HS_RPC_FETCH_REBLOCKING = OFF

HS_KEEP_REMOTE_COLUMN_SIZE = ALL

HS_NLS_LENGTH_SEMANTICS = VARCHAR                  <-- [VARCHAR or CHAR 등으로 환경에 맞게 설정 가능]

HS_FDS_TIMESTAMP_MAPPING = DATE

HS_NLS_NCHAR=UCS2


#

# ODBC specific environment variables

#

set ODBCINI=/etc/odbc.ini


#

# Environment variables required for the non-Oracle system

#



Oracle Gateway를 이용해서 MySQL 서버에 오라클 Listener를 띄운다.

$ vi $ORACLE_HOME/network/admin/listener.ora

# listener.ora Network Configuration File: /oracle/product/11.2.0/tg_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME=MYSQL)
      (ORACLE_HOME=/oracle/product/11.2.0/tg_1)
      (PROGRAM=/oracle/product/11.2.0/tg_1/bin/dg4odbc)
      (ENVS=LD_LIBRARY_PATH = /usr/lib:/usr/lib64:/oracle/product/11.2.0/tg_1/lib:/oracle/product/11.2.0/tg_1/hs/lib)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.44)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )


ADR_BASE_LISTENER = /oracle/product/11.2.0/tg_1


$ lsnrctl start

$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 27-JUL-2018 11:35:58

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Starting /oracle/product/11.2.0/tg_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /oracle/product/11.2.0/tg_1/network/admin/listener.ora
Log messages written to /oracle/product/11.2.0/tg_1/diag/tnslsnr/MYSQL/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=1192.168.0.44)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.44)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                27-JUL-2018 11:35:58
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /oracle/product/11.2.0/tg_1/network/admin/listener.ora
Listener Log File         /oracle/product/11.2.0/tg_1/diag/tnslsnr/MYSQL/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.44)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "MYSQL" has 1 instance(s).
  Instance "MYSQL", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully



오라클 서버에서 tnsping을 실행 했을때


$ tnsping mysql


TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 27-JUL-2018 11:19:40


Copyright (c) 1997, 2013, Oracle.  All rights reserved.


Used parameter files:

/app/oracle/product/11.2.0.4/db_1/network/admin/sqlnet.ora



Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = tcp)(HOST = 192.168.0.44)(PORT = 1521)) (CONNECT_DATA = (SID = MYSQL)) (HS = OK))

OK (10 msec)



나오면 접속 준비가 완료




ORACLE DB의 SCOTT 계정에서 DB LINK TEST


DB LINK 생성 

※ DB Link를 생성하고자하는 계정에 create database link 권한을 주고 작업한다.


$ sqlplus scott/tiger


SQL> create database link mysql

connect to DEMO

IDENTIFIED BY "<password>"

USING 'MYSQL';



MySQL DB에 미리 만들어 놓은 DEMO 테이블을 조회 해본다.

※ 테스트용 계정과 테이블은 알아서 만드시길... DEMO 유저의 DEMO 테이블을 조회 했다.


SQL> select * from "demo"@mysql_test;


      col1 col2       col3 col4     col5

---------- ---------- ---------- ---------- --------------------

1 24-JUL-18  0123456789 0123456789 30313233343536373839

2 25-JUL-18  0123456788 0123456788 30313233343536373838



결과 값이 나오면 성공이다.




Oracle 12c R2 RAC 설치 #1

설치 환경


Esxi 5.5, 

Oracle Linux 6.9 x86_64

Oracle 12c R2 (12.2.0.1)


리눅스6 설치 옵션


SWAP 4GB+

방화벽 사용중지

SELinux 설정 변경 (permissive or disabled)

해당 패키지 그룹 설치

  • Base System > Base
  • Base System > Hardware monitoring utilities
  • Base System > Large Systems Performance
  • Base System > Network file system client
  • Base System > Performance Tools
  • Base System > Perl Support
  • Servers > Server Platform
  • Servers > System administration tools
  • Desktops > Desktop
  • Desktops > Desktop Platform
  • Desktops > Fonts
  • Desktops > General Purpose Desktop
  • Desktops > Graphical Administration Tools
  • Desktops > Input Methods
  • Desktops > X Window System
  • Applications > Internet Browser
  • Development > Additional Development
  • Development > Development Tools


자동 설정


# yum install oracle-database-server-12cR2-preinstall -y

# yum install ntp -y



직접 설정


# groupadd oinstall

# groupadd dba

# useradd -g oinstall -G dba oracle

# passwd oracle



# vi /etc/sysctl.conf


fs.file-max = 6815744

kernel.sem = 250 32000 100 128

kernel.shmmni = 4096

kernel.shmall = 1073741824

kernel.shmmax = 4398046511104

kernel.panic_on_oops = 1

net.core.rmem_default = 262144

net.core.rmem_max = 4194304

net.core.wmem_default = 262144

net.core.wmem_max = 1048576

net.ipv4.conf.all.rp_filter = 2

net.ipv4.conf.default.rp_filter = 2

fs.aio-max-nr = 1048576

net.ipv4.ip_local_port_range = 9000 65500


# sysctl -p



# vi /etc/security/limits.d/oracle-database-server-12cR2-preinstall.conf


oracle   soft   nofile    1024

oracle   hard   nofile    65536

oracle   soft   nproc    16384

oracle   hard   nproc    16384

oracle   soft   stack    10240

oracle   hard   stack    32768

oracle   hard   memlock    134217728

oracle   soft   memlock    134217728


# yum -y install ksh,libaio-devel,unixODBC, unixODBC-devel

# yum -y update



# vi /etc/hosts


127.0.0.1       localhost.localdomain   localhost

# Public

192.168.56.201   ol6-122-rac1.localdomain        ol6-122-rac1

192.168.56.202   ol6-122-rac2.localdomain        ol6-122-rac2

# Private

192.168.1.201   ol6-122-rac1-priv.localdomain   ol6-122-rac1-priv

192.168.1.202   ol6-122-rac2-priv.localdomain   ol6-122-rac2-priv

# Virtual

192.168.56.203   ol6-122-rac1-vip.localdomain    ol6-122-rac1-vip

192.168.56.204   ol6-122-rac2-vip.localdomain    ol6-122-rac2-vip

# SCAN

#192.168.56.205   ol6-122-scan.localdomain ol6-122-scan

#192.168.56.206   ol6-122-scan.localdomain ol6-122-scan

#192.168.56.207   ol6-122-scan.localdomain ol6-122-scan



박화벽 중지


# service iptables stop

# chkconfig iptables off



NTP 설정


# vi /etc/sysconfig/ntpd

OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid"


# service ntpd restart

# chkconfig ntpd on



Grid 설치 폴더 생성


# mkdir -p /u01/app/12.2.0.1/grid

# mkdir -p /u01/app/oracle/product/12.2.0.1/db_1

# chown -R oracle:oinstall /u01

# chmod -R 775 /u01/



Oracle user 접속 후 프로파일 설정


$ vi .bash_profile


# Oracle Settings

export TMP=/tmp

export TMPDIR=$TMP


export ORACLE_HOSTNAME=ol6-122-rac1.localdomain

export ORACLE_UNQNAME=CDBRAC

export ORACLE_BASE=/u01/app/oracle

export GRID_HOME=/u01/app/12.2.0.1/grid

export DB_HOME=$ORACLE_BASE/product/12.2.0.1/db_1

export ORACLE_HOME=$DB_HOME

export ORACLE_SID=cdbrac1

export ORACLE_TERM=xterm

export BASE_PATH=/usr/sbin:$PATH

export PATH=$ORACLE_HOME/bin:$BASE_PATH


export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib

export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib


alias grid_env='. /home/oracle/grid_env'

alias db_env='. /home/oracle/db_env'


$ vi grid_env

export ORACLE_SID=+ASM1

export ORACLE_HOME=$GRID_HOME

export PATH=$ORACLE_HOME/bin:$BASE_PATH


export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib

export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib


$ vi db_env

export ORACLE_SID=cdbrac1

export ORACLE_HOME=$DB_HOME

export PATH=$ORACLE_HOME/bin:$BASE_PATH


export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib

export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib



공유 스토리지 Block device 설정


# fdisk /dev/sdb

 n, p, 1, Enter, Enter, w 



Udev 설정


# vi /etc/scsi_id.config

options=-g


# /sbin/scsi_id -g -u -d /dev/sdb1

36000c299ab492a9c2ff010df22555c9f


# vi /etc/udev/rules.d/99-oracle-asmdevices.rules

KERNEL=="sd?1", SUBSYSTEM=="block", PROGRAM=="/sbin/scsi_id -g -u -d /dev/$parent", RESULT=="36000c299ab492a9c2ff010df22555c9f", SYMLINK+="oracleasm/asm-disk1", OWNER="oracle", GROUP="dba", MODE="0660"



Block Device 파티션 테이블 불러오기


# partprobe /dev/sdb1



Udev Rule 다시 불러오기


# udevadm control --reload-rules


# ls -al /dev/oracleasm/*

lrwxrwxrwx. 1 root root 7 Mar  8 21:11 /dev/oracleasm/asm-disk1 -> ../sdb1




2번 노드도 똑같이 설정.