ITPub博客

首页 > 数据库 > Oracle > 一键RAC环境配置脚本

一键RAC环境配置脚本

原创 Oracle 作者:wmsok 时间:2016-05-09 10:16:55 0 删除 编辑
因为工作中经常要搭建RAC环境,所以编写了一个一键RAC环境配置脚本以简化重复性的工作。下面的脚本是在CentOS/RHEL 6的环境测试无问题。
目前ssh互信还未完成,脚本也还在进一步修改中,以便能兼容更多的系统版本,比如RHEL5,SOLARIS 10/11,AIX等环境,敬请关注!!!如有不妥之处,请不吝指教!!!

脚本分三个文件:
AutoRAC.sh        一键RAC主程序
AutoRAC.conf     RAC环境的配置文件
Software.conf     RAC环境的安装包配置文件
------------------------------------------------------------------------------------------------------------------
AutoRAC.sh 内容如下:

点击(此处)折叠或打开

  1. #! /bin/bash
  2. node_num=$1
  3. base_config=./autorac.conf
  4. software_config=./software.conf

  5. if [ ! ${node_num} ];then
  6. echo "specify the node number"
  7. exit 0
  8. fi


  9. Get_Block()
  10. {
  11. block_name=$1
  12. config_file=$2
  13. begin_line=0
  14. end_line=0
  15. line_num=0
  16. while read line
  17. do
  18.         line_num=`expr ${line_num} + 1`
  19.         is_get=`echo $line | awk "/\[${block_name}]/{print 1;next}{print 0}"`
  20.         if [ ${is_get} -eq 1 ];then
  21.                 begin_line=${line_num}
  22.                 continue
  23.         fi

  24.         if [ ${begin_line} -ne 0 ];then
  25.                 is_get=`echo $line | awk "/\[.*]/{print 1;next}{print 0}"`
  26.                 if [ ${is_get} -eq 1 ];then
  27.                         end_line=`expr ${line_num} - 1`
  28.                         break
  29.                 fi
  30.         fi

  31. done < ${config_file}
  32. }


  33. IP_fun()
  34. {
  35. field_num=`expr $1 + 1`
  36. block_name=$2
  37. tmp_file=/tmp/autorac.tmp

  38. Get_Block ${block_name} ${base_config}

  39. sed -n "${begin_line},${end_line}p" ${base_config} | grep -v ^$ > ${tmp_file}

  40. is_ip=`echo ${block_name} | awk '/IP/{print 1;next}{print 0}'`

  41. if [ ${is_ip} -eq 1 ];then
  42.         IPADDR=`awk -F"[:,]" -v num=${field_num} '/IP-LIST/{print $num}' ${tmp_file}`
  43.         HOSTNAME=`awk -F"[:,]" -v num=${field_num} '/HOSTNAME/{print $num}' ${tmp_file}`
  44.         NETMASK=`awk -F"[:,]" '/NETMASK/{print $2}' ${tmp_file}`
  45.         GATEWAY=`awk -F"[:,]" '/GATEWAY/{print $2}' ${tmp_file}`
  46.         DNS1=`awk -F"[:,]" '/DNS1/{print $2}' ${tmp_file}`
  47.         DNS2=`awk -F"[:,]" '/DNS2/{print $2}' ${tmp_file}`


  48.         if [ "${block_name}" == "PUBLIC-IP" -o "${block_name}" == "PRIVATE-IP" ];then
  49.                 if [ "${block_name}" == "PUBLIC-IP" ];then
  50.                         network="ifcfg-eth0"
  51.                         sed -i "s/HOSTNAME=.*/HOSTNAME=${HOSTNAME}/" /etc/sysconfig/network
  52.                         echo "IPADDR:"${IPADDR}
  53.                         echo "HOSTNAME:"${HOSTNAME}
  54.                 else
  55.                         network="ifcfg-eth1"
  56.                 fi
  57.         
  58.          tmp_ipaddr_file=/tmp/autorac_ipaddr_file.tmp
  59.                  awk '/DEVICE/||/TYPE/||/HWADDR/||/NM_CONTROLLED/{print $1}' /etc/sysconfig/network-scripts/${network} >${tmp_ipaddr_file}
  60.                  echo "IPADDR="${IPADDR} >>${tmp_ipaddr_file}
  61.                  echo "NETMASK="${NETMASK} >>${tmp_ipaddr_file}
  62.                  echo "GATEWAY="${GATEWAY} >>${tmp_ipaddr_file}
  63.                  echo "DNS1="${DNS1} >>${tmp_ipaddr_file}
  64.                  echo "DNS2="${DNS2} >>${tmp_ipaddr_file}
  65.                  echo -e "ARPCHECK=no\nONBOOT=\"yes\"\nBOOTPROTO=static" >>${tmp_ipaddr_file}
  66.                  
  67.                  cat ${tmp_ipaddr_file} > /etc/sysconfig/network-scripts/${network}
  68.                  
  69.         fi

  70.         rac_node_name=/tmp/autorac_node.tmp
  71.         echo >${rac_node_name}
  72.         node_total=`awk -F"[:,]" '/IP-LIST/{print NF}' ${tmp_file}`
  73.         for i in `seq 2 ${node_total}`
  74.         do
  75.                 IPADDR=`awk -F"[:,]" -v num=${i} '/IP-LIST/{print $num}' ${tmp_file}`
  76.                 HOSTNAME_1=`awk -F"[:,]" -v num=${i} '/HOSTNAME/{print $num}' ${tmp_file}`
  77.         HOSTNAME=${HOSTNAME_1:-${HOSTNAME}}

  78.                   echo -e ${IPADDR} ${HOSTNAME} \#ORACLE_CONFIG>> /etc/hosts

  79.                 if [ "${block_name}" == "PUBLIC-IP" -o "${block_name}" == "PRIVATE-IP" ];then
  80.                         echo ${block_name}:${HOSTNAME} >> ${rac_node_name}
  81.                 fi
  82.         done
  83. fi

  84. #is_storage=`echo ${block_name} | awk '/STORAGE/{print 1;next}{print 0}'`

  85. }

  86. sed -i '/ORACLE_CONFIG/d' /etc/hosts

  87. IP_fun ${node_num} PUBLIC-IP
  88. IP_fun ${node_num} PRIVATE-IP
  89. IP_fun ${node_num} VIP
  90. IP_fun ${node_num} SCAN-IP

  91. #shutdown iptables
  92. service iptables stop
  93. chkconfig iptables off

  94. #shutdown fireware
  95. setenforce 0
  96. sed -i 's/SELINUX=.*/SELINUX=disable/g' /etc/selinux/config

  97. #disable ntp server
  98. service ntpd status | grep run && service ntpd stop
  99. chkconfig ntpd off
  100. if [ -e /etc/ntp.conf ];then
  101. mv /etc/ntp.conf /etc/ntp.conf.bak
  102. fi


  103. #install package

  104. Install_package_fun()
  105. {
  106. for i in `ls /etc/yum.repos.d/ | grep -v bak$`
  107. do
  108.         mv /etc/yum.repos.d/$i /etc/yum.repos.d/$i.bak
  109. done

  110. cat > /etc/yum.repos.d/CentOS-Media.repo <<EOF
  111. [c6-media]
  112. name=CentOS-\$releasever - Media
  113. baseurl=file:///media/
  114. gpgcheck=1
  115. enabled=1
  116. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  117. EOF

  118. yum clean all

  119. os_type=`lsb_release -a | awk -F"[:\t]+" '/Distributor ID/{print $2}'`
  120. os_release=`lsb_release -a | awk -F"[:\t]+" '/Release/{printf("%d\n",$2)}'`
  121. if [ ${os_type} == "CentOS" -o ${os_type} == "Red" ];then
  122.         Get_Block "RHEL${os_release}" ${software_config}
  123.         sed -n "${begin_line},${end_line}p" ${software_config} | grep -v ^$ | awk -F'-[0-9].[0-9]' '! /\[/{print $1}' > ${tmp_file}
  124.         while read line
  125.         do
  126.                 yum install -y -q ${line}
  127.         done < ${tmp_file}
  128. fi
  129. }


  130. is_mount=`mount | grep iso9660|wc -l`

  131. if [ ${is_mount} -ge 1 ];then
  132.     echo -e "\033[31mCDROM HAS BEEN MOUNTTED\033[0m" && Install_package_fun
  133. else
  134.     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"
  135. fi




  136. #create user and group
  137. groupadd oinstall
  138. groupadd dba
  139. groupadd oper
  140. groupadd asmadmin
  141. groupadd asmdba
  142. groupadd asmoper
  143. useradd -g oinstall -G dba,asmdba,asmadmin,asmoper grid
  144. useradd -g oinstall -G dba,oper,asmdba,asmadmin oracle
  145. echo -n oracle | passwd --stdin grid
  146. echo -n oracle | passwd --stdin oracle

  147. #create directory
  148. mkdir -p /u01/app/11.2.0/grid
  149. mkdir -p /u01/app/grid
  150. mkdir -p /u01/app/oracle
  151. chown -R grid:oinstall /u01/app/11.2.0/grid
  152. chown -R grid:oinstall /u01/app/grid
  153. chown -R oracle:oinstall /u01/app/oracle
  154. chmod -R 775 /u01/

  155. #modify the bash_profile
  156. is_modified=`awk 'BEGIN{a=0}/ORACLE_CONFIG/{a+=1}END{print a}' /home/grid/.bash_profile`

  157. if [ ${is_modified} -eq 0 ];then
  158. cat>> /home/grid/.bash_profile<< EOF
  159. \#ORACLE_CONFIG
  160. export TMP=/tmp;
  161. export TMPDIR=\$TMP;
  162. export ORACLE_SID=+ASM1;
  163. export ORACLE_BASE=/u01/app/grid;
  164. export ORACLE_HOME=/u01/app/11.2.0/grid;
  165. export NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS";
  166. export PATH=\$ORACLE_HOME/BIN:\$PATH;
  167. export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK;
  168. EOF
  169. fi




  170. is_modified=`awk 'BEGIN{a=0}/ORACLE_CONFIG/{a+=1}END{print a}' /home/oracle/.bash_profile`

  171. if [ ${is_modified} -eq 0 ];then
  172. cat>> /home/oracle/.bash_profile<< EOF
  173. \#ORACLE_CONFIG
  174. export TMP=/tmp;
  175. export TMPDIR=\$TMP;
  176. export ORACLE_BASE=/u01/app/oracle;
  177. export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1;
  178. export ORACLE_UNQNAME=prod;
  179. export ORACLE_SID=prod1;
  180. export ORACLE_TERM=xterm;
  181. export PATH=/usr/sbin:\$PATH;
  182. export PATH=\$ORACLE_HOME/bin:\$PATH;
  183. export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib;
  184. export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib;
  185. export NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS";
  186. export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK";
  187. EOF
  188. fi

  189. #modify core source
  190. is_modified=`awk 'BEGIN{a=0}/ORACLE_CONFIG/{a+=1}END{print a}' /etc/sysctl.conf`

  191. if [ ${is_modified} -eq 0 ];then
  192. sed -i 's/^kernel.shmmax/#kernel.shmmax/g' /etc/sysctl.conf
  193. sed -i 's/^kernel.shmall/#kernel.shmall/g' /etc/sysctl.conf
  194. cat>> /etc/sysctl.conf<<EOF
  195. \#ORACLE_CONFIG
  196. fs.aio-max-nr = 1048576
  197. fs.file-max = 6815744
  198. kernel.shmall = 2097152
  199. kernel.shmmax = 1417529344
  200. kernel.shmmni = 4096
  201. kernel.sem = 250 32000 100 128
  202. net.ipv4.ip_local_port_range = 9000 65500
  203. net.core.rmem_default = 262144
  204. net.core.rmem_max = 4194304
  205. net.core.wmem_default = 262144
  206. net.core.wmem_max = 1048586
  207. EOF
  208. fi



  209. #limit the oracle user
  210. is_modified=`awk '/oracle/||/grid/{a+=1}END{print a}' /etc/security/limits.conf`
  211. if [ ${is_modified} -ne 10 ];then
  212.     cat>> /etc/security/limits.conf<<EOF
  213.     oracle soft nproc 2047
  214.     oracle hard nproc 16384
  215.     oracle soft nofile 1024
  216.     oracle hard nofile 65536
  217.     oracle soft stack 10240
  218.     grid soft nproc 2047
  219.     grid hard nproc 16384
  220.     grid soft nofile 1024
  221.     grid hard nofile 65536
  222.     grid soft stack 10240
  223.     EOF
  224. fi

  225. #modify the /etc/profile
  226. is_modified=`awk 'BEGIN{a=0}/ORACLE_CONFIG/{a+=1}END{print a}' /etc/profile`

  227. if [ ${is_modified} -eq 0 ];then
  228. cat >>/etc/profile<<EOF
  229. \#ORACLE_CONFIG
  230. if [ \$USER = "oracle" ]; then
  231.         if [ \$SHELL = "/bin/ksh" ]; then
  232.               ulimit -p 16384
  233.               ulimit -n 65536
  234.         else
  235.               ulimit -u 16384 -n 65536
  236.         fi
  237. fi
  238. alias grep='grep --color=auto'
  239. export PATH=\$PATH:/u01/app/11.2.0/grid/bin
  240. export DISPLAY=192.168.2.1:0.0
  241. EOF
  242. fi

  243. while [ ${exitcode:=0} -eq 0 ]
  244. do
  245. times=`expr ${times:=0} + 1`
  246. is_install_multipath=`rpm -qa | grep -E "device-mapper-[0-9]|multipath" |wc -l`
  247. if [ ${is_install_multipath} -ge 2 ];then
  248.     if [ ! -e /etc/multipath.conf ];then
  249.         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"
  250.     fi

  251.     is_modified=`awk 'BEGIN{a=0}/ORACLE_CONFIG/{a+=1}END{print a}' /etc/multipath.conf`
  252.     if [ ${is_modified} -eq 0 ];then
  253.         echo '#ORACLE_CONFIG' >> /etc/multipath.conf
  254.         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)} \
  255.             END{print "'}'"}' /etc/multipath/bindings >> /etc/multipath.conf
  256.     fi
  257.     
  258.     service multipathd restart
  259.     sleep 5
  260.     if [ $? -ne 0 ];then
  261.         echo -e "\033[31mMultipath ERROR\033[0m"
  262.     else        
  263.         is_multipath=`multipath -ll | awk -F'[ \t]' '/lun/{print $3}'|wc -l`
  264.     fi
  265.     exitcode=1
  266. else
  267.     rm -rf /var/lib/yum/history/*.sqlite&&yum install -y -q *multipath*&& echo -e "\033[31mInstall device-mapper-* Complete\033[0m"
  268.     if [ ${times} -ge 3 ];then
  269.         echo -e "\033[31mInstall Package device-mpper-* ERROR\033[0m"
  270.         break
  271.     fi
  272. fi
  273. done

  274. if [ ${is_multipath:=0} -ge 1 ];then
  275.    sed -i '/^[^#]/d' /etc/udev/rules.d/60-raw.rules
  276.    for i in `multipath -ll | grep lun | sort| awk -F'[ \t]' '{print $2}'|sed -e 's/(//g' -e 's/)//g'`
  277.    do
  278.         num=`expr ${num:=0} + 1`
  279.         echo "KERNEL==\"sd*\", ACTION==\"add\", PROGRAM==\"/lib/udev/scsi_id --whitelisted --device=/dev/\$name\", \
  280.         RESULT==\"$i\", NAME=\"raw${num}\"" >> /etc/udev/rules.d/60-raw.rules
  281.    done
  282.    echo "NAME==\"raw[0-9]*\",OWNER=\"grid\", GROUP=\"asmadmin\", MODE=\"0660\"" >> /etc/udev/rules.d/60-raw.rules
  283.    start_udev
  284. else
  285.    echo -e "\033[31mNO STORAGE DEVICE BE FOUND\033[0m"
  286. fi


  287. #ssh
  288. ssh_keygen()
  289. {
  290. for user in oracle grid
  291. do
  292.         awk -F':' '/PUBLIC-IP/{print $2}' ${rac_node_name} | while read line
  293.         do
  294.                 node_name=${line}
  295.                 ssh root@${node_name} su - ${user} -c "
  296.                 rm -f ~/.ssh/id_rsa\r
  297.                 rm -f ~/.ssh/id_dsa\r
  298.                 rm -f ~/.ssh/authorized_keys\r
  299.                 ssh-keygen -t rsa -q -f ~/.ssh/id_rsa -N 099q4naefadfasfdadfAADF8W0309QERQSDQ97FGJH\r
  300.                 ssh-keygen -t dsa -q -f ~/.ssh/id_rsa -N 099q4naefadf0w323346ssd0ADF8WsdRQSDQ97FGJH\r"

  301.                 ssh root@${node_name} su - ${user} -c "cat ~/.ssh/*.pub" >> all_node_authorized_keys
  302.         done

  303.         awk -F: '/PUBLIC-IP/{print $2}' ${rac_node_name}| while read line
  304.         do
  305.                 node_name=${line}
  306.                 scp all_node_authorized_keys ${user}@${node_name}:~/.ssh/authorized_keys

  307.         done
  308. done


  309. for user in oracle grid
  310. do
  311.         awk -F':' '/PUBLIC-IP/{print $2}' ${rac_node_name} |while read line
  312.         do
  313.                 node_name=${line}
  314.                 awk -F':' '{print $2}' ${rac_node_name} | while read line
  315.                 do
  316.                         host_name=${line}
  317.                         ssh root@${node_name} su - ${user} -c "ssh ${host_name} date"
  318.                 done
  319.         done
  320. done
  321. }

  322. if [ ${node_num} -eq 1 ];then
  323.     ssh_keygen
  324. fi

配置文件AutoRAC.conf:

点击(此处)折叠或打开

  1. [PUBLIC-IP]
  2. IP-LIST:192.168.2.101,192.168.2.102
  3. HOSTNAME-LIST:RAC1,RAC2
  4. NETMASK:255.255.255.0
  5. GATEWAY:192.168.2.1
  6. DNS1:202.96.128.166
  7. DNS2:202.96.128.86

  8. [PRIVATE-IP]
  9. IP-LIST:192.168.56.101,192.168.56.102
  10. HOSTNAME-LIST:RAC1-PRIV,RAC2-PRIV
  11. NETMASK:255.255.255.0
  12. GATEWAY:192.168.56.1

  13. [VIP]
  14. IP-LIST:192.168.2.10,192.168.2.20
  15. HOSTNAME-LIST:RAC1-VIP,RAC2-VIP

  16. [SCAN-IP]
  17. IP-LIST:192.168.2.91,192.168.2.92,192.168.2.93
  18. HOSTNAME-LIST:RAC-SCAN

  19. [STORAGE]
  20. OCR:OCR_VOTE,NORMAL,2G
  21. DATA:DATAS,NORMAL,20G


配置文件Software.conf

点击(此处)折叠或打开

  1. [RHEL6]
  2. binutils-2.20.51.0.2-5.11.el6 (x86_64)
  3. compat-libcap1-1.10-1 (x86_64)
  4. compat-libstdc++-33-3.2.3-69.el6 (x86_64)
  5. compat-libstdc++-33-3.2.3-69.el6.i686
  6. gcc-4.4.4-13.el6 (x86_64)
  7. gcc-c++-4.4.4-13.el6 (x86_64)
  8. glibc-2.12-1.7.el6 (i686)
  9. glibc-2.12-1.7.el6 (x86_64)
  10. glibc-devel-2.12-1.7.el6 (x86_64)
  11. glibc-devel-2.12-1.7.el6.i686
  12. ksh
  13. libgcc-4.4.4-13.el6 (i686)
  14. libgcc-4.4.4-13.el6 (x86_64)
  15. libstdc++-4.4.4-13.el6 (x86_64)
  16. libstdc++-4.4.4-13.el6.i686
  17. libstdc++-devel-4.4.4-13.el6 (x86_64)
  18. libstdc++-devel-4.4.4-13.el6.i686
  19. libaio-0.3.107-10.el6 (x86_64)
  20. libaio-0.3.107-10.el6.i686
  21. libaio-devel-0.3.107-10.el6 (x86_64)
  22. libaio-devel-0.3.107-10.el6.i686
  23. make-3.81-19.el6
  24. sysstat-9.0.4-11.el6 (x86_64)

  25. [RHEL5]
  26. binutils-2.17.50.0.6
  27. compat-libstdc++-33-3.2.3
  28. compat-libstdc++-33-3.2.3 (32 bit)
  29. elfutils-libelf-0.125
  30. elfutils-libelf-devel-0.125
  31. gcc-4.1.2
  32. gcc-c++-4.1.2
  33. glibc-2.5-24
  34. glibc-2.5-24 (32 bit)
  35. glibc-common-2.5
  36. glibc-devel-2.5
  37. glibc-devel-2.5 (32 bit)
  38. glibc-headers-2.5
  39. ksh-20060214
  40. libaio-0.3.106
  41. libaio-0.3.106 (32 bit)
  42. libaio-devel-0.3.106
  43. libaio-devel-0.3.106 (32 bit)
  44. libgcc-4.1.2
  45. libgcc-4.1.2 (32 bit)
  46. libstdc++-4.1.2
  47. libstdc++-4.1.2 (32 bit)
  48. libstdc++-devel 4.1.2
  49. make-3.81
  50. sysstat-7.0.2



来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25960404/viewspace-2096197/,如需转载,请注明出处,否则将追究法律责任。

上一篇: Bootstrap 按钮
下一篇: 博客已迁往CSDN
全部评论

注册时间:2011-07-07

  • 博文量
    24
  • 访问量
    118071