Oracle 11g R2 RAC安裝規劃

 前言

使用虛擬機VMWARE安裝Oracle 11g R2 RAC,須要模擬兩個主機節點和一個共享存儲,安裝系統和建立虛擬存儲文件這裏不做介紹,能夠自行百度方法,很簡單。node

1、主機規劃

 

2、數據庫規劃

 

3、準備工做

3.一、HOSTS和主機名配置

#在全部節點添加主機名,重啓生效:
[root@node1 ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=node1
NTPSERVERARGS=iburst

[root@node2 ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=node2
NTPSERVERARGS=iburst

#在全部節點添加hosts:
[root@node1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

10.0.0.1 node1-priv
10.0.0.2 node2-priv

192.168.41.141 node1
192.168.41.142 node2

192.168.41.143 node1-vip
192.168.41.144 node2-vip

192.168.41.139 scanip

[root@node2 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

10.0.0.1 node1-priv
10.0.0.2 node2-priv

192.168.41.141 node1
192.168.41.142 node2

192.168.41.143 node1-vip
192.168.41.144 node2-vip

192.168.41.139 scanip

3.二、禁用防火牆、SElinux和NTP

#全部節點執行,關閉防火牆:
[root@node1 ~]# service iptables stop
[root@node1 ~]# chkconfig iptables off

#全部節點執行,關閉SElinux:
[root@node1 ~]# setenforce 0
[root@node1 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

#全部節點執行,關閉NTP服務(禁用ntp並刪除配置文件後,rac的grid安裝時會自動使用其自帶的CTSS進行時間管理):
[root@node1 ~]# service ntpd stop          
[root@node1 ~]# chkconfig ntpd off
[root@node1 ~]# mv /etc/ntp.conf /etc/ntp.conf.bak

3.三、配置用戶、環境變量、依賴包等

爲了提升效率和減小配置的出錯,寫了一個簡單的腳本,在全部節點執行:linux

[root@node1 home]# sh oracleInstall.sh

腳本以下:數據庫

#!/usr/bin/bash

. /etc/init.d/functions

#安裝依賴包
function yumPackge
{
    echo "######################安裝依賴包########################"
	yum install -y binutils* >/dev/null 2>&1 && action "安裝binutils*" /bin/true || action "安裝binutils*" /bin/false	
	yum install -y compat-libstdc* >/dev/null 2>&1 && action "安裝compat-libstdc*" /bin/true || action "安裝compat-libstdc*" /bin/false
	yum install -y elfutils-libelf* >/dev/null 2>&1 && action "安裝elfutils-libelf*" /bin/true || action "安裝elfutils-libelf*" /bin/false
	yum install -y gcc* >/dev/null 2>&1 && action "安裝gcc*" /bin/true || action "安裝gcc*" /bin/false
	yum install -y glibc* >/dev/null 2>&1 && action "安裝glibc*" /bin/true || action "安裝glibc*" /bin/false
	yum install -y ksh* >/dev/null 2>&1 && action "安裝ksh*" /bin/true || action "安裝ksh*" /bin/false	
	yum install -y libaio* >/dev/null 2>&1 && action "安裝libaio*" /bin/true || action "安裝libaio*" /bin/false
	yum install -y libaio.so.1 >/dev/null 2>&1 && action "安裝libaio.so.1" /bin/true || action "安裝libaio.so.1" /bin/false
	yum install -y libgcc* >/dev/null 2>&1 && action "安裝libgcc*" /bin/true || action "安裝libgcc*" /bin/false
	yum install -y libstdc* >/dev/null 2>&1 && action "安裝libstdc*" /bin/true || action "安裝libstdc*" /bin/false	
	yum install -y make* >/dev/null 2>&1 && action "安裝make*" /bin/true || action "安裝make*" /bin/false
	yum install -y sysstat* >/dev/null 2>&1 && action "安裝sysstat*" /bin/true || action "安裝sysstat*" /bin/false
	yum install -y libXp* >/dev/null 2>&1 && action "安裝libXp*" /bin/true || action "安裝libXp*" /bin/false	
	yum install -y glibc-kernheaders >/dev/null 2>&1 && action "安裝glibc-kernheaders" /bin/true || action "安裝glibc-kernheaders" /bin/false
	echo "#########################結束###########################"
}

function modifyKennel
{
	echo "
	fs.aio-max-nr = 1048576
	fs.file-max = 6815744
	kernel.shmall = 2097152
	kernel.shmmax = 4294967295
	kernel.shmmni = 4096
	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 = 1048576
	" >> /etc/sysctl.conf
	if [ "$?" -eq 0 ];then
	sysctl -p >/dev/null 2>&1
	action "修改內核參數" /bin/true
	else
	action "修改內核參數" /bin/false
	fi
}

function modifyLimit
{
	echo "
	oracle soft nproc 2047
	oracle hard nproc 16384
	oracle soft nofile 1024
	oracle hard nofile 65536
	oracle soft stack 10240
	grid soft nproc 16384
	grid hard nproc 16384
	grid soft nofile 65536
	grid hard nofile 65536
	grid soft stack 10240
	grid hard stack 10240
	" >> /etc/security/limits.conf
	if [ "$?" -eq 0 ];then
	action "修改資源限制" /bin/true
	else
	action "修改資源限制" /bin/false
	fi
}

function modifyProfile
{
	echo "
	session required /lib/security/pam_limits.so
	session required pam_limits.so
	" >> /etc/pam.d/login && action "修改login" /bin/true || action "修改login" /bin/false
	echo "
	if [ $USER = "oracle" ]; then
	if [ $SHELL = "/bin/ksh" ]; then
	ulimit -p 16384
	ulimit -n 65536
	else
	ulimit -u 16384 -n 65536
	fi
	fi
	" >> /etc/profile
	if [ "$?" -eq 0 ];then
	source /etc/profile
	action "修改profile" /bin/true
	else
	action "修改profile" /bin/false
	fi
}

function createGroup
{
	[ `cat /etc/group|grep dba|wc -l` -gt 0 ] && groupdel dba
	[ `cat /etc/group|grep oinstall|wc -l` -gt 0 ] && groupdel oinstall
	[ `cat /etc/group|grep oper|wc -l` -gt 0 ] && groupdel oper
	[ `cat /etc/group|grep asmadmin|wc -l` -gt 0 ] && groupdel asmadmin
	[ `cat /etc/group|grep asmdba|wc -l` -gt 0 ] && groupdel asmdba
	[ `cat /etc/group|grep asmoper|wc -l` -gt 0 ] && groupdel asmoper
	read -p "依次輸入dba,oinstall,oper,asmadmin,asmdba,asmoper組號:" dbagid oinstallgid opergid asmadmingid asmdbagid asmopergid
	groupadd -g $dbagid dba
	groupadd -g $oinstallgid oinstall
	groupadd -g $opergid oper
	groupadd -g $asmadmingid asmadmin
	groupadd -g $asmdbagid asmdba
	groupadd -g $asmopergid asmoper
	[ `cat /etc/group|grep dba|wc -l` -gt 0 ] && action "dba組建立成功" /bin/true || action "dba組建立失敗" /bin/false
	[ `cat /etc/group|grep oinstall|wc -l` -gt 0 ] && action "oinstall組建立成功" /bin/true || action "oinstall組建立失敗" /bin/false
	[ `cat /etc/group|grep oper|wc -l` -gt 0 ] && action "oper組建立成功" /bin/true || action "oper組建立失敗" /bin/false
	[ `cat /etc/group|grep asmadmin|wc -l` -gt 0 ] && action "asmadmin組建立成功" /bin/true || action "asmadmin組建立失敗" /bin/false
	[ `cat /etc/group|grep asmdba|wc -l` -gt 0 ] && action "asmdba組建立成功" /bin/true || action "asmdba組建立失敗" /bin/false
	[ `cat /etc/group|grep asmoper|wc -l` -gt 0 ] && action "asmoper組建立成功" /bin/true || action "asmoper組建立失敗" /bin/false		
}


function createUser
{
	[ `cat /etc/passwd|grep oracle|wc -l` -gt 0 ] && userdel oracle
	[ `cat /etc/passwd|grep grid|wc -l` -gt 0 ] && userdel grid
	read -p "請輸入oracle ID:" oracleuid
	read -s -p "請輸入oracle用戶密碼:" orapasswd && echo -e "\r"
	read -p "請輸入grid ID:" griduid	
	read -s -p "請輸入grid用戶密碼:" gridpasswd && echo -e "\r"
	useradd -u $oracleuid -g oinstall -G dba,oper,asmdba,asmadmin oracle
	[ $? -eq 0 ] &&	action "建立oracle用戶成功" /bin/true || action "建立oracle用戶失敗" /bin/false
	echo "$orapasswd"|passwd oracle --stdin >/dev/null
	useradd -u $griduid -g oinstall -G dba,asmadmin,asmdba,asmoper grid
	[ $? -eq 0 ] &&	action "建立grid用戶成功" /bin/true || action "建立grid用戶失敗" /bin/false	
	echo "$gridpasswd"|passwd grid --stdin >/dev/null
}

function createDIR
{
	rm -rf /u01/app
	mkdir -p /u01/app/11.2.0/grid
	mkdir -p /u01/app/grid
	mkdir -p /u01/app/oracle/product/11.2.0/db_1
	if [ -d /u01/app/11.2.0/grid ] && [ -d /u01/app/grid ] && [ -d /u01/app/oracle/product/11.2.0/db_1 ];then
		action "建立目錄成功" /bin/true
	else
		action "建立目錄失敗" /bin/false
	fi
	chown -R grid:oinstall /u01 
	chmod -R 775 /u01/
	chown -R oracle:oinstall /u01/app/oracle 
}


function oracleProfile
{	 
	if [ `su - oracle -c "env|grep ORA|wc -l"` -gt 0 ];then
		action "修改oracle環境" /bin/true
	else
		su - oracle -c 'echo -e "export ORACLE_SID=orcl\nexport ORACLE_BASE=/u01/app/oracle\nexport ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1" >> ~/.bash_profile'
		su - oracle -c 'echo -e "export ORACLE_TERM=xterm\nexport PATH=/usr/sbin:$PATH\nexport PATH=$ORACLE_HOME/bin:$PATH" >> ~/.bash_profile'
		su - oracle -c 'echo -e "export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib\nexport CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib" >> ~/.bash_profile'
		su - oracle -c 'echo -e "ulimit -u 16384 -n 65536\numask 022" >> ~/.bash_profile && source ~/.bash_profile'
		if [ `su - oracle -c "env|grep ORA|wc -l"` -gt 0 ];then
			action "修改oracle環境" /bin/true
		else
			action "修改oracle環境" /bin/false
		fi
	fi
}

function gridProfile
{
	if [ `su - grid -c "env|grep ORA|wc -l"` -gt 0 ];then
		action "修改grid環境" /bin/true
	else
		su - grid -c 'echo -e "export export ORACLE_SID=+ASM\nexport ORACLE_BASE=/u01/app/grid\nexport ORACLE_HOME=/u01/app/11.2.0/grid" >> ~/.bash_profile'
		su - grid -c 'echo -e "export PATH=$PATH:$HOME/bin\nexport PATH=/usr/sbin:$PATH:$ORACLE_HOME/bin:$PATH" >> ~/.bash_profile'
		su - grid -c 'echo -e "export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib\nexport CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib" >> ~/.bash_profile'
		su - grid -c 'echo -e "export TEMP=/tmp\nexport TMP=/tmp\nexport TMPDIR=/tmp\numask 022" >> ~/.bash_profile && source ~/.bash_profile'
		if [ `su - grid -c "env|grep ORA|wc -l"` -gt 0 ];then
			action "修改grid環境" /bin/true
		else
			action "修改grid環境" /bin/false
		fi
	fi
}

function main
{
	yumPackge
	modifyLimit
	modifyKennel
	modifyProfile
	createGroup
	createUser
	createDIR
	oracleProfile
	gridProfile
}

main

3.四、安裝和配置自動存儲管理ASM

#查看內核版本,下載對應的rpm包
[root@node1 ~]# uname -r
2.6.32-696.18.7.el6.x86_64

#對應的rpm包
[root@node1 u01]# ll|grep oracleasm
-rw-r--r--. 1 root   root          13300 Jan 13 16:36 oracleasmlib-2.0.4-1.el6.x86_64.rpm
-rw-r--r--. 1 root   root          74984 Jan 13 16:40 oracleasm-support-2.1.8-1.el6.x86_64.rpm

#在全部節點都安裝rpm包
[root@node1 u01]# rpm -ivh oracleasm-support-2.1.8-1.el6.x86_64.rpm 
warning: oracleasm-support-2.1.8-1.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Preparing...                ########################################### [100%]
        package oracleasm-support-2.1.8-1.el6.x86_64 is already installed
[root@node1 u01]# rpm -ivh oracleasmlib-2.0.4-1.el6.x86_64.rpm 
warning: oracleasmlib-2.0.4-1.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Preparing...                ########################################### [100%]
        package oracleasmlib-2.0.4-1.el6.x86_64 is already installed
#配置oracleasm,輸入grid用戶和屬組:
[root@node1 u01]# oracleasm configure -i

#初始化
[root@node1 u01]# oracleasm init

#建立磁盤(只需在一個節點建立)
[root@node1 u01]# oracleasm createdisk VOL1 /dev/sdb1

#查看建立後的磁盤
[root@node1 u01]# oracleasm listdisks
VOL1
VOL2
VOL3
VOL4
VOL5
VOL6
[root@node1 u01]# ll /dev/oracleasm/disks/
total 0
brw-rw----. 1 grid asmdba 8, 17 Jan 21 10:35 VOL1
brw-rw----. 1 grid asmdba 8, 33 Jan 21 10:35 VOL2
brw-rw----. 1 grid asmdba 8, 49 Jan 21 10:35 VOL3
brw-rw----. 1 grid asmdba 8, 65 Jan 21 10:35 VOL4
brw-rw----. 1 grid asmdba 8, 81 Jan 21 10:35 VOL5
brw-rw----. 1 grid asmdba 8, 97 Jan 21 10:35 VOL6

#在其餘節點,掃描已建立的磁盤
[root@node1 u01]# oracleasm scandisks

4、安裝grid軟件

#全部節點安裝在grid/rpm目錄下的rpm包:
[root@node1 rpm]# rpm -ivh cvuqdisk-1.0.7-1.rpm 
Preparing...                ########################################### [100%]
        package cvuqdisk-1.0.7-1.x86_64 is already installed
#使用vncserver圖形界面安裝
[grid@node1 ~]$ vncserver

New 'node1:1 (grid)' desktop is node1:1

Starting applications specified in /home/grid/.vnc/xstartup
Log file is /home/grid/.vnc/node1:1.log

#vncserver登陸
[grid@node1 ~]$ cd /u01/grid/
[grid@node1 grid]$ ./runInstaller 

添加節點node2和node2-vipbash

點擊配置ssh:session

 

 

修改磁盤查找路徑:oracle

 

按順序執行腳本:app

#grid軟件已安裝完成,用grid用戶在全部節點執行
[grid@node2 ~]$ crsctl check cluster
[grid@node2 ~]$ srvctl status nodeapps
[grid@node2 ~]$ srvctl config nodeapps
#查看集羣的狀態是否正常
[grid@node2 ~]$ crsctl check cluster
CRS-4537: Cluster Ready Services is online
CRS-4529: Cluster Synchronization Services is online
CRS-4533: Event Manager is online
[grid@node2 ~]$ srvctl status nodeapps
VIP node1-vip is enabled
VIP node1-vip is running on node: node1
VIP node2-vip is enabled
VIP node2-vip is running on node: node2
Network is enabled
Network is running on node: node1
Network is running on node: node2
GSD is disabled
GSD is not running on node: node1
GSD is not running on node: node2
ONS is enabled
ONS daemon is running on node: node1
ONS daemon is running on node: node2
[grid@node2 ~]$ 
[grid@node2 ~]$ srvctl config nodeapps
Network exists: 1/192.168.41.0/255.255.255.0/eth1, type static
VIP exists: /node1-vip/192.168.41.143/192.168.41.0/255.255.255.0/eth1, hosting node node1
VIP exists: /node2-vip/192.168.41.144/192.168.41.0/255.255.255.0/eth1, hosting node node2
GSD exists
ONS exists: Local port 6100, remote port 6200, EM port 2016
[grid@node2 ~]$

5、安裝Oracle軟件

集羣框架grid安裝完成並開啓後,剩下的全部操做均只需在節點1執行便可,其他節點會自動完成配置同步。用oracle登陸,使用vncserver安裝:框架

這裏一樣要點擊SSH設置:dom

按順序執行腳本:ssh

6、建立ASM磁盤

使用ASM配置Oracle RAC集羣一般須要建立三個ASM磁盤組:

OCR磁盤組:自Oracle 11.2版之後,votedisk(表決盤:記錄集羣節點信息,提供仲裁防止腦裂)和ocr(oracle集羣註冊表:記錄並維護整個集羣的配置信息)已經支持放置於同一個ASM磁盤組中。所以這裏爲votedisk和ocr提供一個磁盤組:OCRVOTE。

DATA磁盤組:用於存放數據文件的磁盤組。

FRA磁盤組:快速恢復區,用於支持數據庫快速閃回,同時也是默認的歸檔日誌存放位置。單首創建一個磁盤組。

在安裝grid的時候,已經建立了必要的OCR磁盤組,接下來須要使用ASM配置助手建立其餘兩個磁盤組以便完成Oracle數據庫的建立。以grid用戶輸入如下命令開始配置:

#僅在一個節點執行
[grid@node1 ~]$ asmca

7、建立數據庫

#僅在一個節點執行
[oracle@node1 ~]$ dbca

 

 至此,RAC已配置完成。

相關文章
相關標籤/搜索