飞道的博客

ORACLE一键安装单机11G/12C/18C/19C并建库脚本(shell)

877人阅读  评论(0)

废话不多说,直接上脚本:

--增加18c,19c RU补丁安装选项。

--增加linux7安装11g,自动替换 $(MK_EMAGENT_NMECTL) -lnnz11。

--增加卸载db选项。

--增加建库后crontab自动配置删归档和增量备份脚本。

--增加oracle数据库参数优化配置。

--增加swap空间判断,自动挂载缺少的swap空间。

touch AllOracleSilent.sh(:set fileformat=unix)


  
  1. #!/bin/bash
  2. echo "####################################################################################"
  3. echo "##Author : LuciferLiu"
  4. echo "##Blog : https://blog.csdn.net/m0_50546016"
  5. echo "##Version : 2.0"
  6. echo "##Function: Oracle 11g/12c/18c/19c install on Linux 6/7"
  7. echo "####################################################################################"
  8. echo "#执行脚本前:"
  9. echo "# 1. 把脚本放入软件目录,例如:/soft"
  10. echo "# 2. 挂载ISO"
  11. echo "# 3. 把需要本地安装的rpm和software上传到软件目录"
  12. echo "# 4. 设置好主机IP"
  13. echo "####################################################################################"
  14. ####################################################################################
  15. # Parameters For Install
  16. ####################################################################################
  17. PUBLICIP=
  18. HOSTNAME=orcl
  19. ORACLE_SID=orcl
  20. ISCDB=FALSE
  21. PDBNAME=pdb01
  22. SOFTWAREDIR=$( pwd)
  23. DAYTIME=$(date +%Y%m%d)
  24. DB_VERSION=
  25. RELS=$(more /etc/system-release)
  26. OS_VER_PRI=$( echo ${RELS#*release} | awk '{print $1}' | cut -f 1 -d '.')
  27. memTotal=$(grep MemTotal /proc/meminfo | awk '{print $2}')
  28. swapTotal=$(grep -i 'swaptotal' /proc/meminfo | awk '{print $2}')
  29. ORAPASSWD=oracle
  30. ENV_BASE_DIR=/u01/app
  31. ORADATADIR=/oradata
  32. ARCHIVEDIR=/archivelog
  33. BACKUPDIR=/backup
  34. SCRIPTSDIR=/home/oracle/scripts
  35. CHARACTERSET=AL32UTF8
  36. ONLYCONFIGOS=N
  37. ONLYINSTALLSOFTWARE=N
  38. REMOVEINSTANCE=
  39. REMOVEDBSOFTWARE=
  40. RU=
  41. ####################################################################################
  42. ####################################################################################
  43. ##The following is a custom function:
  44. ####################################################################################
  45. #Add colors to fonts through variables
  46. #Define a c1() function here, if you want to change the font color later, you can call it directly
  47. c1() {
  48. RED_COLOR= '\E[1;31m'
  49. GREEN_COLOR= '\E[1;32m'
  50. YELLOW_COLOR= '\E[1;33m'
  51. BLUE_COLOR= '\E[1;34m'
  52. PINK_COLOR= '\E[1;35m'
  53. WHITE_BLUE= '\E[47;34m'
  54. DOWN_BLUE= '\E[4;36m'
  55. FLASH_RED= '\E[5;31m'
  56. RES= '\E[0m'
  57. #Here it is judged whether the incoming parameters are not equal to 2, if not equal to 2, prompt and exit
  58. if [ $# -ne 2 ]; then
  59. echo "Usage $0 content {red|yellow|blue|green|pink|wb|db|fr}"
  60. exit
  61. fi
  62. case "$2" in
  63. red | RED)
  64. echo -e "${RED_COLOR}$1${RES}"
  65. ;;
  66. yellow | YELLOW)
  67. echo -e "${YELLOW_COLOR}$1${RES}"
  68. ;;
  69. green | GREEN)
  70. echo -e "${GREEN_COLOR}$1${RES}"
  71. ;;
  72. blue | BLUE)
  73. echo -e "${BLUE_COLOR}$1${RES}"
  74. ;;
  75. pink | PINK)
  76. echo -e "${PINK_COLOR}$1${RES}"
  77. ;;
  78. wb | WB)
  79. echo -e "${WHITE_BLUE}$1${RES}"
  80. ;;
  81. db | DB)
  82. echo -e "${DOWN_BLUE}$1${RES}"
  83. ;;
  84. fr | FR)
  85. echo -e "${FLASH_RED}$1${RES}"
  86. ;;
  87. *)
  88. echo -e "Please enter the specified color code:{red|yellow|blue|green|pink|wb|db|fr}"
  89. ;;
  90. esac
  91. }
  92. ##Example
  93. ##c1 "Program installation error!" red
  94. ##c1 "The program is successfully installed!" green
  95. ##c1 "Output related annotation information" blue
  96. help() {
  97. c1 "Desc: For ALL Oracle Silent Install" green
  98. echo
  99. c1 "Usage: AllOracleSilent [OPTIONS] OBJECT { COMMAND | help }" green
  100. echo
  101. c1 "Excute: " green
  102. c1 "1.chmod 777 AllOracleSilent.sh" green
  103. echo
  104. c1 "2.How to Excute the script:" green
  105. c1 "./AllOracleSilent.sh -i 192.168.56.120 -d 11g" blue
  106. c1 "or" green
  107. c1 "./AllOracleSilent.sh -i 192.168.56.120 -n orcl -o orcl -c TRUE -pb pdb01 -d 12c -p oracle -b /u01/app -s AL32UTF8 -m N -w N" blue
  108. echo
  109. c1 "3.How to Remove Instance:" green
  110. c1 "./AllOracleSilent.sh -ri orcl" blue
  111. echo
  112. c1 "4.How to Remove Database Software:" green
  113. c1 "./AllOracleSilent.sh -rd /u01/app/oracle/product/19.0.0/db" blue
  114. echo
  115. c1 "OPTIONS: " green
  116. c1 "-i, --PUBLICIP PUBLICIP NETWORK ADDRESS" green
  117. c1 "-n, --HOSTNAME HOSTNAME(orcl)" green
  118. c1 "-o, --ORACLE_SID ORACLE_SID(orcl)" green
  119. c1 "-c, --ISCDB IS CDB OR NOT(TRUE|FALSE)" green
  120. c1 "-pb, --PDBNAME PDBNAME(pdb01)" green
  121. c1 "-d, --DB_VERSION ORALCE DATABASE VERSION(11g|12c|18c|19c)" green
  122. c1 "-p, --ORAPASSWD ORACLE USER PASSWORD(oracle)" green
  123. c1 "-b, --ENV_BASE_DIR ORACLE BASE DIR(/u01/app)" green
  124. c1 "-s, --CHARACTERSET ORACLE CHARACTERSET(ZHS16GBK|AL32UTF8)" green
  125. c1 "-m, --ONLYCONFIGOS ONLY CONFIG SYSTEM PARAMETER(Y|N)" green
  126. c1 "-w, --ONLYINSTALLSOFTWARE ONLY INSTALL ORACLE SOFTWARE(Y|N)" green
  127. c1 "-ri, --REMOVEINSTANCE REMOVE ORACLE INSTANCE(orcl)" green
  128. c1 "-rd, --REMOVEDBSOFTWARE REMOVE ORACLE SOFTWARE(/u01/app/oracle/product/11.2.0/db)" green
  129. c1 "-ru, --RELEASE UPDATE DATABASE RELEASE UPDATE(32072711)" green
  130. exit 0
  131. }
  132. echo
  133. while [ -n "$1" ]; do #Here by judging whether $1 exists
  134. case $1 in
  135. -i | --PUBLICIP)
  136. PUBLICIP= $2 #$2 Is the parameter we want to output
  137. shift 2
  138. ;; # Move the parameter back by 2 and enter the judgment of the next parameter
  139. -n | --HOSTNAME)
  140. HOSTNAME= $2
  141. shift 2
  142. ;;
  143. -o | --ORACLE_SID)
  144. ORACLE_SID= $2
  145. shift 2
  146. ;;
  147. -c | --ISCDB)
  148. ISCDB= $2
  149. shift 2
  150. ;;
  151. -pb | --PDBNAME)
  152. PDBNAME= $2
  153. shift 2
  154. ;;
  155. -d | --DB_VERSION)
  156. DB_VERSION= $2
  157. shift 2
  158. ;;
  159. -p | --ORAPASSWD)
  160. ORAPASSWD= $2
  161. shift 2
  162. ;;
  163. -b | --ENV_BASE_DIR)
  164. ENV_BASE_DIR= $2
  165. shift 2
  166. ;;
  167. -s | --CHARACTERSET)
  168. CHARACTERSET= $2
  169. shift 2
  170. ;;
  171. -m | --ONLYCONFIGOS)
  172. ONLYCONFIGOS= $2
  173. shift 2
  174. ;;
  175. -w | --ONLYINSTALLSOFTWARE)
  176. ONLYINSTALLSOFTWARE= $2
  177. shift 2
  178. ;;
  179. -ri | --REMOVEINSTANCE)
  180. REMOVEINSTANCE= $2
  181. shift 2
  182. ;;
  183. -rd | --REMOVEDBSOFTWARE)
  184. REMOVEDBSOFTWARE= $2
  185. shift 2
  186. ;;
  187. -ru | --RU)
  188. RU= $2
  189. shift 2
  190. ;;
  191. -h | -- help) help ;; # function help is called
  192. --)
  193. shift
  194. break
  195. ;; # end of options
  196. -*)
  197. echo "Error: Option '$1' is unknown, try './AllOracleSilent.sh --help'."
  198. exit 1
  199. ;;
  200. *) break ;;
  201. esac
  202. done
  203. ##check Swap
  204. COUNT=
  205. if [ $memTotal -ge 1048576 ] && [ $memTotal -le 2097152 ]; then
  206. swapNeed=$(expr $memTotal \* 1.5)
  207. if [ $swapNeed -gt $swapTotal ]; then
  208. COUNT=$(expr $swapNeed - $swapTotal)
  209. fi
  210. elif [ $memTotal -gt 2097152 ] && [ $memTotal -le 16777216 ]; then
  211. swapNeed= $memTotal
  212. if [ $swapNeed -gt $swapTotal ]; then
  213. COUNT=$(expr $swapNeed - $swapTotal)
  214. fi
  215. elif [ $memTotal -gt 16777216 ]; then
  216. swapNeed=16777216
  217. if [ $swapNeed -gt $swapTotal ]; then
  218. COUNT=$(expr $swapNeed - $swapTotal)
  219. fi
  220. else
  221. echo
  222. c1 "At least 1 GB RAM for Oracle Database installations. 2 GB RAM recommended." red
  223. exit 99
  224. fi
  225. ##set swap space
  226. if [ -n ${COUNT} ] && [ ! -f /swapfile ] && [ ${COUNT} > 40 ]; then
  227. dd if=/dev/zero of=/swapfile bs=1K count= ${COUNT}
  228. mkswap /swapfile
  229. swapon /swapfile
  230. echo "/swapfile swap swap defaults 0 0" >>/etc/fstab
  231. fi
  232. ##Judge whether user is root, if it is not, exit
  233. if [ $USER != "root" ]; then
  234. echo
  235. c1 "The user must be root,and now you user is $USER,please su to root." red
  236. exit 1
  237. fi
  238. ##Judge whether ip or dbversion is empty, if it is empty, exit
  239. if [ -z "${REMOVEINSTANCE}" ] && [ -z "${REMOVEDBSOFTWARE}" ]; then
  240. if [ -z "${PUBLICIP}" ] || [ -z "${DB_VERSION}" ]; then
  241. echo
  242. c1 "PUBLICIP and DB_VERSION is a required parameter, try'./AllOracleSilent.sh --help' to execute the script" red
  243. echo
  244. exit
  245. fi
  246. ####################################################################################
  247. # ORACLE SID
  248. ####################################################################################
  249. if [ -f /home/oracle/.bash_profile ] && [ $(egrep "#OraConfBegin" /home/oracle/.bash_profile | wc -l) -ne 0 ]; then
  250. oracleSid=$(grep "ORACLE_SID=" /home/oracle/.bash_profile | awk '{print $2}')
  251. oracleSid=$( echo ${oracleSid#*=})
  252. oracleHostname=$(grep "ORACLE_HOSTNAME=" /home/oracle/.bash_profile | awk '{print $2}')
  253. oracleHostname=$( echo ${oracleHostname#*=})
  254. oracleBase=$(grep "ORACLE_BASE=" /home/oracle/.bash_profile | awk '{print $2}')
  255. oracleBase=$( echo ${oracleBase#*=})
  256. oracleHome=$(grep "ORACLE_HOME=" /home/oracle/.bash_profile | awk '{print $2}')
  257. oracleHome=$( echo ${oracleHome#*=})
  258. fi
  259. if [ -f /etc/oratab ] && [ $(egrep "${ORACLE_SID}" /etc/oratab | wc -l) -ne 0 ]; then
  260. if [ "${oracleSid}" = "${ORACLE_SID}" ]; then
  261. echo
  262. c1 "ORACLE_SID:${oracleSid}" blue
  263. echo
  264. c1 "Specified SID Name (${oracleSid}) already exists, Specify a different SID Name that does not already exist OR :" red
  265. echo
  266. c1 "./AllOracleSilent -ri ${oracleSid} to remove it" blue
  267. echo
  268. exit 99
  269. fi
  270. fi
  271. fi
  272. ####################################################################################
  273. ## Remove Instance && database
  274. ####################################################################################
  275. ##Judge whether OracleSID is empty, if it is empty ,exit
  276. REMOVEINSTANCE() {
  277. su - oracle -c "dbca -silent -deleteDatabase -sourceDB ${REMOVEINSTANCE}"
  278. if [ $? -ne 0 ]; then
  279. c1 "You need to install Oracle Database Software First." red
  280. oracleHOme=$(grep "ORACLE_HOME=" /home/oracle/.bash_profile | awk '{print $2}')
  281. oracleHOme=$( echo ${oracleHOme#*=})
  282. rm -rf ${oracleHOme}
  283. exit 99
  284. fi
  285. exit 99
  286. }
  287. ##Judge whether OracleHome is empty, if it is empty ,exit
  288. REMOVEDBSOFTWARE() {
  289. if [ ! -d "${REMOVEDBSOFTWARE}" ]; then
  290. c1 "What You Input OracleHome (${REMOVEDBSOFTWARE}) is not exist, exit" red
  291. exit 99
  292. else
  293. su - oracle -c "${REMOVEDBSOFTWARE}/deinstall/deinstall -local -o ${REMOVEDBSOFTWARE}"
  294. if [ $? -ne 0 ]; then
  295. c1 "You need to install Oracle Database Software First." red
  296. rm -rf ${REMOVEDBSOFTWARE}
  297. fi
  298. rm -rf /etc/oraInst.loc
  299. rm -rf /opt/ORCLfmap
  300. rm -rf /etc/oratab
  301. exit 99
  302. fi
  303. }
  304. ####################################################################################
  305. ## Log Write
  306. ####################################################################################
  307. rm -rf ${SOFTWAREDIR}/oracleAllSilent_*. log
  308. oracl19clog= ${SOFTWAREDIR}/oracleAllSilent_$(date + "20%y%m%d%H%M%S"). log
  309. logwrite() {
  310. echo $(c1 "####################################################################################" green) >> ${oracl19clog}
  311. echo $( echo) >> ${oracl19clog}
  312. echo $(c1 "# $1" blue) >> ${oracl19clog}
  313. echo $( echo) >> ${oracl19clog}
  314. echo $(c1 "####################################################################################" green) >> ${oracl19clog}
  315. echo $( echo) >> ${oracl19clog}
  316. echo "$1 :" >> ${oracl19clog}
  317. echo $( echo) >> ${oracl19clog}
  318. echo "$2" > ${SOFTWAREDIR}/ex.sh
  319. chmod +x ${SOFTWAREDIR}/ex.sh
  320. echo "$(${SOFTWAREDIR}/ex.sh)" >> ${oracl19clog}
  321. rm -rf ${SOFTWAREDIR}/ex.sh
  322. echo $( echo) >> ${oracl19clog}
  323. }
  324. ##Example
  325. ##logwrite "HostName" "hostname"
  326. ##logwrite "Firewalld" "systemctl status firewalld"
  327. echo $(c1 "####################################################################################" green) >> ${oracl19clog}
  328. echo $( echo) >> ${oracl19clog}
  329. echo $(c1 "# Installation Logging" wb) >> ${oracl19clog}
  330. echo $( echo) >> ${oracl19clog}
  331. echo $(c1 "####################################################################################" green) >> ${oracl19clog}
  332. echo $( echo) >> ${oracl19clog}
  333. echo $( echo) >> ${oracl19clog}
  334. ####################################################################################
  335. # OS Version
  336. ####################################################################################
  337. if [ $OS_VER_PRI -eq 7 ]; then
  338. OS_VERSION=linux7
  339. elif [ $OS_VER_PRI -eq 6 ]; then
  340. OS_VERSION=linux6
  341. else
  342. c1 "sorry, this operating system is not supported!!!" red
  343. exit
  344. fi
  345. logwrite "OS Version" "more /etc/system-release"
  346. ####################################################################################
  347. # Choice DB Version
  348. ####################################################################################
  349. if [[ -z "${DB_VERSION}" ]] || [[ "${DB_VERSION}" = "19c" ]] || [[ "${DB_VERSION}" = "19C" ]] || [[ "${DB_VERSION}" = "19" ]]; then
  350. DB_VERSION=19.3.0.0
  351. elif [[ "${DB_VERSION}" = "18c" ]] || [[ "${DB_VERSION}" = "18C" ]] || [[ "${DB_VERSION}" = "18" ]]; then
  352. DB_VERSION=18.0.0.0
  353. elif [[ "${DB_VERSION}" = "12c" ]] || [[ "${DB_VERSION}" = "12C" ]] || [[ "${DB_VERSION}" = "12" ]]; then
  354. DB_VERSION=12.2.0.1
  355. elif [[ "${DB_VERSION}" = "11g" ]] || [[ "${DB_VERSION}" = "11G" ]] || [[ "${DB_VERSION}" = "11" ]]; then
  356. DB_VERSION=11.2.0.4
  357. else
  358. c1 "DB version is a required parameter!!! Try'./AllOracleSilent.sh --help' to execute the script" red
  359. exit
  360. fi
  361. logwrite "DB Version" "echo ${DB_VERSION}"
  362. ####################################################################################
  363. # Choice DB HOME
  364. ####################################################################################
  365. ENV_ORACLE_BASE= $ENV_BASE_DIR/oracle
  366. ENV_ORACLE_INVEN= $ENV_BASE_DIR/oraInventory
  367. if [ "${DB_VERSION}" = "11.2.0.4" ]; then
  368. ENV_ORACLE_HOME= $ENV_ORACLE_BASE/product/11.2.0/db
  369. elif [ "${DB_VERSION}" = "12.2.0.1" ]; then
  370. ENV_ORACLE_HOME= $ENV_ORACLE_BASE/product/12.2.0/db
  371. elif [ "${DB_VERSION}" = "18.0.0.0" ]; then
  372. ENV_ORACLE_HOME= $ENV_ORACLE_BASE/product/18.0.0/db
  373. elif [ "${DB_VERSION}" = "19.3.0.0" ]; then
  374. ENV_ORACLE_HOME= $ENV_ORACLE_BASE/product/19.3.0/db
  375. else
  376. c1 "Error database version! please check again!" red
  377. exit
  378. fi
  379. if [ -z "${REMOVEINSTANCE}" ] && [ -z "${REMOVEDBSOFTWARE}" ]; then
  380. if [[ -d ${ENV_ORACLE_HOME} ]] && [[ "$(ls -A ${ENV_ORACLE_HOME})" != "" ]]; then
  381. c1 "ORACLE_HOME is not empty.Try ./AllOracleSilent -rd ${ENV_ORACLE_HOME} to remove it" red
  382. exit 99
  383. fi
  384. fi
  385. logwrite "DB HOME" "echo ${ENV_ORACLE_HOME}"
  386. ####################################################################################
  387. # Configure hostname
  388. ####################################################################################
  389. SetHostName() {
  390. if [ "${OS_VERSION}" = "linux6" ]; then
  391. hostname=$(egrep "HOSTNAME=" /etc/sysconfig/network)
  392. if [[ $(egrep "${HOSTNAME}" /etc/sysconfig/network) != "${HOSTNAME}" ]]; then
  393. /bin/hostname $HOSTNAME
  394. sed -i "s/${hostname}/HOSTNAME=${HOSTNAME}/" /etc/sysconfig/network
  395. fi
  396. elif [ "${OS_VERSION}" = "linux7" ]; then
  397. if [[ $(egrep "${HOSTNAME}" /etc/hostname) != "${HOSTNAME}" ]]; then
  398. /usr/bin/hostnamectl set-hostname $HOSTNAME
  399. fi
  400. fi
  401. }
  402. logwrite "HOSTNAME" "echo ${HOSTNAME}"
  403. ####################################################################################
  404. # Configure /etc/hosts
  405. ####################################################################################
  406. SetHosts() {
  407. if [[ $(egrep "${HOSTNAME}" /etc/hosts) != "${HOSTNAME}" ]] || [[ $(egrep "${PUBLICIP}" /etc/hosts) != "${PUBLICIP}" ]]; then
  408. [ ! -f /etc/hosts. ${DAYTIME} ] && cp /etc/hosts /etc/hosts. ${DAYTIME}
  409. cat <<EOF >/etc/hosts
  410. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  411. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  412. #Public IP
  413. $PUBLICIP $HOSTNAME
  414. EOF
  415. fi
  416. }
  417. logwrite "/etc/hosts" "su -c \"cat /etc/hosts\""
  418. ####################################################################################
  419. #install rpm that oracle is necessary for installing
  420. ####################################################################################
  421. InstallRPM() {
  422. ####################################################################################
  423. # Judge ISO file mount status
  424. ####################################################################################
  425. mountPatch=$(mount | egrep "iso|ISO" | awk '{print $3}')
  426. if [ ! "${mountPatch}" ]; then
  427. echo
  428. c1 "The ISO file is not mounted on system." red
  429. exit 99
  430. else
  431. if [ $(egrep "#OraConfBegin" /etc/yum.repos.d/local.repo | wc -l) -eq 0 ]; then
  432. [ ! -f /etc/yum.repos.d/local.repo. ${DAYTIME} ] && cp /etc/yum.repos.d/local.repo /etc/yum.repos.d/local.repo. ${DAYTIME}
  433. echo "#OraConfBegin" >>/etc/yum.repos.d/local.repo
  434. echo "[server]" >>/etc/yum.repos.d/local.repo
  435. echo "name=server" >>/etc/yum.repos.d/local.repo
  436. echo "baseurl=file://" ${mountPatch} >>/etc/yum.repos.d/local.repo
  437. echo "enabled=1" >>/etc/yum.repos.d/local.repo
  438. echo "gpgcheck=1" >>/etc/yum.repos.d/local.repo
  439. rpm --import ${mountPatch}/RPM-GPG-KEY-redhat-release
  440. fi
  441. if [ "${OS_VERSION}" = "linux6" ]; then
  442. if [ $(rpm -q bc binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ elfutils-libelf elfutils-libelf-devel glibc glibc-devel libaio libaio-devel libgcc libstdc++ libstdc++-devel libxcb libX11 libXau libXi libXrender make net-tools smartmontools sysstat e2fsprogs e2fsprogs-libs expect unzip openssh-clients readline psmisc --qf '%{name}.%{arch}\n' | grep "not installed" | wc -l) -gt 0 ]; then
  443. yum install -y bc binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ elfutils-libelf elfutils-libelf-devel glibc glibc-devel libaio libaio-devel libgcc libstdc++ libstdc++-devel libxcb libX11 libXau libXi libXrender make net-tools smartmontools sysstat e2fsprogs e2fsprogs-libs expect unzip openssh-clients readline* psmisc
  444. fi
  445. elif [ "${OS_VERSION}" = "linux7" ]; then
  446. if [ $(rpm -q bc binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ elfutils-libelf elfutils-libelf-devel glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libxcb libX11 libXau libXi libXtst libXrender libXrender-devel make net-tools nfs-utils smartmontools sysstat e2fsprogs e2fsprogs-libs fontconfig-devel expect unzip openssh-clients readline psmisc --qf '%{name}.%{arch}\n' | grep "not installed" | wc -l) -gt 0 ]; then
  447. yum install -y bc binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ elfutils-libelf elfutils-libelf-devel glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libxcb libX11 libXau libXi libXtst libXrender libXrender-devel make net-tools nfs-utils smartmontools sysstat e2fsprogs e2fsprogs-libs fontconfig-devel expect unzip openssh-clients readline* psmisc
  448. fi
  449. fi
  450. fi
  451. if [ "${OS_VERSION}" = "linux6" ]; then
  452. logwrite "RPM Check" "rpm -q bc binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ elfutils-libelf elfutils-libelf-devel glibc glibc-devel libaio libaio-devel libgcc libstdc++ libstdc++-devel libxcb libX11 libXau libXi libXrender make net-tools smartmontools sysstat e2fsprogs e2fsprogs-libs expect unzip openssh-clients readline"
  453. elif [ "${OS_VERSION}" = "linux7" ]; then
  454. logwrite "RPM Check" "rpm -q bc binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ elfutils-libelf elfutils-libelf-devel glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libxcb libX11 libXau libXi libXtst libXrender libXrender-devel make net-tools nfs-utils smartmontools sysstat e2fsprogs e2fsprogs-libs fontconfig-devel expect unzip openssh-clients readline"
  455. fi
  456. }
  457. ####################################################################################
  458. # create user and groups
  459. ####################################################################################
  460. CreateUsersAndDirs() {
  461. ####################################################################################
  462. # create user and groups
  463. ####################################################################################
  464. if [ $(egrep "oinstall" /etc/group | wc -l) -eq 0 ]; then
  465. /usr/sbin/groupadd -g 54321 oinstall
  466. fi
  467. if [ $(egrep "dba" /etc/group | wc -l) -eq 0 ]; then
  468. /usr/sbin/groupadd -g 54322 dba
  469. fi
  470. if [ $(egrep "oper" /etc/group | wc -l) -eq 0 ]; then
  471. /usr/sbin/groupadd -g 54323 oper
  472. fi
  473. if [[ "${DB_VERSION}" = "19.3.0.0" ]] || [[ "${DB_VERSION}" = "18.0.0.0" ]] || [[ "${DB_VERSION}" = "12.2.0.1" ]]; then
  474. if [ $(egrep "backupdba" /etc/group | wc -l) -eq 0 ]; then
  475. /usr/sbin/groupadd -g 54324 backupdba
  476. fi
  477. if [ $(egrep "dgdba" /etc/group | wc -l) -eq 0 ]; then
  478. /usr/sbin/groupadd -g 54325 dgdba
  479. fi
  480. if [ $(egrep "kmdba" /etc/group | wc -l) -eq 0 ]; then
  481. /usr/sbin/groupadd -g 54326 kmdba
  482. fi
  483. if [ $(egrep "racdba" /etc/group | wc -l) -eq 0 ]; then
  484. /usr/sbin/groupadd -g 54330 racdba
  485. fi
  486. fi
  487. ##Create user
  488. if [ $(egrep "oracle" /etc/passwd | wc -l) -eq 0 ]; then
  489. if [[ "${DB_VERSION}" = "19.3.0.0" ]] || [[ "${DB_VERSION}" = "18.0.0.0" ]] || [[ "${DB_VERSION}" = "12.2.0.1" ]]; then
  490. /usr/sbin/useradd -u 54321 -g oinstall -G dba,backupdba,dgdba,kmdba,racdba,oper oracle
  491. elif [ "${DB_VERSION}" = "11.2.0.4" ]; then
  492. /usr/sbin/useradd -u 54321 -g oinstall -G dba,oper oracle
  493. fi
  494. if [ $? -ne 0 ]; then
  495. echo "Command failed to adding user --oracle."
  496. exit 93
  497. fi
  498. else
  499. if [[ "${DB_VERSION}" = "19.3.0.0" ]] || [[ "${DB_VERSION}" = "18.0.0.0" ]] || [[ "${DB_VERSION}" = "12.2.0.1" ]]; then
  500. /usr/sbin/usermod -g oinstall -G dba,backupdba,dgdba,kmdba,racdba,oper oracle
  501. elif [ "${DB_VERSION}" = "11.2.0.4" ]; then
  502. /usr/sbin/usermod -g oinstall -G dba,oper oracle
  503. fi
  504. fi
  505. ##Set user oracle's password
  506. echo "${ORAPASSWD}" | passwd --stdin oracle
  507. if [ $? -ne 0 ]; then
  508. c1 "User oracle is not existing." red
  509. exit 92
  510. fi
  511. ####################################################################################
  512. #make directory
  513. ####################################################################################
  514. [ ! -d "${ENV_ORACLE_HOME}" ] && mkdir -p ${ENV_ORACLE_HOME}
  515. [ ! -d "${ENV_ORACLE_INVEN}" ] && mkdir -p ${ENV_ORACLE_INVEN}
  516. [ ! -d ${ORADATADIR} ] && mkdir -p ${ORADATADIR}
  517. [ ! -d ${ARCHIVEDIR} ] && mkdir -p ${ARCHIVEDIR}
  518. [ ! -d ${BACKUPDIR} ] && mkdir -p ${BACKUPDIR}
  519. [ ! -d ${SCRIPTSDIR} ] && mkdir -p ${SCRIPTSDIR}
  520. chown -R oracle:oinstall ${SCRIPTSDIR}
  521. chown -R oracle:oinstall ${ORADATADIR}
  522. chown -R oracle:oinstall ${ARCHIVEDIR}
  523. chown -R oracle:oinstall ${BACKUPDIR}
  524. chown -R oracle:oinstall ${ENV_BASE_DIR}
  525. chmod -R 775 ${ENV_BASE_DIR}
  526. if [ "${DB_VERSION}" = "12.2.0.1" ]; then
  527. touch /etc/oraInst.loc
  528. echo "inventory_loc=${ENV_ORACLE_INVEN}" >>/etc/oraInst.loc
  529. echo "inst_group=oinstall" >>/etc/oraInst.loc
  530. fi
  531. logwrite "Create user and groups" "id oracle"
  532. }
  533. ####################################################################################
  534. #Time dependent Settings
  535. ####################################################################################
  536. TimeDepSet() {
  537. if [ "${OS_VERSION}" = "linux6" ]; then
  538. if [ $(egrep "Asia/Shanghai" /etc/sysconfig/clock | wc -l) -eq 0 ]; then
  539. [ ! -f /etc/sysconfig/clock. ${DAYTIME} ] && cp /etc/sysconfig/clock /etc/sysconfig/clock. ${DAYTIME}
  540. cat <<EOF >/etc/sysconfig/clock
  541. ZONE= "Asia/Shanghai"
  542. EOF
  543. fi
  544. if [ $(chkconfig --list | grep ntpd | grep on | wc -l) -gt 0 ]; then
  545. service ntpd stop
  546. chkconfig ntpd off
  547. fi
  548. logwrite "ntpd" "service ntpd status"
  549. [ -f /etc/ntp.conf ] && mv /etc/ntp.conf /etc/ntp.conf.orig
  550. elif [ "${OS_VERSION}" = "linux7" ]; then
  551. timedatectl set-timezone Asia/Shanghai
  552. if [ $(systemctl status chronyd | grep running | wc -l) -gt 0 ]; then
  553. systemctl stop chronyd.service
  554. systemctl disable chronyd.service
  555. fi
  556. logwrite "chronyd" "systemctl status chronyd"
  557. fi
  558. logwrite "Time dependent" "date"
  559. }
  560. ####################################################################################
  561. #Stop avahi deamon
  562. ####################################################################################
  563. Disableavahi() {
  564. if [ "${OS_VERSION}" = "linux6" ]; then
  565. if [ $(chkconfig --list | grep avahi-daemon | grep '3:on' | wc -l) -gt 0 ]; then
  566. service avahi-daemon stop
  567. chkconfig avahi-daemon off
  568. fi
  569. logwrite "avahi-daemon" "service avahi-daemon status"
  570. elif [ "${OS_VERSION}" = "linux7" ]; then
  571. if [ $(systemctl status avahi-daemon | grep running | wc -l) -gt 0 ]; then
  572. systemctl stop avahi-daemon.socket
  573. systemctl disable avahi-daemon.socket
  574. systemctl stop avahi-daemon.service
  575. systemctl disable avahi-daemon.service
  576. ps -ef | grep avahi-daemon | egrep -v "grep" | awk '{print "kill -9 "$2}'
  577. fi
  578. logwrite "avahi-daemon" "systemctl status avahi-daemon"
  579. fi
  580. }
  581. ####################################################################################
  582. # Stop firefall
  583. ####################################################################################
  584. DisableFirewall() {
  585. if [ "${OS_VERSION}" = "linux6" ]; then
  586. if [ $(chkconfig --list | grep tables | grep on | wc -l) -gt 0 ]; then
  587. service iptables stop
  588. chkconfig iptables off
  589. service ip6tables stop
  590. chkconfig ip6tables off
  591. fi
  592. logwrite "Iptables" "service iptables status"
  593. elif [ "${OS_VERSION}" = "linux7" ]; then
  594. if [ $(systemctl status firewalld.service | grep running | wc -l) -gt 0 ]; then
  595. systemctl stop firewalld.service
  596. systemctl disable firewalld.service
  597. fi
  598. logwrite "Firewalld" "systemctl status firewalld"
  599. fi
  600. }
  601. ####################################################################################
  602. # Disable Selinux
  603. ####################################################################################
  604. DisableSelinux() {
  605. if [ "$(/usr/sbin/getenforce)" != "Disabled" ]; then
  606. /usr/sbin/setenforce 0
  607. fi
  608. if [ ! -z $(grep "SELINUX=enforcing" /etc/selinux/config) ]; then
  609. [ ! -f /etc/selinux/config. ${DAYTIME} ] && cp /etc/selinux/config /etc/selinux/config. ${DAYTIME}
  610. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  611. fi
  612. logwrite "SELINUX" "getenforce"
  613. }
  614. ####################################################################################
  615. # Disable transparent_hugepages&&numa
  616. ####################################################################################
  617. DisableTHPAndNUMA() {
  618. if [ "${OS_VERSION}" = "linux6" ]; then
  619. if [ $(egrep "/sys/kernel/mm/transparent_hugepage/enabled" /etc/rc.d/rc.local | wc -l) -eq 0 ]; then
  620. cat >>/etc/rc.d/rc.local <<EOF
  621. if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
  622. echo never > /sys/kernel/mm/transparent_hugepage/enabled
  623. fi
  624. if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
  625. echo never > /sys/kernel/mm/transparent_hugepage/defrag
  626. fi
  627. EOF
  628. fi
  629. if [ $(egrep "numa=off" /boot/grub/grub.conf | wc -l) -eq 0 ]; then
  630. [ ! -f /boot/grub/grub.conf. ${DAYTIME} ] && cp /boot/grub/grub.conf /boot/grub/grub.conf. ${DAYTIME}
  631. sed -i 's/quiet/quiet numa=off/' /boot/grub/grub.conf
  632. fi
  633. logwrite "/boot/grub/grub.conf" "cat /boot/grub/grub.conf"
  634. elif [ "${OS_VERSION}" = "linux7" ]; then
  635. if [ $(egrep "transparent_hugepage=never numa=off" /etc/default/grub | wc -l) -eq 0 ]; then
  636. [ ! -f /etc/default/grub. ${DAYTIME} ] && cp /etc/default/grub /etc/default/grub. ${DAYTIME}
  637. sed -i 's/quiet/quiet transparent_hugepage=never numa=off/' /etc/default/grub
  638. grub2-mkconfig -o /boot/grub2/grub.cfg
  639. fi
  640. logwrite "/etc/default/grub" "cat /etc/default/grub"
  641. fi
  642. logwrite "Transparent_hugepages" "cat /sys/kernel/mm/transparent_hugepage/enabled"
  643. logwrite "NUMA" "cat /proc/cmdline"
  644. }
  645. ####################################################################################
  646. # Disable NetworkManager
  647. ####################################################################################
  648. DisableNetworkManager() {
  649. if [ "${OS_VERSION}" = "linux6" ]; then
  650. if [ $(chkconfig --list | grep NetworkManager | grep on | wc -l) -gt 0 ]; then
  651. service NetworkManager stop
  652. chkconfig NetworkManager off
  653. service NetworkManager off
  654. fi
  655. logwrite "NetworkManager" "service NetworkManager status"
  656. elif [ "${OS_VERSION}" = "linux7" ]; then
  657. #Turn off the NetworkManager(Linux 7)
  658. if [ $(systemctl status NetworkManager.service | grep running | wc -l) -gt 0 ]; then
  659. systemctl stop NetworkManager.service
  660. systemctl disable NetworkManager.service
  661. fi
  662. logwrite "NetworkManager" "systemctl status NetworkManager"
  663. fi
  664. }
  665. EditParaFiles() {
  666. ####################################################################################
  667. # Edit sysctl.conf
  668. ####################################################################################
  669. ##shmmal's Calculation formula: physical memory 8G:(8*1024*1024*1024)/4096=2097152
  670. ##shmmax's Calculation formula: physical memory 8G:(8/2)*1024*1024*1024 -1=4294967295
  671. totalMemory=$(expr $memTotal / 2048)
  672. shmall=$(expr $memTotal / 4)
  673. if [ $shmall -lt 2097152 ]; then
  674. shmall=2097152
  675. fi
  676. shmmax=$(expr $memTotal \* 1024 - 1)
  677. if [ $shmmax -lt 4294967295 ]; then
  678. shmmax=4294967295
  679. fi
  680. if [ "${OS_VERSION}" = "linux6" ]; then
  681. if [ $(egrep "#OraConfBegin" /etc/sysctl.conf | wc -l) -eq 0 ]; then
  682. [ ! -f /etc/sysctl.conf. ${DAYTIME} ] && cp /etc/sysctl.conf /etc/sysctl.conf. ${DAYTIME}
  683. cat <<EOF >>/etc/sysctl.conf
  684. #OraConfBegin
  685. ##shmmal's Calculation formula: physical memory 8G:(8*1024*1024*1024)/4096=2097152
  686. ##shmmax's Calculation formula: physical memory 8G:(8/2)*1024*1024*1024 -1=4294967295
  687. fs.aio-max-nr = 1048576
  688. fs.file-max = 6815744
  689. kernel.shmall = $shmall
  690. kernel.shmmax = $shmmax
  691. kernel.shmmni = 4096
  692. kernel.sem = 250 32000 100 128
  693. net.ipv4.ip_local_port_range = 9000 65500
  694. net.core.rmem_default = 262144
  695. net.core.rmem_max = 4194304
  696. net.core.wmem_default = 262144
  697. net.core.wmem_max = 1048576
  698. #OraConfEnd
  699. EOF
  700. sysctl -p
  701. logwrite "/etc/sysctl.conf" "sysctl -p"
  702. fi
  703. elif [ "${OS_VERSION}" = "linux7" ]; then
  704. if [ ! -f /etc/sysctl.d/97-oracledatabase-sysctl.conf ]; then
  705. echo "##For oracle" >>/etc/sysctl.d/97-oracledatabase-sysctl.conf
  706. fi
  707. if [ $(egrep "#OraConfBegin" /etc/sysctl.d/97-oracledatabase-sysctl.conf | wc -l) -eq 0 ]; then
  708. [ ! -f /etc/sysctl.d/97-oracledatabase-sysctl.conf. ${DAYTIME} ] && cp /etc/sysctl.d/97-oracledatabase-sysctl.conf /etc/sysctl.d/97-oracledatabase-sysctl.conf. ${DAYTIME}
  709. cat <<EOF >>/etc/sysctl.d/97-oracledatabase-sysctl.conf
  710. #OraConfBegin
  711. ##shmmal's Calculation formula: physical memory 8G:(8*1024*1024*1024)/4096=2097152
  712. ##shmmax's Calculation formula: physical memory 8G:(8/2)*1024*1024*1024 -1=4294967295
  713. fs.aio-max-nr = 1048576
  714. fs.file-max = 6815744
  715. kernel.shmall = $shmall
  716. kernel.shmmax = $shmmax
  717. kernel.shmmni = 4096
  718. kernel.sem = 250 32000 100 128
  719. net.ipv4.ip_local_port_range = 9000 65500
  720. net.core.rmem_default = 262144
  721. net.core.rmem_max = 4194304
  722. net.core.wmem_default = 262144
  723. net.core.wmem_max = 1048576
  724. #OraConfEnd
  725. EOF
  726. /sbin/sysctl --system
  727. logwrite "/etc/sysctl.d/97-oracledatabase-sysctl.conf" "/sbin/sysctl --system"
  728. fi
  729. fi
  730. ####################################################################################
  731. # Edit nsysctl.conf
  732. ####################################################################################
  733. if [ $(egrep "#OraConfBegin" /etc/sysconfig/network | wc -l) -eq 0 ]; then
  734. [ ! -f /etc/sysconfig/network. ${DAYTIME} ] && cp /etc/sysconfig/network /etc/sysconfig/network. ${DAYTIME}
  735. echo "#OraConfBegin" >>/etc/sysconfig/network
  736. echo "NOZEROCONF=yes" >>/etc/sysconfig/network
  737. echo "#OraConfEnd" >>/etc/sysconfig/network
  738. fi
  739. logwrite "NOZEROCONF" "cat /etc/sysconfig/network"
  740. ####################################################################################
  741. # Edit limits.conf
  742. ####################################################################################
  743. if [ "${OS_VERSION}" = "linux7" ]; then
  744. sed -i 's/* soft nproc 4096/* - nproc 16384/g' /etc/security/limits.d/20-nproc.conf
  745. logwrite "/etc/security/limits.d/20-nproc.conf" "cat /etc/security/limits.d/20-nproc.conf"
  746. fi
  747. if [ $(egrep "#OraConfBegin" /etc/security/limits.conf | wc -l) -eq 0 ]; then
  748. [ ! -f /etc/security/limits.conf. ${DAYTIME} ] && cp /etc/security/limits.conf /etc/security/limits.conf. ${DAYTIME}
  749. cat <<EOF >>/etc/security/limits.conf
  750. #OraConfBegin
  751. oracle soft nofile 1024
  752. oracle hard nofile 65536
  753. oracle soft stack 10240
  754. oracle hard stack 32768
  755. oracle soft nproc 2047
  756. oracle hard nproc 16384
  757. oracle hard memlock 134217728
  758. oracle soft memlock 134217728
  759. #OraConfEnd
  760. EOF
  761. fi
  762. logwrite "/etc/security/limits.conf" "cat /etc/security/limits.conf"
  763. ##Configure pam.d
  764. if [ $(egrep "#OraConfBegin" /etc/pam.d/login | wc -l) -eq 0 ]; then
  765. cat <<EOF >>/etc/pam.d/login
  766. #OraConfBegin
  767. session required pam_limits.so
  768. session required /lib64/security/pam_limits.so
  769. #OraConfEnd
  770. EOF
  771. fi
  772. logwrite "/etc/pam.d/login" "cat /etc/pam.d/login"
  773. ####################################################################################
  774. # Configure /dev/shm
  775. ####################################################################################
  776. if [ $(egrep "/dev/shm" /etc/fstab | wc -l) -eq 0 ]; then
  777. [ ! -f /etc/fstab. ${DAYTIME} ] && cp /etc/fstab /etc/fstab. ${DAYTIME}
  778. cat <<EOF >>/etc/fstab
  779. tmpfs /dev/shm tmpfs size=4G 0 0
  780. EOF
  781. mount -o remount /dev/shm
  782. fi
  783. logwrite "/dev/shm" "cat /etc/fstab"
  784. logwrite "df -hP" "df -hP"
  785. ####################################################################################
  786. # Edit bash_profile
  787. ####################################################################################
  788. ##ORALCE:
  789. if [ $(egrep "#OraConfBegin" /home/oracle/.bash_profile | wc -l) -eq 0 ]; then
  790. [ ! -f /home/oracle/.bash_profile ${daytime}.bak ] && su - oracle -c "cp /home/oracle/.bash_profile /home/oracle/.bash_profile${daytime}.bak"
  791. [ -f home/oracle/.bash_profile ] && su - oracle -c "sed -i '/^#OraConfBegin/,/^#OraConfEnd/d' /home/oracle/.bash_profile"
  792. cat <<EOF >>/home/oracle/.bash_profile
  793. ################OraConfBegin#########################
  794. umask 022
  795. export TMP=/tmp
  796. export TMPDIR=\ $TMP
  797. export NLS_LANG=AMERICAN_AMERICA. ${CHARACTERSET} #AL32UTF8,ZHS16GBK
  798. export ORACLE_BASE= ${ENV_ORACLE_BASE}
  799. export ORACLE_HOME= ${ENV_ORACLE_HOME}
  800. export ORACLE_HOSTNAME= ${HOSTNAME}
  801. export ORACLE_TERM=xterm
  802. export TNS_ADMIN=\ $ORACLE_HOME/network/admin
  803. export LD_LIBRARY_PATH=\ $ORACLE_HOME/lib:/lib:/usr/lib
  804. export ORACLE_SID= ${ORACLE_SID}
  805. export PATH=/usr/sbin:\ $PATH
  806. export PATH=\ $ORACLE_HOME/bin:\ $ORACLE_HOME/OPatch:\ $PATH
  807. alias sqlplus= 'rlwrap sqlplus'
  808. alias rman= 'rlwrap rman'
  809. alias lsnrctl= 'rlwrap lsnrctl'
  810. alias asmcmd= 'rlwrap asmcmd'
  811. alias adrci= 'rlwrap adrci'
  812. alias sas= 'sqlplus / as sysdba'
  813. alias ggsci= 'rlwrap ggsci'
  814. alias alert= 'tail -500f \$ORACLE_BASE/diag/rdbms/\$ORACLE_SID/\$ORACLE_SID/trace/alert_\$ORACLE_SID.log|more'
  815. export PS1= "[\`whoami\`@\`hostname\`:" '\$PWD]\$ '
  816. ################OraConfEnd###########################
  817. EOF
  818. else
  819. if [ "${oracleSid}" != "${ORACLE_SID}" ]; then
  820. sed -i "s/ORACLE_SID=${oracleSid}/ORACLE_SID=${ORACLE_SID}/" /home/oracle/.bash_profile
  821. fi
  822. if [ "${oracleHostname}" != "${HOSTNAME}" ]; then
  823. sed -i "s/ORACLE_HOSTNAME=${oracleHostname}/ORACLE_HOSTNAME=${HOSTNAME}/" /home/oracle/.bash_profile
  824. fi
  825. if [ "${oracleBase}" != "${ENV_ORACLE_BASE}" ]; then
  826. sed -i "s#ORACLE_BASE=${oracleBase}#ORACLE_BASE=${ENV_ORACLE_BASE}#" /home/oracle/.bash_profile
  827. fi
  828. if [ "${oracleHome}" != "${ENV_ORACLE_HOME}" ]; then
  829. sed -i "s#ORACLE_HOME=${oracleHome}#ORACLE_HOME=${ENV_ORACLE_HOME}#" /home/oracle/.bash_profile
  830. fi
  831. fi
  832. logwrite "Oracle Profile" "cat /home/oracle/.bash_profile"
  833. }
  834. ####################################################################################
  835. # Install rlwrap
  836. ####################################################################################
  837. InstallRlwrap() {
  838. if [ $(ls -l ${SOFTWAREDIR}/rlwrap-*gz | wc -l) -gt 0 ]; then
  839. rlwrap -v
  840. if [ $? -ne 0 ]; then
  841. tar -zxvf ${SOFTWAREDIR}/rlwrap* -C ${SOFTWAREDIR}
  842. cd ${SOFTWAREDIR}/rlwrap-*/
  843. ./configure
  844. make
  845. make install
  846. fi
  847. logwrite "rlwrap" "rlwrap -v"
  848. fi
  849. }
  850. ####################################################################################
  851. # Unzip DB Software
  852. ####################################################################################
  853. UnzipDBSoft() {
  854. if [ "${DB_VERSION}" = "11.2.0.4" ]; then
  855. if [ $(ls -l ${SOFTWAREDIR}/p13390677_112040_Linux-x86-64_*of7.zip | wc -l) -gt 0 ]; then
  856. rm -rf ${SOFTWAREDIR}/database
  857. unzip -o ${SOFTWAREDIR}/p13390677_112040_Linux-x86-64_1of7.zip -d ${SOFTWAREDIR}
  858. unzip -o ${SOFTWAREDIR}/p13390677_112040_Linux-x86-64_2of7.zip -d ${SOFTWAREDIR}
  859. else
  860. c1 "Make sure the database installation package is in the ${SOFTWAREDIR} directory:" red
  861. c1 "p13390677_112040_Linux-x86-64_1of7.zip" blue
  862. c1 "p13390677_112040_Linux-x86-64_2of7.zip" blue
  863. exit 99
  864. fi
  865. elif [ "${DB_VERSION}" = "12.2.0.1" ]; then
  866. if [ $(ls -l ${SOFTWAREDIR}/LINUX.X64_122010_db_home.zip | wc -l) -gt 0 ]; then
  867. rm -rf ${SOFTWAREDIR}/database
  868. unzip -o ${SOFTWAREDIR}/LINUX.X64_122010_db_home.zip -d ${SOFTWAREDIR}
  869. else
  870. c1 "Make sure the database installation package is in the ${SOFTWAREDIR} directory:" red
  871. c1 "LINUX.X64_122010_db_home.zip" blue
  872. exit 99
  873. fi
  874. elif [ "${DB_VERSION}" = "18.0.0.0" ]; then
  875. if [ $(ls -l ${SOFTWAREDIR}/LINUX.X64_180000_db_home.zip | wc -l) -gt 0 ]; then
  876. unzip -o ${SOFTWAREDIR}/LINUX.X64_180000_db_home.zip -d ${ENV_ORACLE_HOME}
  877. chown -R oracle:oinstall ${ENV_ORACLE_HOME}
  878. else
  879. c1 "Make sure the database installation package is in the ${SOFTWAREDIR} directory:" red
  880. c1 "LINUX.X64_180000_db_home.zip" blue
  881. exit 99
  882. fi
  883. elif [ "${DB_VERSION}" = "19.3.0.0" ]; then
  884. if [ $(ls -l ${SOFTWAREDIR}/LINUX.X64_193000_db_home.zip | wc -l) -gt 0 ]; then
  885. unzip -o ${SOFTWAREDIR}/LINUX.X64_193000_db_home.zip -d ${ENV_ORACLE_HOME}
  886. chown -R oracle:oinstall ${ENV_ORACLE_HOME}
  887. else
  888. c1 "Make sure the database installation package is in the ${SOFTWAREDIR} directory:" red
  889. c1 "LINUX.X64_193000_db_home.zip" blue
  890. exit 99
  891. fi
  892. else
  893. c1 "Error database version! please check again!" red
  894. exit
  895. fi
  896. }
  897. ####################################################################################
  898. # Unzip DB Software
  899. ####################################################################################
  900. InstallDBsoftware() {
  901. ####################################################################################
  902. # Unzip oracle OPATCH&&RU
  903. ####################################################################################
  904. if [ -n "${RU}" ]; then
  905. if [ "${DB_VERSION}" = "18.0.0.0" ] || [[ "${DB_VERSION}" = "19.3.0.0" ]]; then
  906. if [ "${DB_VERSION}" = "18.0.0.0" ]; then
  907. su - oracle -c "unzip -o ${SOFTWAREDIR}/p6880880_180000_Linux-x86-64.zip -d ${ENV_ORACLE_HOME}"
  908. if [ $? -ne 0 ]; then
  909. c1 "Make sure the Patch 6880880 is in the ${SOFTWAREDIR} directory:" red
  910. c1 "p6880880_180000_Linux-x86-64.zip" blue
  911. exit 92
  912. fi
  913. elif [ "${DB_VERSION}" = "19.3.0.0" ]; then
  914. su - oracle -c "unzip -o ${SOFTWAREDIR}/p6880880_190000_Linux-x86-64.zip -d ${ENV_ORACLE_HOME}"
  915. if [ $? -ne 0 ]; then
  916. c1 "Make sure the Patch 6880880 is in the ${SOFTWAREDIR} directory:" red
  917. c1 "p6880880_190000_Linux-x86-64.zip" blue
  918. exit 92
  919. fi
  920. fi
  921. if [ ! -d ${SOFTWAREDIR}/ ${RU} ]; then
  922. chown -R oracle:oinstall ${SOFTWAREDIR}
  923. if [ $? -ne 0 ]; then
  924. su - oracle -c "unzip -o ${SOFTWAREDIR}/*p${RU}* -d ${SOFTWAREDIR}"
  925. c1 "Make sure the database release update ${RU} is in the ${SOFTWAREDIR} directory:" red
  926. c1 "p${RU}.......zip" blue
  927. exit 99
  928. fi
  929. fi
  930. fi
  931. fi
  932. if [ "${DB_VERSION}" = "18.0.0.0" ] || [[ "${DB_VERSION}" = "19.3.0.0" ]]; then
  933. logwrite "OPatch Version" "su - oracle -c \"opatch version\""
  934. fi
  935. #Create db.rsp
  936. rm -rf ${SOFTWAREDIR}/db.rsp
  937. if [ ${DB_VERSION} = 11.2.0.4 ]; then
  938. cat <<EOF >> ${SOFTWAREDIR}/db.rsp
  939. oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
  940. oracle.install.option=INSTALL_DB_SWONLY
  941. ORACLE_HOSTNAME= ${HOSTNAME}
  942. UNIX_GROUP_NAME=oinstall
  943. INVENTORY_LOCATION= ${ENV_BASE_DIR}/oraInventory
  944. SELECTED_LANGUAGES=en,zh_CN
  945. ORACLE_HOME= ${ENV_ORACLE_HOME}
  946. ORACLE_BASE= ${ENV_ORACLE_BASE}
  947. oracle.install.db.InstallEdition=EE
  948. oracle.install.db.DBA_GROUP=dba
  949. oracle.install.db.OPER_GROUP=oinstall
  950. DECLINE_SECURITY_UPDATES= true
  951. oracle.installer.autoupdates.option=SKIP_UPDATES
  952. EOF
  953. elif [ "${DB_VERSION}" = "12.2.0.1" ]; then
  954. cat <<EOF >> ${SOFTWAREDIR}/db.rsp
  955. oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v12.2.0
  956. oracle.install.option=INSTALL_DB_SWONLY
  957. UNIX_GROUP_NAME=oinstall
  958. ORACLE_HOME= ${ENV_ORACLE_HOME}
  959. INVENTORY_LOCATION= ${ENV_ORACLE_INVEN}
  960. ORACLE_BASE= ${ENV_ORACLE_BASE}
  961. SELECTED_LANGUAGES=en,zh_CN
  962. ORACLE_HOME= $ENV_ORACLE_HOME
  963. ORACLE_BASE= $ENV_ORACLE_BASE
  964. oracle.install.db.InstallEdition=EE
  965. oracle.install.db.OSDBA_GROUP=dba
  966. oracle.install.db.OSOPER_GROUP=oper
  967. oracle.install.db.OSBACKUPDBA_GROUP=backupdba
  968. oracle.install.db.OSDGDBA_GROUP=dgdba
  969. oracle.install.db.OSKMDBA_GROUP=kmdba
  970. oracle.install.db.OSRACDBA_GROUP=racdba
  971. DECLINE_SECURITY_UPDATES= true
  972. EOF
  973. elif [ "${DB_VERSION}" = "18.0.0.0" ]; then
  974. cat <<EOF >> ${SOFTWAREDIR}/db.rsp
  975. oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v18.0.0
  976. oracle.install.option=INSTALL_DB_SWONLY
  977. UNIX_GROUP_NAME=oinstall
  978. ORACLE_HOSTNAME= ${HOSTNAME}
  979. ORACLE_HOME= ${ENV_ORACLE_HOME}
  980. INVENTORY_LOCATION= ${ENV_ORACLE_INVEN}
  981. ORACLE_BASE= ${ENV_ORACLE_BASE}
  982. oracle.install.db.InstallEdition=EE
  983. oracle.install.db.OSDBA_GROUP=dba
  984. oracle.install.db.OSOPER_GROUP=oper
  985. oracle.install.db.OSBACKUPDBA_GROUP=backupdba
  986. oracle.install.db.OSDGDBA_GROUP=dgdba
  987. oracle.install.db.OSKMDBA_GROUP=kmdba
  988. oracle.install.db.OSRACDBA_GROUP=racdba
  989. EOF
  990. elif [ "${DB_VERSION}" = "19.3.0.0" ]; then
  991. cat <<EOF >> ${SOFTWAREDIR}/db.rsp
  992. oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v19.0.0
  993. oracle.install.option=INSTALL_DB_SWONLY
  994. UNIX_GROUP_NAME=oinstall
  995. INVENTORY_LOCATION= ${ENV_ORACLE_INVEN}
  996. ORACLE_BASE= ${ENV_ORACLE_BASE}
  997. oracle.install.db.InstallEdition=EE
  998. oracle.install.db.OSDBA_GROUP=dba
  999. oracle.install.db.OSOPER_GROUP=oper
  1000. oracle.install.db.OSBACKUPDBA_GROUP=backupdba
  1001. oracle.install.db.OSDGDBA_GROUP=dgdba
  1002. oracle.install.db.OSKMDBA_GROUP=kmdba
  1003. oracle.install.db.OSRACDBA_GROUP=racdba
  1004. oracle.install.db.rootconfig.executeRootScript= false
  1005. oracle.install.db.rootconfig.configMethod=
  1006. EOF
  1007. fi
  1008. logwrite "${SOFTWAREDIR}/db.rsp" "cat ${SOFTWAREDIR}/db.rsp"
  1009. #Install Database software
  1010. chown oracle.oinstall ${SOFTWAREDIR}/db.rsp
  1011. ##Juge whether ${ENV_ORACLE_INVEN}/ContentsXML/inventory.xml contains ${ENV_ORACLE_HOME},if exists ,delete it
  1012. if [ -f "${ENV_ORACLE_INVEN}/ContentsXML/inventory.xml" ] && [ $(egrep "${ENV_ORACLE_HOME}" ${ENV_ORACLE_INVEN}/ContentsXML/inventory.xml | wc -l) -gt 0 ]; then
  1013. line=$(grep -n "${ENV_ORACLE_HOME}" ${ENV_ORACLE_INVEN}/ContentsXML/inventory.xml | awk -F ":" '{print $1}')
  1014. sed -i "${line} d" ${ENV_ORACLE_INVEN}/ContentsXML/inventory.xml
  1015. fi
  1016. if [[ "${DB_VERSION}" = "12.2.0.1" ]] || [[ "${DB_VERSION}" = "11.2.0.4" ]]; then
  1017. su - oracle -c "${SOFTWAREDIR}/database/runInstaller -silent -force -ignoreSysPrereqs -responseFile ${SOFTWAREDIR}/db.rsp -ignorePrereq" | tee ${SOFTWAREDIR}/setupDatabase.out
  1018. rm -rf ${SOFTWAREDIR}/setupDatabase.out
  1019. elif [ "${DB_VERSION}" = "18.0.0.0" ] || [[ "${DB_VERSION}" = "19.3.0.0" ]]; then
  1020. if [ -n "${RU}" ]; then
  1021. su - oracle <<EOF
  1022. cd ${ENV_ORACLE_HOME};
  1023. ./runInstaller -silent -force -responseFile ${SOFTWAREDIR}/db.rsp -ignorePrereqFailure -waitForCompletion -applyRU ${SOFTWAREDIR}/ ${RU}
  1024. EOF
  1025. else
  1026. su - oracle <<EOF
  1027. cd ${ENV_ORACLE_HOME};
  1028. ./runInstaller -silent -force -responseFile ${SOFTWAREDIR}/db.rsp -ignorePrereqFailure -waitForCompletion
  1029. EOF
  1030. fi
  1031. fi
  1032. if [ -f ${ENV_ORACLE_INVEN}/orainstRoot.sh ] || [ -f ${ENV_ORACLE_HOME}/root.sh ]; then
  1033. if [ -f ${ENV_ORACLE_INVEN}/orainstRoot.sh ]; then
  1034. ${ENV_ORACLE_INVEN}/orainstRoot.sh
  1035. fi
  1036. if [ -f ${ENV_ORACLE_HOME}/root.sh ]; then
  1037. ${ENV_ORACLE_HOME}/root.sh
  1038. fi
  1039. else
  1040. echo
  1041. c1 "Oracle software installation failed, please check the log." red
  1042. exit 99
  1043. fi
  1044. ##LINUX7 INSTALL 11G,NEED TO SET -lnnz11
  1045. if [ "${DB_VERSION}" = "11.2.0.4" ]; then
  1046. sed -i 's/^\(\s*\$(MK_EMAGENT_NMECTL)\)\s*$/\1 -lnnz11/g' ${ENV_ORACLE_HOME}/sysman/lib/ins_emagent.mk
  1047. fi
  1048. logwrite "Oracle RDBMS" "su - oracle -c \"sqlplus -V\""
  1049. logwrite "OPatch lspatches" "su - oracle -c \"opatch lspatches\""
  1050. }
  1051. ####################################################################################
  1052. # Create netca.rsp
  1053. ####################################################################################
  1054. creareNetca() {
  1055. rm -rf ${SOFTWAREDIR}/netca.rsp
  1056. if [ "${DB_VERSION}" = "11.2.0.4" ]; then
  1057. RESPONSEFILE_VERSION=11.2
  1058. elif [ "${DB_VERSION}" = "12.2.0.1" ]; then
  1059. RESPONSEFILE_VERSION=12.2
  1060. elif [ "${DB_VERSION}" = "18.0.0.0" ]; then
  1061. RESPONSEFILE_VERSION=18.0
  1062. elif [ "${DB_VERSION}" = "19.3.0.0" ]; then
  1063. RESPONSEFILE_VERSION=19.3
  1064. fi
  1065. cat <<EOF >> ${SOFTWAREDIR}/netca.rsp
  1066. [GENERAL]
  1067. RESPONSEFILE_VERSION= "${RESPONSEFILE_VERSION}"
  1068. CREATE_TYPE= "CUSTOM"
  1069. [oracle.net.ca]
  1070. INSTALLED_COMPONENTS={ "server", "net8", "javavm"}
  1071. INSTALL_TYPE= ""typical ""
  1072. LISTENER_NUMBER=1
  1073. LISTENER_NAMES={ "LISTENER"}
  1074. LISTENER_PROTOCOLS={ "TCP;1521"}
  1075. LISTENER_START= ""LISTENER ""
  1076. NAMING_METHODS={ "TNSNAMES", "ONAMES", "HOSTNAME"}
  1077. NSN_NUMBER=1
  1078. NSN_NAMES={ "EXTPROC_CONNECTION_DATA"}
  1079. NSN_SERVICE={ "PLSExtProc"}
  1080. NSN_PROTOCOLS={ "TCP;HOSTNAME;1521"}
  1081. EOF
  1082. logwrite "${SOFTWAREDIR}/netca.rsp" "cat ${SOFTWAREDIR}/netca.rsp"
  1083. su - oracle -c "netca -silent -responsefile ${SOFTWAREDIR}/netca.rsp"
  1084. logwrite "ORACLE LISTENER" "su - oracle -c \"lsnrctl status\""
  1085. }
  1086. ####################################################################################
  1087. ## Create database
  1088. ####################################################################################
  1089. createDB() {
  1090. if [ "${DB_VERSION}" = "11.2.0.4" ]; then
  1091. su - oracle -c "dbca -silent -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE -gdbname ${ORACLE_SID} -sid ${ORACLE_SID} -sysPassword oracle -systemPassword oracle -redoLogFileSize 120 -storageType FS -datafileDestination ${ORADATADIR} -sampleSchema true -characterSet ${CHARACTERSET} -nationalCharacterSet AL16UTF16 -emConfiguration NONE -automaticMemoryManagement false -totalMemory ${totalMemory} -databaseType OLTP"
  1092. elif [ "${DB_VERSION}" = "12.2.0.1" ] || [ "${DB_VERSION}" = "18.0.0.0" ] || [[ "${DB_VERSION}" = "19.3.0.0" ]]; then
  1093. su - oracle -c "dbca -silent -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE -gdbName ${ORACLE_SID} -sid ${ORACLE_SID} -sysPassword oracle -systemPassword oracle -redoLogFileSize 120 -storageType FS -datafileDestination ${ORADATADIR} -enableArchive true -archiveLogDest ${ARCHIVEDIR} -sampleSchema true -characterset ${CHARACTERSET} -nationalCharacterSet AL16UTF16 -emConfiguration NONE -automaticMemoryManagement false -totalMemory ${totalMemory} -databaseType OLTP -createAsContainerDatabase ${ISCDB} "
  1094. fi
  1095. logwrite "ORACLE Instance" "su - oracle -c \"lsnrctl status\""
  1096. }
  1097. ####################################################################################
  1098. # Configure DBParaSet
  1099. ####################################################################################
  1100. DBParaSet() {
  1101. cat <<EOF >/home/oracle/oracleParaset.sql
  1102. -- set db_create_file_dest
  1103. ALTER SYSTEM SET DB_CREATE_FILE_DEST= '${ORADATADIR}';
  1104. ALTER SYSTEM SET LOG_ARCHIVE_DEST_1= 'LOCATION=${ARCHIVEDIR}';
  1105. exit;
  1106. EOF
  1107. su - oracle -c "sqlplus / as sysdba @/home/oracle/oracleParaset.sql"
  1108. ####################################################################################
  1109. # Create PDB and Set pdb autostart with cdb
  1110. ####################################################################################
  1111. if [ "${ISCDB}" = "TRUE" ]; then
  1112. if [ ! -f /home/oracle/pdbs_save_state.sql ]; then
  1113. cat <<EOF >>/home/oracle/pdbs_save_state.sql
  1114. --create pluggable database
  1115. create pluggable database ${PDBNAME} admin user admin identified by oracle;
  1116. --open pluggable database
  1117. alter pluggable database all open;
  1118. -- set pdb autostart with cdb
  1119. alter pluggable database all save state;
  1120. exit
  1121. EOF
  1122. fi
  1123. su - oracle -c "sqlplus / as sysdba @/home/oracle/pdbs_save_state.sql"
  1124. ####################################################################################
  1125. # Add pdb TNS
  1126. ####################################################################################
  1127. if [ $(egrep "#OraConfBegin" ${ENV_ORACLE_HOME}/network/admin/tnsnames.ora | wc -l) -eq 0 ]; then
  1128. [ ! -f ${ENV_ORACLE_HOME}/network/admin/tnsnames.ora. ${DAYTIME} ] && cp ${ENV_ORACLE_HOME}/network/admin/tnsnames.ora ${ENV_ORACLE_HOME}/network/admin/tnsnames.ora. ${DAYTIME}
  1129. su - oracle -c "cat <<EOF >>${ENV_ORACLE_HOME}/network/admin/tnsnames.ora
  1130. #OraConfBegin
  1131. ${PDBNAME} =
  1132. (DESCRIPTION =
  1133. (ADDRESS = (PROTOCOL = TCP)(HOST = ${HOSTNAME})(PORT = 1521))
  1134. (CONNECT_DATA =
  1135. (SERVER = DEDICATED)
  1136. (SERVICE_NAME = ${PDBNAME})
  1137. )
  1138. )
  1139. #OraConfEnd
  1140. EOF
  1141. "
  1142. fi
  1143. fi
  1144. ####################################################################################
  1145. # Configure instances autostart with OS start
  1146. ####################################################################################
  1147. if [ $(egrep "#OraConfBegin" /etc/oratab | wc -l) -eq 0 ]; then
  1148. [ ! -f /etc/oratab. ${DAYTIME} ] && cp /etc/oratab /etc/oratab. ${DAYTIME}
  1149. sed -i 's/db:N/db:Y/' /etc/oratab
  1150. sed -i 's/ORACLE_HOME_LISTNER=$1/ORACLE_HOME_LISTNER=$ORACLE_HOME/' ${ENV_ORACLE_HOME}/bin/dbstart
  1151. cat <<EOF >>/etc/rc.d/rc.local
  1152. #OraConfBegin
  1153. su oracle -lc "${ENV_ORACLE_HOME}/bin/lsnrctl start"
  1154. su oracle -lc ${ENV_ORACLE_HOME}/bin/dbstart
  1155. #OraConfEnd
  1156. EOF
  1157. chmod +x /etc/rc.d/rc.local
  1158. fi
  1159. ####################################################################################
  1160. # Configure del_arch.sh to crontab
  1161. ####################################################################################
  1162. ##create del_arch.sh
  1163. if [ ! -f ${SCRIPTSDIR}/del_arch.sh ]; then
  1164. echo '#!/bin/bash' >> ${SCRIPTSDIR}/del_arch.sh
  1165. echo 'source ~/.bash_profile' >> ${SCRIPTSDIR}/del_arch.sh
  1166. echo 'deltime=`date +"20%y%m%d%H%M%S"`' >> ${SCRIPTSDIR}/del_arch.sh
  1167. echo "rman target / nocatalog msglog ${SCRIPTSDIR}/del_arch_\${deltime}.log<<EOF" >> ${SCRIPTSDIR}/del_arch.sh
  1168. echo 'crosscheck archivelog all;' >> ${SCRIPTSDIR}/del_arch.sh
  1169. echo "delete noprompt archivelog until time 'sysdate-7';" >> ${SCRIPTSDIR}/del_arch.sh
  1170. echo "delete noprompt force archivelog until time 'SYSDATE-10';" >> ${SCRIPTSDIR}/del_arch.sh
  1171. echo 'EOF' >> ${SCRIPTSDIR}/del_arch.sh
  1172. fi
  1173. ##create dbbackup_lv0.sh
  1174. if [ ! -f ${SCRIPTSDIR}/dbbackup_lv0.sh ]; then
  1175. echo '#!/bin/sh' >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1176. echo 'source ~/.bash_profile' >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1177. echo 'backtime=`date +"20%y%m%d%H%M%S"`' >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1178. echo "rman target / log=${backupDir}/level0_backup_\${backtime}.log<<EOF" >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1179. echo 'run {' >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1180. echo 'allocate channel c1 device type disk;' >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1181. echo 'allocate channel c2 device type disk;' >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1182. echo 'crosscheck backup;' >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1183. echo 'crosscheck archivelog all; ' >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1184. echo 'alter system switch logfile;' >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1185. echo 'delete noprompt expired backup;' >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1186. echo 'delete noprompt obsolete device type disk;' >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1187. echo "backup incremental level 0 database include current controlfile format '${backupDir}/backlv0_%d_%T_%t_%s_%p';" >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1188. echo 'backup archivelog all DELETE INPUT;' >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1189. echo 'release channel c1;' >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1190. echo 'release channel c2;' >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1191. echo '}' >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1192. echo 'EOF' >> ${SCRIPTSDIR}/dbbackup_lv0.sh
  1193. fi
  1194. ##create dbbackup_lv1.sh
  1195. if [ ! -f ${SCRIPTSDIR}/dbbackup_lv1.sh ]; then
  1196. echo '#!/bin/sh' >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1197. echo 'source ~/.bash_profile' >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1198. echo 'backtime=`date +"20%y%m%d%H%M%S"`' >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1199. echo "rman target / log=${backupDir}/level1_backup_\${backtime}.log<<EOF" >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1200. echo 'run {' >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1201. echo 'allocate channel c1 device type disk;' >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1202. echo 'allocate channel c2 device type disk;' >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1203. echo 'crosscheck backup;' >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1204. echo 'crosscheck archivelog all; ' >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1205. echo 'alter system switch logfile;' >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1206. echo 'delete noprompt expired backup;' >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1207. echo 'delete noprompt obsolete device type disk;' >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1208. echo "backup incremental level 1 database include current controlfile format '${backupDir}/backlv1_%d_%T_%t_%s_%p';" >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1209. echo 'backup archivelog all DELETE INPUT;' >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1210. echo 'release channel c1;' >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1211. echo 'release channel c2;' >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1212. echo '}' >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1213. echo 'EOF' >> ${SCRIPTSDIR}/dbbackup_lv1.sh
  1214. fi
  1215. ##create dbbackup_lv2.sh
  1216. if [ ! -f ${SCRIPTSDIR}/dbbackup_lv2.sh ]; then
  1217. echo '#!/bin/sh' >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1218. echo 'source ~/.bash_profile' >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1219. echo 'backtime=`date +"20%y%m%d%H%M%S"`' >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1220. echo "rman target / log=${backupDir}/level2_backup_\${backtime}.log<<EOF" >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1221. echo 'run {' >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1222. echo 'allocate channel c2 device type disk;' >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1223. echo 'allocate channel c2 device type disk;' >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1224. echo 'crosscheck backup;' >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1225. echo 'crosscheck archivelog all; ' >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1226. echo 'alter system switch logfile;' >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1227. echo 'delete noprompt expired backup;' >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1228. echo 'delete noprompt obsolete device type disk;' >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1229. echo "backup incremental level 2 database include current controlfile format '${backupDir}/backlv2_%d_%T_%t_%s_%p';" >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1230. echo 'backup archivelog all DELETE INPUT;' >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1231. echo 'release channel c2;' >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1232. echo 'release channel c2;' >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1233. echo '}' >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1234. echo 'EOF' >> ${SCRIPTSDIR}/dbbackup_lv2.sh
  1235. fi
  1236. ####################################################################################
  1237. # Configure scripts to crontab
  1238. ####################################################################################
  1239. ##Set to oracle crontab
  1240. if [ ! -f /var/spool/cron/oracle ]; then
  1241. echo "##For oracle" >>/var/spool/cron/oracle
  1242. fi
  1243. if [ $(egrep "#OraConfBegin" /var/spool/cron/oracle | wc -l) -eq 0 ]; then
  1244. [ ! -f /var/spool/cron/oracle. ${daytime} ] && cp /var/spool/cron/oracle /var/spool/cron/oracle. ${daytime} >/dev/null 2>&1
  1245. chown -R oracle:oinstall ${SCRIPTSDIR}/d*
  1246. chmod +x ${SCRIPTSDIR}/d*
  1247. echo "#OraConfBegin" >>/var/spool/cron/oracle
  1248. echo "#12 00 * * * ${SCRIPTSDIR}/del_arch.sh" >>/var/spool/cron/oracle
  1249. echo "#00 00 * * 0 ${SCRIPTSDIR}/dbbackup_lv0.sh" >>/var/spool/cron/oracle
  1250. echo "#00 00 * * 1,2,4,5 ${SCRIPTSDIR}/dbbackup_lv1.sh" >>/var/spool/cron/oracle
  1251. echo "#00 00 * * 3,6 ${SCRIPTSDIR}/dbbackup_lv2.sh" >>/var/spool/cron/oracle
  1252. echo "#OraConfEnd" >>/var/spool/cron/oracle
  1253. fi
  1254. ####################################################################################
  1255. # Configure PASSWORD_LIFE_TIME UNLIMITED
  1256. ####################################################################################
  1257. if [ "${ISCDB}" = "TRUE" ]; then
  1258. cat <<EOF >/home/oracle/password_unlimt.sql
  1259. ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
  1260. ALTER SYSTEM SET AUDIT_TRAIL=NONE SCOPE=SPFILE;
  1261. ALTER SYSTEM SET DEFERRED_SEGMENT_CREATION=FALSE;
  1262. ALTER SYSTEM SET "_OPTIMIZER_CARTESIAN_ENABLED"=FALSE;
  1263. ALTER SYSTEM SET "_USE_SINGLE_LOG_WRITER"=FALSE SCOPE=SPFILE;
  1264. ALTER SYSTEM SET RESULT_CACHE_MAX_SIZE= 0;
  1265. ALTER SYSTEM SET event= '10949 trace name context forever:28401 trace name context forever,level 1:10849 trace name context forever, level 1:19823 trace name context forever, level 90' scope=spfile;
  1266. ALTER SESSION SET CONTAINER= ${PDBNAME};
  1267. ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
  1268. GRANT DBA TO ADMIN;
  1269. exit;
  1270. EOF
  1271. else
  1272. cat <<EOF >/home/oracle/password_unlimt.sql
  1273. ALTER PROFILE DEFAULT LIMIT PASSWORD_LIFE_TIME UNLIMITED;
  1274. ALTER SYSTEM SET AUDIT_TRAIL=NONE SCOPE=SPFILE;
  1275. ALTER SYSTEM SET DEFERRED_SEGMENT_CREATION=FALSE;
  1276. ALTER SYSTEM SET "_OPTIMIZER_CARTESIAN_ENABLED"=FALSE;
  1277. --ALTER SYSTEM SET "_USE_SINGLE_LOG_WRITER"=FALSE SCOPE=SPFILE;
  1278. ALTER SYSTEM SET RESULT_CACHE_MAX_SIZE= 0;
  1279. ALTER SYSTEM SET event= '10949 trace name context forever:28401 trace name context forever,level 1:10849 trace name context forever, level 1:19823 trace name context forever, level 90' scope=spfile;
  1280. exit;
  1281. EOF
  1282. fi
  1283. su - oracle -c "sqlplus / as sysdba @/home/oracle/password_unlimt.sql"
  1284. cat <<EOF >/home/oracle/Impliedparameters.sql
  1285. col name for a40
  1286. col VALUE for a10
  1287. col DESCRIB for a60
  1288. set lines 200
  1289. SHOW PARAMETER AUDIT_TRAIL
  1290. SHOW PARAMETER DEFERRED_SEGMENT_CREATION
  1291. SHOW PARAMETER RESULT_CACHE_MAX_SIZE
  1292. SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
  1293. FROM SYS.x\ $ksppi x, SYS.x\ $ksppcv y
  1294. WHERE x.inst_id = USERENV ( 'Instance')
  1295. AND y.inst_id = USERENV ( 'Instance')
  1296. AND x.indx = y.indx
  1297. and x.ksppinm in ( '_optimizer_cartesian_enabled', '_use_single_log_writer', '_use_adaptive_log_file_sync');
  1298. exit;
  1299. EOF
  1300. logwrite "Oracle Implied parameters" "su - oracle -c \"sqlplus / as sysdba @/home/oracle/Impliedparameters.sql\""
  1301. ####################################################################################
  1302. # Sqlnet.ora Configure lower Oracle client to connect
  1303. ####################################################################################
  1304. if [ $(egrep "#OraConfBegin" ${ENV_ORACLE_HOME}/network/admin/sqlnet.ora | wc -l) -eq 0 ]; then
  1305. [ ! -f ${ENV_ORACLE_HOME}/network/admin/sqlnet.ora. ${DAYTIME} ] && cp ${ENV_ORACLE_HOME}/network/admin/sqlnet.ora ${ENV_ORACLE_HOME}/network/admin/sqlnet.ora. ${DAYTIME}
  1306. su - oracle -c "cat <<EOF >>${ENV_ORACLE_HOME}/network/admin/sqlnet.ora
  1307. #OraConfBegin
  1308. SQLNET.ALLOWED_LOGON_VERSION_CLIENT=8
  1309. SQLNET.ALLOWED_LOGON_VERSION_SERVER=8
  1310. #OraConfEnd
  1311. EOF
  1312. "
  1313. fi
  1314. }
  1315. ##remove instance
  1316. if [ -n "${REMOVEINSTANCE}" ]; then
  1317. REMOVEINSTANCE
  1318. fi
  1319. ##remove rdbms
  1320. if [ -n "${REMOVEDBSOFTWARE}" ]; then
  1321. REMOVEDBSOFTWARE
  1322. fi
  1323. ##For OS CONFIG
  1324. SetHostName
  1325. SetHosts
  1326. InstallRPM
  1327. CreateUsersAndDirs
  1328. TimeDepSet
  1329. Disableavahi
  1330. DisableFirewall
  1331. DisableSelinux
  1332. DisableTHPAndNUMA
  1333. DisableNetworkManager
  1334. EditParaFiles
  1335. InstallRlwrap
  1336. ##If ONLY INSTALL ORACLE SOFTWARE
  1337. if [ "${ONLYCONFIGOS}" = 'N' ]; then
  1338. UnzipDBSoft
  1339. InstallDBsoftware
  1340. if [ "${ONLYINSTALLSOFTWARE}" = 'N' ]; then
  1341. creareNetca
  1342. createDB
  1343. DBParaSet
  1344. fi
  1345. fi

 


转载:https://blog.csdn.net/m0_50546016/article/details/115491761
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场