rhel6/7如何自动安装oracle11g单实例

小编给大家分享一下rhel6/7如何自动安装oracle11g单实例,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

成都创新互联公司从2013年开始,先为淮阳等服务建站,淮阳等地企业,进行企业商务咨询服务。为淮阳企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

因日常工作,经常需要在rhel6.X,rhel7.X,CentOS6.X,CentOS7.x上安装oracle 11.2.0.4版本单实例数据库(基于文件系统)
故写了自动安装脚本oracle脚本。

全部文件列表如下:
rhel6/7如何自动安装oracle11g单实例


1、其中iso文件是对应的红帽系统的镜像源(根据cat /etc/redhat-release获取红帽版本)
2、其中两个zip安装包,可以从SR上下载(搜索13390677找到对应的文件,注意文件名必须一致)
3、其中三个rsp文件是安装oracle的配置文件,db_install.rsp用于安装数据库软件,dbca.rsp用于创建数据库,netca.rsp用于创建监听。
4、其中sh文件是本人写的脚本,直接使用root用户执行即可(需要chmod u+x auto_install_oracle_server.sh),期间需要用户输入几个信息:字符集、oracle_sid、主机ip地址,memory_target。



因只在红帽6与7的部分版本测试过,可能还有一些问题。可具体修改shell脚本。

操作过程:
1、查看文件是否齐全

点击(此处)折叠或打开

  1. [root@testlihb ~]# cd /tmp

  2. [root@testlihb tmp]# ls -lrt

  3. total 6120464

  4. -rw-r--r-- 1 root root 5871 Apr 28 07:00 netca.rsp #监听配置文件

  5. -rwxr--r-- 1 root root 17977 Apr 28 07:00 auto_install_oracle_server.sh #主脚本

  6. -rw-r--r-- 1 root root 25287 Apr 28 07:00 db_install.rsp #数据库软件配置文件

  7. -rw-r--r-- 1 root root 44580 Apr 28 07:00 dbca.rsp #数据库配置文件

  8. -rwxr-xr-x 1 root root 1395582860 Apr 28 07:07 p13390677_112040_Linux-x86-64_1of7.zip #11.2.0.4 安装包1

  9. -rwxr-xr-x 1 root root 1151304589 Apr 28 07:12 p13390677_112040_Linux-x86-64_2of7.zip #11.2.0.4 安装包2

  10. -rw-r--r-- 1 root root 3720347648 Jul 24 2018 rhel-server-6.4-x86_64-dvd.iso #操作系统光盘文件

  11. [root@testlihb tmp]# chmod u+x auto_install_oracle_server.sh #root赋予可执行权限

2、配置yum源,如果确认yum源已经配置完毕,可忽略此步骤

点击(此处)折叠或打开

  1. [root@testlihb tmp]# ./auto_install_oracle_server.sh #root直接执行

  2. ========>-------- seletion------------

  3. ========>1.install database #安装数据库

  4. ========>2.deinstall database #卸载数据库(只可以卸载通过本脚本安装的数据库)

  5. ========>3.configure local yum #配置yum源

  6. ========>-----------------------------

  7. ========>Your choice:3 #选择配置yum源,如果确认yum源已经配置好了,此处可忽略

  8. ========>please input the iso location(eg:/tmp/xxx.iso):/tmp/rhel-server-6.4-x86_64-dvd.iso #输入iso文件的路径

  9. [OK]====>the yum configure


3、安装数据库

点击(此处)折叠或打开

  1. [root@testlihb tmp]# ./auto_install_oracle_server.sh

  2. ========>-------- seletion------------

  3. ========>1.install database

  4. ========>2.deinstall database

  5. ========>3.configure local yum

  6. ========>-----------------------------

  7. ========>Your choice:1 #安装数据库

  8. [ok]====>begin install_db

  9. [ok]====>current user is root #检查当前用户是否为root

  10. [OK]====>the yum configure #检查yum源是否正常

  11. [OK]====>the installfile #检查oracle安装包是否存在

  12. [OK]====>the config file #检查配置文件是否存在

  13. ========>----charcaterset seletion----

  14. ========>1.AMERICAN_AMERICA.ZHS16GBK

  15. ========>2.AMERICAN_AMERICA.AL32UTF8

  16. ========>-----------------------------

  17. ========>Your choice:(default 1):1 #选择数据库字符集,此处只有两个选择

  18. ========>please input sid(less than 8 letters):oragbk #输入sid,sid必须少于8个字符

  19. ========>please input memory target(MB):4096 #输入内存,其中sga和pga比例为3:1

  20. ========>please input ORACLE_BASE(will auto create):/database/oragbk #oracle软件目录(如果目录不存在,会自动创建。如果目录存在,该目录必须为空)

  21. ========>please input host IP address:192.168.75.236 #输入本机ip地址

  22. [ok]====>cpu #检查cpu

  23. [ok]====>memory #检查内存

  24. [ok]====>/tmp #检查/tmp目录

  25. [ok]====>swap #检查交换分区

  26. [ok]====>ORACLE_BASE #检查oracle软件目录

  27. [OK]====>the yum configure #检查yum源配置

  28. [ok]====>the yum package has been installed #通过yum安装依赖包

  29. [ok]====>the sysctl.conf has been backup and change #备份和修改sysctl.conf文件

  30. [ok]====>the limits.conf has been backup and change #备份和修改limits.conf文件

  31. [ok]====>the login has been backup and change #备份和修改login文件

  32. [ok]====>the profile has been backup and change #备份和修改profile文件

  33. [ok]====>the oracle user and oinstall,dba group has been created #创建oracle用户,oinstall和dba组

  34. [ok]====>the .bash_profile has been backup and change #备份和修改.bash_profile文件

  35. [ok]====>the dir has been created #检查和创建oracle_base目录

  36. [ok]====>the install file has been unzip #解压oracle安装包

  37. [ok]====>the hosts has been backup and change #备份和修改hosts文件

  38. [ok]====>the db_install.rsp has been backup and change #备份和修改db_install.rsp文件

  39. [ok]====>waiting for software install . . . . . . . . . . #此处在安装oracle软件,需要等较长时间,可查看/tmp/db_install.rsp.log

  40. [ok]====>software has installed #oracle软件安装完成

  41. [ok]====>two script has been run by root #root执行两个shell script文件

  42. [ok]====>netca.rsp has been backup and change #备份和修改netca.rsp文件

  43. [ok]====>waiting for netca install . #此处在创建listener,不需要等待太长时间,可查看/tmp/netca.rsp.log

  44. [ok]====>netca has installed #listener创建完成

  45. [ok]====>dbca.rsp has been backup and change #备份和修改dbca.rsp文件

  46. Copying database files

  47. 1% complete

  48. 3% complete

  49. 11% complete

  50. 18% complete

  51. 26% complete

  52. 37% complete

  53. Creating and starting Oracle instance

  54. 40% complete

  55. 45% complete

  56. 50% complete

  57. 55% complete

  58. 56% complete

  59. 60% complete

  60. 62% complete

  61. Completing Database Creation

  62. 66% complete

  63. 70% complete

  64. 73% complete

  65. 85% complete

  66. 96% complete

  67. 100% complete

  68. Look at the log file "/database/oragbk/cfgtoollogs/dbca/oragbk/oragbk.log" for further details.

  69. [ok]====>dbca has installed #数据库创建完成

  70. [ok]====>the install process success


4、检查数据库是否正常

点击(此处)折叠或打开

  1. [root@testlihb tmp]# ps -ef|grep smon_ |grep -v grep

  2. oracle 12863 1 0 07:34 ? 00:00:00 ora_smon_oragbk #进程存在

  3. [root@testlihb tmp]# su - oracle

  4. [oracle@testlihb ~]$ sqlplus / as sysdba

  5. SQL*Plus: Release 11.2.0.4.0 Production on Sat Apr 28 07:35:09 2018

  6. Copyright (c) 1982, 2013, Oracle. All rights reserved.

  7. Connected to:

  8. Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

  9. With the Partitioning, OLAP, Data Mining and Real Application Testing options

  10. SQL> show parameter name

  11. NAME TYPE VALUE

  12. ------------------------------------ ----------- ------------------------------

  13. cell_offloadgroup_name string

  14. db_file_name_convert string

  15. db_name string oragbk

  16. db_unique_name string oragbk

  17. global_names boolean FALSE

  18. instance_name string oragbk

  19. lock_name_space string

  20. log_file_name_convert string

  21. processor_group_name string

  22. service_names string oragbk

  23. SQL> show parameter memory

  24. NAME TYPE VALUE

  25. ------------------------------------ ----------- ------------------------------

  26. hi_shared_memory_address integer 0

  27. memory_max_target big integer 0

  28. memory_target big integer 0

  29. shared_memory_address integer 0

  30. SQL> show parameter sga

  31. NAME TYPE VALUE

  32. ------------------------------------ ----------- ------------------------------

  33. lock_sga boolean FALSE

  34. pre_page_sga boolean FALSE

  35. sga_max_size big integer 3G

  36. sga_target big integer 3G

  37. SQL> show parameter pga

  38. NAME TYPE VALUE

  39. ------------------------------------ ----------- ------------------------------

  40. pga_aggregate_target big integer 1G

  41. SQL> set lines 150 pages 10000

  42. SQL> select * from nls_database_parameters where PARAMETER='NLS_CHARACTERSET';

  43. PARAMETER VALUE

  44. ------------------------------ --------------------------------------------------------------------------------

  45. NLS_CHARACTERSET ZHS16GBK

  46. SQL> exit

  47. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

  48. With the Partitioning, OLAP, Data Mining and Real Application Testing options

  49. [oracle@testlihb ~]$ logout


5、卸载数据库

点击(此处)折叠或打开

  1. [root@testlihb tmp]# ./auto_install_oracle_server.sh

  2. ========>-------- seletion------------

  3. ========>1.install database

  4. ========>2.deinstall database

  5. ========>3.configure local yum

  6. ========>-----------------------------

  7. ========>Your choice:2

  8. please use oracle to run $ORACLE_HOME/deinstall/deinstall and use root to run /tmp/del_ora.sh #切到oracle用户执行脚本,然后在切到root用户执行脚本

  9. [root@testlihb tmp]# su - oracle

  10. [oracle@testlihb ~]$ $ORACLE_HOME/deinstall/deinstall

  11. Checking for required files and bootstrapping ...

  12. Please wait ...

  13. Location of logs /tmp/deinstall2018-04-28_07-36-48AM/logs/

  14. 。。。

  15. Specify all Single Instance listeners that are to be de-configured [LISTENER]:

  16. Specify the list of database names that are configured in this Oracle home [oragbk]:

  17. The details of database(s) oragbk have been discovered automatically. Do you still want to modify the details of oragbk database(s)? [n]: y

  18. Specify the type of this database (1.Single Instance Database|2.Oracle Restart Enabled Database) [1]:

  19. Specify the diagnostic destination location of the database [/database/oragbk/diag/rdbms/oragbk]:

  20. Specify the storage type used by the Database ASM|FS [FS]:

  21. Specify the list of directories if any database files exist on a shared file system. If 'oragbk' subdirectory is found, then it will be deleted. Otherwise, the specified directory will be deleted. Alternatively, you can specify list of database files with full path [/database/oragbk/oradata/oragbk,/database/oragbk/fast_recovery_area/oragbk]:

  22. Specify the fast recovery area location, if it is configured on the file system. If 'oragbk' subdirectory is found, then it will be deleted. [/database/oragbk/fast_recovery_area/ORAGBK]:

  23. Specify the database spfile location [/database/oragbk/product/11.2.0/db_1/dbs/spfileoragbk.ora]:

  24. Do you want to continue (y - yes, n - no)? [n]: y

  25. 。。。

  26. [oracle@testlihb ~]$ logout

  27. [root@testlihb tmp]# /tmp/del_ora.sh

6、检查是否已经删除数据库

点击(此处)折叠或打开

  1. [root@testlihb tmp]# ps -ef|grep smon_

  2. root 16003 7948 0 07:45 pts/1 00:00:00 grep smon_

  3. [root@testlihb tmp]# id oracle

  4. id: oracle: No such user






如下是具体的脚本:
 auto_install_oracle_server.sh

点击(此处)折叠或打开

  1. #!/bin/bash

  2. HOSTNAME=`hostname`

  3. PWD="$( cd "$( dirname "$0"  )" && pwd  )"

  4. # 102 去掉目录最后的/

  5. change_dir(){

  6. flag=${1##*/}

  7. if [ -z $flag  ];then

  8. ORACLE_BASE=${1%?}

  9. fi

  10. }

  11. ##change_dir $dir

  12. # 101 检查文件夹是否可以作为ORACLE_BASE目录

  13. check_dir(){

  14. if [ -d $1 ];then

  15. if [ `ls -al $1|wc -l` -gt 3 ];then

  16. echo "[fail]====>the ORACLE_BASE must without any file(s)"

  17. exit 101

  18. fi

  19. else

  20. mkdir -p $1

  21. fi

  22. }

  23. ##read -p "input dir:" dir

  24. ##check_dir $dir

  25. # 0 检查传入参数是否为空

  26. isnull(){

  27. if [ -z $1 ];then

  28. echo $1

  29. echo "[fail]====>parameter is null"

  30. exit 0

  31. fi

  32. }

  33. ##isnull $hah

  34. # 1 检查yum源是否正常

  35. check_yum(){

  36. yum clean all >/dev/null 2>&1

  37. var=`yum repolist|grep repolist|awk -F : '{print $2}'|awk -F , '{print $1}'`

  38. ##    echo $var

  39. if [ $var -eq 0 ];then

  40. echo "[fail]====>the yum configure is wrong ,see /etc/yum.repos.d/*.repo"

  41. exit 1

  42. else

  43. echo "[OK]====>the yum configure"

  44. fi

  45. }

  46. ##check_yum

  47. # 2 检查数据库安装软件是否已经上传

  48. check_installfile(){

  49. cd $PWD

  50. if [ -f "p13390677_112040_Linux-x86-64_1of7.zip" -a -f "p13390677_112040_Linux-x86-64_2of7.zip" ];then

  51. echo "[OK]====>the installfile"

  52. else

  53. echo "[fail]====>the $PWD does not have p13390677_112040_Linux-* "

  54. exit 2

  55. fi

  56. if [ -f "dbca.rsp" -a -f "netca.rsp" -a -f "db_install.rsp" ];then

  57. echo "[OK]====>the config file"

  58. else

  59. echo "[fail]====>the $PWD does not have *.rsp"

  60. exit 2

  61. fi

  62. }

  63. ##check_installfile

  64. # 3 判断执行用户是否root

  65. isroot(){

  66. if [ $USER != "root" ];then

  67. echo "[fail]====>current user is not root"

  68. exit 3

  69. else

  70. echo "[ok]====>current user is root"

  71. fi

  72. }

  73. ##isroot

  74. # 4 获取输入数据库基本信息

  75. get_information(){

  76. echo "========>----charcaterset seletion----"

  77. echo "========>1.AMERICAN_AMERICA.ZHS16GBK"

  78. echo "========>2.AMERICAN_AMERICA.AL32UTF8"

  79. echo "========>-----------------------------"

  80. echo -e "========>Your choice:(default 1):\c"

  81. read NLS_LANG

  82. case $NLS_LANG in

  83. 1) NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

  84. CHARACTERSET=ZHS16GBK

  85. ;;

  86. 2) NLS_LANG=AMERICAN_AMERICA.AL32UTF8

  87. CHARACTERSET=AL32UTF8

  88. ;;

  89. *) NLS_LANG=AMERICAN_AMERICA.ZHS16GBK

  90. CHARACTERSET=ZHS16GBK

  91. ;;

  92. esac

  93. echo -e "========>please input sid(less than 8 letters):\c"

  94. read SID

  95. isnull $SID

  96. echo -e "========>please input memory target(MB):\c"

  97. read MEMORY

  98. isnull $MEMORY

  99. echo -e "========>please input ORACLE_BASE(will auto create):\c"

  100. read ORACLE_BASE

  101. isnull $ORACLE_BASE

  102. check_dir $ORACLE_BASE

  103. change_dir $ORACLE_BASE

  104. ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1

  105. echo -e "========>please input host IP address:\c"

  106. read IP

  107. isnull $IP

  108. }

  109. ##get_information

  110. # 5 检查cpu,内存,磁盘空间

  111. check_cpu_mem_disk(){

  112. cpu=`cat /proc/cpuinfo | grep name|wc -l`

  113. ##    echo $cpu

  114. if [ $cpu -gt 1 ];then

  115. echo "[ok]====>cpu "

  116. else

  117. echo "[fail]====>cpu must more than 1 cores"

  118. exit 5

  119. fi

  120. mem=`free -m|grep '+'|awk '{print $4}'`

  121. mem7=`free -m|grep Mem|awk '{print $7}'`

  122. ##    echo $mem

  123. if [[ $mem -gt 2048 || $mem7 -gt 2048 ]];then

  124. echo "[ok]====>memory"

  125. else

  126. echo "[fail]====>the memory must more than 2G available"

  127. exit 5

  128. fi

  129. if [ `df -m /tmp|wc -l` -eq 2 ];then

  130. tmp=`df -m /tmp|tail -1|awk '{print $4}'`

  131. else

  132. tmp=`df -m /tmp|tail -1|awk '{print $3}'`

  133. fi

  134. if [ $tmp -gt 120 ];then

  135. echo "[ok]====>/tmp"

  136. else

  137. echo "[fail]====>/tmp must more than 120MB"

  138. exit 5

  139. fi

  140. if [ `free -m|grep Swap|awk '{print $2}'` -gt 150 ];then

  141. echo "[ok]====>swap"

  142. else

  143. echo "[fail]====>swap must more than 150MB"

  144. exit 5

  145. fi

  146. if [ `df -m $ORACLE_BASE|wc -l` -eq 2 ];then

  147. base=`df -m $ORACLE_BASE|tail -1|awk '{print $4}'`

  148. else

  149. base=`df -m $ORACLE_BASE|tail -1|awk '{print $3}'`

  150. fi

  151. if [ $base -gt 8000 ];then

  152. echo "[ok]====>ORACLE_BASE"

  153. else

  154. echo "[fail]====>ORACLE_BASE must more than 20g"

  155. exit 5

  156. fi

  157. }

  158. ##check_cpu_mem_disk

  159. # 6 安装依赖包

  160. yum_install(){

  161. check_yum

  162. yum install -y binutils  >/dev/null

  163. yum install -y compat-libstdc++-33 >/dev/null

  164. yum install -y elfutils-libelf  >/dev/null

  165. yum install -y elfutils-libelf-devel  >/dev/null

  166. yum install -y gcc  >/dev/null

  167. yum install -y gcc-c++ >/dev/null

  168. yum install -y glibc-common >/dev/null

  169. yum install -y glibc-devel >/dev/null

  170. yum install -y glibc-headers >/dev/null

  171. yum install -y libaio >/dev/null

  172. yum install -y libaio-devel >/dev/null

  173. yum install -y libgcc >/dev/null

  174. yum install -y libstdc++ >/dev/null

  175. yum install -y libstdc++-devel >/dev/null

  176. yum install -y make >/dev/null

  177. yum install -y sysstat >/dev/null

  178. yum install -y unzip >/dev/null

  179. echo "[ok]====>the yum package has been installed"

  180. }

  181. ##yum_install

  182. # 7 修改/etc/sysctl.conf文件

  183. sysctl_set(){

  184. if [ ! -f /etc/sysctl.conf.lihb_bak ];then

  185. cp /etc/sysctl.conf /etc/sysctl.conf.lihb_bak

  186. echo "kernel.shmmni = 4096" >>/etc/sysctl.conf

  187. echo "kernel.sem = 250 32000 100 128" >>/etc/sysctl.conf

  188. echo "fs.file-max = 6815744" >>/etc/sysctl.conf

  189. echo "net.ipv4.ip_local_port_range = 9000 65500" >>/etc/sysctl.conf

  190. echo "net.core.rmem_default = 1048576" >>/etc/sysctl.conf

  191. echo "net.core.rmem_max = 4194304" >>/etc/sysctl.conf

  192. echo "net.core.wmem_default = 262144" >>/etc/sysctl.conf

  193. echo "net.core.wmem_max = 1048576" >>/etc/sysctl.conf

  194. echo "fs.aio-max-nr = 1048576" >>/etc/sysctl.conf

  195. /sbin/sysctl -p >/dev/null 2>&1

  196. echo "[ok]====>the sysctl.conf has been backup and change"

  197. fi

  198. }

  199. ##sysctl_set

  200. # 8 修改/etc/security/limits.conf文件

  201. limits_set(){

  202. if [ ! -f /etc/security/limits.conf.lihb_bak ];then

  203. cp /etc/security/limits.conf /etc/security/limits.conf.lihb_bak

  204. echo "oracle    soft    nproc    2047" >>/etc/security/limits.conf

  205. echo "oracle    hard    nproc    16384" >>/etc/security/limits.conf

  206. echo "oracle    soft    nofile    1024" >>/etc/security/limits.conf

  207. echo "oracle    hard    nofile    65536" >>/etc/security/limits.conf

  208. echo "[ok]====>the limits.conf has been backup and change"

  209. fi

  210. }

  211. ##limits_set

  212. # 9 修改/etc/pam.d/login文件

  213. login_set(){

  214. if [ ! -f /etc/pam.d/login.lihb_bak ];then

  215. cp /etc/pam.d/login /etc/pam.d/login.lihb_bak

  216. echo "session    required    /lib64/security/pam_limits.so" >>/etc/pam.d/login

  217. echo "[ok]====>the login has been backup and change"

  218. fi

  219. }

  220. ##login_set

  221. # 10 修改/etc/profile文件

  222. profile_set(){

  223. if [ ! -f /etc/profile.lihb_bak ];then

  224. cp /etc/profile /etc/profile.lihb_bak

  225. echo 'if [ "$USER" = "oracle" ];then ' >>/etc/profile

  226. echo '    if [ "$SHELL" = "/bin/ksh" ];then ' >>/etc/profile

  227. echo '        ulimit -p 16384' >>/etc/profile

  228. echo '        ulimit -n 65536' >>/etc/profile

  229. echo '    else' >>/etc/profile

  230. echo '        ulimit -u 16384' >>/etc/profile

  231. echo '        ulimit -n 65536' >>/etc/profile

  232. echo '    fi' >>/etc/profile

  233. echo '    umask 022' >>/etc/profile

  234. echo 'fi' >>/etc/profile

  235. echo "[ok]====>the profile has been backup and change"

  236. fi

  237. }

  238. ##profile_set

  239. # 11 创建oracle用户和oinstall,dba用户组

  240. user_group_add(){

  241. if [[ `grep "oinstall" /etc/group` = "" ]];then

  242. /usr/sbin/groupadd  -g 1100 oinstall >/dev/null 2>&1

  243. fi

  244. if [[ `grep "dba" /etc/group` = "" ]];then

  245. /usr/sbin/groupadd  -g 1101 dba   >/dev/null 2>&1

  246. fi

  247. if [[ `grep "oracle" /etc/passwd` = "" ]];then

  248. /usr/sbin/useradd -g 1100 -G 1101 -u 1100 -m oracle >/dev/null 2>&1

  249. echo "[ok]====>the oracle user and oinstall,dba group has been created"

  250. else

  251. echo "[fail]====>the oracle user has exist"

  252. exit 11

  253. fi

  254. }

  255. ##user_group_add

  256. # 12 修改/home/oracle/.bash_profile文件

  257. bash_profile_set(){

  258. if [ ! -f /home/oracle/.bash_profile.lihb_bak ];then

  259. cp /home/oracle/.bash_profile /home/oracle/.bash_profile.lihb_bak

  260. echo "" >>/home/oracle/.bash_profile

  261. echo "export ORACLE_BASE=$ORACLE_BASE" >>/home/oracle/.bash_profile

  262. echo "export ORACLE_HOME=$ORACLE_HOME" >>/home/oracle/.bash_profile

  263. echo "export ORACLE_SID=$SID" >>/home/oracle/.bash_profile

  264. echo 'export LD_LIBRARY_PATH=$ORACLE_HOME/lib' >>/home/oracle/.bash_profile

  265. echo 'stty erase ^H' >>/home/oracle/.bash_profile

  266. echo 'export NLS_LANG10=$ORACLE_HOME/nls/data' >>/home/oracle/.bash_profile

  267. echo 'export ORACLE_HOME_LISTNER=$ORACLE_HOME' >>/home/oracle/.bash_profile

  268. echo 'export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin' >>/home/oracle/.bash_profile

  269. echo 'export TEMP=/tmp' >>/home/oracle/.bash_profile

  270. echo 'export TMPDIR=/tmp' >>/home/oracle/.bash_profile

  271. echo "export NLS_LANG=$NLS_LANG" >>/home/oracle/.bash_profile

  272. echo "export NLS_DATE_FORMAT='yyyy-mm-dd hh34:mi:ss'" >>/home/oracle/.bash_profile

  273. echo 'umask 022' >>/home/oracle/.bash_profile

  274. echo "[ok]====>the .bash_profile has been backup and change"

  275. fi

  276. }

  277. ##bash_profile_set

  278. # 13 创建ORACLE_BASE和ORACLE_HOME和数据文件目录并授权

  279. create_dir(){

  280. mkdir -p $ORACLE_HOME

  281. mkdir -p $ORACLE_BASE/oradata

  282. mkdir -p $ORACLE_BASE/oraInventory

  283. mkdir -p $ORACLE_BASE/flash_recovery_area

  284. chown -R oracle:oinstall  $ORACLE_BASE

  285. echo "[ok]====>the dir has been created"

  286. }

  287. ##create_dir

  288. # 14 解压数据库安装包

  289. unzip_file(){

  290. cd $PWD

  291. /usr/bin/unzip p13390677_112040_Linux-x86-64_1of7.zip >/dev/null 2>&1

  292. /usr/bin/unzip p13390677_112040_Linux-x86-64_2of7.zip >/dev/null 2>&1

  293. chown -R oracle:oinstall $PWD/database

  294. echo "[ok]====>the install file has been unzip"

  295. }

  296. ##unzip_file

  297. # 15 修改/etc/hosts文件

  298. hosts_set(){

  299. if [ ! -f /etc/hosts.lihb_bak ];then

  300. cp /etc/hosts /etc/hosts.lihb_bak

  301. echo "$IP    $HOSTNAME" >>/etc/hosts

  302. echo "[ok]====>the hosts has been backup and change"

  303. fi

  304. }

  305. ##hosts_set

  306. # 16 修改db_install.rsp 数据库软件安装配置文件

  307. db_install_set(){

  308. cd $PWD

  309. chown oracle:oinstall db_install.rsp

  310. if [ ! -f db_install.rsp.lihb_bak ];then

  311. cp db_install.rsp db_install.rsp.lihb_bak

  312. sed -i "s|lihb_hostname|$HOSTNAME|g" db_install.rsp

  313. sed -i "s|lihb_location|$ORACLE_BASE/oraInventory|g" db_install.rsp

  314. sed -i "s|lihb_home|$ORACLE_HOME|g" db_install.rsp

  315. sed -i "s|lihb_base|$ORACLE_BASE|g" db_install.rsp

  316. sed -i "s|lihb_globaldbname|$SID|g" db_install.rsp

  317. sed -i "s|lihb_sid|$SID|g" db_install.rsp

  318. sed -i "s|lihb_datalocation|$ORACLE_BASE/oradata|g" db_install.rsp

  319. echo "[ok]====>the db_install.rsp has been backup and change"

  320. fi

  321. }

  322. ##db_install_set

  323. # 17 开始安装oracle软件

  324. install_software(){

  325. su - oracle -c "$PWD/database/runInstaller -silent -force -ignorePrereq -responseFile $PWD/db_install.rsp"  >/tmp/db_install.rsp.log

  326. sleep 10s

  327. echo -e "[ok]====>waiting for software install \c"

  328. while [ ! `grep "root.sh" /tmp/db_install.rsp.log |wc -l` -eq 1 ]

  329. do

  330. echo -e ". \c"

  331. sleep 2s

  332. done

  333. echo "."

  334. echo "[ok]====>software has installed"

  335. $ORACLE_BASE/oraInventory/orainstRoot.sh >/dev/null 2>&1

  336. $ORACLE_BASE/product/11.2.0/db_1/root.sh >/dev/null 2>&1

  337. echo "[ok]====>two script has been run by root"

  338. }

  339. ##install_software

  340. # 18 修改netca.rsp  监听安装配置文件

  341. netca_set(){

  342. cd $PWD

  343. chown oracle:oinstall netca.rsp

  344. if [ ! -f netca.rsp.lihb_bak ];then

  345. cp netca.rsp netca.rsp.lihb_bak

  346. echo "[ok]====>netca.rsp has been backup and change"

  347. fi

  348. }

  349. ##netca_set

  350. # 19 开始安装监听软件

  351. install_netca(){

  352. #    ORACLE_HOME=/database/oracle/product/11.2.0/db_1/

  353. chown -R oracle:dba /var/tmp/.oracle >/dev/null 2>&1

  354. chown -R oracle:dba /tmp/.oracle >/dev/null 2>&1

  355. su - oracle -c "$ORACLE_HOME/bin/netca -silent -responseFile $PWD/netca.rsp" >/tmp/netca.rsp.log

  356. sleep 2s

  357. echo -e "[ok]====>waiting for netca install \c"

  358. while [ ! `grep "The exit code is" /tmp/netca.rsp.log|wc -l` -eq 1 ]

  359. do

  360. echo -e ". \c"

  361. sleep 1s

  362. done

  363. echo "."

  364. echo "[ok]====>netca has installed"

  365. chown -R oracle:dba /var/tmp/.oracle >/dev/null 2>&1

  366. chown -R oracle:dba /tmp/.oracle >/dev/null 2>&1

  367. }

  368. ##install_netca

  369. # 20  修改dbca.rsp 创建数据库配置文件

  370. dbca_set(){

  371. cd $PWD

  372. chown oracle:oinstall dbca.rsp

  373. if [ ! -f dbca.rsp.lihb_bak ];then

  374. cp dbca.rsp dbca.rsp.lihb_bak

  375. #        SID=cgkcglxt

  376. #        ORACLE_BASE=/database/oracle

  377. #        CHARACTERSET=ZHS16GBK

  378. #        MEMORY=4096

  379. sed -i "s|lihb_sid|$SID|g" dbca.rsp

  380. sed -i "s|lihb_datafiledestination|$ORACLE_BASE/oradata|g" dbca.rsp

  381. sed -i "s|lihb_recoveryareadestination|$ORACLE_BASE/flash_recovery_area|g" dbca.rsp

  382. sed -i "s|lihb_characterset|$CHARACTERSET|g" dbca.rsp

  383. sed -i "s|lihb_totalmemory|$MEMORY|g" dbca.rsp

  384. sed -i "s|lihb_gdbname|$SID|g" dbca.rsp

  385. echo "[ok]====>dbca.rsp has been backup and change"

  386. fi

  387. }

  388. ##dbca_set

  389. # 21 开始创建数据库

  390. install_dbca(){

  391. #    ORACLE_HOME=/database/oracle/product/11.2.0/db_1/

  392. su - oracle -c "$ORACLE_HOME/bin/dbca -silent -force -responseFile $PWD/dbca.rsp"

  393. echo "[ok]====>dbca has installed"

  394. }

  395. ##install_dbca

  396. # install_db 安装数据库

  397. install_db(){

  398. echo "[ok]====>begin install_db"

  399. #    check_dir  $dir        #检查文件夹是否可以作为ORACLE_BASE目录

  400. #    isnull $hah            #检查传入参数是否为空

  401. isroot                 #判断执行用户是否root

  402. check_yum              #检查yum源是否正常

  403. check_installfile      #检查数据库安装软件是否已经上传

  404. get_information        #获取输入数据库基本信息

  405. check_cpu_mem_disk     #检查cpu,内存,磁盘空间

  406. yum_install            #安装依赖包

  407. sysctl_set             #修改/etc/sysctl.conf文件

  408. limits_set             #修改/etc/security/limits.conf文件

  409. login_set              #修改/etc/pam.d/login文件

  410. profile_set            #修改/etc/profile文件

  411. user_group_add         #创建oracle用户和oinstall,dba用户组

  412. bash_profile_set       #修改/home/oracle/.bash_profile文件

  413. create_dir             #创建ORACLE_BASE和ORACLE_HOME和数据文件目录并授权

  414. unzip_file             #解压数据库安装包

  415. hosts_set              #修改/etc/hosts文件

  416. db_install_set         #修改db_install.rsp 数据库软件安装配置文件

  417. install_software       #开始安装oracle软件

  418. netca_set              #修改netca.rsp  监听安装配置文件

  419. install_netca          #开始安装监听软件

  420. dbca_set               #修改dbca.rsp 创建数据库配置文件

  421. install_dbca           #开始创建数据库

  422. echo "[ok]====>the install process success"

  423. }

  424. ##install_db

  425. # deinstall_db 卸载数据库软件

  426. deinstall_db(){

  427. PWD="$( cd "$( dirname "$0"  )" && pwd  )"

  428. touch /tmp/del_ora.sh >/dev/null 2>&1

  429. echo "#!/bin/bash" >/tmp/del_ora.sh

  430. echo "cd $PWD" >>/tmp/del_ora.sh

  431. echo 'rm -rf database' >>/tmp/del_ora.sh

  432. echo 'mv -f db_install.rsp.lihb_bak db_install.rsp >/dev/null 2>&1' >>/tmp/del_ora.sh

  433. echo 'mv -f netca.rsp.lihb_bak netca.rsp >/dev/null 2>&1' >>/tmp/del_ora.sh

  434. echo 'mv -f dbca.rsp.lihb_bak dbca.rsp >/dev/null 2>&1' >>/tmp/del_ora.sh

  435. echo 'mv -f /etc/hosts.lihb_bak /etc/hosts >/dev/null 2>&1' >>/tmp/del_ora.sh

  436. echo 'mv -f /etc/profile.lihb_bak /etc/profile >/dev/null 2>&1' >>/tmp/del_ora.sh

  437. echo 'mv -f /etc/pam.d/login.lihb_bak /etc/pam.d/login >/dev/null 2>&1' >>/tmp/del_ora.sh

  438. echo 'mv -f /etc/security/limits.conf.lihb_bak /etc/security/limits.conf >/dev/null 2>&1' >>/tmp/del_ora.sh

  439. echo 'mv -f /etc/sysctl.conf.lihb_bak /etc/sysctl.conf >/dev/null 2>&1' >>/tmp/del_ora.sh

  440. echo '/sbin/sysctl -p >/dev/null 2>&1' >>/tmp/del_ora.sh

  441. echo 'rm -rf /opt/tmp/.oracle' >>/tmp/del_ora.sh

  442. echo 'rm -rf /tmp/.oracle' >>/tmp/del_ora.sh

  443. echo 'rm -rf /opt/ORCLfmap' >>/tmp/del_ora.sh

  444. echo 'rm -rf /etc/oraInst.loc' >>/tmp/del_ora.sh

  445. echo 'rm -rf /etc/oratab' >>/tmp/del_ora.sh

  446. echo 'userdel -r oracle >/dev/null 2>&1' >>/tmp/del_ora.sh

  447. ORACLE_BASE=`cat /home/oracle/.bash_profile|grep ORACLE_BASE|awk -F = '{print $2}'`

  448. echo "rm -rf $ORACLE_BASE" >>/tmp/del_ora.sh

  449. chmod u+x /tmp/del_ora.sh

  450. echo 'please use oracle to run $ORACLE_HOME/deinstall/deinstall and use root to run /tmp/del_ora.sh'

  451. }

  452. ##deinstall_db

  453. # configure_yum 配置yum源

  454. configure_yum(){

  455. echo -e "========>please input the iso location(eg:/tmp/xxx.iso):\c"

  456. read ISOLOCATION

  457. mkdir -p /media/lihb_iso

  458. mount -t iso9660 -o loop $ISOLOCATION /media/lihb_iso

  459. mkdir -p /etc/yum.repos.d/lihb_bak

  460. mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/lihb_bak

  461. touch /etc/yum.repos.d/lihb_local.repo

  462. echo "[lihb_local]" >/etc/yum.repos.d/lihb_local.repo

  463. echo "name=lihb_local" >>/etc/yum.repos.d/lihb_local.repo

  464. echo "baseurl=file:///media/lihb_iso" >>/etc/yum.repos.d/lihb_local.repo

  465. echo "gpgcheck=0" >>/etc/yum.repos.d/lihb_local.repo

  466. echo "enabled=1" >>/etc/yum.repos.d/lihb_local.repo

  467. check_yum

  468. }

  469. ##configure_yum

  470. # main 程序入口

  471. main(){

  472. echo "========>-------- seletion------------"

  473. echo "========>1.install database"

  474. echo "========>2.deinstall database"

  475. echo "========>3.configure local yum"

  476. echo "========>-----------------------------"

  477. echo -e "========>Your choice:\c"

  478. read FLAG

  479. case $FLAG in

  480. 1) install_db     #安装数据库

  481. ;;

  482. 2) deinstall_db   #卸载数据库

  483. ;;

  484. 3) configure_yum  #配置本地yum源

  485. ;;

  486. *) exit 200

  487. ;;

  488. esac

  489. }

  490. main

如下是db_install.rsp的内容:

点击(此处)折叠或打开

  1. ####################################################################

  2. ## Copyright(c) Oracle Corporation 1998,2013. All rights reserved.##

  3. ##                                                                ##

  4. ## Specify values for the variables listed below to customize     ##

  5. ## your installation.                                             ##

  6. ##                                                                ##

  7. ## Each variable is associated with a comment. The comment        ##

  8. ## can help to populate the variables with the appropriate        ##

  9. ## values.  ##

  10. ##                                                                ##

  11. ## IMPORTANT NOTE: This file contains plain text passwords and    ##

  12. ## should be secured to have read permission only by oracle user  ##

  13. ## or db administrator who owns this installation.                ##

  14. ##                                                                ##

  15. ####################################################################

  16. #------------------------------------------------------------------------------

  17. # Do not change the following system generated value.

  18. #------------------------------------------------------------------------------

  19. oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0

  20. #------------------------------------------------------------------------------

  21. # Specify the installation option.

  22. # It can be one of the following:

  23. #   - INSTALL_DB_SWONLY

  24. #   - INSTALL_DB_AND_CONFIG

  25. #   - UPGRADE_DB

  26. #-------------------------------------------------------------------------------

  27. oracle.install.option=INSTALL_DB_SWONLY

  28. #-------------------------------------------------------------------------------

  29. # Specify the hostname of the system as set during the install. It can be used

  30. # to force the installation to use an alternative hostname rather than using the

  31. # first hostname found on the system. (e.g., for systems with multiple hostnames

  32. # and network interfaces)

  33. #-------------------------------------------------------------------------------

  34. ORACLE_HOSTNAME=lihb_hostname

  35. #-------------------------------------------------------------------------------

  36. # Specify the Unix group to be set for the inventory directory.

  37. #-------------------------------------------------------------------------------

  38. UNIX_GROUP_NAME=oinstall

  39. #-------------------------------------------------------------------------------

  40. # Specify the location which holds the inventory files.

  41. # This is an optional parameter if installing on

  42. # Windows based Operating System.

  43. #-------------------------------------------------------------------------------

  44. INVENTORY_LOCATION=lihb_location

  45. #-------------------------------------------------------------------------------

  46. # Specify the languages in which the components will be installed.

  47. #

  48. # en   : English                  ja   : Japanese

  49. # fr   : French                   ko   : Korean

  50. # ar   : Arabic                   es   : Latin American Spanish

  51. # bn   : Bengali                  lv   : Latvian

  52. # pt_BR: Brazilian Portuguese     lt   : Lithuanian

  53. # bg   : Bulgarian                ms   : Malay

  54. # fr_CA: Canadian French          es_MX: Mexican Spanish

  55. # ca   : Catalan                  no   : Norwegian

  56. # hr   : Croatian                 pl   : Polish

  57. # cs   : Czech                    pt   : Portuguese

  58. # da   : Danish                   ro   : Romanian

  59. # nl   : Dutch                    ru   : Russian

  60. # ar_EG: Egyptian                 zh_CN: Simplified Chinese

  61. # en_GB: English (Great Britain)  sk   : Slovak

  62. # et   : Estonian                 sl   : Slovenian

  63. # fi   : Finnish                  es_ES: Spanish

  64. # de   : German                   sv   : Swedish

  65. # el   : Greek                    th   : Thai

  66. # iw   : Hebrew                   zh_TW: Traditional Chinese

  67. # hu   : Hungarian                tr   : Turkish

  68. # is   : Icelandic                uk   : Ukrainian

  69. # in   : Indonesian               vi   : Vietnamese

  70. # it   : Italian

  71. #

  72. # all_langs   : All languages

  73. #

  74. # Specify value as the following to select any of the languages.

  75. # Example : SELECTED_LANGUAGES=en,fr,ja

  76. #

  77. # Specify value as the following to select all the languages.

  78. # Example : SELECTED_LANGUAGES=all_langs

  79. #------------------------------------------------------------------------------

  80. SELECTED_LANGUAGES=en

  81. #------------------------------------------------------------------------------

  82. # Specify the complete path of the Oracle Home.

  83. #------------------------------------------------------------------------------

  84. ORACLE_HOME=lihb_home

  85. #------------------------------------------------------------------------------

  86. # Specify the complete path of the Oracle Base.

  87. #------------------------------------------------------------------------------

  88. ORACLE_BASE=lihb_base

  89. #------------------------------------------------------------------------------

  90. # Specify the installation edition of the component.

  91. #

  92. # The value should contain only one of these choices.

  93. #   - EE     : Enterprise Edition

  94. #   - SE     : Standard Edition

  95. #   - SEONE  : Standard Edition One

  96. #   - PE     : Personal Edition (WINDOWS ONLY)

  97. #------------------------------------------------------------------------------

  98. oracle.install.db.InstallEdition=EE

  99. #------------------------------------------------------------------------------

  100. # This variable is used to enable or disable custom install and is considered

  101. # only if InstallEdition is EE.

  102. #

  103. # true  : Components mentioned as part of 'optionalComponents' property

  104. #         are considered for install.

  105. # false : Value for 'optionalComponents' is not considered.

  106. #------------------------------------------------------------------------------

  107. oracle.install.db.EEOptionsSelection=false

  108. #------------------------------------------------------------------------------

  109. # This variable is considered only if 'EEOptionsSelection' is set to true.

  110. #

  111. # Description: List of Enterprise Edition Options you would like to enable.

  112. #

  113. #              The following choices are available. You may specify any

  114. #              combination of these choices.  The components you choose should

  115. #              be specified in the form "internal-component-name:version"

  116. #              Below is a list of components you may specify to enable.

  117. #

  118. #              oracle.oraolap:11.2.0.4.0 - Oracle OLAP

  119. #              oracle.rdbms.dm:11.2.0.4.0 - Oracle Data Mining

  120. #              oracle.rdbms.dv:11.2.0.4.0 - Oracle Database Vault

  121. #              oracle.rdbms.lbac:11.2.0.4.0 - Oracle Label Security

  122. #              oracle.rdbms.partitioning:11.2.0.4.0 - Oracle Partitioning

  123. #              oracle.rdbms.rat:11.2.0.4.0 - Oracle Real Application Testing

  124. #------------------------------------------------------------------------------

  125. oracle.install.db.optionalComponents=oracle.rdbms.partitioning:11.2.0.4.0,oracle.oraolap:11.2.0.4.0,oracle.rdbms.dm:11.2.0.4.0,oracle.rdbms.dv:11.2.0.4.0,oracle.rdbms.lbac:11.2.0.4.0,oracle.rdbms.rat:11.2.0.4.0

  126. ###############################################################################

  127. #                                                                             #

  128. # PRIVILEGED OPERATING SYSTEM GROUPS                                        #

  129. # ------------------------------------------                                  #

  130. # Provide values for the OS groups to which OSDBA and OSOPER privileges       #

  131. # needs to be granted. If the install is being performed as a member of the   #

  132. # group "dba", then that will be used unless specified otherwise below.      #

  133. #                                                                             #

  134. # The value to be specified for OSDBA and OSOPER group is only for UNIX based #

  135. # Operating System.                                                           #

  136. #                                                                             #

  137. ###############################################################################

  138. #------------------------------------------------------------------------------

  139. # The DBA_GROUP is the OS group which is to be granted OSDBA privileges.

  140. #------------------------------------------------------------------------------

  141. oracle.install.db.DBA_GROUP=dba

  142. #------------------------------------------------------------------------------

  143. # The OPER_GROUP is the OS group which is to be granted OSOPER privileges.

  144. # The value to be specified for OSOPER group is optional.

  145. #------------------------------------------------------------------------------

  146. oracle.install.db.OPER_GROUP=oinstall

  147. #------------------------------------------------------------------------------

  148. # Specify the cluster node names selected during the installation.

  149. # Example : oracle.install.db.CLUSTER_NODES=node1,node2

  150. #------------------------------------------------------------------------------

  151. oracle.install.db.CLUSTER_NODES=

  152. #------------------------------------------------------------------------------

  153. # This variable is used to enable or disable RAC One Node install.

  154. #

  155. #   - true  : Value of RAC One Node service name is used.

  156. #   - false : Value of RAC One Node service name is not used.

  157. #

  158. # If left blank, it will be assumed to be false


  159. 当前文章:rhel6/7如何自动安装oracle11g单实例
    文章地址:http://cdiso.cn/article/ggjpcg.html

其他资讯