Thursday, February 20, 2014

Renaming a Linux Host running Oracle 11gR2

Renaming a Linux Host running Oracle 11gR2
In this blog post, we are going to rename the Linux host name of an existing Oracle 11gR2 system. We can also use this technique to change the IP address of our host.
Host renames are a useful technique in virtualized environments, where vCenter may be used to clone entire hosts including the Oracle databases installed on them. This technique will also work with physical hosts should you wish to simply rename an existing Oracle host.
In 2009, Martin Nash who writes the ORAganism blog demonstrated the host rename process using Oracle 11.2.0.1. This post is heavily based on his work, but updated for Oracle 11.2.0.3. In this example I am using RedHat 6.0 but the process should be exactly the same for CentOS 6.x and OEL Linux.
Martin’s original work can be found here: ORAganism: Oracle Restart – Changing Hostname
Whereas this demonstration is not completely automated, it might form the basis of a fully scripted database deployment model for non-production use.
Time Required: 45 minutes

Part I – Deconfigure OEM/DBC.

Time Required: 5 mins.
Before renaming a host, it is important to shut down and remove the Oracle Enterprise Manager DB Console if it has been installed.
The emca tool allows the DBA to configure and de-configure the OEM/DBC repository. In this example we use the silent option. The command is as follows:
emca -deconfig dbcontrol db -repos drop -silent \
 -SID gctdev \
 -PORT 1521 \
 -LISTENER_OH /u01/app/11.2.0/grid \
 -SYS_PWD mypassword \
 -DBSNMP_PWD dbsnmp \
 -SYSMAN_PWD mypassword \
 -ASM_OH /u01/app/11.2.0/grid \
 -ASM_SID +ASM \
 -ASM_PORT 1521 \
 -ASM_USER_NAME asmsnmp \
 -ASM_USER_PWD mypassword

Most of these directives should be self explanatory. Note that directives here are case sensitive and must be upper-case.
DirectiveMeaning
SIDDatabase SID to be deconfigured
PORTListener port number used by database instance
LISTENER_OHThe Oracle Home path where the listener is running
SYS_PWDThe SYS user password
DBSNMP_PWDThe DBSNMP user password
SYSMAN_PWDThe SYSMAN user password
ASM_OHThe Oracle Home path where the ASM instance is running
ASM_SIDThe ASM instance SID name
ASM_PORTListener port number used by ASM instance
ASM_USER_NAMEThe ASM user name to connect to the ASM instance
ASM_USER_PWDThe password of the ASM user used to connect to the ASM instance
These directives may optionally be placed into a response file rather than added on the command line. If a response file is used they will be presented as follows:
SID=gctdev
PORT=1521
LISTENER_OH=/u01/app/11.2.0/grid

The emca tool can then be invoked with the -respFile=[filename] directive to include the response file.
We can now launch emca to deconfigure OEM/DBC:
STARTED EMCA at Jan 11, 2013 12:50:13 PM
EM Configuration Assistant, Version 11.2.0.3.0 Production
Copyright (c) 2003, 2011, Oracle.  All rights reserved.


----------------------------------------------------------------------
WARNING : While repository is dropped the database will be put in quiesce mode.
----------------------------------------------------------------------
Jan 11, 2013 12:50:14 PM oracle.sysman.emcp.EMConfig perform
INFO: This operation is being logged at /u01/app/oracle/cfgtoollogs/emca/gctdev/emca_2013_01_11_12_50_13.log.
Jan 11, 2013 12:50:14 PM oracle.sysman.emcp.util.DBControlUtil stopOMS
INFO: Stopping Database Control (this may take a while) ...
Jan 11, 2013 12:50:35 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Dropping the EM repository (this may take a while) ...
Jan 11, 2013 12:51:52 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Repository successfully dropped
Enterprise Manager configuration completed successfully
FINISHED EMCA at Jan 11, 2013 12:51:59 PM

In some cases the deconfig script will not complete cleanly. It is good practice to check the database to ensure that both the SYSMAN and MGMT_VIEW users as well as the MGMT_USER role have been dropped.

Part II – Shutdown Oracle Databases and Grid Infrastructure.

Time Required: 5 mins.
With OEM/DBC deconfigured, we can shut down the Oracle software on the server. In this example I am using crs_stop to do the shutdown:
[oracle@attila ~]$ crs_stat -t
Name           Type           Target    State     Host        
------------------------------------------------------------
ora.DATA.dg    ora....up.type ONLINE    ONLINE    attila      
ora....ER.lsnr ora....er.type ONLINE    ONLINE    attila      
ora.asm        ora.asm.type   ONLINE    ONLINE    attila      
ora.cssd       ora.cssd.type  ONLINE    ONLINE    attila      
ora.diskmon    ora....on.type OFFLINE   OFFLINE               
ora.evmd       ora.evm.type   ONLINE    ONLINE    attila      
ora.gctdev.db  ora....se.type ONLINE    ONLINE    attila      
ora.ons        ora.ons.type   OFFLINE   OFFLINE

[oracle@attila ~]$ crs_stop -all
CRS-2500: Cannot stop resource 'ora.diskmon' as it is not running
CRS-2500: Cannot stop resource 'ora.ons' as it is not running
Attempting to stop `ora.evmd` on member `attila`
Attempting to stop `ora.DATA.dg` on member `attila`
Attempting to stop `ora.gctdev.db` on member `attila`
Attempting to stop `ora.LISTENER.lsnr` on member `attila`
Stop of `ora.LISTENER.lsnr` on member `attila` succeeded.
Stop of `ora.evmd` on member `attila` succeeded.
Stop of `ora.gctdev.db` on member `attila` succeeded.
Stop of `ora.DATA.dg` on member `attila` succeeded.
Attempting to stop `ora.asm` on member `attila`
Stop of `ora.asm` on member `attila` succeeded.
Attempting to stop `ora.cssd` on member `attila`
Stop of `ora.cssd` on member `attila` succeeded.
CRS-0216: Could not stop resource 'ora.diskmon'.

CRS-0216: Could not stop resource 'ora.ons'.
We can now check to see that everything is down:
[oracle@attila ~]$ crs_stat -t
Name           Type           Target    State     Host        
------------------------------------------------------------
ora.DATA.dg    ora....up.type OFFLINE   OFFLINE               
ora....ER.lsnr ora....er.type OFFLINE   OFFLINE               
ora.asm        ora.asm.type   OFFLINE   OFFLINE               
ora.cssd       ora.cssd.type  OFFLINE   OFFLINE               
ora.diskmon    ora....on.type OFFLINE   OFFLINE               
ora.evmd       ora.evm.type   OFFLINE   OFFLINE               
ora.gctdev.db  ora....se.type OFFLINE   OFFLINE               
ora.ons        ora.ons.type   OFFLINE   OFFLINE 

Part III – Deconfigure Oracle Restart.

Time Required: 5 mins.
Next we are going to log in as root and deconfigure the Oracle Restart components. The command to do this has changed slightly since earlier releases. For 11.2.0.3 the command is as follows:
$ORACLE_HOME/perl/bin/perl -I \
  $ORACLE_HOME/perl/lib -I $ORACLE_HOME/crs/install \
  $ORACLE_HOME/crs/install/roothas.pl -deconfig -force
Log in as root and source the Oracle ASM environment so that we are pointed at the Grid home, and then execute the command:
[root@attila ~]# . oraenv
ORACLE_SID = [root] ? +ASM
The Oracle base has been set to /u01/app/oracle

[root@attila ~]# $ORACLE_HOME/perl/bin/perl -I \
  $ORACLE_HOME/perl/lib -I $ORACLE_HOME/crs/install \
  $ORACLE_HOME/crs/install/roothas.pl -deconfig -force
Using configuration parameter file: /u01/app/11.2.0/grid/crs/install/crsconfig_params
CRS resources for listeners are still configured
PRKO-2573 : ONS daemon is already stopped.
CRS-2500: Cannot stop resource 'ora.cssd' as it is not running
CRS-4000: Command Stop failed, or completed with errors.
CRS-4133: Oracle High Availability Services has been stopped.
Successfully deconfigured Oracle Restart stack

Part IV – Rename the Host.

Time Required: 5 mins.
While logged in as root, we can rename our Linux host and update the IP address. The files we typically edit for this are as follows:
  • /etc/sysconfig/network
  • /etc/hosts
  • /etc/sysconfig/network-scripts/ifcfg-eth0
In my case I am going to rename my host Attila to another character from the same opera; Odabella. Below is my revised /etc/sysconfig/network file:
[root@attila ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=odabella.operanet

Once this is done, reboot the Linux machine so that the new settings take effect. Don’t worry about the database trying to start, we disabled Oracle Restart so it will stay down.

Part V – Configure Oracle Restart.

Time Required: 5 mins.
Once the server comes back up, check that the new hostname and network addresses are working as expected, before trying to reconfigure Oracle.
Once we are satisfied our Linux machine has the correct new identity, we can use the following command to re-configure Oracle Restart:
$ORACLE_HOME/perl/bin/perl -I \
  $ORACLE_HOME/perl/lib -I \
  $ORACLE_HOME/crs/install $ORACLE_HOME/crs/install/roothas.pl
Log in as root and source the Oracle ASM environment so that we are pointed at the Grid home, and then execute the command:
[root@odabella ~]# . oraenv
ORACLE_SID = [root] ? +ASM
The Oracle base has been set to /u01/app/oracle

[root@odabella ~]# $ORACLE_HOME/perl/bin/perl -I \
>   $ORACLE_HOME/perl/lib -I \
>   $ORACLE_HOME/crs/install $ORACLE_HOME/crs/install/roothas.pl
Using configuration parameter file: /u01/app/11.2.0/grid/crs/install/crsconfig_params
LOCAL ADD MODE 
Creating OCR keys for user 'oracle', privgrp 'oinstall'..
Operation successful.
LOCAL ONLY MODE 
Successfully accumulated necessary OCR keys.
Creating OCR keys for user 'root', privgrp 'root'..
Operation successful.
CRS-4664: Node odabella successfully pinned.
Adding Clusterware entries to upstart

odabella     2013/01/10 22:29:25     /u01/app/11.2.0/grid/cdata/odabella/backup_20130110_222925.olr
Successfully configured Oracle Grid Infrastructure for a Standalone Server 

Part VI – Reconfigure Oracle Listener, ASM and DB.

Time Required: 10 mins.
Log into the server as the Oracle user and source the Oracle ASM environment so that we are pointed at the Grid home. We can now update the listener files and add the listener, the ASM instance and the databases back into our configuration:
First, edit the listener.ora file and update the host name:
[oracle@odabella ~]$ cat $ORACLE_HOME/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/app/11.2.0/grid/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = odabella.operanet)(PORT = 1521))
    )
  )

Next we add the listener back into the Oracle Restart configuration: (SID=+ASM)
[oracle@odabella ~]$ srvctl add listener

Next we add the ASM instance back in, setting the ASM disk discovery string as we do.(SID=+ASM)
[oracle@odabella ~]$ srvctl add asm -d '/dev/oracleasm/*'

Next we start the listener and the ASM instance:(SID=+ASM)
[oracle@odabella ~]$ srvctl start listener
[oracle@odabella ~]$ srvctl start asm

We now need to mount any disk groups that we use in ASM. In this example I have only the DATA diskgroup:(+ASM)
[oracle@odabella ~]$ asmcmd mount DATA
Now we can add the diskgroup under Oracle Restart control:(SID=+ASM)
[oracle@odabella ~]$ srvctl status diskgroup -g DATA
Finally we can add our databases back into the configuration. The command to do this is as follows:(+ASM)
srvctl add database -d gctdev \
 -o /u01/app/oracle/product/11.2.0/dbhome_1 \
 -n gctdev \
 -p +DATA/gctdev/spfilegctdev.ora \
 -a DATA
The arguments here are as follows:
ArgumentMeaning
dDatabase Name
oOracle Home of the database
nInstance Name
pParameter file location
aASM Diskgroups to mount
Note: Be careful to specify the Oracle Home of the database here and not the ASM home. I find it best to fully specify the path and not rely on environment variables.
We can verify our database configuration as follows:(SID=+ASM)
[oracle@odabella ~]$ srvctl config database -d gctdev
Database unique name: gctdev
Database name: gctdev
Oracle home: /u01/app/oracle/product/11.2.0/dbhome_1
Oracle user: oracle
Spfile: +DATA/gctdev/spfilegctdev.ora
Domain: 
Start options: open
Stop options: immediate
Database role: PRIMARY
Management policy: AUTOMATIC
Database instance: gctdev
Disk Groups: DATA
Services:
If the configuration looks good, we should be able to start the database with the following command:(SID=+ASM)
[oracle@odabella ~]$ srvctl start database -d gctdev
If everything worked, you should be able to check the status with the crs_stat command:
[oracle@odabella ~]$ crs_stat -t
Name           Type           Target    State     Host        
------------------------------------------------------------
ora.DATA.dg    ora....up.type ONLINE    ONLINE    attila      
ora....ER.lsnr ora....er.type ONLINE    ONLINE    attila      
ora.asm        ora.asm.type   ONLINE    ONLINE    attila      
ora.cssd       ora.cssd.type  ONLINE    ONLINE    attila      
ora.diskmon    ora....on.type OFFLINE   OFFLINE               
ora.evmd       ora.evm.type   ONLINE    ONLINE    attila      
ora.gctdev.db  ora....se.type ONLINE    ONLINE    attila      
ora.ons        ora.ons.type   OFFLINE   OFFLINE
Check you can connect to the database from a different machine to ensure all components are working normally.

Part VII – Configure OEM/DBC (Optional).

Time Required: 10 mins.
If you need the OEM Database Control functionality on your renamed Linux host, then you will need to recreate the OEM repository. Again we can use the emca to do this silently.
The command to use is as follows:
emca -config dbcontrol db -repos create -silent \
 -SID gctdev \
 -PORT 1521 \
 -LISTENER_OH /u01/app/11.2.0/grid \
 -SYS_PWD mypassword \
 -DBSNMP_PWD dbsnmp \
 -SYSMAN_PWD mypassword \
 -ASM_OH /u01/app/11.2.0/grid \
 -ASM_SID +ASM \
 -ASM_PORT 1521 \
 -ASM_USER_NAME asmsnmp \
 -ASM_USER_PWD mypassword
You need to set the Oracle environment variables for the Oracle Home where the target database resides, if you are still pointing at the Grid home the command will fail.
The command can take some time to run, so be patient:
[oracle@odabella Desktop]$ . oraenv
ORACLE_SID = [+ASM] ? gctdev
The Oracle base remains unchanged with value /u01/app/oracle

[oracle@odabella ~]$ emca -config dbcontrol db -repos create -silent  -SID gctdev  -PORT 1521  -LISTENER_OH /u01/app/11.2.0/grid  -SYS_PWD mypassword  -DBSNMP_PWD dbsnmp  -SYSMAN_PWD mypassword  -ASM_OH /u01/app/11.2.0/grid  -ASM_SID +ASM  -ASM_PORT 1521  -ASM_USER_NAME asmsnmp  -ASM_USER_PWD mypassword

STARTED EMCA at Jan 11, 2013 12:40:51 PM
EM Configuration Assistant, Version 11.2.0.3.0 Production
Copyright (c) 2003, 2011, Oracle.  All rights reserved.

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

You have specified the following settings

Database ORACLE_HOME ................ /u01/app/oracle/product/11.2.0/dbhome_1

Local hostname ................ odabella.operanet
Listener ORACLE_HOME ................ /u01/app/11.2.0/grid
Listener port number ................ 1521
Database SID ................ gctdev
Email address for notifications ............... null
Outgoing Mail (SMTP) server for notifications ............... null
ASM ORACLE_HOME ................ /u01/app/11.2.0/grid
ASM SID ................ +ASM
ASM port ................ 1521
ASM user role ................ SYSDBA
ASM username ................ asmsnmp

-----------------------------------------------------------------
Jan 11, 2013 12:40:52 PM oracle.sysman.emcp.EMConfig perform
INFO: This operation is being logged at /u01/app/oracle/cfgtoollogs/emca/gctdev/emca_2013_01_11_12_40_50.log.
Jan 11, 2013 12:40:53 PM oracle.sysman.emcp.EMReposConfig createRepository
INFO: Creating the EM repository (this may take a while) ...
Jan 11, 2013 12:44:30 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Repository successfully created
Jan 11, 2013 12:44:33 PM oracle.sysman.emcp.EMReposConfig uploadConfigDataToRepository
INFO: Uploading configuration data to EM repository (this may take a while) ...
Jan 11, 2013 12:45:18 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Uploaded configuration data successfully
Jan 11, 2013 12:45:20 PM oracle.sysman.emcp.util.DBControlUtil secureDBConsole
INFO: Securing Database Control (this may take a while) ...
Jan 11, 2013 12:46:14 PM oracle.sysman.emcp.util.DBControlUtil secureDBConsole
INFO: Database Control secured successfully.
Jan 11, 2013 12:46:14 PM oracle.sysman.emcp.util.DBControlUtil startOMS
INFO: Starting Database Control (this may take a while) ...
Jan 11, 2013 12:46:47 PM oracle.sysman.emcp.EMDBPostConfig performConfiguration
INFO: Database Control started successfully
Jan 11, 2013 12:46:47 PM oracle.sysman.emcp.EMDBPostConfig performConfiguration
INFO: >>>>>>>>>>> The Database Control URL is https://odabella.operanet:1158/em <<<<<<<<<<<
Jan 11, 2013 12:46:50 PM oracle.sysman.emcp.EMDBPostConfig invoke
WARNING: 
************************  WARNING  ************************

Management Repository has been placed in secure mode wherein Enterprise Manager data will be encrypted.  The encryption key has been placed in the file: /u01/app/oracle/product/11.2.0/dbhome_1/odabella.operanet_gctdev/sysman/config/emkey.ora. Ensure this file is backed up as the encrypted data will become unusable if this file is lost. 

***********************************************************
Enterprise Manager configuration completed successfully
FINISHED EMCA at Jan 11, 2013 12:46:50 PM

No comments:

Post a Comment

  How to Change Instance Type & Security Group of EC2 in AWS By David Taylor Updated April 29, 2023 EC2 stands for Elastic Compute Cloud...