2015年11月24日 星期二

Oracle Database 11g Release 2 (11.2) Installation On Redhat Linux 6 & Dataguard

This article describes the installation of Oracle Database 11g Release 2 (11.2) (64-bit) on Redhat Linux 6 (64-bit). The article is based on a server installation with a minimum of 2G swap, with SELinux set to disabled and the firewall disabled. The following package groups were included for this installation.

Base System > Base
Base System > Compatibility libraries
Base System > Console internet tools
Base System > Debugging Tools
Base System > Directory Client
Base System > Hardware monitoring utilities
Base System > Java Platform
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
An example of this type of Linux installations can be seen here. Alternative installations may require more packages to be loaded, in addition to the ones listed below.
挑選後,大概在 1,300 個套件左右
l  Download Software
l  Hosts File
l  Oracle Installation Prerequisites
n  Manual Setup
n  Additional Setup
l  Unpack Files
l  Installation

Download Software
Download the Oracle software from OTN or MOS (My Oracle Support) depending on your support status.
Hosts File

The "/etc/hosts" file must contain a fully qualified name for the server.
   
For example.
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.1.1.164      brian-db        primary
10.1.1.165      brian-dg        standby

Oracle Installation Prerequisites

Perform either the Automatic Setup or the Manual Setup to complete the basic prerequisites. The Additional Setup is required for all installations.

Manual Setup

Add or amend the following lines in the "/etc/sysctl.conf" file.
cat >> /etc/sysctl.conf << EOF
fs.suid_dumpable = 1
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 984936448
kernel.shmmni = 4096
# semaphores: semmsl, semmns, semopm, semmni
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default=262144
net.core.rmem_max=4194304
net.core.wmem_default=262144
net.core.wmem_max=1048586
EOF

Run the following command to change the current kernel parameters.
/sbin/sysctl -p

Add the following lines to the "/etc/security/limits.conf" file.
cat >> /etc/security/limits.conf << EOF
oracle              soft    nproc   16384
oracle              hard    nproc   16384
oracle              soft    nofile   4096
oracle              hard    nofile  65536
oracle              soft    stack   10240
EOF

可以不加
#######################################################################################
Add the following lines to the "/etc/pam.d/login" file.
cat >> /etc/pam.d/login << EOF
session required /lib64/security/pam_limits.so
session required pam_limits.so
EOF

Add the following lines to the "/etc/profile" file.
cat >> /etc/profile << EOF
if [ $USER = "oracle" ] || [ $USER = "grid" ]; then
umask 022
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
EOF
#######################################################################################

Install the following packages if they are not already present.
# From Redhat Linux 6 DVD
配置yum來源,方便安裝套裝軟體  rhel6
[root@brian-db ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/vda2             28898428   3583444  23847032  14% /
tmpfs                   961228       224    961004   1% /dev/shm
/dev/sr0               3632776   3632776         0 100% /media/RHEL_6.4 x86_64 Disc 1
[root@brian-db ~]# umount /media/RHEL_6.4\ x86_64\ Disc\ 1/
[root@brian-db ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/vda2             28898428   3583436  23847040  14% /
tmpfs                   961228       224    961004   1% /dev/shm
[root@brian-db ~]# mount /dev/cdrom /media
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@brian-db ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/vda2             28898428   3583436  23847040  14% /
tmpfs                   961228       224    961004   1% /dev/shm
/dev/sr0               3632776   3632776         0 100% /media
[root@brian-db ~]# vi /etc/yum.repos.d/rhel-source.repo

rhel-source.repo進行修改
[rhel-source]
name=Red Hat Enterprise Linux $releasever - $basearch - Source
baseurl=file:///media
enabled=1
gpgcheck=1
gpgkey=file:///media/RPM-GPG-KEY-redhat-release


[rhel-source-beta]
name=Red Hat Enterprise Linux $releasever Beta - $basearch - Source
baseurl=ftp://ftp.redhat.com/pub/redhat/linux/beta/$releasever/en/os/SRPMS/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta,file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

配置完yum之後執行下面命令之後就可以進行套裝軟體的安裝了
[root@brian-db ~]# yum clean all
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: rhel-source
Cleaning up Everything
[root@brian-db ~]# yum repolist
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
rhel-source                                                       | 3.9 kB     00:00 ...
rhel-source/primary_db                                             | 3.1 MB     00:00 ...
repo id               repo name                                                    status
rhel-source           Red Hat Enterprise Linux 6Server - x86_64 - Source           3,648
repolist: 3,648

Install package software
[root@brian-db ~]#
 rpm -qa --qf "%{NAME}_%{VERSION}_%{ARCH}\n"|sort|less 查看已經安裝的套裝軟體

install oracle need pachage
[root@brian-db ~]# yum -y install binutils compat-libstdc++-33 compat-libcap1 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel

Create the new groups and users.
groupadd -g 501 oinstall
groupadd -g 502 dba
useradd -u 502 -g oinstall -G dba oracle
passwd oracle

Additional Setup

Set secure Linux to disabled by editing the "/etc/selinux/config" file, making sure the SELINUX flag is set as follows.
SELINUX=disabled
Once the change is complete, restart the server.

If you have the Linux firewall enabled, you will need to disable or configure it, as shown here or here.

Login as the oracle user and add the following lines at the end of the ".bash_profile" file.
# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR
ORACLE_HOSTNAME=`hostname` ; export ORACLE_HOSTNAME
ORACLE_UNQNAME=brian; export ORACLE_UNQNAME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/11.2.0.4/dbhome_1; export ORACLE_HOME
ORACLE_SID=brian; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH

LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH

#alias sqlplus='/usr/local/rlwrap/bin/rlwrap sqlplus'
#alias rman='/usr/local/rlwrap/bin/rlwrap rman'

SFTP Oracle Source to machine /u01/app/oracle/source
mkdir -p /u01/app/oracle/source
p13390677_112040_Linux-x86-64_1of7.zip
p13390677_112040_Linux-x86-64_2of7.zip
pdksh-5.2.14-30.x86_64.rpm

Create the directories in which the Oracle software will be installed.
mkdir -p /u01/app/oracle/product/11.2.0.4/dbhome_1
chown -R oracle:oinstall /u01
Login as root and issue the following command.

Unzip the files

cd /u01/app/oracle/source
# 11.2.0.1
unzip linux.x64_11gR2_database_1of2.zip
unzip linux.x64_11gR2_database_2of2.zip

#11.2.0.4
[root@brian-db ~]# cd /u01/app/oracle/source/
unzip p13390677_112040_Linux-x86-64_1of7.zip
unzip p13390677_112040_Linux-x86-64_2of7.zip

Install pdksh package
[root@brian-db ~]# cd /u01/app/oracle/source/
[root@brian-db source]# rpm -ivh pdksh-5.2.14-30.x86_64.rpm
warning: pdksh-5.2.14-30.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 4f2a6fd2: NOKEY
Preparing...                ########################################### [100%]
   1:pdksh                ########################################### [100%]

Reboot machine

Installation
./runInstaller

Login as oracle and issue the following command.














Finsh oracle software

Create listener
Netca









Create database include sample
dbca
















Complete create database



Steps to configure 11g Physical Standby Database
Oracle rdbms software is installed with one database(dell) following is details:

Primary DB_NAME=brian                            IP - 10.1.1.164
Primary DB_UNIQUE_name=primary

On Physical standby I have installed only rdbms software (std will be my standby database)

Standby DB_NAME=brian                            IP - 10.1.1.165
Standby DB_UNIQUE_name=standby

Required Parameters:
Parameter
Recommended Setting for Standby Database
DB_Name
Must be same on parimary and on all dtandby
DB_UNIQUE_NAME
Must be different on parimary and on all dtandby
LOG_ARCHIVE_CONFIG
This parameter includes db_unique_name which are the part of Dataguard configuration
LOG_ARCHIVE_DEST_n
Define local and remote archive log file location
LOG_ARCHIVE_DEST_STATE_n
Define state of archiving (ENABLE or DIFER)
REMOTE_LOGIN_PASSWORDFILE
Must be in EXCLUSIVE Mode
FAL_SERVER
Use for archivelog gap resolution (required only in physical standby server)
DB_FILE_NAME_CONVERT
required when directory structure is different datafile
LOG_FILE_NAME_CONVERT
required when directory structure is different logfile
STANDBY_FILE_MANAGEMENT
Keep auto to create file automatically on standby

Steps
Perform following steps on Primary database:

Make sure database is in archivelog mode
select name from v$database;

if note use following command to change to archive mode
SQL> archive log list
Database log mode            No Archive Mode
Automatic archival            Disabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence      4
Current log sequence           6

shutdown immediate
startup mount
alter database archivelog;
alter database open;

SQL> archive log list
Database log mode            Archive Mode
Automatic archival            Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence      4
Next log sequence to archive    6
Current log sequence           6

Make sure database is in force logging mode

select force_logging from v$database;
alter database force logging;

Verify DB_NAME and DB_UNIQUE_NAME of Primary Database

show parameter db_name
show parameter db_unique_name

Change db_unique_name

alter system set db_unique_name='primary' scope=spfile;

shutdown immediate
startup

Make DB_UNIQUE_NAME to be part of dataguard.(std service we will create soon)

alter system set log_archive_config='dg_config=(primary,standby)';

Set archivelog destinations
mkdir -p /u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch

alter system set log_archive_dest_1='location=/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch valid_for=(all_logfiles,all_roles) db_unique_name=primary' scope=both;

alter system set log_archive_dest_2='service=standby LGWR ASYNC valid_for=(online_logfiles,primary_role) db_unique_name=standby' scope=both;

alter system set log_archive_dest_state_1='ENABLE' scope=both;
alter system set log_archive_dest_state_2='ENABLE' scope=both;

Set remote login password to exclusive

alter system set remote_login_passwordfile=exclusive scope=spfile;
show parameter remote_login

Set fal server and file name convert parameter incase if dirrctory structure is different in primary and standby database

alter system set fal_server=standby scope=both;
alter system set fal_client=primary scope=both;
alter system set db_file_name_convert='standby','primary' scope=spfile;
alter system set log_file_name_convert='standby','primary' scope=spfile;
alter system set log_archive_max_processes=10 scope=both;
alter system set standby_file_management=auto scope=both;

Now configure required service (primary and standby)
netmgr











Now backup Primary Database using rman

rman target /
RMAN> backup database plus archivelog;

Now Create standby controlfile and pfile

alter database create standby controlfile as '/tmp/stdcontrol.ctl';
create pfile='/tmp/initbrian.ora' from spfile;

Modify initbrian.ora file

1.     Change db_unique_name
2.     log_file_name_convert
3.     Change fal_server
4.     Change fal_client
5.     Change log_archive_dest_n
6.     Change location of controlfile


ps: Standby add directory
[oracle@brian-dg database]$ mkdir -p /u01/app/oracle/admin/brian/adump
[oracle@brian-dg database]$ mkdir -p /u01/app/oracle/oradata/brian
[oracle@brian-dg database]$ mkdir -p /u01/app/oracle/fast_recovery_area/brian
[oracle@brian-dg database]$ mkdir -p /u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/arch

Create appropriate directory on physical standby and copy backupset, archivelog, pfile, standby controlfile and password file to physical standby database

# Standby controlfile to all locations.
scp /tmp/stdcontrol.ctl oracle@standby:/u01/app/oracle/oradata/brian/control01.ctl
scp /tmp/stdcontrol.ctl oracle@standby:/u01/app/oracle/fast_recovery_area/brian/control02.ctl

Archivelogs and backups
scp -r /u01/app/oracle/fast_recovery_area/PRIMARY oracle@standby:/u01/app/oracle/fast_recovery_area/

# Parameter file.
scp /tmp/initbrian.ora oracle@standby:/tmp/initbrian.ora

# Remote login password file.
scp /u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/orapwbrian oracle@standby:/u01/app/oracle/product/11.2.0.4/dbhome_1/dbs/

On physical standby server

netmgr
















Now start listener on both server
lsnrctl start

Create service on physical standby database and update /etc/oratab file

vi /etc/oratab
brian:/u01/app/oracle/product/11.2.0.4/dbhome_1:N

Restore backup on standby:
create spfile from pfile


. oraenv
brian
sqlplus / as sysdba
create spfile from pfile='/tmp/initbrian.ora';
Restore backupfile

rman target /
startup mount
restore database;

Create standby redolog files on primary and standby database

alter database add standby logfile ('/u01/app/oracle/oradata/brian/standby_redo01.log') size 50M;
alter database add standby logfile ('/u01/app/oracle/oradata/brian/standby_redo02.log') size 50M;
alter database add standby logfile ('/u01/app/oracle/oradata/brian/standby_redo03.log') size 50M;
alter database add standby logfile ('/u01/app/oracle/oradata/brian/standby_redo04.log') size 50M;

select member from v$logfile where type='STANDBY';

On Primary Database

alter database add standby logfile ('/u01/app/oracle/oradata/brian/standby_redo01.log') size 50M;
alter database add standby logfile ('/u01/app/oracle/oradata/brian/standby_redo02.log') size 50M;
alter database add standby logfile ('/u01/app/oracle/oradata/brian/standby_redo03.log') size 50M;
alter database add standby logfile ('/u01/app/oracle/oradata/brian/standby_redo04.log') size 50M;

select member from v$logfile where type='STANDBY';
                                                 
Now start redo apply process on standby

alter database recover managed standby database disconnect from session;

Following command is use to stop redo apply process

alter database recover managed standby database cancel;

Test Log Transport
On the primary server, check the latest archived redo log and force a log switch.

alter session set nls_date_format='DD-MON-YYYY HH24:MI:SS';
select sequence#, first_time, next_time from v$archived_log order by sequence#;
alter system switch logfile;

Check the now archived redo log has arrived at the standby server and been applied.

alter session set nls_date_format='DD-MON-YYYY HH24:MI:SS';
select sequence#, first_time, next_time, applied from v$archived_log order by sequence#;

SQL> select name, open_mode, database_role, db_unique_name, protection_mode from v$database;
NAME      OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME
--------- -------------------- ---------------- ------------------------------
PROTECTION_MODE
--------------------
BRIAN     MOUNTED              PHYSICAL STANDBY standby
MAXIMUM PERFORMANCE

Steps to Configure Read Only Standby
step standby
shutdown immediate;
startup mount;
alter database open read only;

Change start redo apply process on standby
shutdown immediate;
startup mount;
alter database recover managed standby database disconnect from session;

alter session set nls_date_format='DD-MON-YYYY HH24:MI:SS';
select sequence#, first_time, next_time, applied from v$archived_log order by sequence#;


Active Data Guard aconfiguration
step standby
shutdown immediate;
startup mount;
alter database open read only;
alter database recover managed standby database disconnect from session;
select name, open_mode, database_role, protection_mode from v$database;




Snapshot Standby Configuration
step standby
SQL> select flashback_on from v$database;

FLASHBACK_ON
------------------
NO

SQL> shutdown immediate;
SQL> startup mount;
SQL> alter database convert to snapshot standby;
SQL> alter database open;

SQL> select flashback_on from v$database;

FLASHBACK_ON
------------------
RESTORE POINT ONLY

SQL> create table hr.emp5 as select * from hr.employees;

Table created.

SQL> select count(*) from hr.emp5;

  COUNT(*)
----------
       107
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

SQL> startup mount
ORACLE instance started.
Total System Global Area  784998400 bytes
Fixed Size                  2257352 bytes
Variable Size             515903032 bytes
Database Buffers          264241152 bytes
Redo Buffers                2596864 bytes
Database mounted.
shutdown again
SQL> shutdown immediate
ORA-01507: database not mounted


ORACLE instance shut down.

SQL> startup nomount;
ORACLE instance started.

Total System Global Area  784998400 bytes
Fixed Size                  2257352 bytes
Variable Size             515903032 bytes
Database Buffers          264241152 bytes
Redo Buffers                2596864 bytes
SQL> alter database mount standby database;

Database altered.

SQL> alter database recover managed standby database disconnect;

Database altered.

SQL> select flashback_on from v$database;

FLASHBACK_ON
------------------
NO

SQL> select count(*) from hr.emp5;
select count(*) from hr.emp5
                        *
ERROR at line 1:
ORA-01219: database not open: queries allowed on fixed tables/views only

Database Switchover Roles
step standby

SQL> select name, open_mode, database_role, protection_mode from v$database;

NAME      OPEN_MODE            DATABASE_ROLE    PROTECTION_MODE
--------- -------------------- ---------------- --------------------
BRIAN     MOUNTED              PHYSICAL STANDBY MAXIMUM PERFORMANCE
SQL> select sequence#, first_time, next_time, applied from v$archived_log order by sequence#;

step primary

SQL> select name, open_mode, database_role, db_unique_name, protection_mode from v$database;

NAME      OPEN_MODE            DATABASE_ROLE    DB_UNIQUE_NAME
--------- -------------------- ---------------- ------------------------------
PROTECTION_MODE
--------------------
BRIAN     READ WRITE           PRIMARY          primary
MAXIMUM PERFORMANCE

step primary
SQL> alter database commit to switchover to standby;
SQL> shutdown immediate;
SQL> start nomount;
SQL> alter database mount standby database;
SQL> alter database recover managed standby database disconnect from session;
SQL> select name, open_mode, database_role, db_unique_name, protection_mode from v$database;

step standby
SQL> alter database commit to switchover to primary;
SQL> shutdown immediate;
SQL> startup
SQL> select name, open_mode, database_role, protection_mode from v$database;
SQL> select sequence#, first_time, next_time from v$archived_log order by sequence#;
SQL> alter system switch logfile;
SQL> select sequence#, first_time, next_time from v$archived_log order by sequence#;

step primary

SQL> select sequence#, first_time, next_time, applied from v$archived_log order by sequence#;


沒有留言: