小編給大家分享一下rhel6/7如何自動安裝oracle11g單實(shí)例,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
成都創(chuàng)新互聯(lián)公司從2013年開始,先為淮陽等服務(wù)建站,淮陽等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為淮陽企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
因日常工作,經(jīng)常需要在rhel6.X,rhel7.X,CentOS6.X,CentOS7.x上安裝oracle 11.2.0.4版本單實(shí)例數(shù)據(jù)庫(基于文件系統(tǒng))
故寫了自動安裝腳本oracle腳本。
全部文件列表如下:
1、其中iso文件是對應(yīng)的紅帽系統(tǒng)的鏡像源(根據(jù)cat /etc/redhat-release獲取紅帽版本)
2、其中兩個zip安裝包,可以從SR上下載(搜索13390677找到對應(yīng)的文件,注意文件名必須一致)
3、其中三個rsp文件是安裝oracle的配置文件,db_install.rsp用于安裝數(shù)據(jù)庫軟件,dbca.rsp用于創(chuàng)建數(shù)據(jù)庫,netca.rsp用于創(chuàng)建監(jiān)聽。
4、其中sh文件是本人寫的腳本,直接使用root用戶執(zhí)行即可(需要chmod u+x auto_install_oracle_server.sh),期間需要用戶輸入幾個信息:字符集、oracle_sid、主機(jī)ip地址,memory_target。
因只在紅帽6與7的部分版本測試過,可能還有一些問題??删唧w修改shell腳本。
操作過程:
1、查看文件是否齊全
點(diǎn)擊(此處)折疊或打開
[root@testlihb ~]# cd /tmp
[root@testlihb tmp]# ls -lrt
total 6120464
-rw-r--r-- 1 root root 5871 Apr 28 07:00 netca.rsp #監(jiān)聽配置文件
-rwxr--r-- 1 root root 17977 Apr 28 07:00 auto_install_oracle_server.sh #主腳本
-rw-r--r-- 1 root root 25287 Apr 28 07:00 db_install.rsp #數(shù)據(jù)庫軟件配置文件
-rw-r--r-- 1 root root 44580 Apr 28 07:00 dbca.rsp #數(shù)據(jù)庫配置文件
-rwxr-xr-x 1 root root 1395582860 Apr 28 07:07 p13390677_112040_Linux-x86-64_1of7.zip #11.2.0.4 安裝包1
-rwxr-xr-x 1 root root 1151304589 Apr 28 07:12 p13390677_112040_Linux-x86-64_2of7.zip #11.2.0.4 安裝包2
-rw-r--r-- 1 root root 3720347648 Jul 24 2018 rhel-server-6.4-x86_64-dvd.iso #操作系統(tǒng)光盤文件
[root@testlihb tmp]# chmod u+x auto_install_oracle_server.sh #root賦予可執(zhí)行權(quán)限
2、配置yum源,如果確認(rèn)yum源已經(jīng)配置完畢,可忽略此步驟
點(diǎn)擊(此處)折疊或打開
[root@testlihb tmp]# ./auto_install_oracle_server.sh #root直接執(zhí)行
========>-------- seletion------------
========>1.install database #安裝數(shù)據(jù)庫
========>2.deinstall database #卸載數(shù)據(jù)庫(只可以卸載通過本腳本安裝的數(shù)據(jù)庫)
========>3.configure local yum #配置yum源
========>-----------------------------
========>Your choice:3 #選擇配置yum源,如果確認(rèn)yum源已經(jīng)配置好了,此處可忽略
========>please input the iso location(eg:/tmp/xxx.iso):/tmp/rhel-server-6.4-x86_64-dvd.iso #輸入iso文件的路徑
[OK]====>the yum configure
3、安裝數(shù)據(jù)庫
點(diǎn)擊(此處)折疊或打開
[root@testlihb tmp]# ./auto_install_oracle_server.sh
========>-------- seletion------------
========>1.install database
========>2.deinstall database
========>3.configure local yum
========>-----------------------------
========>Your choice:1 #安裝數(shù)據(jù)庫
[ok]====>begin install_db
[ok]====>current user is root #檢查當(dāng)前用戶是否為root
[OK]====>the yum configure #檢查yum源是否正常
[OK]====>the installfile #檢查oracle安裝包是否存在
[OK]====>the config file #檢查配置文件是否存在
========>----charcaterset seletion----
========>1.AMERICAN_AMERICA.ZHS16GBK
========>2.AMERICAN_AMERICA.AL32UTF8
========>-----------------------------
========>Your choice:(default 1):1 #選擇數(shù)據(jù)庫字符集,此處只有兩個選擇
========>please input sid(less than 8 letters):oragbk #輸入sid,sid必須少于8個字符
========>please input memory target(MB):4096 #輸入內(nèi)存,其中sga和pga比例為3:1
========>please input ORACLE_BASE(will auto create):/database/oragbk #oracle軟件目錄(如果目錄不存在,會自動創(chuàng)建。如果目錄存在,該目錄必須為空)
========>please input host IP address:192.168.75.236 #輸入本機(jī)ip地址
[ok]====>cpu #檢查cpu
[ok]====>memory #檢查內(nèi)存
[ok]====>/tmp #檢查/tmp目錄
[ok]====>swap #檢查交換分區(qū)
[ok]====>ORACLE_BASE #檢查oracle軟件目錄
[OK]====>the yum configure #檢查yum源配置
[ok]====>the yum package has been installed #通過yum安裝依賴包
[ok]====>the sysctl.conf has been backup and change #備份和修改sysctl.conf文件
[ok]====>the limits.conf has been backup and change #備份和修改limits.conf文件
[ok]====>the login has been backup and change #備份和修改login文件
[ok]====>the profile has been backup and change #備份和修改profile文件
[ok]====>the oracle user and oinstall,dba group has been created #創(chuàng)建oracle用戶,oinstall和dba組
[ok]====>the .bash_profile has been backup and change #備份和修改.bash_profile文件
[ok]====>the dir has been created #檢查和創(chuàng)建oracle_base目錄
[ok]====>the install file has been unzip #解壓oracle安裝包
[ok]====>the hosts has been backup and change #備份和修改hosts文件
[ok]====>the db_install.rsp has been backup and change #備份和修改db_install.rsp文件
[ok]====>waiting for software install . . . . . . . . . . #此處在安裝oracle軟件,需要等較長時間,可查看/tmp/db_install.rsp.log
[ok]====>software has installed #oracle軟件安裝完成
[ok]====>two script has been run by root #root執(zhí)行兩個shell script文件
[ok]====>netca.rsp has been backup and change #備份和修改netca.rsp文件
[ok]====>waiting for netca install . #此處在創(chuàng)建listener,不需要等待太長時間,可查看/tmp/netca.rsp.log
[ok]====>netca has installed #listener創(chuàng)建完成
[ok]====>dbca.rsp has been backup and change #備份和修改dbca.rsp文件
Copying database files
1% complete
3% complete
11% complete
18% complete
26% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
50% complete
55% complete
56% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
85% complete
96% complete
100% complete
Look at the log file "/database/oragbk/cfgtoollogs/dbca/oragbk/oragbk.log" for further details.
[ok]====>dbca has installed #數(shù)據(jù)庫創(chuàng)建完成
[ok]====>the install process success
4、檢查數(shù)據(jù)庫是否正常
點(diǎn)擊(此處)折疊或打開
[root@testlihb tmp]# ps -ef|grep smon_ |grep -v grep
oracle 12863 1 0 07:34 ? 00:00:00 ora_smon_oragbk #進(jìn)程存在
[root@testlihb tmp]# su - oracle
[oracle@testlihb ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sat Apr 28 07:35:09 2018
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
cell_offloadgroup_name string
db_file_name_convert string
db_name string oragbk
db_unique_name string oragbk
global_names boolean FALSE
instance_name string oragbk
lock_name_space string
log_file_name_convert string
processor_group_name string
service_names string oragbk
SQL> show parameter memory
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
hi_shared_memory_address integer 0
memory_max_target big integer 0
memory_target big integer 0
shared_memory_address integer 0
SQL> show parameter sga
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
lock_sga boolean FALSE
pre_page_sga boolean FALSE
sga_max_size big integer 3G
sga_target big integer 3G
SQL> show parameter pga
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
pga_aggregate_target big integer 1G
SQL> set lines 150 pages 10000
SQL> select * from nls_database_parameters where PARAMETER='NLS_CHARACTERSET';
PARAMETER VALUE
------------------------------ --------------------------------------------------------------------------------
NLS_CHARACTERSET ZHS16GBK
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@testlihb ~]$ logout
5、卸載數(shù)據(jù)庫
點(diǎn)擊(此處)折疊或打開
[root@testlihb tmp]# ./auto_install_oracle_server.sh
========>-------- seletion------------
========>1.install database
========>2.deinstall database
========>3.configure local yum
========>-----------------------------
========>Your choice:2
please use oracle to run $ORACLE_HOME/deinstall/deinstall and use root to run /tmp/del_ora.sh #切到oracle用戶執(zhí)行腳本,然后在切到root用戶執(zhí)行腳本
[root@testlihb tmp]# su - oracle
[oracle@testlihb ~]$ $ORACLE_HOME/deinstall/deinstall
Checking for required files and bootstrapping ...
Please wait ...
Location of logs /tmp/deinstall2018-04-28_07-36-48AM/logs/
。。。
Specify all Single Instance listeners that are to be de-configured [LISTENER]:
Specify the list of database names that are configured in this Oracle home [oragbk]:
The details of database(s) oragbk have been discovered automatically. Do you still want to modify the details of oragbk database(s)? [n]: y
Specify the type of this database (1.Single Instance Database|2.Oracle Restart Enabled Database) [1]:
Specify the diagnostic destination location of the database [/database/oragbk/diag/rdbms/oragbk]:
Specify the storage type used by the Database ASM|FS [FS]:
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]:
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]:
Specify the database spfile location [/database/oragbk/product/11.2.0/db_1/dbs/spfileoragbk.ora]:
Do you want to continue (y - yes, n - no)? [n]: y
。。。
[oracle@testlihb ~]$ logout
[root@testlihb tmp]# /tmp/del_ora.sh
6、檢查是否已經(jīng)刪除數(shù)據(jù)庫
點(diǎn)擊(此處)折疊或打開
[root@testlihb tmp]# ps -ef|grep smon_
root 16003 7948 0 07:45 pts/1 00:00:00 grep smon_
[root@testlihb tmp]# id oracle
id: oracle: No such user
如下是具體的腳本:
auto_install_oracle_server.sh
點(diǎn)擊(此處)折疊或打開
#!/bin/bash
HOSTNAME=`hostname`
PWD="$( cd "$( dirname "$0" )" && pwd )"
# 102 去掉目錄最后的/
change_dir(){
flag=${1##*/}
if [ -z $flag ];then
ORACLE_BASE=${1%?}
fi
}
##change_dir $dir
# 101 檢查文件夾是否可以作為ORACLE_BASE目錄
check_dir(){
if [ -d $1 ];then
if [ `ls -al $1|wc -l` -gt 3 ];then
echo "[fail]====>the ORACLE_BASE must without any file(s)"
exit 101
fi
else
mkdir -p $1
fi
}
##read -p "input dir:" dir
##check_dir $dir
# 0 檢查傳入?yún)?shù)是否為空
isnull(){
if [ -z $1 ];then
echo $1
echo "[fail]====>parameter is null"
exit 0
fi
}
##isnull $hah
# 1 檢查yum源是否正常
check_yum(){
yum clean all >/dev/null 2>&1
var=`yum repolist|grep repolist|awk -F : '{print $2}'|awk -F , '{print $1}'`
## echo $var
if [ $var -eq 0 ];then
echo "[fail]====>the yum configure is wrong ,see /etc/yum.repos.d/*.repo"
exit 1
else
echo "[OK]====>the yum configure"
fi
}
##check_yum
# 2 檢查數(shù)據(jù)庫安裝軟件是否已經(jīng)上傳
check_installfile(){
cd $PWD
if [ -f "p13390677_112040_Linux-x86-64_1of7.zip" -a -f "p13390677_112040_Linux-x86-64_2of7.zip" ];then
echo "[OK]====>the installfile"
else
echo "[fail]====>the $PWD does not have p13390677_112040_Linux-* "
exit 2
fi
if [ -f "dbca.rsp" -a -f "netca.rsp" -a -f "db_install.rsp" ];then
echo "[OK]====>the config file"
else
echo "[fail]====>the $PWD does not have *.rsp"
exit 2
fi
}
##check_installfile
# 3 判斷執(zhí)行用戶是否root
isroot(){
if [ $USER != "root" ];then
echo "[fail]====>current user is not root"
exit 3
else
echo "[ok]====>current user is root"
fi
}
##isroot
# 4 獲取輸入數(shù)據(jù)庫基本信息
get_information(){
echo "========>----charcaterset seletion----"
echo "========>1.AMERICAN_AMERICA.ZHS16GBK"
echo "========>2.AMERICAN_AMERICA.AL32UTF8"
echo "========>-----------------------------"
echo -e "========>Your choice:(default 1):\c"
read NLS_LANG
case $NLS_LANG in
1) NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
CHARACTERSET=ZHS16GBK
;;
2) NLS_LANG=AMERICAN_AMERICA.AL32UTF8
CHARACTERSET=AL32UTF8
;;
*) NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
CHARACTERSET=ZHS16GBK
;;
esac
echo -e "========>please input sid(less than 8 letters):\c"
read SID
isnull $SID
echo -e "========>please input memory target(MB):\c"
read MEMORY
isnull $MEMORY
echo -e "========>please input ORACLE_BASE(will auto create):\c"
read ORACLE_BASE
isnull $ORACLE_BASE
check_dir $ORACLE_BASE
change_dir $ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
echo -e "========>please input host IP address:\c"
read IP
isnull $IP
}
##get_information
# 5 檢查cpu,內(nèi)存,磁盤空間
check_cpu_mem_disk(){
cpu=`cat /proc/cpuinfo | grep name|wc -l`
## echo $cpu
if [ $cpu -gt 1 ];then
echo "[ok]====>cpu "
else
echo "[fail]====>cpu must more than 1 cores"
exit 5
fi
mem=`free -m|grep '+'|awk '{print $4}'`
mem7=`free -m|grep Mem|awk '{print $7}'`
## echo $mem
if [[ $mem -gt 2048 || $mem7 -gt 2048 ]];then
echo "[ok]====>memory"
else
echo "[fail]====>the memory must more than 2G available"
exit 5
fi
if [ `df -m /tmp|wc -l` -eq 2 ];then
tmp=`df -m /tmp|tail -1|awk '{print $4}'`
else
tmp=`df -m /tmp|tail -1|awk '{print $3}'`
fi
if [ $tmp -gt 120 ];then
echo "[ok]====>/tmp"
else
echo "[fail]====>/tmp must more than 120MB"
exit 5
fi
if [ `free -m|grep Swap|awk '{print $2}'` -gt 150 ];then
echo "[ok]====>swap"
else
echo "[fail]====>swap must more than 150MB"
exit 5
fi
if [ `df -m $ORACLE_BASE|wc -l` -eq 2 ];then
base=`df -m $ORACLE_BASE|tail -1|awk '{print $4}'`
else
base=`df -m $ORACLE_BASE|tail -1|awk '{print $3}'`
fi
if [ $base -gt 8000 ];then
echo "[ok]====>ORACLE_BASE"
else
echo "[fail]====>ORACLE_BASE must more than 20g"
exit 5
fi
}
##check_cpu_mem_disk
# 6 安裝依賴包
yum_install(){
check_yum
yum install -y binutils >/dev/null
yum install -y compat-libstdc++-33 >/dev/null
yum install -y elfutils-libelf >/dev/null
yum install -y elfutils-libelf-devel >/dev/null
yum install -y gcc >/dev/null
yum install -y gcc-c++ >/dev/null
yum install -y glibc-common >/dev/null
yum install -y glibc-devel >/dev/null
yum install -y glibc-headers >/dev/null
yum install -y libaio >/dev/null
yum install -y libaio-devel >/dev/null
yum install -y libgcc >/dev/null
yum install -y libstdc++ >/dev/null
yum install -y libstdc++-devel >/dev/null
yum install -y make >/dev/null
yum install -y sysstat >/dev/null
yum install -y unzip >/dev/null
echo "[ok]====>the yum package has been installed"
}
##yum_install
# 7 修改/etc/sysctl.conf文件
sysctl_set(){
if [ ! -f /etc/sysctl.conf.lihb_bak ];then
cp /etc/sysctl.conf /etc/sysctl.conf.lihb_bak
echo "kernel.shmmni = 4096" >>/etc/sysctl.conf
echo "kernel.sem = 250 32000 100 128" >>/etc/sysctl.conf
echo "fs.file-max = 6815744" >>/etc/sysctl.conf
echo "net.ipv4.ip_local_port_range = 9000 65500" >>/etc/sysctl.conf
echo "net.core.rmem_default = 1048576" >>/etc/sysctl.conf
echo "net.core.rmem_max = 4194304" >>/etc/sysctl.conf
echo "net.core.wmem_default = 262144" >>/etc/sysctl.conf
echo "net.core.wmem_max = 1048576" >>/etc/sysctl.conf
echo "fs.aio-max-nr = 1048576" >>/etc/sysctl.conf
/sbin/sysctl -p >/dev/null 2>&1
echo "[ok]====>the sysctl.conf has been backup and change"
fi
}
##sysctl_set
# 8 修改/etc/security/limits.conf文件
limits_set(){
if [ ! -f /etc/security/limits.conf.lihb_bak ];then
cp /etc/security/limits.conf /etc/security/limits.conf.lihb_bak
echo "oracle soft nproc 2047" >>/etc/security/limits.conf
echo "oracle hard nproc 16384" >>/etc/security/limits.conf
echo "oracle soft nofile 1024" >>/etc/security/limits.conf
echo "oracle hard nofile 65536" >>/etc/security/limits.conf
echo "[ok]====>the limits.conf has been backup and change"
fi
}
##limits_set
# 9 修改/etc/pam.d/login文件
login_set(){
if [ ! -f /etc/pam.d/login.lihb_bak ];then
cp /etc/pam.d/login /etc/pam.d/login.lihb_bak
echo "session required /lib64/security/pam_limits.so" >>/etc/pam.d/login
echo "[ok]====>the login has been backup and change"
fi
}
##login_set
# 10 修改/etc/profile文件
profile_set(){
if [ ! -f /etc/profile.lihb_bak ];then
cp /etc/profile /etc/profile.lihb_bak
echo 'if [ "$USER" = "oracle" ];then ' >>/etc/profile
echo ' if [ "$SHELL" = "/bin/ksh" ];then ' >>/etc/profile
echo ' ulimit -p 16384' >>/etc/profile
echo ' ulimit -n 65536' >>/etc/profile
echo ' else' >>/etc/profile
echo ' ulimit -u 16384' >>/etc/profile
echo ' ulimit -n 65536' >>/etc/profile
echo ' fi' >>/etc/profile
echo ' umask 022' >>/etc/profile
echo 'fi' >>/etc/profile
echo "[ok]====>the profile has been backup and change"
fi
}
##profile_set
# 11 創(chuàng)建oracle用戶和oinstall,dba用戶組
user_group_add(){
if [[ `grep "oinstall" /etc/group` = "" ]];then
/usr/sbin/groupadd -g 1100 oinstall >/dev/null 2>&1
fi
if [[ `grep "dba" /etc/group` = "" ]];then
/usr/sbin/groupadd -g 1101 dba >/dev/null 2>&1
fi
if [[ `grep "oracle" /etc/passwd` = "" ]];then
/usr/sbin/useradd -g 1100 -G 1101 -u 1100 -m oracle >/dev/null 2>&1
echo "[ok]====>the oracle user and oinstall,dba group has been created"
else
echo "[fail]====>the oracle user has exist"
exit 11
fi
}
##user_group_add
# 12 修改/home/oracle/.bash_profile文件
bash_profile_set(){
if [ ! -f /home/oracle/.bash_profile.lihb_bak ];then
cp /home/oracle/.bash_profile /home/oracle/.bash_profile.lihb_bak
echo "" >>/home/oracle/.bash_profile
echo "export ORACLE_BASE=$ORACLE_BASE" >>/home/oracle/.bash_profile
echo "export ORACLE_HOME=$ORACLE_HOME" >>/home/oracle/.bash_profile
echo "export ORACLE_SID=$SID" >>/home/oracle/.bash_profile
echo 'export LD_LIBRARY_PATH=$ORACLE_HOME/lib' >>/home/oracle/.bash_profile
echo 'stty erase ^H' >>/home/oracle/.bash_profile
echo 'export NLS_LANG10=$ORACLE_HOME/nls/data' >>/home/oracle/.bash_profile
echo 'export ORACLE_HOME_LISTNER=$ORACLE_HOME' >>/home/oracle/.bash_profile
echo 'export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin' >>/home/oracle/.bash_profile
echo 'export TEMP=/tmp' >>/home/oracle/.bash_profile
echo 'export TMPDIR=/tmp' >>/home/oracle/.bash_profile
echo "export NLS_LANG=$NLS_LANG" >>/home/oracle/.bash_profile
echo "export NLS_DATE_FORMAT='yyyy-mm-dd hh34:mi:ss'" >>/home/oracle/.bash_profile
echo 'umask 022' >>/home/oracle/.bash_profile
echo "[ok]====>the .bash_profile has been backup and change"
fi
}
##bash_profile_set
# 13 創(chuàng)建ORACLE_BASE和ORACLE_HOME和數(shù)據(jù)文件目錄并授權(quán)
create_dir(){
mkdir -p $ORACLE_HOME
mkdir -p $ORACLE_BASE/oradata
mkdir -p $ORACLE_BASE/oraInventory
mkdir -p $ORACLE_BASE/flash_recovery_area
chown -R oracle:oinstall $ORACLE_BASE
echo "[ok]====>the dir has been created"
}
##create_dir
# 14 解壓數(shù)據(jù)庫安裝包
unzip_file(){
cd $PWD
/usr/bin/unzip p13390677_112040_Linux-x86-64_1of7.zip >/dev/null 2>&1
/usr/bin/unzip p13390677_112040_Linux-x86-64_2of7.zip >/dev/null 2>&1
chown -R oracle:oinstall $PWD/database
echo "[ok]====>the install file has been unzip"
}
##unzip_file
# 15 修改/etc/hosts文件
hosts_set(){
if [ ! -f /etc/hosts.lihb_bak ];then
cp /etc/hosts /etc/hosts.lihb_bak
echo "$IP $HOSTNAME" >>/etc/hosts
echo "[ok]====>the hosts has been backup and change"
fi
}
##hosts_set
# 16 修改db_install.rsp 數(shù)據(jù)庫軟件安裝配置文件
db_install_set(){
cd $PWD
chown oracle:oinstall db_install.rsp
if [ ! -f db_install.rsp.lihb_bak ];then
cp db_install.rsp db_install.rsp.lihb_bak
sed -i "s|lihb_hostname|$HOSTNAME|g" db_install.rsp
sed -i "s|lihb_location|$ORACLE_BASE/oraInventory|g" db_install.rsp
sed -i "s|lihb_home|$ORACLE_HOME|g" db_install.rsp
sed -i "s|lihb_base|$ORACLE_BASE|g" db_install.rsp
sed -i "s|lihb_globaldbname|$SID|g" db_install.rsp
sed -i "s|lihb_sid|$SID|g" db_install.rsp
sed -i "s|lihb_datalocation|$ORACLE_BASE/oradata|g" db_install.rsp
echo "[ok]====>the db_install.rsp has been backup and change"
fi
}
##db_install_set
# 17 開始安裝oracle軟件
install_software(){
su - oracle -c "$PWD/database/runInstaller -silent -force -ignorePrereq -responseFile $PWD/db_install.rsp" >/tmp/db_install.rsp.log
sleep 10s
echo -e "[ok]====>waiting for software install \c"
while [ ! `grep "root.sh" /tmp/db_install.rsp.log |wc -l` -eq 1 ]
do
echo -e ". \c"
sleep 2s
done
echo "."
echo "[ok]====>software has installed"
$ORACLE_BASE/oraInventory/orainstRoot.sh >/dev/null 2>&1
$ORACLE_BASE/product/11.2.0/db_1/root.sh >/dev/null 2>&1
echo "[ok]====>two script has been run by root"
}
##install_software
# 18 修改netca.rsp 監(jiān)聽安裝配置文件
netca_set(){
cd $PWD
chown oracle:oinstall netca.rsp
if [ ! -f netca.rsp.lihb_bak ];then
cp netca.rsp netca.rsp.lihb_bak
echo "[ok]====>netca.rsp has been backup and change"
fi
}
##netca_set
# 19 開始安裝監(jiān)聽軟件
install_netca(){
# ORACLE_HOME=/database/oracle/product/11.2.0/db_1/
chown -R oracle:dba /var/tmp/.oracle >/dev/null 2>&1
chown -R oracle:dba /tmp/.oracle >/dev/null 2>&1
su - oracle -c "$ORACLE_HOME/bin/netca -silent -responseFile $PWD/netca.rsp" >/tmp/netca.rsp.log
sleep 2s
echo -e "[ok]====>waiting for netca install \c"
while [ ! `grep "The exit code is" /tmp/netca.rsp.log|wc -l` -eq 1 ]
do
echo -e ". \c"
sleep 1s
done
echo "."
echo "[ok]====>netca has installed"
chown -R oracle:dba /var/tmp/.oracle >/dev/null 2>&1
chown -R oracle:dba /tmp/.oracle >/dev/null 2>&1
}
##install_netca
# 20 修改dbca.rsp 創(chuàng)建數(shù)據(jù)庫配置文件
dbca_set(){
cd $PWD
chown oracle:oinstall dbca.rsp
if [ ! -f dbca.rsp.lihb_bak ];then
cp dbca.rsp dbca.rsp.lihb_bak
# SID=cgkcglxt
# ORACLE_BASE=/database/oracle
# CHARACTERSET=ZHS16GBK
# MEMORY=4096
sed -i "s|lihb_sid|$SID|g" dbca.rsp
sed -i "s|lihb_datafiledestination|$ORACLE_BASE/oradata|g" dbca.rsp
sed -i "s|lihb_recoveryareadestination|$ORACLE_BASE/flash_recovery_area|g" dbca.rsp
sed -i "s|lihb_characterset|$CHARACTERSET|g" dbca.rsp
sed -i "s|lihb_totalmemory|$MEMORY|g" dbca.rsp
sed -i "s|lihb_gdbname|$SID|g" dbca.rsp
echo "[ok]====>dbca.rsp has been backup and change"
fi
}
##dbca_set
# 21 開始創(chuàng)建數(shù)據(jù)庫
install_dbca(){
# ORACLE_HOME=/database/oracle/product/11.2.0/db_1/
su - oracle -c "$ORACLE_HOME/bin/dbca -silent -force -responseFile $PWD/dbca.rsp"
echo "[ok]====>dbca has installed"
}
##install_dbca
# install_db 安裝數(shù)據(jù)庫
install_db(){
echo "[ok]====>begin install_db"
# check_dir $dir #檢查文件夾是否可以作為ORACLE_BASE目錄
# isnull $hah #檢查傳入?yún)?shù)是否為空
isroot #判斷執(zhí)行用戶是否root
check_yum #檢查yum源是否正常
check_installfile #檢查數(shù)據(jù)庫安裝軟件是否已經(jīng)上傳
get_information #獲取輸入數(shù)據(jù)庫基本信息
check_cpu_mem_disk #檢查cpu,內(nèi)存,磁盤空間
yum_install #安裝依賴包
sysctl_set #修改/etc/sysctl.conf文件
limits_set #修改/etc/security/limits.conf文件
login_set #修改/etc/pam.d/login文件
profile_set #修改/etc/profile文件
user_group_add #創(chuàng)建oracle用戶和oinstall,dba用戶組
bash_profile_set #修改/home/oracle/.bash_profile文件
create_dir #創(chuàng)建ORACLE_BASE和ORACLE_HOME和數(shù)據(jù)文件目錄并授權(quán)
unzip_file #解壓數(shù)據(jù)庫安裝包
hosts_set #修改/etc/hosts文件
db_install_set #修改db_install.rsp 數(shù)據(jù)庫軟件安裝配置文件
install_software #開始安裝oracle軟件
netca_set #修改netca.rsp 監(jiān)聽安裝配置文件
install_netca #開始安裝監(jiān)聽軟件
dbca_set #修改dbca.rsp 創(chuàng)建數(shù)據(jù)庫配置文件
install_dbca #開始創(chuàng)建數(shù)據(jù)庫
echo "[ok]====>the install process success"
}
##install_db
# deinstall_db 卸載數(shù)據(jù)庫軟件
deinstall_db(){
PWD="$( cd "$( dirname "$0" )" && pwd )"
touch /tmp/del_ora.sh >/dev/null 2>&1
echo "#!/bin/bash" >/tmp/del_ora.sh
echo "cd $PWD" >>/tmp/del_ora.sh
echo 'rm -rf database' >>/tmp/del_ora.sh
echo 'mv -f db_install.rsp.lihb_bak db_install.rsp >/dev/null 2>&1' >>/tmp/del_ora.sh
echo 'mv -f netca.rsp.lihb_bak netca.rsp >/dev/null 2>&1' >>/tmp/del_ora.sh
echo 'mv -f dbca.rsp.lihb_bak dbca.rsp >/dev/null 2>&1' >>/tmp/del_ora.sh
echo 'mv -f /etc/hosts.lihb_bak /etc/hosts >/dev/null 2>&1' >>/tmp/del_ora.sh
echo 'mv -f /etc/profile.lihb_bak /etc/profile >/dev/null 2>&1' >>/tmp/del_ora.sh
echo 'mv -f /etc/pam.d/login.lihb_bak /etc/pam.d/login >/dev/null 2>&1' >>/tmp/del_ora.sh
echo 'mv -f /etc/security/limits.conf.lihb_bak /etc/security/limits.conf >/dev/null 2>&1' >>/tmp/del_ora.sh
echo 'mv -f /etc/sysctl.conf.lihb_bak /etc/sysctl.conf >/dev/null 2>&1' >>/tmp/del_ora.sh
echo '/sbin/sysctl -p >/dev/null 2>&1' >>/tmp/del_ora.sh
echo 'rm -rf /opt/tmp/.oracle' >>/tmp/del_ora.sh
echo 'rm -rf /tmp/.oracle' >>/tmp/del_ora.sh
echo 'rm -rf /opt/ORCLfmap' >>/tmp/del_ora.sh
echo 'rm -rf /etc/oraInst.loc' >>/tmp/del_ora.sh
echo 'rm -rf /etc/oratab' >>/tmp/del_ora.sh
echo 'userdel -r oracle >/dev/null 2>&1' >>/tmp/del_ora.sh
ORACLE_BASE=`cat /home/oracle/.bash_profile|grep ORACLE_BASE|awk -F = '{print $2}'`
echo "rm -rf $ORACLE_BASE" >>/tmp/del_ora.sh
chmod u+x /tmp/del_ora.sh
echo 'please use oracle to run $ORACLE_HOME/deinstall/deinstall and use root to run /tmp/del_ora.sh'
}
##deinstall_db
# configure_yum 配置yum源
configure_yum(){
echo -e "========>please input the iso location(eg:/tmp/xxx.iso):\c"
read ISOLOCATION
mkdir -p /media/lihb_iso
mount -t iso9660 -o loop $ISOLOCATION /media/lihb_iso
mkdir -p /etc/yum.repos.d/lihb_bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/lihb_bak
touch /etc/yum.repos.d/lihb_local.repo
echo "[lihb_local]" >/etc/yum.repos.d/lihb_local.repo
echo "name=lihb_local" >>/etc/yum.repos.d/lihb_local.repo
echo "baseurl=file:///media/lihb_iso" >>/etc/yum.repos.d/lihb_local.repo
echo "gpgcheck=0" >>/etc/yum.repos.d/lihb_local.repo
echo "enabled=1" >>/etc/yum.repos.d/lihb_local.repo
check_yum
}
##configure_yum
# main 程序入口
main(){
echo "========>-------- seletion------------"
echo "========>1.install database"
echo "========>2.deinstall database"
echo "========>3.configure local yum"
echo "========>-----------------------------"
echo -e "========>Your choice:\c"
read FLAG
case $FLAG in
1) install_db #安裝數(shù)據(jù)庫
;;
2) deinstall_db #卸載數(shù)據(jù)庫
;;
3) configure_yum #配置本地yum源
;;
*) exit 200
;;
esac
}
main
如下是db_install.rsp的內(nèi)容:
點(diǎn)擊(此處)折疊或打開
####################################################################
## Copyright(c) Oracle Corporation 1998,2013. All rights reserved.##
## ##
## Specify values for the variables listed below to customize ##
## your installation. ##
## ##
## Each variable is associated with a comment. The comment ##
## can help to populate the variables with the appropriate ##
## values. ##
## ##
## IMPORTANT NOTE: This file contains plain text passwords and ##
## should be secured to have read permission only by oracle user ##
## or db administrator who owns this installation. ##
## ##
####################################################################
#------------------------------------------------------------------------------
# Do not change the following system generated value.
#------------------------------------------------------------------------------
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
#------------------------------------------------------------------------------
# Specify the installation option.
# It can be one of the following:
# - INSTALL_DB_SWONLY
# - INSTALL_DB_AND_CONFIG
# - UPGRADE_DB
#-------------------------------------------------------------------------------
oracle.install.option=INSTALL_DB_SWONLY
#-------------------------------------------------------------------------------
# Specify the hostname of the system as set during the install. It can be used
# to force the installation to use an alternative hostname rather than using the
# first hostname found on the system. (e.g., for systems with multiple hostnames
# and network interfaces)
#-------------------------------------------------------------------------------
ORACLE_HOSTNAME=lihb_hostname
#-------------------------------------------------------------------------------
# Specify the Unix group to be set for the inventory directory.
#-------------------------------------------------------------------------------
UNIX_GROUP_NAME=oinstall
#-------------------------------------------------------------------------------
# Specify the location which holds the inventory files.
# This is an optional parameter if installing on
# Windows based Operating System.
#-------------------------------------------------------------------------------
INVENTORY_LOCATION=lihb_location
#-------------------------------------------------------------------------------
# Specify the languages in which the components will be installed.
#
# en : English ja : Japanese
# fr : French ko : Korean
# ar : Arabic es : Latin American Spanish
# bn : Bengali lv : Latvian
# pt_BR: Brazilian Portuguese lt : Lithuanian
# bg : Bulgarian ms : Malay
# fr_CA: Canadian French es_MX: Mexican Spanish
# ca : Catalan no : Norwegian
# hr : Croatian pl : Polish
# cs : Czech pt : Portuguese
# da : Danish ro : Romanian
# nl : Dutch ru : Russian
# ar_EG: Egyptian zh_CN: Simplified Chinese
# en_GB: English (Great Britain) sk : Slovak
# et : Estonian sl : Slovenian
# fi : Finnish es_ES: Spanish
# de : German sv : Swedish
# el : Greek th : Thai
# iw : Hebrew zh_TW: Traditional Chinese
# hu : Hungarian tr : Turkish
# is : Icelandic uk : Ukrainian
# in : Indonesian vi : Vietnamese
# it : Italian
#
# all_langs : All languages
#
# Specify value as the following to select any of the languages.
# Example : SELECTED_LANGUAGES=en,fr,ja
#
# Specify value as the following to select all the languages.
# Example : SELECTED_LANGUAGES=all_langs
#------------------------------------------------------------------------------
SELECTED_LANGUAGES=en
#------------------------------------------------------------------------------
# Specify the complete path of the Oracle Home.
#------------------------------------------------------------------------------
ORACLE_HOME=lihb_home
#------------------------------------------------------------------------------
# Specify the complete path of the Oracle Base.
#------------------------------------------------------------------------------
ORACLE_BASE=lihb_base
#------------------------------------------------------------------------------
# Specify the installation edition of the component.
#
# The value should contain only one of these choices.
# - EE : Enterprise Edition
# - SE : Standard Edition
# - SEONE : Standard Edition One
# - PE : Personal Edition (WINDOWS ONLY)
#------------------------------------------------------------------------------
oracle.install.db.InstallEdition=EE
#------------------------------------------------------------------------------
# This variable is used to enable or disable custom install and is considered
# only if InstallEdition is EE.
#
# true : Components mentioned as part of 'optionalComponents' property
# are considered for install.
# false : Value for 'optionalComponents' is not considered.
#------------------------------------------------------------------------------
oracle.install.db.EEOptionsSelection=false
#------------------------------------------------------------------------------
# This variable is considered only if 'EEOptionsSelection' is set to true.
#
# Description: List of Enterprise Edition Options you would like to enable.
#
# The following choices are available. You may specify any
# combination of these choices. The components you choose should
# be specified in the form "internal-component-name:version"
# Below is a list of components you may specify to enable.
#
# oracle.oraolap:11.2.0.4.0 - Oracle OLAP
# oracle.rdbms.dm:11.2.0.4.0 - Oracle Data Mining
# oracle.rdbms.dv:11.2.0.4.0 - Oracle Database Vault
# oracle.rdbms.lbac:11.2.0.4.0 - Oracle Label Security
# oracle.rdbms.partitioning:11.2.0.4.0 - Oracle Partitioning
# oracle.rdbms.rat:11.2.0.4.0 - Oracle Real Application Testing
#------------------------------------------------------------------------------
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
###############################################################################
# #
# PRIVILEGED OPERATING SYSTEM GROUPS #
# ------------------------------------------ #
# Provide values for the OS groups to which OSDBA and OSOPER privileges #
# needs to be granted. If the install is being performed as a member of the #
# group "dba", then that will be used unless specified otherwise below. #
# #
# The value to be specified for OSDBA and OSOPER group is only for UNIX based #
# Operating System. #
# #
###############################################################################
#------------------------------------------------------------------------------
# The DBA_GROUP is the OS group which is to be granted OSDBA privileges.
#------------------------------------------------------------------------------
oracle.install.db.DBA_GROUP=dba
#------------------------------------------------------------------------------
# The OPER_GROUP is the OS group which is to be granted OSOPER privileges.
# The value to be specified for OSOPER group is optional.
#------------------------------------------------------------------------------
oracle.install.db.OPER_GROUP=oinstall
#------------------------------------------------------------------------------
# Specify the cluster node names selected during the installation.
# Example : oracle.install.db.CLUSTER_NODES=node1,node2
#------------------------------------------------------------------------------
oracle.install.db.CLUSTER_NODES=
#------------------------------------------------------------------------------
# This variable is used to enable or disable RAC One Node install.
#
# - true : Value of RAC One Node service name is used.
# - false : Value of RAC One Node service name is not used.
#
# If left blank, it will be assumed to be false