一鍵RAC環境配置指令碼
因為工作中經常要搭建RAC環境,所以編寫了一個一鍵RAC環境配置指令碼以簡化重複性的工作。下面的指令碼是在CentOS/RHEL 6的環境測試無問題。
目前ssh互信還未完成,指令碼也還在進一步修改中,以便能相容更多的系統版本,比如RHEL5,SOLARIS 10/11,AIX等環境,敬請關注!!!如有不妥之處,請不吝指教!!!
指令碼分三個檔案:
AutoRAC.sh 一鍵RAC主程式
AutoRAC.conf RAC環境的配置檔案
Software.conf RAC環境的安裝包配置檔案
------------------------------------------------------------------------------------------------------------------
AutoRAC.sh 內容如下:
配置檔案AutoRAC.conf:
配置檔案Software.conf
目前ssh互信還未完成,指令碼也還在進一步修改中,以便能相容更多的系統版本,比如RHEL5,SOLARIS 10/11,AIX等環境,敬請關注!!!如有不妥之處,請不吝指教!!!
指令碼分三個檔案:
AutoRAC.sh 一鍵RAC主程式
AutoRAC.conf RAC環境的配置檔案
Software.conf RAC環境的安裝包配置檔案
------------------------------------------------------------------------------------------------------------------
AutoRAC.sh 內容如下:
點選(此處)摺疊或開啟
-
#! /bin/bash
-
node_num=$1
-
base_config=./autorac.conf
-
software_config=./software.conf
-
-
if [ ! ${node_num} ];then
-
echo "specify the node number"
-
exit 0
-
fi
-
-
-
Get_Block()
-
{
-
block_name=$1
-
config_file=$2
-
begin_line=0
-
end_line=0
-
line_num=0
-
while read line
-
do
-
line_num=`expr ${line_num} + 1`
-
is_get=`echo $line | awk "/\[${block_name}]/{print 1;next}{print 0}"`
-
if [ ${is_get} -eq 1 ];then
-
begin_line=${line_num}
-
continue
-
fi
-
-
if [ ${begin_line} -ne 0 ];then
-
is_get=`echo $line | awk "/\[.*]/{print 1;next}{print 0}"`
-
if [ ${is_get} -eq 1 ];then
-
end_line=`expr ${line_num} - 1`
-
break
-
fi
-
fi
-
-
done < ${config_file}
-
}
-
-
-
IP_fun()
-
{
-
field_num=`expr $1 + 1`
-
block_name=$2
-
tmp_file=/tmp/autorac.tmp
-
-
Get_Block ${block_name} ${base_config}
-
-
sed -n "${begin_line},${end_line}p" ${base_config} | grep -v ^$ > ${tmp_file}
-
-
is_ip=`echo ${block_name} | awk '/IP/{print 1;next}{print 0}'`
-
-
if [ ${is_ip} -eq 1 ];then
-
IPADDR=`awk -F"[:,]" -v num=${field_num} '/IP-LIST/{print $num}' ${tmp_file}`
-
HOSTNAME=`awk -F"[:,]" -v num=${field_num} '/HOSTNAME/{print $num}' ${tmp_file}`
-
NETMASK=`awk -F"[:,]" '/NETMASK/{print $2}' ${tmp_file}`
-
GATEWAY=`awk -F"[:,]" '/GATEWAY/{print $2}' ${tmp_file}`
-
DNS1=`awk -F"[:,]" '/DNS1/{print $2}' ${tmp_file}`
-
DNS2=`awk -F"[:,]" '/DNS2/{print $2}' ${tmp_file}`
-
-
-
if [ "${block_name}" == "PUBLIC-IP" -o "${block_name}" == "PRIVATE-IP" ];then
-
if [ "${block_name}" == "PUBLIC-IP" ];then
-
network="ifcfg-eth0"
-
sed -i "s/HOSTNAME=.*/HOSTNAME=${HOSTNAME}/" /etc/sysconfig/network
-
echo "IPADDR:"${IPADDR}
-
echo "HOSTNAME:"${HOSTNAME}
-
else
-
network="ifcfg-eth1"
-
fi
-
-
tmp_ipaddr_file=/tmp/autorac_ipaddr_file.tmp
-
awk '/DEVICE/||/TYPE/||/HWADDR/||/NM_CONTROLLED/{print $1}' /etc/sysconfig/network-scripts/${network} >${tmp_ipaddr_file}
-
echo "IPADDR="${IPADDR} >>${tmp_ipaddr_file}
-
echo "NETMASK="${NETMASK} >>${tmp_ipaddr_file}
-
echo "GATEWAY="${GATEWAY} >>${tmp_ipaddr_file}
-
echo "DNS1="${DNS1} >>${tmp_ipaddr_file}
-
echo "DNS2="${DNS2} >>${tmp_ipaddr_file}
-
echo -e "ARPCHECK=no\nONBOOT=\"yes\"\nBOOTPROTO=static" >>${tmp_ipaddr_file}
-
-
cat ${tmp_ipaddr_file} > /etc/sysconfig/network-scripts/${network}
-
-
fi
-
-
rac_node_name=/tmp/autorac_node.tmp
-
echo >${rac_node_name}
-
node_total=`awk -F"[:,]" '/IP-LIST/{print NF}' ${tmp_file}`
-
for i in `seq 2 ${node_total}`
-
do
-
IPADDR=`awk -F"[:,]" -v num=${i} '/IP-LIST/{print $num}' ${tmp_file}`
-
HOSTNAME_1=`awk -F"[:,]" -v num=${i} '/HOSTNAME/{print $num}' ${tmp_file}`
-
HOSTNAME=${HOSTNAME_1:-${HOSTNAME}}
-
-
echo -e ${IPADDR} ${HOSTNAME} \#ORACLE_CONFIG>> /etc/hosts
-
-
if [ "${block_name}" == "PUBLIC-IP" -o "${block_name}" == "PRIVATE-IP" ];then
-
echo ${block_name}:${HOSTNAME} >> ${rac_node_name}
-
fi
-
done
-
fi
-
-
#is_storage=`echo ${block_name} | awk '/STORAGE/{print 1;next}{print 0}'`
-
-
}
-
-
sed -i '/ORACLE_CONFIG/d' /etc/hosts
-
-
IP_fun ${node_num} PUBLIC-IP
-
IP_fun ${node_num} PRIVATE-IP
-
IP_fun ${node_num} VIP
-
IP_fun ${node_num} SCAN-IP
-
-
#shutdown iptables
-
service iptables stop
-
chkconfig iptables off
-
-
#shutdown fireware
-
setenforce 0
-
sed -i 's/SELINUX=.*/SELINUX=disable/g' /etc/selinux/config
-
-
#disable ntp server
-
service ntpd status | grep run && service ntpd stop
-
chkconfig ntpd off
-
if [ -e /etc/ntp.conf ];then
-
mv /etc/ntp.conf /etc/ntp.conf.bak
-
fi
-
-
-
#install package
-
-
Install_package_fun()
-
{
-
for i in `ls /etc/yum.repos.d/ | grep -v bak$`
-
do
-
mv /etc/yum.repos.d/$i /etc/yum.repos.d/$i.bak
-
done
-
-
cat > /etc/yum.repos.d/CentOS-Media.repo <<EOF
-
[c6-media]
-
name=CentOS-\$releasever - Media
-
baseurl=file:///media/
-
gpgcheck=1
-
enabled=1
-
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
-
EOF
-
-
yum clean all
-
-
os_type=`lsb_release -a | awk -F"[:\t]+" '/Distributor ID/{print $2}'`
-
os_release=`lsb_release -a | awk -F"[:\t]+" '/Release/{printf("%d\n",$2)}'`
-
if [ ${os_type} == "CentOS" -o ${os_type} == "Red" ];then
-
Get_Block "RHEL${os_release}" ${software_config}
-
sed -n "${begin_line},${end_line}p" ${software_config} | grep -v ^$ | awk -F'-[0-9].[0-9]' '! /\[/{print $1}' > ${tmp_file}
-
while read line
-
do
-
yum install -y -q ${line}
-
done < ${tmp_file}
-
fi
-
}
-
-
-
is_mount=`mount | grep iso9660|wc -l`
-
-
if [ ${is_mount} -ge 1 ];then
-
echo -e "\033[31mCDROM HAS BEEN MOUNTTED\033[0m" && Install_package_fun
-
else
-
mount /dev/cdrom /media/ 2>&1| grep mounting && echo -e "\033[31mCDROM IS MOUNTING\033[0m" && Install_package_fun || echo -e "\033[31mNO CDROM INSERTED\033[0m"
-
fi
-
-
-
-
-
#create user and group
-
groupadd oinstall
-
groupadd dba
-
groupadd oper
-
groupadd asmadmin
-
groupadd asmdba
-
groupadd asmoper
-
useradd -g oinstall -G dba,asmdba,asmadmin,asmoper grid
-
useradd -g oinstall -G dba,oper,asmdba,asmadmin oracle
-
echo -n oracle | passwd --stdin grid
-
echo -n oracle | passwd --stdin oracle
-
-
#create directory
-
mkdir -p /u01/app/11.2.0/grid
-
mkdir -p /u01/app/grid
-
mkdir -p /u01/app/oracle
-
chown -R grid:oinstall /u01/app/11.2.0/grid
-
chown -R grid:oinstall /u01/app/grid
-
chown -R oracle:oinstall /u01/app/oracle
-
chmod -R 775 /u01/
-
-
#modify the bash_profile
-
is_modified=`awk 'BEGIN{a=0}/ORACLE_CONFIG/{a+=1}END{print a}' /home/grid/.bash_profile`
-
-
if [ ${is_modified} -eq 0 ];then
-
cat>> /home/grid/.bash_profile<< EOF
-
\#ORACLE_CONFIG
-
export TMP=/tmp;
-
export TMPDIR=\$TMP;
-
export ORACLE_SID=+ASM1;
-
export ORACLE_BASE=/u01/app/grid;
-
export ORACLE_HOME=/u01/app/11.2.0/grid;
-
export NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS";
-
export PATH=\$ORACLE_HOME/BIN:\$PATH;
-
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK;
-
EOF
-
fi
-
-
-
-
-
is_modified=`awk 'BEGIN{a=0}/ORACLE_CONFIG/{a+=1}END{print a}' /home/oracle/.bash_profile`
-
-
if [ ${is_modified} -eq 0 ];then
-
cat>> /home/oracle/.bash_profile<< EOF
-
\#ORACLE_CONFIG
-
export TMP=/tmp;
-
export TMPDIR=\$TMP;
-
export ORACLE_BASE=/u01/app/oracle;
-
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1;
-
export ORACLE_UNQNAME=prod;
-
export ORACLE_SID=prod1;
-
export ORACLE_TERM=xterm;
-
export PATH=/usr/sbin:\$PATH;
-
export PATH=\$ORACLE_HOME/bin:\$PATH;
-
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib;
-
export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib;
-
export NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS";
-
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK";
-
EOF
-
fi
-
-
#modify core source
-
is_modified=`awk 'BEGIN{a=0}/ORACLE_CONFIG/{a+=1}END{print a}' /etc/sysctl.conf`
-
-
if [ ${is_modified} -eq 0 ];then
-
sed -i 's/^kernel.shmmax/#kernel.shmmax/g' /etc/sysctl.conf
-
sed -i 's/^kernel.shmall/#kernel.shmall/g' /etc/sysctl.conf
-
cat>> /etc/sysctl.conf<<EOF
-
\#ORACLE_CONFIG
-
fs.aio-max-nr = 1048576
-
fs.file-max = 6815744
-
kernel.shmall = 2097152
-
kernel.shmmax = 1417529344
-
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 = 1048586
-
EOF
-
fi
-
-
-
-
#limit the oracle user
-
is_modified=`awk '/oracle/||/grid/{a+=1}END{print a}' /etc/security/limits.conf`
-
if [ ${is_modified} -ne 10 ];then
-
cat>> /etc/security/limits.conf<<EOF
-
oracle soft nproc 2047
-
oracle hard nproc 16384
-
oracle soft nofile 1024
-
oracle hard nofile 65536
-
oracle soft stack 10240
-
grid soft nproc 2047
-
grid hard nproc 16384
-
grid soft nofile 1024
-
grid hard nofile 65536
-
grid soft stack 10240
-
EOF
-
fi
-
-
#modify the /etc/profile
-
is_modified=`awk 'BEGIN{a=0}/ORACLE_CONFIG/{a+=1}END{print a}' /etc/profile`
-
-
if [ ${is_modified} -eq 0 ];then
-
cat >>/etc/profile<<EOF
-
\#ORACLE_CONFIG
-
if [ \$USER = "oracle" ]; then
-
if [ \$SHELL = "/bin/ksh" ]; then
-
ulimit -p 16384
-
ulimit -n 65536
-
else
-
ulimit -u 16384 -n 65536
-
fi
-
fi
-
alias grep='grep --color=auto'
-
export PATH=\$PATH:/u01/app/11.2.0/grid/bin
-
export DISPLAY=192.168.2.1:0.0
-
EOF
-
fi
-
-
while [ ${exitcode:=0} -eq 0 ]
-
do
-
times=`expr ${times:=0} + 1`
-
is_install_multipath=`rpm -qa | grep -E "device-mapper-[0-9]|multipath" |wc -l`
-
if [ ${is_install_multipath} -ge 2 ];then
-
if [ ! -e /etc/multipath.conf ];then
-
cp /usr/share/doc/device-mapper-multipath-0.4.9/multipath.conf /etc/multipath.conf && service multipathd restart || echo -e "\033[31mMultipath ERROR\033[0m"
-
fi
-
-
is_modified=`awk 'BEGIN{a=0}/ORACLE_CONFIG/{a+=1}END{print a}' /etc/multipath.conf`
-
if [ ${is_modified} -eq 0 ];then
-
echo '#ORACLE_CONFIG' >> /etc/multipath.conf
-
awk -F'[ \t]+' 'BEGIN{print "multipaths '{'";a=0}NF==2&&/mpath/{a+=1;printf("\tmultipath '{'\n\t\twwid\t%s\n\t\talias\tlun%d\n\t'}'\n",$2,a)} \
-
END{print "'}'"}' /etc/multipath/bindings >> /etc/multipath.conf
-
fi
-
-
service multipathd restart
-
sleep 5
-
if [ $? -ne 0 ];then
-
echo -e "\033[31mMultipath ERROR\033[0m"
-
else
-
is_multipath=`multipath -ll | awk -F'[ \t]' '/lun/{print $3}'|wc -l`
-
fi
-
exitcode=1
-
else
-
rm -rf /var/lib/yum/history/*.sqlite&&yum install -y -q *multipath*&& echo -e "\033[31mInstall device-mapper-* Complete\033[0m"
-
if [ ${times} -ge 3 ];then
-
echo -e "\033[31mInstall Package device-mpper-* ERROR\033[0m"
-
break
-
fi
-
fi
-
done
-
-
if [ ${is_multipath:=0} -ge 1 ];then
-
sed -i '/^[^#]/d' /etc/udev/rules.d/60-raw.rules
-
for i in `multipath -ll | grep lun | sort| awk -F'[ \t]' '{print $2}'|sed -e 's/(//g' -e 's/)//g'`
-
do
-
num=`expr ${num:=0} + 1`
-
echo "KERNEL==\"sd*\", ACTION==\"add\", PROGRAM==\"/lib/udev/scsi_id --whitelisted --device=/dev/\$name\", \
-
RESULT==\"$i\", NAME=\"raw${num}\"" >> /etc/udev/rules.d/60-raw.rules
-
done
-
echo "NAME==\"raw[0-9]*\",OWNER=\"grid\", GROUP=\"asmadmin\", MODE=\"0660\"" >> /etc/udev/rules.d/60-raw.rules
-
start_udev
-
else
-
echo -e "\033[31mNO STORAGE DEVICE BE FOUND\033[0m"
-
fi
-
-
-
#ssh
-
ssh_keygen()
-
{
-
for user in oracle grid
-
do
-
awk -F':' '/PUBLIC-IP/{print $2}' ${rac_node_name} | while read line
-
do
-
node_name=${line}
-
ssh root@${node_name} su - ${user} -c "
-
rm -f ~/.ssh/id_rsa\r
-
rm -f ~/.ssh/id_dsa\r
-
rm -f ~/.ssh/authorized_keys\r
-
ssh-keygen -t rsa -q -f ~/.ssh/id_rsa -N 099q4naefadfasfdadfAADF8W0309QERQSDQ97FGJH\r
-
ssh-keygen -t dsa -q -f ~/.ssh/id_rsa -N 099q4naefadf0w323346ssd0ADF8WsdRQSDQ97FGJH\r"
-
-
ssh root@${node_name} su - ${user} -c "cat ~/.ssh/*.pub" >> all_node_authorized_keys
-
done
-
-
awk -F: '/PUBLIC-IP/{print $2}' ${rac_node_name}| while read line
-
do
-
node_name=${line}
-
scp all_node_authorized_keys ${user}@${node_name}:~/.ssh/authorized_keys
-
-
done
-
done
-
-
-
for user in oracle grid
-
do
-
awk -F':' '/PUBLIC-IP/{print $2}' ${rac_node_name} |while read line
-
do
-
node_name=${line}
-
awk -F':' '{print $2}' ${rac_node_name} | while read line
-
do
-
host_name=${line}
-
ssh root@${node_name} su - ${user} -c "ssh ${host_name} date"
-
done
-
done
-
done
-
}
-
-
if [ ${node_num} -eq 1 ];then
-
ssh_keygen
- fi
配置檔案AutoRAC.conf:
點選(此處)摺疊或開啟
-
[PUBLIC-IP]
-
IP-LIST:192.168.2.101,192.168.2.102
-
HOSTNAME-LIST:RAC1,RAC2
-
NETMASK:255.255.255.0
-
GATEWAY:192.168.2.1
-
DNS1:202.96.128.166
-
DNS2:202.96.128.86
-
-
[PRIVATE-IP]
-
IP-LIST:192.168.56.101,192.168.56.102
-
HOSTNAME-LIST:RAC1-PRIV,RAC2-PRIV
-
NETMASK:255.255.255.0
-
GATEWAY:192.168.56.1
-
-
[VIP]
-
IP-LIST:192.168.2.10,192.168.2.20
-
HOSTNAME-LIST:RAC1-VIP,RAC2-VIP
-
-
[SCAN-IP]
-
IP-LIST:192.168.2.91,192.168.2.92,192.168.2.93
-
HOSTNAME-LIST:RAC-SCAN
-
-
[STORAGE]
-
OCR:OCR_VOTE,NORMAL,2G
- DATA:DATAS,NORMAL,20G
配置檔案Software.conf
點選(此處)摺疊或開啟
-
[RHEL6]
-
binutils-2.20.51.0.2-5.11.el6 (x86_64)
-
compat-libcap1-1.10-1 (x86_64)
-
compat-libstdc++-33-3.2.3-69.el6 (x86_64)
-
compat-libstdc++-33-3.2.3-69.el6.i686
-
gcc-4.4.4-13.el6 (x86_64)
-
gcc-c++-4.4.4-13.el6 (x86_64)
-
glibc-2.12-1.7.el6 (i686)
-
glibc-2.12-1.7.el6 (x86_64)
-
glibc-devel-2.12-1.7.el6 (x86_64)
-
glibc-devel-2.12-1.7.el6.i686
-
ksh
-
libgcc-4.4.4-13.el6 (i686)
-
libgcc-4.4.4-13.el6 (x86_64)
-
libstdc++-4.4.4-13.el6 (x86_64)
-
libstdc++-4.4.4-13.el6.i686
-
libstdc++-devel-4.4.4-13.el6 (x86_64)
-
libstdc++-devel-4.4.4-13.el6.i686
-
libaio-0.3.107-10.el6 (x86_64)
-
libaio-0.3.107-10.el6.i686
-
libaio-devel-0.3.107-10.el6 (x86_64)
-
libaio-devel-0.3.107-10.el6.i686
-
make-3.81-19.el6
-
sysstat-9.0.4-11.el6 (x86_64)
-
-
[RHEL5]
-
binutils-2.17.50.0.6
-
compat-libstdc++-33-3.2.3
-
compat-libstdc++-33-3.2.3 (32 bit)
-
elfutils-libelf-0.125
-
elfutils-libelf-devel-0.125
-
gcc-4.1.2
-
gcc-c++-4.1.2
-
glibc-2.5-24
-
glibc-2.5-24 (32 bit)
-
glibc-common-2.5
-
glibc-devel-2.5
-
glibc-devel-2.5 (32 bit)
-
glibc-headers-2.5
-
ksh-20060214
-
libaio-0.3.106
-
libaio-0.3.106 (32 bit)
-
libaio-devel-0.3.106
-
libaio-devel-0.3.106 (32 bit)
-
libgcc-4.1.2
-
libgcc-4.1.2 (32 bit)
-
libstdc++-4.1.2
-
libstdc++-4.1.2 (32 bit)
-
libstdc++-devel 4.1.2
-
make-3.81
- sysstat-7.0.2
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25960404/viewspace-2096197/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle RAC一鍵部署001(主機環境校驗)Oracle
- 新入手 mac,需要配置環境,索性就建立了一鍵安裝指令碼(homebrew+omz)Mac指令碼
- 用Node寫一條配置環境的指令
- springboot打包不同環境配置與shell指令碼部署Spring Boot指令碼
- 環境配置難?教你一鍵幫你搞定伺服器環境部署伺服器
- 關於Solidity指令碼相關環境配置及指令碼資料的查詢Solid指令碼
- 一、環境配置
- LNMP環境一鍵部署LNMP
- 一鍵部署指令碼指令碼
- RMAN之環境配置(一)
- vue 構建環境切換指令碼Vue指令碼
- app自動化測試環境配置:adb環境配置、monkey環境配置、appium環境配置大全APP
- PHP 一鍵 Docker LNMP 環境PHPDockerLNMP
- RAC環境修改spfile的位置
- DM8 配置DMDSC主備環境(rac到單節點 )
- KingbaseES RAC部署案例之---SAN環境構建RAC
- 一鍵化安裝 docker,一鍵化部署 lnmp+Redis 環境,快速部署 Laravel 環境DockerLNMPRedisLaravel
- Windows環境PgSql自動備份指令碼WindowsSQL指令碼
- 利用 Docker 一鍵搭建 LNMP 環境DockerLNMP
- 環境配置
- Docker 指令碼化一鍵部署Docker指令碼
- RAC和ASM環境下打patchASM
- 手工清理19c RAC環境
- RAC環境下建立物理DATAGUARD(1)
- RAC環境下建立物理DATAGUARD(2)
- 配置開發環境、生成環境、測試環境開發環境
- 8.4.9 在truffle環境中執行外部指令碼指令碼
- 一、虛擬機器環境配置虛擬機
- ApacheCordovaforios環境配置ApacheiOS
- Linux環境配置Linux
- vue – 環境配置Vue
- JAV A環境配置
- Flutter環境配置Flutter
- 配置python環境Python
- nerfstudio環境配置
- IDEA配置環境Idea
- JAVA環境配置Java
- conda環境配置
- Anaconda環境配置