目 录
一、 目的 4
二、 参考文档 4
三、 软硬件环境 4
四、 安装基本的操作系统 5
五、 操作系统的配置 6
1. 修改操作系统启动模式 6
2. 设置主机名 7
3. 设置双网卡BONDING7
4. MOUNT NFS共享目录9
5. 设置HOSTS 9
6. 增强提示符 10
7. 配置NTP服务 10
8. 设置SAR 10
9. 安装HDS多路径软件 11
六、 安装Oracle GI和DB前的配置11
1. 创建ORACLE用户 11
2. 创建相关目录 12
3. 设置环境变量 12
4. 设置SQLPATH目录13
5. SESSION登录安全设置13
6. 相关RPM包的安装 13
7. 设置SYSCTL.CONF参数15
8. 设置LIMITS.CONF15
9. 清空RESOLV.CONF16
七、 安装ORACLE软件 16
八、 实例的创建 16
九、 ORACLE DB的配置17
1. LISTENER设置 17
2. 开启归档模式 18
3. TNSNAMES设置 19
4. 修改SUPPLEMENT的参数19
5. 设置ONLINE REDO LOGFILE19
6. 增加一个CONTROLFILE20
7. PROFILE改为UNLIMITED20
8. TEMP的DATAFILE增加21
9. 其他初始化参数 21
10. 关闭DRM和一些新特性22
11. 大页内存设置 23
12. 关闭OCM功能 23
13. 其他 23
十、 升级PSU 24
1. 安装前的检查版本是 24
2. 安装的准备工作 25
3. 安装 26
十一、 安全加固 26
十二、 物理DG的搭建, 27
4. 安装数据库软件 27
十三、 物理DG的搭建 27
1. 主库上的设置 27
2. 物理DG上的设置 28
3. 传输主库的密码文件到备库31
4. 进行数据库的DUPLICATE31
5. 主库和备库添加STANDBY LOG31
6. 物理DG启动到APPLY状态31
7. 开启SUPPLEMENT31
8. 主库开启向物理DG传输LOG32
十四、 完成 32
一、 目的
用于生产环境快速搭建Oracle 11gR2 DG的结构,单节点
本文不会详细介绍 DG的理论,可以学习以下文档
《2 Day + Real Application Clusters Guide.pdf》
《Automatic Storage Management Administrator's Guide.pdf》
《Clusterware Administration and Deployment Guide.pdf》
《Real Application Clusters Administration and Deployment Guide.pdf》
二、 参考文档
Oracle 11g documentation 11.2(E11882_01)文档集
《Grid Infrastructure Installation Guide for Linux.pdf》
《Real Application Clusters Installation Guide for Linux and UNIX》
《DB服务器标准安装文档_DOC_DBA_INS_0001.docx》
三、 软硬件环境
两台R620服务器
1U高度
内存80G
硬盘900*8(RAID1+0),可用空间理论3.6T
4个千兆网口
使用两台网络交换机做内部通讯用
存储
使用本地存储来存放数据
操作系统版本为RedHat Enterprise Linux 6.5 x86_64
Oracle DG架构
DB 11.2.0.4.0
PSU 11.2.0.4.2
四、 安装基本的操作系统
生产环境的DELL服务器都有远程控制卡,通过远程控制卡,可以方便的安装操作系统
以下步骤是安装一个最基本的操作系统 RHEL 6.5 x86_64
RHEL6的内核版本不低于 2.6.32-71.el6 (x86_64),包安装要求如下:
1.) binutils-2.20.51.0.2-5.11.el6 (x86_64)
2.)compat-libstdc++-33-3.2.3-69.el6 (x86_64)
3.) glibc-2.12-1.7.el6 (x86_64)
4.) ksh-*.el6 (x86_64)
5.) libaio-0.3.107-10.el6 (x86_64)
6.) libgcc-4.4.4-13.el6 (x86_64)
7.) libstdc++-4.4.4-13.el6 (x86_64)
8.) make-3.81-19.el6 (x86_64)
1.) compat-libcap1-1.10-1 (x86_64)
2.)gcc-4.4.4-13.el6 (x86_64)
3.) gcc-c++-4.4.4-13.el6 (x86_64)
4.) glibc-devel-2.12-1.7.el6 (x86_64)
5.) libaio-devel-0.3.107-10.el6 (x86_64)
6.) libstdc++-devel-4.4.4-13.el6 (x86_64)
7.) sysstat-9.0.4-11.el6 (x86_64)
步骤:
Install or upgrade an existing system
Basic Storage Devices
Yes,discard any data
Hostname
dbcadb
Please select the nearest city in your time zone
Asia/Shanghai
System clock uses UTC 打钩
Enter a password for the root user:
Create Custom Layout
/boot 103M
/ 50G
/home 30G
swap 32G
/u01 50G
/usr/openv 10G
/u02 使用剩下所有的存储空间
Write changes to disk
Optionally select a different set of software now
Basic Server
Red Hat Enterprise linux
Customize now
选择的包
X Window System
Networking Tools
Iptraf-3.01-14.el6x86_64 勾选
System administration Tools
lsscsi-0.23-2.el6.x86_64
screen-4.03-16.el6.x86_64
Desktop
tigervnc-server-1.1.0-5.el6_4.1.x86_64
Additional Development
Compatibility Libraries
按照官方文档的介绍,这个里面的包也要加上
操作系统安装完成后,我们需要关闭防火墙跟selinux,命令如下:
# service iptables stop
#chkconfig iptables off
修改/etc/selinux/config 文件
将SELINUX=enforcing改为SELINUX=disabled
重启机器即可
五、 操作系统的配置
在安装Oracle前,需要配置好操作系统,以下是详细的配置过程
1. 修改操作系统启动模式
把level 5的图形界面改为level 3的字符界面,启动操作系统后会进入字符界面
# vi /etc/inittab
id:3:initdefault:
2. 设置主机名
bdcadb:
# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME= bdcadb
NOZEROCONF=yes
bdcadg:
# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME= bdcadg
NOZEROCONF=yes
3. 设置双网卡bonding
生产环境中的网卡需要冗余,分别连接到不同的网络交换机,当一块网卡出现故障时会自动切换到另一块网卡,所以一个IP需要绑定在两块网卡,使用bonding技术
Oracle RAC需要配置local IP和private IP,local IP配置在bond0,private IP配置在bond1
bdcadb
# cd /etc/sysconfig/network-scripts/
# cat > ifcfg-em1
DEVICE=em1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
# cat > ifcfg-em2
DEVICE=em2
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
# cat > ifcfg-bond0
DEVICE=bond0
IPADDR=192.168.1.196
NETMASK=255.255.255.0
GATEWAY=192.168.1.2
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
增加最后四行
# cd /etc/modprobe.d
# vi bond0.conf
alias bond0 bonding
options bond0 miimon=100 mode=1
重启network
service network restart
bdcadg:
# cd /etc/sysconfig/network-scripts/
# cat > ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
TYPE=Ethernet
# cat > ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no
TYPE=Ethernet
# cat > ifcfg-bond0
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.1.197
USERCTL=no
IPV6INIT=no
PEERDNS=yes
GATEWAY=192.168.1.2
TYPE=Ethernet
增加最后两行
# vi/etc/modprobe.d/bond0.conf
alias bond0 bonding
options bond0 miimon=100 mode=1
重启network
service network restart
需要Disable Network Manager
serviceNetworkManager stop
chkconfigNetworkManager off
这个一定需要关掉,以防止ip冲突导致CRT连接失败
bonding配置完成后要测试冗余性,分别拔掉一根网线,看是否还可以连通
4. mount NFS共享目录
生产环境中安装的软件都在DBA的共享目录中,所以需要mount共享目录
以下mount命令放入/etc/rc.local,服务器启动时会自动mount
# mkdir /u07 /u08
# vi /etc/rc.local
mount -t nfs -o rw,bg,hard,rsize=32768,wsize=32768,nfsvers=3,nointr,timeo=600,tcp,noac,addr=172.16.51.163 172.16.51.163:/vol/vol_sata/backup /u07
mount -t nfs -o rw,bg,hard,rsize=32768,wsize=32768,nfsvers=3,nointr,timeo=600,tcp,noac,addr=172.16.51.163,nolock 172.16.51.163:/vol/vol_sata2/backup /u08
手工运行以上两条mount命令,mount共享目录到/u07和/u08,mount前确认portmap服务是否开启
5. 设置hosts
Linux使用/etc/hosts文件解析名字,需要先设置好hosts
注意127.0.0.1不要包含bdcadb1 或者bdcadb2
127.0.0.1 localhost localhost.localdomain
#public
192.168.1.196 bdcadb.99bill.com bdcadb
#physical standby
192.168.1.197 bdcadg.99bill.com bdcadg
#ntp server
172.16.50.181 ntp-hb1.99bill.com
172.16.50.136 ntp-hb2.99bill.com
172.16.173.108 ntp-idx1.99bill.com
172.16.173.109 ntp-idx2.99bill.com
#smtp server
172.16.80.103 smtp.99bill.com
172.16.80.103 account.99bill.com
172.16.22.25 yum.99bill.com
bonding配置完成后要测试冗余性,分别拔掉一根网线,看是否还可以连通!
6. 增强提示符
为了使用同一用户oracle更好的分辨在哪个ORACLE_HOME中,使用以下增强的命令提示符
# vi /etc/profile
export PS1='[t u(${ORACLE_HOME##*/})@h W]$ '
7. 配置NTP服务
根据公司的NTP策略,需要布置NTP脚本,从IDC处取得ntpd-deploy.sh
目前有一份脚本存放在/u07/system_configuration/ntpd/for_linux目录
如果时间与实现的时间相关太多,先使用ntpdate手工同步一下
# ntpdate ntp-hb1.99bill.com
# ./ntpd-deploy.sh hb
GI环境的ntpd需要加上-x参数
# vi /etc/sysconfig/ntpd
加上参数-x
OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid"
为了保证BIOS时间和系统时间差别太大,ntpd会不同步,在系统重启时增加自动同步一次的脚本
# vi /etc/rc.local
ntpdate ntp-hb1.99bill.com
8. 设置sar
默认sar记录为10分钟一次,改为1分钟一次
日志保存目录为/var/log/sa
运行频率修改,把时间*/10改为*/1,出下面
# vi /etc/cron.d/sysstat
# run system activity accounting tool every 10 minutes
*/1 * * * * root /usr/lib64/sa/sa1 1 1
如果没有配置文件则需要安装sysstat-7.0.2-3.el5_5.1.x86_64.rpm包
日志保存时间,改为30天
# vi /etc/sysconfig/sysstat
HISTORY=30
9. 安装HDS多路径软件
RHEL 5.X可以使用6.3版本的多路径软件,RHEL 6.X要使用7版本的多路径软件
软件在/u07/software/hds目录
# unzip hdlm7.3_linux.zip
# cd hdlm6.3_linux
# chmod -R 777 *
把license拷贝到/var/tmp
# cp hdlm_license /var/tmp
安装
# ./installhdlm
重启服务器
# reboot
修改心跳的参数
# cd /opt/DynamicLinkManager/bin/
# ./dlnkmgr view -sys
# ./dlnkmgr set -pchk on -intvl 5 //Path Health Checking : on(1)
# ./dlnkmgr set -afb on -intvl 1 //Auto Failback : on(1)
六、 安装Oracle GI和DB前的配置
1. 创建oracle用户
groupadd -g 500 oinstall
groupadd -g 501 dba
useradd -g oinstall -G dba oracle
passwd oracle
2. 创建相关目录
创建存放GI和DB软件的目录
chown -R oracle:oinstall /u01 /u02
chmod -R 775 /u01
su - oracle
mkdir -p /u01/app/oracle/product/11.2.0/db
3. 设置环境变量
bdcadb、oracle用户
$ vi .bash_profile
umask 022
set –o vi
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=bdcadb
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin:
export TMP=/tmp
export TMPDIR=/tmp
export LD_LIBRARY_PATH=$ORACLE_BASE/product/11.2.0/db/lib:/usr/lib
export LC_TYPE=en_US.UTF-8
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export SQLPATH=/home/oracle/sqlpath
alias sql='sqlplus / as sysdba'
alias bdump='cd /u02/app/oracle/diag/rdbms/bdcadb/bdcadb1/trace'
bdcadg、oracle用户
$ vi .bash_profile
umask 022
set –o vi
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=bdcadg
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin:
export TMP=/tmp
export TMPDIR=/tmp
export LD_LIBRARY_PATH=$ORACLE_BASE/product/11.2.0/db/lib:/usr/lib
export LC_TYPE=en_US.UTF-8
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export SQLPATH=/home/oracle/sqlpath
alias sql='sqlplus / as sysdba'
alias jdb='export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db;export ORACLE_SID=bdcadg'
alias bdump='cd /u02/app/oracle/diag/rdbms/bdcadb/bdcadb2/trace'
bdcadb、bdcadg、root用户
# vi .bash_profile
export ORACLE_BASE=/u01/app/oracle
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
4. 设置SQLPATH目录
sqlpath目录中的login.sql设置了登录sqlplus的环境变量
$ mkdir -p /home/oracle/sqlpath
$ cat > sqlpath/login.sql
set TERM OFF
define_editor=vim
define loginname=idle
column global_name new_value loginname
select lower(USER||'@'
||substr(global_name,1,decode(dot,0,length(global_name),dot-1))) global_name
from
(select global_name, instr(global_name,'.') dot
from global_name);
set sqlprompt '&loginname> '
alter session set nls_date_format = 'yyyy-mm-dd hh24:mi:ss';
SET TIMING ON
SET TIME ON
SET SERVEROUTPUT ON
SET LINESIZE 130
SET TERM ON
SET NUMWIDTH 13
SET PAGESIZE 1000
SET ECHO ON
5. session登录安全设置
# vi /etc/pam.d/login #增加以下一行
session required pam_limits.so
6. 相关RPM包的安装
根据Oralce官方文档,在RHEL 5.6 x86_64中安装GI和DB,需要安装以下RPM包
unixODBC-devel-2.2.14-12.el6_3.x86_64
expat-2.0.1-11.el6_2.x86_64
compat-libstdc++-33-3.2.3-69.el6.x86_64-
elfutils-libelf-0.152-1.el6.x86_64
glibc-devel-2.12-1.132.el6.x86_64
libgcc-4.4.7-4.el6.i686
glibc-common-2.12-1.132.el6.x86_64
binutils-2.20.51.0.2-5.36.el6.x86_64
unixODBC-2.2.14-12.el6_3.x86_64
elfutils-libelf-devel-0.152-1.el6.x86_64
gcc-4.4.7-4.el6.x86_64
gcc-c++-4.4.7-4.el6.x86_64
libgcc-4.4.7-4.el6.x86_64
libstdc++-4.4.7-4.el6.x86_64
libaio-0.3.107-10.el6.x86_64
libaio-devel-0.3.107-10.el6.x86_64
sysstat-9.0.4-22.el6.x86_64
pdksh-5.2.14-1.i386
glibc-2.12-1.132.el6.x86_64
glibc-headers-2.12-1.132.el6.x86_64
glibc-2.12-1.132.el6.i686
make-3.81-20.el6.x86_64
libstdc++-devel-4.4.7-4.el6.x86_64
其他RPM包安装
rpm -ivh unzip-5.52-3.el5.x86_64.rpm
rpm -ivh lrzsz-0.12.20-22.1.x86_64.rpm
在包已经全部装好以后,我们可以通过如下的命令来检测rpm包的安装情况:
rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel expat gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make pdksh sysstat
unixODBC unixODBC-devel | grep "not installed"
对于缺包,我们可以通过两种方法来配置yum源
1) 安装本地镜像的yum源
cd /etc/yum.repos.d
[root@node1 yum.repos.d]# cp rhel-debuginfo.repo yum.repo
[root@node1 yum.repos.d]# mv rhel-debuginfo.repo rhel-debuginfo.repo.bk
[root@node1 yum.repos.d]#vi yum.repo
[base]
name=Red Hat Enterprise Linux
baseurl=file:///media/Server
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
mount -t iso9660 -o loop /soft/rhel-server-6.5-x86_64-dvd.iso /media
2) 安装公司的yum服务器来配置yum源
执行 sh setup_yum.sh yum.99bill.com
对于linux 6.5的环境中pdksh的包在光盘镜像中是没有的是没有的,现提供提供一个该包的下载
7. 设置sysctl.conf参数
在sysctl.conf中添加以下配置
# vi /etc/sysctl.conf
kernel.shmmni = 4096
kernel.sem = 2048 65536 1024 256
fs.file-max = 6815744
fs.aio-max-nr = 1048576
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 = 1048576
使配置生效
# sysctl -p
8. 设置limits.conf
在limits.conf中添加以下配置
# vi /etc/security/limits.conf
oracle soft nproc 65536
oracle hard nproc 65536
oracle soft nofile 65536
oracle hard nofile 65536
9. 清空resolv.conf
在生产环境中,不建议使用resolve.conf解析域名,可能会使客户端登录缓慢,建议清空它
# vi /etc/resolv.conf
清空
七、 安装ORACLE软件
进入oracle软件的安装目录
$ ./runInstaller
去掉I wish to receive security updates via My Oracle Support的勾选
Skip software updates
Install database software only
Single instance database installation
Enterprise Edition
Specify Installation Locaion
Oracle Base /u01/app/oracle
Software Location/u01/app/oracle/product/11.2.0/db
Privileged Operating System Groups
OSOPER Group选择 dba
Perform Prerequistite Checks
开始安装
以root用户运行两个脚本:
/u01/app/oraInventory/orainstRoot.sh
/u01/app/oracle/product/11.2.0/db/root.sh
八、 实例的创建
$ dbca
Global Database Namebdcadb.99bill.com
SID Prefix bdcadb
如果报scan listener没有运行,忽略
Select All
去掉Enterprise Manager
Use Common Location for All Data File
/u02/oradata
去掉specify fash recovery area
Character Sets AL32UTF8
National Character Set UTF8
其他默认,将来改
九、 Oracle DB的配置
以下为详细的DB配置,配置完成建议重启所有节点服务器,检查是否可以正常启动服务及让参数生效
因为是搭建的DG环境,所以主备库使用静态监听,配置如下
1. listener设置
bdcadb:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = bdcadb.99bill.com)(PORT = 1530))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1530))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = BDCADB.99BILL.COM)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db)
(SID_NAME = bdcadb)
)
(SID_DESC=
(SID_NAME=plsextproc)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db)
(PROGRAM=extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = bdcataf.99bill.com)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db)
(SID_NAME = bdcadb)
)
)
ADR_BASE_LISTENER = /u01/app/oracle ;
bdcadg:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = bdcadg.99bill.com)(PORT = 1530))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1530))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = bdcadb.99bill.com)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db)
(SID_NAME = bdcadb)
)
(SID_DESC=
(SID_NAME=plsextproc)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db)
(PROGRAM=extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = bdcataf.99bill.com)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db)
(SID_NAME = bdcadb)
)
)
ADR_BASE_LISTENER = /u01/app/oracle
2. 开启归档模式
$ mkdir -p /u02/archive/bdcadb
$ sqlplus / as sysdba
alter system set log_archive_format = 'Arc_%t_%s_%r.arc' scope = spfile;
alter system set log_archive_dest_1 = 'LOCATION=/u02/archive/bdcadb/ VALID_FOR=(ONLINE_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME='bdcadb';
alter system set log_archive_config = 'DG_CONFIG=( bdcadb,bdcadg)';
shutdown immediate
startup mount
alter database archive log;
alter database open;
3. TNSNAMES设置
$ cd $ORACLE_HOME/network/admin
$ vi tnsnames.ora
BDCADB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = bdcadb.99bill.com)(PORT = 1530))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = bdcadb.99bill.com)
)
)
BDCADG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = bdcadg.99bill.com)(PORT = 1530))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = bdcadb.99bill.com)
)
)
BDCATAF =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = bdcadb.99bill.com)(PORT = 1530))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = bdcataf.99bill.com)
)
)
LISTENER_BDCADB =
(ADDRESS = (PROTOCOL = TCP)(HOST = bdcadb.99bill.com)(PORT = 1530))
然后拷贝到备库上面
4. 修改supplement的参数
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY, UNIQUE) COLUMNS;
5. 设置online redo logfile
每个节点创建4组logfile,每组logfile有2个member,每个member 512M
增加1个 group
alter database add logfile group 5 ('/u02/oradata/bdcadb/redo05_1.log','/u02/oradata/bdcadb/redo05_2.log') size 512M;
使用以下命令查询status为INACTIVE状态的logfile并删除,如果不是,可以切换几次,并使用checkpoint命令状态改为INACTIVE
alter system checkpoint;
online redo logfile物理不会自动删除,需要进入ASM手工删除
select group#, thread#, bytes, members, archived, status from v$log;
删除group1,2,3
alter database drop logfile group 1;
alter database drop logfile group 2;
alter database drop logfile group 3;
增加3个 group
alter database add logfile group 1 ('/u02/oradata/bdcadb/redo01_1.log','/u02/oradata/bdcadb/redo01_2.log') size 512M;
alter database add logfile group 2 ('/u02/oradata/bdcadb/redo02_1.log','/u02/oradata/bdcadb/redo02_2.log') size 512M;
alter database add logfile group 3 ('/u02/oradata/bdcadb/redo03_1.log','/u02/oradata/bdcadb/redo03_2.log') size 512M;
6. 增加一个controlfile
默认只有2个controlfile,需要手工增加一个
alter system set control_files = '/u02/oradata/bdcadb/control01.ctl','/u02/oradata/bdcadb/control02.ctl','/u02/oradata/bdcadb/control03.ctl' scope = spfile
关闭INSTANCE,把controlfile拷贝一份
cp control01.ctl control03.ctl
启动数据库
7. profile改为unlimited
alter profile DEFAULT limit
failed_login_attempts unlimited
password_life_time unlimited
password_lock_time unlimited
password_grace_time unlimited;
8. TEMP的datafile增加
alter tablespace temp add tempfile '/u02/oradata/bdcadb/temp02.dbf' size 10000M autoextend on ;
9. 其他初始化参数
$ mkdir -p /u02/app/oracle
alter system set diagnostic_dest = '/u02/app/oracle';
alter system set utl_file_dir = '/tmp' scope = spfile;
alter system set processes = 4000 scope = spfile;
alter system set db_writer_processes = 4 scope = spfile;
alter system set open_cursors = 1000 scope = spfile;
alter system set undo_retention = 86400;
alter system set memory_target=0;
alter system set sga_max_size = 48G scope = spfile;
alter system set sga_target = 48G scope = spfile;
alter system set pga_aggregate_target = 12G;
alter system set db_file_multiblock_read_count = 16;
alter system set db_files = 2048 scope = spfile;
alter system set optimizer_index_caching = 90;
alter system set optimizer_index_cost_adj = 15;
alter system set log_archive_max_processes = 6;
alter system set nls_date_format = 'yyyy-mm-dd hh24:mi:ss' scope = spfile;
alter system set standby_file_management = auto;
设置adump
$ mkdir -p /u02/app/oracle/admin/bdcadb/adump
alter system set audit_file_dest = '/u02/app/oracle/admin/bdcadb/adump' scope = spfile;
设置AWR收集频率
begin
dbms_workload_repository.modify_snapshot_settings(retention => 14*24*60,
interval => 15
);
end;
/
10. 关闭DRM和一些新特性
在Oracle 11gR2中,使用以下参数关闭DRM
alter system set "_gc_policy_time" = 0 scope = spfile;
Oracle 11gR2中建议关闭新功能
http://www.askmaclean.com/archives/direct-read-impact-on-delayed-block-read.html
alter system set event= '10949 trace name context forever, level 1' scope = spfile;
alter system set event= '28401 trace name context forever, level 1' scope = spfile;
关闭审计
alter system set audit_trail = none scope = spfile;
truncate table SYS.AUD$;
禁用直接路径读 DIRECT PATH READ
alter system set "_serial_direct_read" = never;
禁用11g的新密码策略
alter system set sec_case_sensitive_logon = false;
禁用密码延迟验证
alter system set EVENT="28401 TRACE NAME CONTEXT FOREVER, LEVEL 1" scope=spfile;
禁用SQL优化器自动任务 SQL TUNING ADVISOR
BEGIN
dbms_auto_task_admin.disable(
client_name => 'sql tuning advisor',
operation => NULL,
window_name => NULL);
END;
/
禁用11g自动任务中的自动分段顾问
BEGIN
dbms_auto_task_admin.disable(
client_name => 'auto space advisor',
operation => NULL,
window_name => NULL);
END;
/
查看自动任务的开启情况,状态应该都为FALSE
--select * from dba_autotask_client;
--select * from dba_autotask_window_clients;
11. 大页内存设置
大页内存单位为2M,所以数值为 SGA / 2M
vm.nr_hugepages = (128M + 48G * 1024) / 2M = 24576,再取个整数24700
# vi /etc/sysctl.conf
vm.nr_hugepages = 24700
# vi /etc/security/limits.conf
oracle - memlock unlimited
# sysctl -p
# cat /proc/meminfo | grep Huge
alter system set lock_sga = true scope = spfile;
重启DB
12. 关闭OCM功能
如果报以下错误,关闭这个功能
Errors in file /u02/app/oracle/diag/rdbms/bdcadb/bdcadb1/trace/bdcadb1_j001_31131.trc:
ORA-12012: error on auto execute of job "ORACLE_OCM"."MGMT_CONFIG_JOB_2_1"
ORA-29280: invalid directory path
ORA-06512: at "ORACLE_OCM.MGMT_DB_LL_METRICS", line 2436
ORA-06512: at line 1
exec dbms_scheduler.disable('ORACLE_OCM.MGMT_CONFIG_JOB');
exec dbms_scheduler.disable('ORACLE_OCM.MGMT_STATS_CONFIG_JOB');
13. 其他
禁用direct path read
alter system set "_serial_direct_read" = never;
解决11g一致性读问题
alter system set "_row_cr" = false scope = spfile;
禁用SQL优化器自动任务(SQL TUNING ADVISOR)
BEGIN
dbms_auto_task_admin.disable(
client_name => 'sql tuning advisor',
operation => NULL,
window_name => NULL);
END;
/
十、 升级PSU
升级GI和DB到版本11.2.0.4.2,需要打PSU(18139609)
可以下载下面两个补丁号的patch(11.2.0.4.2),一个是GI的,一个是DB的,根据你们的需要决定,建议直接安装GI的PSU,因GI的PUS包括了DB的PSU
安装任何补丁时一定要仔细阅读补丁对应的 readme 文件,因为每个补丁的安装步骤可能有所不同
使用opatch auto 就可以把GI和数据库的PSU都安装上,使用opatch auto 的好处是完全的自动化,不需要手工停止/启动GI,建议把DB关闭
安装完成后,在GI和DB的ORACLE_HOME会分别安装了GI和DB的PSU,也就是每个ORACLE_HOME下都有两个PSU,一个是GI的,一个是DB的。
推荐这种安装方法,因为有的Bug既需要在GI中修复,又需要在DB中修复。
安装PSU的过程是滚动的,依次在每个节点执行
1. 安装前的检查版本是
由于我们是使用11.2.0.4的oracle软件直接来安装的,grid,oracle默认的
$ ./opatch version
OPatch Version: 11.2.0.3.4
OPatch succeeded.
通过PSU的readme.html中,我们可以看到这样的话
You must use the OPatch utility version 11.2.0.3.6 or later to apply this patch. Oracle recommends that you use the latest released OPatch version for 11.2, which is available for download from My Oracle Support patch 6880880 by selecting the 11.2.0.0.0 release.
升级所需要的最低的版本是11.2.0.3.6,显然我们安装的软件是达不到最低的升级标准的,所以我们需要一个另外的PATCH来更新opatch的版本Oracle 提供了这样的一个补丁包p6880880_112000_Linux-x86-64.zip
用来把OPATCH提成到最新的版本
2. 安装的准备工作
备份GRID_HOME和DB_HOME的ORACLE_HOME/OPatch
GI的ORACLE_HOME
# cd $ORACLE_HOME
# tar zcvf OPatch_11.2.0.1.7.tar.gz OPatch
# rm -fr $ORACLE_HOME/OPatch
DB的$ORACLE_HOME
$ jdb
$ cd $ORACLE_HOME
$ tar zcvf OPatch_11.2.0.1.7.tar.gz OPatch
$ rm -fr $ORACLE_HOME/OPatch
解压缩Opatch
GI的ORACLE_HOME
# unzip p6880880_112000_Linux-x86-64.zip -d $ORACLE_HOME
# chown -R oracle:oinstall $ORACLE_HOME/OPatch
DB的ORACLE_HOME
$ jdb
$ unzip p6880880_112000_Linux-x86-64.zip -d $ORACLE_HOME
查看版本
$ ./opatch version
OPatch Version: 11.2.0.3.6
OPatch succeeded.
如果没有配置OCM,按照下面的步骤执行:
运行后在当前目录生成ocm.rsp文件,一般在/home/oracle目录
$ jgrid
$ $ORACLE_HOME/OPatch/ocm/bin/emocmrsp
检查
$ jgrid
$ $GRID_HOME/OPatch/opatch lsinventory -detail -oh $GRID_HOME
$ jdb
$ $ORACLE_HOME/OPatch/opatch lsinventory -detail -oh $ORACLE_HOME
3. 安装
此步操作我们需要注意几个问题
(1) 补丁集的属组需要为oracle:oinstall
(2) 我们需要断开一切的数据库的连接,不然的话在进行升级的时候会报错
optach auto的过程中我们是看不到具体的错误内容的
它的安装日志在/u01/app/11.2.0/grid/cfgtoollogs这个文件夹下来,如果遇到错误,我们可以看到详细的错误日志,从而分析出错误的原因
(3) 进行opatch auto的时候我们需要关闭掉数据库,grid可以不用关闭,在升级的时候会自动的进行关闭用root身份安装补丁(不需要停止GI),建议停止DB
检查/u01的owner是否为oracle,如果不是则运行以下命令
# chown -R oracle:oinstall /u01
# cd $GRID_HOME/OPatch
# ./opatch auto /u07/software/oracle_db/patch/psu_11.2.0.3.6/p16083653_112030_Linux-x86-64-11020306-gi -ocmrf /home/oracle/ocm.rsp
安装过程中有日志文件显示详细,见安装提示
全部节点更新完PSU后在任意一个节点DB中运行
$ jdb
$ cd $ORACLE_HOME/rdbms/admin
$ sqlplus /as sysdba
SQL> STARTUP
SQL> @catbundle.sql psu apply
SQL> quit
如果您使用了RMAN,需要将您的RMAN catalog库升级一下,执行:
$ rman catalog username/password@alias
RMAN> UPGRADE CATALOG;
查看历史,会显示PSU版本为11.2.0.4.2
select * from dba_registry_history;
./opatch lsinventory
十一、 安全加固
从安全中心取得安装加固脚本,注意以下几点
加固前开个root用户窗口,当加固完成可以正常可以su到root后再关闭
加固后关闭iptables服务
加固后开启portmap服务
加固后打开以下命令的oracle权限
# chmod 755 /usr/bin/whereis
十二、 物理DG的搭建,
4. 安装数据库软件
$ export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db
$ ./runInstaller
Configure Security Updates
去掉 I wish to receive ....
Skip software updates
Install database software only
Single Instance database installation
English
Specify Installation Location
Oracle Base /u01/app/oracle
Software Location/u01/app/oracle/product/11.2.0/db
Privileged Operating System Groups
OSOPER选dba
开始安装
运行root.sh
完成安装
十三、 物理DG的搭建
1. 主库上的设置
Oracle数据库之间是通过tnsname.ora文件来解析tnsname并进行通信的,listener来接收Oracle的连接请求,所以在创建DataGuard前必须设置了tnsnames.ora和listener.ora
主库中添加物理DG的hostname
# vi /etc/hosts #添加
#physical standby
192.168.1.197 bdcadg.99bill.com bdcadg
主库添加tnsnames.ora
$ cd $ORACLE_HOME/network/admin
$ vi tnsnames.ora --增加以下内容
BDCADG =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.197)(PORT = 1530))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = bdcataf.99bill.com)
)
)
主库开启force logging
SQL>alter database force logging;
设置主库的db_unique_name,默认是设好的,如果没有设则使用以下命令设置
SQL>alter system set db_unique_name = 'bdcadb' scope = spfile;
设好后需要重启生效
主库设置其他初始化参数
mkdir -p /u02/stdlog/bdcadb
alter system set log_archive_config = 'DG_CONFIG=(bdcadb,bdcadg)';
alter system set log_archive_dest_2= 'LOCATION=/u02/stdlog/bdcadb VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=bdcadb';
alter system set log_archive_dest_3= 'SERVICE=bdcadg LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=bdcadg';
alter system set fal_server=bdcadg';
alter system set fal_client = 'bdcadb';
先临时关闭archived_log的传输
alter system set log_archive_dest_state_3 = defer;
2. 物理DG上的设置
在/etc/hosts中添加主库的hostname
# vi /etc/hosts --添加
#public
192.168.1.196 bdcadb.99bill.com bdcadb
192.168.1.197 bdcadg.99bill.com bdcadg
物理DG添加tnsnames
$ cd $ORACLE_HOME/network/admin
$ vi tnsnames.ora
BDCADB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.151)(PORT = 1530))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = bdcataf.99bill.com)
)
)
物理DG上手工创建相关目录
mkdir -p /u02/app/oracle/admin/bdcadb/adump
mkdir -p /u02/archive/bdcadb
mkdir -p /u02/oradata/bdcadb
mkdir -p /u02/stdlog/bdcadb
创建物理DG的初始化参数
$ jdb
$ cd /home/oracle
$ vi initbdcadb.ora
bdcadb.__db_cache_size=45365592064
bdcadb.__java_pool_size=805306368
bdcadb.__large_pool_size=939524096
bdcadb.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
bdcadb.__pga_aggregate_target=12884901888
bdcadb.__sga_target=51539607552
bdcadb.__shared_io_pool_size=0
bdcadb.__shared_pool_size=4160749568
bdcadb.__streams_pool_size=0
*._gc_policy_time=0
*._serial_direct_read='NEVER'
*.audit_file_dest='/u02/app/oracle/admin/bdcadb/adump'
*.audit_trail='NONE'
*.compatible='11.2.0.4.0'
*.control_files='/u02/oradata/bdcadb/bdcadb/control01.ctl','/u02/oradata/bdcadb/bdcadb/control02.ctl','/u02/oradata/bdcadb/bdcadb/control03.ctl'
*.db_block_size=8192
*.db_domain='99bill.com'
*.db_file_multiblock_read_count=16
*.db_file_name_convert='bdcadb','bdcadb'
*.db_files=2048
*.db_name='bdcadb'
*.db_unique_name='bdcadg'
*.db_writer_processes=4
*.diagnostic_dest='/u02/app/oracle'
*.event='28401 TRACE NAME CONTEXT FOREVER, LEVEL 1'
*.fal_client='bdcadg'
*.fal_server='bdcadb'
*.lock_sga=TRUE
*.log_archive_config='DG_CONFIG=(bdcadg,bdcadb)'
*.log_archive_dest_1='location=/u02/archive/bdcadb VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=bdcadb'
*.log_archive_dest_2='SERVICE=BDCADB LGWR ASYNC AFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=bdcadb'
*.log_archive_dest_3='LOCATION=/u02/stdlog/bdcadb VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=bdcadg'
*.log_archive_dest_state_1='enable'
*.log_archive_dest_state_2='enable'
*.log_archive_max_processes=6
*.log_file_name_convert='bdcadb','bdcadb'
*.memory_target=0
*.nls_date_format='yyyy-mm-dd hh24:mi:ss'
*.open_cursors=1000
*.optimizer_index_caching=90
*.optimizer_index_cost_adj=15
*.pga_aggregate_target=12884901888
*.processes=4000
*.remote_login_passwordfile='EXCLUSIVE'
*.sec_case_sensitive_logon=FALSE
*.service_names='bdcadb.99bill.com','bdcataf.99bill.com'
*.sessions=4405
*.sga_max_size=51539607552
*.sga_target=51539607552
*.standby_file_management='AUTO'
*.undo_retention=86400
*.undo_tablespace='UNDOTBS1'
*.utl_file_dir='/tmp''
启动数据库到nomount状态并生成spfile
$ jdb
$ sqlplus / as sysdba
startup nomount pfile='/home/oracle/initbdcadb.ora'
create spfile='/u02/oradata/bdcadb/spfilebdcadb.ora' from pfile='/home/oracle/initbdcadb.ora';
shutdown immediate
3. 传输主库的密码文件到备库
Oracle 11g的备库密码通过orapwd命令生成会出现问题,必须从主库上传输一份,并且logdb2的密码文件也必须从logdb1拷贝过来,保证两节点主库和备库三个密码文件是同一个文件
4. 进行数据库的duplicate
将备库打开到nomount状态,主库执行:
$ rman target sys/oracle@bdcadb auxiliary sys/oracle@logdg ;
$RMAN>run{
duplicate target database for standby from active database nofilenamecheck;
}
5. 主库和备库添加standby log
添加standby log公式:(每线程的日志组数+1)×最大线程数
alter database add standby logfile group 5 ('/u02/oradata/bdcadb/standby05_1.log','/u02/oradata/bdcadb/standby05_2.log') size 536870912;
alter database add standby logfile group 6 ('/u02/oradata/bdcadb/standby06_1.log','/u02/oradata/bdcadb/standby06_2.log') size 536870912;
alter database add standby logfile group 7 ('/u02/oradata/bdcadb/standby07_1.log','/u02/oradata/bdcadb/standby07_2.log') size 536870912;
alter database add standby logfile group 8 ('/u02/oradata/bdcadb/standby08_1.log','/u02/oradata/bdcadb/standby08_2.log') size 536870912;
alter database add standby logfile group 9 ('/u02/oradata/bdcadb/standby09_1.log','/u02/oradata/bdcadb/standby09_2.log') size 536870912;
6. 物理DG启动到apply状态
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
Oracle 11gR2可以启动到READ ONLY模式进行APPLY
alter database open;
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
7. 开启supplement
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;
ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY, UNIQUE) COLUMNS;
8. 主库开启向物理DG传输log
alter system set log_archive_dest_state_3 = enable;
十四、 完成
: