Thursday, August 15, 2019

Clone a RAC 12c VM environment with Virtualbox (import/export)

 

Intro

Have you ever finished a lab in your laptop with several virtual machines connected to each other and thought “Well that was neat! but how can I create a backup in my external hard drive and run it again at work or in any other computer?” The answer lays in this very article. For those of you who have finished any RAC environment lab (i.e Racattack) in VirtualBox, saving images of the created Oracle RAC system and hand it over to another location for a restore could be done in a matter of minutes! 
As matter of fact, Oracle VM VirtualBox can import and export virtual machines in Open Virtualization Format (OVF) which is an industry-standard format that we are going to use in this tutorial.

This tutorial will describe the steps to export then import a RAC environment in Virtualbox through import/export Appliance tools and other commands.

Considerations

The export of a VM is a straightforward process and saving RAC images would be an easy task if it weren’t for the shared asm disks.Therefore asm disks needed a bit more care than the guest systems but all was done in a timely manner. Furthermore, make sure your new computer’s VirtualBox Host Only Ethernet Adapter has the same IP segment than your Vms before importing them.

Note:
The directory path names used during the export/import (C:/,D;/) should be adapted to your own environment.

Follow the below steps and try the GUI alternatives if you find it easier than the command line options.


1. Export Shared disks

     - Detach the disks from RAC VMs:

image
     - Export them to a new location
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" clonemedium disk "C:\VM\RAC lab\london1\asm_1.vdi" "H:\OS\ORACLE\Lab Oracle\asm_1.vdi" --format VDI --variant Fixed
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" clonemedium disk "C:\VM\RAC lab\london1\asm_2.vdi" "H:\OS\ORACLE\Lab Oracle\asm_2.vdi" --format VDI --variant Fixed
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" clonemedium disk "C:\VM\RAC lab\london1\asm_3.vdi" "H:\OS\ORACLE\Lab Oracle\asm_3.vdi" --format VDI --variant Fixed
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" clonemedium disk "C:\VM\RAC lab\london1\asm_4.vdi" "H:\OS\ORACLE\Lab Oracle\asm_4.vdi" --format VDI --variant Fixed
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" clonemedium disk "C:\VM\RAC lab\london1\asm_5.vdi" "H:\OS\ORACLE\Lab Oracle\asm_5.vdi" --format VDI --variant Fixed

  Note: You can also start Disk Copying Wizard which is a GUI equivalent to the above.

image

2. Export the VMs to ovf templates

     - List VMs

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exelist vms
"london1" {45ae6298-7e95-4ef1-864d-85c995cb46ff}                             
"london2" {3c6a0e27-74f0-47ea-b3d7-ac9c253bb03b}                             

     - Export the VMs
    The OVA extension encapsulates all OVF folder content (.ovf,.mf*.vhd or *.vmdk) into a single zipped file

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" export "london1" -o  "H:\OS\ORACLE\Lab Oracle\london1.ova"  --ovf10     
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" export "london2" -o  "H:\OS\ORACLE\Lab Oracle\london2.ova"  --ovf10                         

  Note: You can also start Export Appliance Wizard for each VM which is the GUI equivalent to the above commands.

image

3. Copy the shared disks and exported VMs to a new Host

image


4. Import both VMS

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" import "D:\VM\Racattack\london1.ova"     --options keepallmacs 
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" import "D:\VM\Racattack\london2.ova"     --options keepallmacs   
Note: You can also start Import Appliance Wizard for VM which is the GUI equivalent to the above commands.
 *** Make sure your new computer’s VirtualBox Host Only Ethernet Adapter has the same IP segment than your Vms (example in my lab :192.168.78.1)

image

5. Change asm disks to shared

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifymedium disk "D:\VM\Racattack\asm_1.vdi" –type shareable
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifymedium disk "D:\VM\Racattack\asm_2.vdi"  --type shareable "C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifymedium disk "D:\VM\Racattack\asm_3.vdi"  --type shareable                          
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifymedium disk "D:\VM\Racattack\asm_4.vdi"  --type shareable                          
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifymedium disk "D:\VM\Racattack\asm_5.vdi"  --type shareable                          

   Note: You can also do the above through Virtual Media Manager  (GUI equivalent).

6. Attach the asm disks to both RAC VMs

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" storageattach london1 --storagectl "SATA" --port 1  --device 0 --type hdd --medium "D:\VM\Racattack\asm_1.vdi" --mtype shareable  
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" storageattach london1 --storagectl "SATA" --port 2  --device 0 --type hdd --medium "D:\VM\Racattack\asm_2.vdi" --mtype shareable                                 
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" storageattach london1 --storagectl "SATA" --port 3  --device 0 --type hdd --medium "D:\VM\Racattack\asm_3.vdi" --mtype shareable
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" storageattach london1 --storagectl "SATA" --port 4  --device 0 --type hdd --medium "D:\VM\Racattack\asm_4.vdi" --mtype shareable
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" storageattach london1 --storagectl "SATA" --port 5  --device 0 --type hdd --medium "D:\VM\Racattack\asm_5.vdi" --mtype shareable
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" storageattach london2 --storagectl "SATA" --port 1  --device 0 --type hdd --medium "H:\OS\ORACLE\Lab Oracle\asm_1.vdi" --mtype shareable       
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" storageattach london2 --storagectl "SATA" --port 2  --device 0 --type hdd --medium "D:\VM\Racattack\asm_2.vdi" --mtype shareable      
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" storageattach london2 --storagectl "SATA" --port 3  --device 0 --type hdd --medium "D:\VM\Racattack\asm_3.vdi" --mtype shareable      
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" storageattach london2 --storagectl "SATA" --port 4  --device 0 --type hdd --medium "D:\VM\Racattack\asm_4.vdi" --mtype shareable      
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" storageattach london2 --storagectl "SATA" --port 5  --device 0 --type hdd --medium "D:\VM\Racattack\asm_5.vdi" --mtype shareable
        image

7. ReConfigure the asm disks in each RAC nodes

   Since udev Device Mapping configuration got somehow lost during the import we will have to redo that again.
    On each VM do the following:

7.1 Create partition from above added disks
   - As root user use fdisk command to partition the attached disks. Repeat the steps below for all the disks (sdb, sdc, sdd,
   sde,sdf). 

 [root@london1 ~]# fidsk /dev/sd*     
      >> n    -- new
      > p     -- primary
      > 1     -- 1 partition
      > w     -- write the change for all the disks
      [root@london1 ~]# ls -l /dev/sd?1
      brw-rw---- 1 root disk 8,  1 Jul 19 05:34 /dev/sda1
      brw-rw---- 1 root disk 8, 17 Jul 19 05:52 /dev/sdb1
      brw-rw---- 1 root disk 8, 33 Jul 19 05:53 /dev/sdc1
      brw-rw---- 1 root disk 8, 49 Jul 19 05:54 /dev/sdd1
      brw-rw---- 1 root disk 8, 65 Jul 19 05:54 /dev/sde1
      brw-rw---- 1 root disk 8, 65 Jul 19 05:54 /dev/sdf1   

   

7.2 Verify scsi_id configuration 

   - The content of /etc/scsi_id.config should include the option -g for the scsi_id command to expect an UUID from the
    shared devices. if not run the below in one line 

printf  "options=-g --whitelisted --replace-whitespace"  > /etc/scsi_id.config
   - Check if the the symbolic link for scsi_id is still there (RHEL 7 only)            
ln -s  '/usr/lib/udev/scsi_id'   '/sbin/scsi_id'

7.3 Rebuild the Udev rules in the /etc/udev/rules.d/99-oracle-asmdevices.rules file

  - Run the following script as root

i=1
cmd="/sbin/scsi_id -g -u -d"
for disk in sdb sdc sdd sde sdf; do
cat <<EOF >> /etc/udev/rules.d/99-oracle-asmdevices.rules KERNEL=="sd?1",SUBSYSTEM=="block", PROGRAM=="$cmd /dev/\$parent", \
RESULT=="`$cmd /dev/$disk`", SYMLINK+="asm-disk$i", OWNER="grid", GROUP="dba", MODE="0660"
EOF i=$(($i+1)) done
7.4 Reload the udev rules and restart udev:
# /sbin/partprobe /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1                                                                                                               
# /sbin/udevadm test /block/sdb/sdb1                              
# /sbin/udevadm test /block/sdc/sdc1                              
# /sbin/udevadm test /block/sdd/sdd1                              
# /sbin/udevadm test /block/sde/sde1                        
# /sbin/udevadm test /block/sde/sdf1     
# /sbin/udevadm control --reload-rules                                 
   - Check the generated sim links
[root@london1 ~]# ls -l /dev/asm-*                                   
brw-rw---- 1 grid dba 8, 17 Jul 19 07:28 /dev/asm-disk1           
brw-rw---- 1 grid dba 8, 33 Jul 19 07:28 /dev/asm-disk2           
brw-rw---- 1 grid dba 8, 49 Jul 19 07:28 /dev/asm-disk3           
brw-rw---- 1 grid dba 8, 65 Jul 19 07:28 /dev/asm-disk4 
brw-rw---- 1 grid dba 8, 65 Jul 19 07:28 /dev/asm-disk4

8. Restart The clusterware on both new VMs and voila   

image

Friday, July 12, 2019

Oracle Cloud 2nd gen DBAAS Tutorial: Deploy a 2 Nodes RAC database service


Intro

Oracle Database Cloud Service (DBaaS) provides a platform to create full Oracle database instances in a virtual machine (VM). It's the same familiar Oracle Database, now in Oracle cloud.
Oracle made things even easier since you can now Sign Up for Free Oracle Cloud service and Get $300 of free credits good for up to 3500 hours of Oracle Cloud usage for 30 days. This could be a good oprtunity to have hands on experience in creating and managing Oracle Database Cloud Service .

Purpose

This tutorial shows you how to create a RAC service instances in Oracle Database Cloud Service when creating a database deployment . I wanted to add the exhaustive list of steps including all the necessary information (Network,compute,RAC) so you could try it yourself using the free trial subscription.

Note : The components' names used in this example  (compartment 'ECorp',Internet Gateway,VCN,Subnet,DBname,PDB..etc) can be changed to the value of your liking.

• To create a Database Cloud Service database deployment that uses Oracle Real Application Clusters (Oracle RAC) , Follow the below steps and fill in the displayed information on each of the listed wizards.

I. CREATE COMPARTMENT

A compartment is a logical container within your account used to store Oracle Cloud Infrastructure (OCI) Resources created within that compartment (such as compute, storage, and network) .

Go to – Identity section>compartments> Create compartment
                 > Name : ECorp 
> Description:
• Click create Compartment

II. CREATE VCN & RELATED NETWORK RESOURCES

Specifications

  • Allowable VCN size range: /16 to /30. recommended (10.0.0.0/8,172.16.0/12, and 192.168.0/16).
  • VCN reserves the first two IP addresses and the last one in each subnet's CIDR

1- Create the VCN

Go to Networking Section> Virtual Cloud Networks. 

> Create VCN only (VNC created without resources : add )
> Create in compartment : >Name : Ecorp
> VCN Name: Ecorpvcn
> CIDR block 192.168.64.0/20
> DNS resolution : use DNS hostname in this VNC
> DNS label:ecorpvcn >DnsDomain Name: ecorp.oraclevcn.com    
> 'No Tags'

* [Skip if VCN only option was selected ]

   If you want to rather create a VCN with related resources : (option checked)

   The following resources will be added for you

- CIDR block range of 10.0.0.0/16 
- An internet gateway
- Default security list.
- A public subnet in each availability domain.
- Internet and VCN Resolver for DNS

2- Create the internet gateway

In this example the route table will direct traffic to an internet gateway.

Go to Networking and click Virtual Cloud Networks then Click Internet Gateways.

1. Click Create Internet gateway :> Create in Compartment :> name: ECorp
2. Create default route table RULE :
Target type : > InternetGuateway  :> Destination CIDR BLOCK : 0.0.0.0
> Compartment: ECorp
> Target Internet Gateway: Ecorp internet gateway

3- Create two Subnets (DATA & BACKUP)

 

Description

  • A Subnet is a subdivision of your VCN that you define in a single availability domain. The subnet directs traffic
    according to a route table.

  • The Subnet also uses a security list to control traffic in and out of the instance. Each subnet exists in a single 
    availability domain.

  • A region contains several availability domains.

A- Create primary Subnet

Under VCN details page > click Create Subnet. 
> Name : Data                         #first subnet
> Availability Domain:  AD1
> CIDR block : 192.168.78.0/24
> Route Table: Default
> Public subnet
> DNS resolution: Use DNS hostname
> DNS label :data
> DNS Domain Name: data.ecorpvcn.com
> DHCP : Default


B- Create backup Subnet

> Name : BAckup                         #second subnet
> Availability Domain: AD2
> CIDR block : 192.168.79.0/24
> Route Table: Default
> Public subnet
> DNS resolution: Use DNS hostname
> DNS label :backup
> DNS Domain Name: backup.ecorpvcn.com
> DHCP : default
Add ingress Rules (statefull rule) to the subnet Default Security list (all tcp allow all trafic for all ports)



III. CREATE A RAC DATABASE DEPLOYMENT


Vm based Database System LAUNCH 

  • Two nodes RAC instance:  the main attributes here are The software edition, Database Type, and computer shape.

Go to Console >Click Create service page 
> Service Name : CloudRAC             #choose any name                       
> Description : > Service level : Oracle Database Cloud service
> Metering frequency : Hourly
> Software release : Oracle soft 12c R1
> Software Edition : EE Extreme performance
> Database Type: Db clustering with RAC 
> Client subnet:data
> Hostname: london                  #choose your hostname             
> DB Name SID: RACDB                #choose your DB instance name
> PDB Name: PDBRAC                  #choose your PDB name
> Admin Pass:New_Pass123#
> Usable storage : 25GB
TOTAL GB : 88
> Compute Shape: VM.Standard1.2    #choose a shape with two or more OCPUs.
> SSH public key:   ....        #copy your own ssh key.
Follow this tutorial to create an ssh Public/Private Key Pair.
> Backup option :None
> Database Workload : OLTP
cluster name : london-cls   #choose your cluster name
Domain : data.ecorpvcn.oraclevcn.com
Hostname london.data.ecorpvcn.oraclevcn.com
Service Name: testDB_iad132.data.ecorpvcn.oraclevcn.com    



The result

Here are the details of the created database system (see above step) .

DB System Version: 12.2.0.1.180116
Oracle Database Software Edition: Enterprise Edition
Shape: VM.Standard1.2
Virtual Cloud Network: Ecorpvcn
Client Subnet: Data
Private IP: 192.168.78.3
Public IP: 129.213.85.69
Available Data Storage: 256 GB
Total Storage Size: 712 GB

IV. CONNECT TO THE DATABASE


TNS entries example
  Use the service name/public IPs generated after the DB system creation (available on the DB system details page)

CLOUD_RAC_INST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =publicIp1)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST =publicIp2)(PORT = 1521))
(LOAD_BALANCE=ON)(FAILOVER=ON))(CONNECT_DATA =
(SERVICE_NAME =testDB_iad132.data.ecorpvcn.oraclevcn.com)))

CLOUD_RAC_PDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST =publicIp1)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST =publicIp2)(PORT = 1521))
(LOAD_BALANCE=ON)(FAILOVER=ON))(CONNECT_DATA =(SERVICE_NAME=PDB1.data.ecorpvcn.oraclevcn.com)))
Any Remark, comments ? Feel free to leave them below the article.