Oracle安装脚本

前端之家收集整理的这篇文章主要介绍了Oracle安装脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Oracle脚本,便于快速部署。现在用的是11G,可以针对不同版本加以调整,主要涉及以下几块内容
1. vnc安装
2. 安装涉及到的内核参数设置
3. 数据库dbca配置
4. netca设置
5. sqlplus设置

  1. #!/bin/bash
  2. #oralce install for 11.2.0.1
  3. #usage:./oracle_installer.sh dp_ip db_hostname db_name
  4.  
  5.  
  6.  
  7. #modified time 2017-8-28 13:02:54
  8. #modified content
  9. #add db_files variabe(install zipname)
  10. #
  11. #
  12. #
  13.  
  14. #read -p "db_ip:" db_ip
  15. #read -p "db_hostname:" db_hostname
  16. #read -p "db_name:" db_name
  17. #export db_name
  18.  
  19.  
  20.  
  21. db_ip=$1
  22. db_hostname=$2
  23. db_name=$3
  24. db_files1=linux.x64_11gR2_database_1of2.zip
  25. db_files2=linux.x64_11gR2_database_2of2.zip
  26.  
  27.  
  28. echo -e "------------------db_ip=$1-------------\n"
  29. echo -e "------------------db_hostname=$2-------\n"
  30. echo -e "------------------db_name=$3-------------\n\n"
  31. echo -e "------------------db_files=linux.x64_11gR2_database_1of2.zip------------\n"
  32.  
  33.  
  34. echo -e "------------------uninstall last installation-------------\n\n"
  35. rm -rf /u01
  36. rm -rf /usr/local/bin/*
  37. rm -rf /etc/oratab
  38. rm -rf /etc/oraInst.loc
  39. rm -rf /opt/ORCLfmap
  40. rm -rf /home/oracle/oracle_install.sh
  41. rm -rf /home/oracle/tmp.rsp
  42.  
  43. echo -e "---------------add group and member----------------\n\n"
  44. groupadd oinstall
  45. groupadd dba
  46. useradd -g oinstall -G dba oracle
  47. passwd oracle
  48.  
  49.  
  50.  
  51. echo -e "\n\n------------mount and cfg yum---------------------\n\n"
  52.  
  53. mount /dev/cdrom /media
  54.  
  55.  
  56. #add local source
  57. grep "local-source" /etc/yum.repos.d/rhel-source.repo > /dev/null
  58. if [ $? -eq 0 ]; then
  59. echo "local-source found!"
  60. else
  61. echo "local-source is configuring"
  62. echo -e "\n\n[local-source]\nname=yum server\nbaseurl=file:///media\nenabled=1\ngpgcheck=0\n">>/etc/yum.repos.d/rhel-source.repo
  63. fi
  64.  
  65. echo -e "\n\n--------------about vnc---------------------------\n\n"
  66.  
  67. yum install tigervnc-server.x86_64 -y
  68.  
  69.  
  70. #iptables stop
  71. service iptables stop
  72.  
  73.  
  74.  
  75. grep "${db_ip} ${db_hostname}" /etc/hosts > /dev/null
  76. if [ $? -eq 0 ]; then
  77. echo "hostname found"
  78. else
  79. echo "hostname is configuring"
  80. echo -e "\n"${db_ip} ${db_hostname}"\n" >> /etc/hosts
  81. fi
  82.  
  83.  
  84. #configure vnc
  85. vncserver
  86. su - oracle -c "vncserver"
  87.  
  88.  
  89. sed -i 's/^twm/#twm/g' /home/oracle/.vnc/xstartup
  90. grep "gnome-session &" /home/oracle/.vnc/xstartup > /dev/null
  91.  
  92. if [ $? -eq 0 ];then
  93. echo "ora gnome-session & found"
  94. else
  95. echo "ora gnome-session & is configuring"
  96. echo "gnome-session &" >> /home/oracle/.vnc/xstartup
  97. fi
  98.  
  99.  
  100. sed -i 's/^twm/#twm/g' /root/.vnc/xstartup
  101. grep "gnome-session &" /root/.vnc/xstartup > /dev/null
  102.  
  103. if [ $? -eq 0 ];then
  104. echo "gnome-session & found"
  105. else
  106. echo "gnome-session & is configuring"
  107. echo "gnome-session &" >> /root/.vnc/xstartup
  108. fi
  109.  
  110.  
  111.  
  112. grep "1:root 2:oracle" /etc/sysconfig/vncservers > /dev/null
  113.  
  114. if [ $? -eq 0 ];then
  115. echo "VNCSERVERS found"
  116. else
  117. echo "VNCSERVERS is configuring"
  118. echo -e "\nVNCSERVERS=\"1:root 2:oracle\"\nVNCSERVERARGS[1]=\"-geometry 1024x768\"\nVNCSERVERARGS[2]=\"-geometry 1024x768\"" >> /etc/sysconfig/vncservers
  119. fi
  120.  
  121.  
  122. echo -e "\n\n---------------make oracle directories----------------------\n\n"
  123.  
  124.  
  125. usermod -g oinstall -G dba oracle
  126. mkdir -p /u01/app/oracle
  127. mkdir -p /u01/app/oradata
  128. mkdir -p /u01/app/oracle/product
  129. chown -R oracle:oinstall /u01
  130. chmod -R 775 /u01
  131.  
  132.  
  133. echo -e "\n\n---------------about oracle configure------------------\n\n"
  134.  
  135.  
  136. grep "oracle configure" /etc/sysctl.conf > /dev/null
  137. if [ $? -eq 0 ];then
  138. echo "#oracle configure found"
  139. else
  140. echo "#oracle configure is configuring"
  141. echo -e \
  142. "#oracle configure\n\ fs.file-max = 6815744\n\ fs.aio-max-nr = 1048576\n\ fs.aio-max-nr = 1048576\n\ kernel.shmall = 2097152\n\ kernel.shmmax = 2147483648\n\ kernel.shmmni = 4096\n\ kernel.sem = 250 32000 100 128\n\ net.ipv4.ip_local_port_range = 9000 65500\n\ net.core.rmem_default = 4194304\n\ net.core.rmem_max = 4194304\n\ net.core.wmem_default = 262144\n\ net.core.wmem_max = 1048576\n"\
  143. >> /etc/sysctl.conf
  144.  
  145. fi
  146.  
  147.  
  148. sysctl -p
  149.  
  150.  
  151.  
  152. grep "oracle shell limits" /etc/security/limits.conf > /dev/null
  153. if [ $? -eq 0 ];then
  154. echo "oracle shell limits found"
  155. else
  156. echo "oracle shell limits is configuring"
  157. echo -e \
  158. "#oracle shell limits\n\ oracle soft nproc 2047\n\ oracle hard nproc 16384\n\ oracle soft nofile 1024\n\ oracle hard nofile 65536\n"\
  159. >> /etc/security/limits.conf
  160.  
  161.  
  162. fi
  163.  
  164.  
  165. grep "#oracle pam configuring" /etc/pam.d/login > /dev/null
  166. if [ $? -eq 0 ];then
  167. echo "oracle pam found"
  168. else
  169. echo "oracle pam is configuring"
  170. echo -e \
  171. "#oracle pam configuring\n\ session required pam_limits.so\n\ session required /lib/security/pam_limits.so\n"\
  172. >> /etc/pam.d/login
  173.  
  174. fi
  175.  
  176.  
  177.  
  178. grep "#oracle profile configuring" /etc/profile > /dev/null
  179. if [ $? -eq 0 ];then
  180. echo "oracle profile found"
  181. else
  182. "#oracle profile configuring\n\ if [ $USER = "oracle" ]; then\n\ if [ $SHELL = "/bin/ksh" ]; then\n\ ulimit -p 16384\n\ ulimit -n 65536\n\ else\n\ ulimit -u 16384 -n 65536\n\ fi\n\ fi\n"\
  183. >> /etc/profile
  184.  
  185. fi
  186.  
  187.  
  188.  
  189. grep "#oracle csh configuring" /etc/csh.login > /dev/null
  190. if [ $? -eq 0 ];then
  191. echo "oracle csh found"
  192. else
  193. echo "oracle csh is configuring"
  194. echo -e \
  195. "#oracle csh configuring\n\ if ( \$USER == \"oracle\" ) then\n\ limit maxproc 16384\n\ limit descriptors 65536\n\ endif\n"\
  196. >> /etc/csh.login
  197.  
  198. fi
  199.  
  200. echo -e "\n\n------------------about selinux-------------------\n\n"
  201.  
  202. sed -r 's/(SELINUX=)*/\1disabled/' /etc/selinux/config > /dev/null
  203.  
  204. grep "SELINUX=disabled" /etc/selinux/config > /dev/null
  205.  
  206. if [ $? -eq 0 ]; then
  207. echo "SELINUX=disabled found"
  208. else
  209. echo "SELINUX=disabled is configuring"
  210. echo -e "\nSELINUX=disabled\n" >> /etc/selinux/config
  211. fi
  212.  
  213.  
  214. echo -e "\n\n--------------install dependecies---------------------\n\n"
  215. yum -y install compat-libstdc++-33 elfutils-libelf-devel gcc gcc-c++ glibc-devel glibc-headers libaio-devel libstdc++-devel pdksh unixODBC unixODBC-devel gcc* glibc* ksh
  216. * libstdc* make* libXp*
  217.  
  218. echo -e "\n\n--------------------oracle env varibales-----------------------\n\n"
  219. grep "ORACLE_ENV" /home/oracle/.bash_profile > /dev/null
  220.  
  221. if [ $? -eq 0 ]; then
  222. echo "ORACLE_ENV found"
  223. else
  224. echo "ORACLE_ENV is configuring"
  225. su - oracle -c \
  226. "echo -e \ \"#ORACLE_ENV\n\ export ORACLE_BASE=/u01/app/oracle\n\ export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1\n\ export ORACLE_SID=${db_name}\n\ export PATH=$PATH:$HOME/bin:/u01/app/oracle/product/11.2.0/db_1/bin\n\ export LD_LIBRARY_PATH=/u01/app/oracle/product/11.2.0/db_1/lib:/usr/lib\n\"\ >> ~/.bash_profile"
  227. fi
  228. su - oracle -c "source .bash_profile"
  229.  
  230.  
  231. echo -e "\n\n----------------install oralce and create database-------------------------------\n\n"
  232. unzip /$db_files1 -d /
  233. unzip /$db_files2 -d /
  234.  
  235. cp ./db_install.rsp ./tmp.rsp
  236. sed -i "s/sky2/${db_name}/g" ./tmp.rsp
  237. mv ./tmp.rsp /home/oracle/tmp.rsp
  238.  
  239.  
  240. chown oracle:oinstall /home/oracle/tmp.rsp
  241. chown -R oracle:oinstall /database
  242.  
  243.  
  244.  
  245. su - oracle -c "cd /database && ./runInstaller -waitforcompletion -silent -ignoreSysPrereqs -ignorePrereq -responseFile /home/oracle/tmp.rsp"
  246.  
  247.  
  248. /u01/app/oraInventory/orainstRoot.sh
  249. /u01/app/oracle/product/11.2.0/db_1/root.sh
  250.  
  251. echo -e "\n\n----------------create database-------------------------------\n\n"
  252.  
  253.  
  254. export db_name
  255. su - oracle -c "dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname $db_name -sid $db_name -responseFile NO_VALUE -characterSet AL32UTF8 \ -memoryPercentage 30 -emConfiguration LOCAL"
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263. echo -e "\n\n----------------netca-------------------------------\n\n"
  264. su - oracle -c "netca /silent /responsefile /database/response/netca.rsp "
  265.  
  266.  
  267.  
  268. echo -e "\n\n----------------sqlplus-------------------------------\n\n"
  269. grep "ORACLE_INSTALL_CONFIG" /u01/app/oracle/product/11.2.0/db_1/sqlplus/admin/glogin.sql > /dev/null
  270. if [ $? -eq 0 ]; then
  271. echo -e "sqlPLUS ORACLE_INSTALL_CONFIG SET\n"
  272. else
  273. echo -e "sqlPLUS ORACLE_INSTALL_CONFIG NOT SET\n"
  274. echo -e \
  275. "--ORACLE_INSTALL_CONFIG\n\ set linesize 160\n\ set pagesize 100\n\ set sqlprompt '_user@ _connect_identifier>'\n\ define _editor=vi\n\ \n"\
  276. >>/u01/app/oracle/product/11.2.0/db_1/sqlplus/admin/glogin.sql
  277. fi
  278.  
  279.  
  280. echo -e "\n\n----------------oralce installed successfully-------------------------------\n\n"
  281.  
  282.  
  283. exit 0

猜你在找的Oracle相关文章