Thursday, March 24, 2011

Cloning Oracle Home to New Server.

About Cloning oracle home

Cloning is the process of copying an existing Oracle installation to a different location and updating the copied bits to work in the new environment. The changes made by one-off patches applied on the source Oracle home, would also be present after the clone operation. The source and the destination path (host to be cloned) need not be the same. During cloning, OUI replays the actions that were run to install the home. Cloning is similar to installation except that OUI runs the actions in a special mode that is referred to as clone mode. Some situations in which cloning is useful are:

•Creating an installation that is a copy of a production, test, or development installation. Cloning enables you to create a new installation with all patches applied to it in a single step. This is in contrast with going through the installation process by performing separate steps to install, configure, and patch the installation.

•Rapidly deploying an instance and the applications that it hosts.

•Preparing an Oracle home and deploying it to many hosts.

The cloned installation behaves the same as the source installation. For example, the cloned Oracle home can be removed using OUI or patched using OPatch. You can also use the cloned Oracle home as the source for another cloning operation. You can create a cloned copy of a test, development, or production installation by using the command-line cloning scripts. The default cloning procedure is adequate for most usage cases. However, you can also customize various aspects of cloning, for example, to specify custom port assignments, or to preserve custom settings.

The cloning process works by copying all of the files from the source Oracle home to the destination Oracle home. Thus, any files used by the source instance that are located outside the source Oracle home's directory structure are not copied to the destination location.

The size of the binaries at the source and the destination may differ because these are relinked as part of the clone operation and the operating system patch levels may also differ between these two locations. Additionally, the number of files in the cloned home would increase because several files copied from the source, specifically those being instantiated, are backed up as part of the clone operation.

OUI Cloning is more beneficial than using the tarball approach because cloning configures the Central Inventory and the Oracle home inventory in the cloned home. Cloning also makes the home manageable and allows the paths in the cloned home and the target home to be different.

Example :-

We have a oracle 10g Software been installed in the souce server now we have a new server been setup into which we are going to copy the oracle home from the source.

Source Server : 192.168.1.3 Hostname : rhel
Target Server : 192.168.1.11 Hostname : oracln

Setting up the environment in the new server.

a) Create Oralce User

[root@oracln ~]# groupadd oinstall
[root@oracln ~]# groupadd dba
[root@oracln ~]# useradd -g oinstall -G dba oracle
[root@oracln ~]# passwd oracle
Changing password for user oracle.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

b) Create Oracle home directory structure

[root@oracln ~]# mkdir -p /u01/app/oracle/product/10.2.0/db_1
[root@oracln ~]# chown -R oracle:dba /u01
[root@oracln ~]# ls -l

c) Setup the Kernel Parameters.

[root@oracln ~]# vi /etc/sysctl.conf

kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.shmall = 2097152
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 262144
net.core.wmem_max = 262144

d) Add the Oracle user lime in the profile file.

[root@oracln ~]# vi /etc/profile

if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
umask 022
fi

e) Set up the Security limits for oracle User.

[root@oracln ~]# vi /etc/security/limits.conf

oracle soft nofile 65536
oracle hard nofile 65536
oracle soft nproc 16384
oracle hard nproc 16384

f) Set up the environment variables for the oracle user.

[root@oracln ~]# su - oracle

[oracle@oracln ~]$ vi .bash_profile

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_TERM=Xterm
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_OWNER=oracle
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib; export CLASSPATH
export TMP=/tmp
export TMPDIR=$TMP
export TNS_ADMIN=$ORACLE_HOME/network/admin

Configure the below steps to setup ssh , if ssh is already been setup then
skip the below and go to "Steps after ssh been confgured"

g) Add the Source and Target hosts details in the /etc/hosts file.

[root@oracln ~]# vi /etc/hosts

127.0.0.1 localhost.localdomain localhost
192.168.1.11 oracln.manzoor.com oracln
192.168.1.3 rhel.manzoor.com rhel

h) Generate the rsa and dsa keys for ssh.

oracle@oracln ~]$ pwd
/home/oracle
[oracle@oracln ~]$ mkdir .ssh
[oracle@oracln ~]$ chmod 700 .ssh
[oracle@oracln ~]$ cd .ssh
[oracle@oracln .ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/oracle/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/oracle/.ssh/id_rsa.
Your public key has been saved in /home/oracle/.ssh/id_rsa.pub.
The key fingerprint is:
57:af:54:e5:14:b4:14:c8:3b:93:7f:e8:6f:a4:e9:8d oracle@oracln.manzoor.com
[oracle@oracln .ssh]$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/oracle/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/oracle/.ssh/id_dsa.
Your public key has been saved in /home/oracle/.ssh/id_dsa.pub.
The key fingerprint is:
43:54:c2:28:16:c6:0f:42:78:52:b5:9b:a1:d9:48:6d oracle@oracln.manzoor.com




i) Now log on to the source server and copy the contents of the rsa and dsa keys of target server and append it to the authorized keys file and then copy the same to the new Server.

[root@rhel] # vi /etc/hosts

127.0.0.1 localhost.localdomain localhost
192.168.1.11 oracln.manzoor.com oracln
192.168.1.3 rhel.manzoor.com rhel

[root@rhel] # su - oracle
[oracle@rhel ~]$ pwd
/home/oracle
[oracle@rhel ~]$ mkdir .ssh
[oracle@rhel ~]$ cd .ssh
[oracle@rhel .ssh]$ cd ..
[oracle@rhel ~]$ chmod 700 .ssh
[oracle@rhel ~]$ cd .ssh
[oracle@rhel .ssh]$ ls -l
total 0
[oracle@rhel .ssh]$ ssh-keygen -t rsa
[oracle@rhel .ssh]$ ssh-keygen -t dsa
[oracle@rhel .ssh]$ cat id_rsa.pub >> authorized_keys
[oracle@rhel .ssh]$ cat id_dsa.pub >> authorized_keys
[oracle@rhel .ssh]$ ssh oracln cat /home/oracle/.ssh/id_rsa.pub >> authorized_keys
oracle@oracln's password:
[oracle@rhel .ssh]$ ssh oracln cat /home/oracle/.ssh/id_dsa.pub >> authorized_keys


j) Now copy the authorized keys file to the New server.

[oracle@rhel .ssh]$ scp authorized_keys oracln:/home/oracle/.ssh/
oracle@oracln's password:
authorized_keys 100% 2544 2.5KB/s 00:00



Steps after ssh been confgured.

1) On Source Server.

Check the Oracle home to clone.

[oracle@rhel Opatch]$ opatch lsinv
Invoking OPatch 10.2.0.1.0

Oracle interim Patch Installer version 10.2.0.1.0
Copyright (c) 2005, Oracle Corporation. All rights reserved..


Oracle Home : /u01/app/oracle/product/10.2.0/db_1
Central Inventory : /u01/app/oracle/oraInventory
from : /u01/app/oracle/product/10.2.0/db_1/oraInst.loc
OPatch version : 10.2.0.1.0
OUI version : 10.2.0.1.0
OUI location : /u01/app/oracle/product/10.2.0/db_1/oui
Log file location : /u01/app/oracle/product/10.2.0/db_1/cfgtoollogs/opatch/opatch-2011_Mar_25_08-28-27-IST_Fri.log

Lsinventory Output file location : /u01/app/oracle/product/10.2.0/db_1/cfgtoollogs/opatch/lsinv/lsinventory-2011_Mar_25_08-28-27-IST_Fri.txt

--------------------------------------------------------------------------------
Installed Top-level Products (1):

Oracle Database 10g 10.2.0.1.0
There are 1 products installed in this Oracle Home.


There are no Interim patches installed in this Oracle Home.

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

OPatch succeeded.

2) Check the Size of the Oracle Home to be cloned.

[oracle@rhel ~]$ cd /u01/app/oracle/product/10.2.0/db_1
[oracle@rhel db_1]$
[oracle@rhel db_1]$ du -h . | tail -1
1.4G

3) Execute the tar command to tape archive the oracle home and trasfer the contents over the network to the new server.

[oracle@rhel db_1]$ tar cvf - . | ( ssh oracln "cd /u01/app/oracle/product/10.2.0/db_1 ; tar xvf -" )

(or)

[oracle@rhel ~]$ cd /u01/app/oracle/product/10.2.0/
[oracle@rhel ~]$ tar -cvf /tmp/10.2.0_bin.tar db_1

Secure copy to the remote server.

$ scp /tmp/10.2.0_bin.tar oracle@cloned-server/u01/app/oracle/product/10.2.0/db_1/.

Login to the cloned server using ssh or telnet …
# ssh –l oracle cloned-server
# cd /u01/app/oracle/product/10.2.0/db_1/

Untar the file.
# tar –xvf 10.2.0_bin.tar



The above tar command will archive the oracle home and tranfer it over the network to the new server and un compress it in your new server. This process will run for 30-45 minutes depending upon the size of the oracle home and the network speed.

4) Once the copy is completed check the size of oracle home in the target server, the size should match with the size of source oracle home.

[oracle@oracln ~]$ cd /u01/app/oracle/product/10.2.0/db_1
[oracle@oracln db_1]$
[oracle@oracln db_1]$ du -h . | tail -1
1.4G

5) Complete the Cloning Operation using the OUI in the target server.

[oracle@oracln ~]$ cd $ORACLE_HOME/oui/bin
[oracle@oracln bin]$ ./runInstaller -clone -silent -ignorePreReq ORACLE_HOME="/u01/app/oracle/product/10.2.0/db_1" ORACLE_HOME_NAME="Ora10gHome" ORACLE_BASE="/u01/app/oracle" OSDBA_GROUP=dba OSOPER_GROUP=dba
Starting Oracle Universal Installer...

No pre-requisite checks found in oraparam.ini, no system pre-requisite checks will be executed.
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2011-03-25_08-10-36AM. Please wait ...[oracle@oracln bin]$ Oracle Universal Installer, Version 10.2.0.1.0 Production
Copyright (C) 1999, 2005, Oracle. All rights reserved.

You can find a log of this install session at:
/u01/app/oracle/oraInventory/logs/cloneActions2011-03-25_08-10-36AM.log
.................................................................................................... 100% Done.

Installation in progress (Fri Mar 25 08:11:26 IST 2011)
......................................................................... 73% Done.
Install successful

Linking in progress (Fri Mar 25 08:11:44 IST 2011)
. 74% Done.
Link successful

Setup in progress (Fri Mar 25 08:14:01 IST 2011)
.................... 100% Done.
Setup successful

End of install phases.(Fri Mar 25 08:14:03 IST 2011)
WARNING:A new inventory has been created in this session. However, it has not yet been registered as the central inventory of this system.
To register the new inventory please run the script '/u01/app/oracle/oraInventory/orainstRoot.sh' with root privileges.
If you do not register the inventory, you may not be able to update or patch the products you installed.

The following configuration scripts
/u01/app/oracle/product/10.2.0/db_1/root.sh
need to be executed as root for configuring the system.

The cloning of Ora10gHome was successful.
Please check '/u01/app/oracle/oraInventory/logs/cloneActions2011-03-25_08-10-36AM.log' for more details.

(or)

$ cd /u01/app/oracle/product/10.2.0/db_1/clone/bin
$ perl clone.pl ORACLE_HOME="/u01/app/oracle/product/10.2.0/db_1" ORACLE_HOME_NAME="Ora10gHome" ORACLE_BASE="/u01/app/oracle" OSDBA_GROUP=dba OSOPER_GROUP=dba
===========
./runInstaller -silent -clone -waitForCompletion "ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1" "ORACLE_HOME_NAME=Ora10ghome" -noConfig -nowait
Starting Oracle Universal Installer...

No pre-requisite checks found in oraparam.ini, no system pre-requisite checks will be executed.
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2012-06-25_11-03-17PM. Please wait ...Oracle Universal Installer, Version 10.2.0.4.0 Production
Copyright (C) 1999, 2008, Oracle. All rights reserved.

You can find a log of this install session at:
/optware/oracle/oraInventory/logs/cloneActions2012-06-25_11-03-17PM.log
.................................................................................................... 100% Done.



Installation in progress (Monday, June 25, 2012 11:03:58 PM PDT)
........................................................................ 72% Done.
Install successful

Linking in progress (Monday, June 25, 2012 11:04:15 PM PDT)
Link successful

Setup in progress (Monday, June 25, 2012 11:04:22 PM PDT)
Setup successful

End of install phases.(Monday, June 25, 2012 11:04:25 PM PDT)
WARNING:
The following configuration scripts need to be executed as the "root" user.
#!/bin/sh
#Root script to run
/u01/app/oracle/product/10.2.0/db_1/root.sh
To execute the configuration scripts:
1. Open a terminal window
2. Log in as "root"
3. Run the scripts






6) Once done execute the configuration scripts as the root user.

[root@oracln ~]# sh /u01/app/oracle/oraInventory/orainstRoot.sh
Changing permissions of /u01/app/oracle/oraInventory to 770.
Changing groupname of /u01/app/oracle/oraInventory to oinstall.
The execution of the script is complete


[root@oracln ~]# sh /u01/app/oracle/product/10.2.0/db_1/root.sh
Running Oracle10 root.sh script...

The following environment variables are set as:
ORACLE_OWNER= oracle
ORACLE_HOME= /u01/app/oracle/product/10.2.0/db_1

Enter the full pathname of the local bin directory: [/usr/local/bin]:
Copying dbhome to /usr/local/bin ...
Copying oraenv to /usr/local/bin ...
Copying coraenv to /usr/local/bin ...


Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root.sh script.
Now product-specific root actions will be performed.

7) Now Check the patch details using the opatch tool, it should match with the souce server.

[oracle@oracln OPatch]$ ./opatch lsinventory
Invoking OPatch 10.2.0.1.0

Oracle interim Patch Installer version 10.2.0.1.0
Copyright (c) 2005, Oracle Corporation. All rights reserved..


Oracle Home : /u01/app/oracle/product/10.2.0/db_1
Central Inventory : /u01/app/oracle/oraInventory
from : /u01/app/oracle/product/10.2.0/db_1/oraInst.loc
OPatch version : 10.2.0.1.0
OUI version : 10.2.0.1.0
OUI location : /u01/app/oracle/product/10.2.0/db_1/oui
Log file location : /u01/app/oracle/product/10.2.0/db_1/cfgtoollogs/opatch/opatch-2011_Mar_25_08-28-27-IST_Fri.log

Lsinventory Output file location : /u01/app/oracle/product/10.2.0/db_1/cfgtoollogs/opatch/lsinv/lsinventory-2011_Mar_25_08-28-27-IST_Fri.txt

--------------------------------------------------------------------------------
Installed Top-level Products (1):

Oracle Database 10g 10.2.0.1.0
There are 1 products installed in this Oracle Home.


There are no Interim patches installed in this Oracle Home.

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

OPatch succeeded.


9) Oracle home has been successfully cloned to the new server.


Refer for more details:-

Oracle® Universal Installer and OPatch User's Guide
10g Release 2 (10.2) for Windows and UNIX
Part Number B16227-12

1 comment:

  1. Really good explanation....understood the concept... Need ur suggestion on the below link for oracle support.
    How to Relink Oracle Database Software on UNIX [ID 131321.1

    I didn't understood below command for relink oracle database software can you help me what is the difference between ur command and below command.

    $ORACLE_HOME/oui/bin/runInstaller -relink -waitForCompletion -maketargetsxml $ORACLE_HOME/inventory/make/makeorder.xml \
    ORACLE_HOME=$ORACLE_HOME 2>&1 | tee $ORACLE_HOME/install/relink.log | grep -i error | grep -iv warning

    Your information will be highly appreciated...

    ReplyDelete