大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
小编给大家分享一下rhel6/7如何自动安装oracle11g单实例,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
成都创新互联公司从2013年开始,先为淮阳等服务建站,淮阳等地企业,进行企业商务咨询服务。为淮阳企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
因日常工作,经常需要在rhel6.X,rhel7.X,CentOS6.X,CentOS7.x上安装oracle 11.2.0.4版本单实例数据库(基于文件系统)
故写了自动安装脚本oracle脚本。
全部文件列表如下:
1、其中iso文件是对应的红帽系统的镜像源(根据cat /etc/redhat-release获取红帽版本)
2、其中两个zip安装包,可以从SR上下载(搜索13390677找到对应的文件,注意文件名必须一致)
3、其中三个rsp文件是安装oracle的配置文件,db_install.rsp用于安装数据库软件,dbca.rsp用于创建数据库,netca.rsp用于创建监听。
4、其中sh文件是本人写的脚本,直接使用root用户执行即可(需要chmod u+x auto_install_oracle_server.sh),期间需要用户输入几个信息:字符集、oracle_sid、主机ip地址,memory_target。
因只在红帽6与7的部分版本测试过,可能还有一些问题。可具体修改shell脚本。
操作过程:
1、查看文件是否齐全
点击(此处)折叠或打开
[root@testlihb ~]# cd /tmp
[root@testlihb tmp]# ls -lrt
total 6120464
-rw-r--r-- 1 root root 5871 Apr 28 07:00 netca.rsp #监听配置文件
-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 #数据库软件配置文件
-rw-r--r-- 1 root root 44580 Apr 28 07:00 dbca.rsp #数据库配置文件
-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 #操作系统光盘文件
[root@testlihb tmp]# chmod u+x auto_install_oracle_server.sh #root赋予可执行权限
2、配置yum源,如果确认yum源已经配置完毕,可忽略此步骤
点击(此处)折叠或打开
[root@testlihb tmp]# ./auto_install_oracle_server.sh #root直接执行
========>-------- seletion------------
========>1.install database #安装数据库
========>2.deinstall database #卸载数据库(只可以卸载通过本脚本安装的数据库)
========>3.configure local yum #配置yum源
========>-----------------------------
========>Your choice:3 #选择配置yum源,如果确认yum源已经配置好了,此处可忽略
========>please input the iso location(eg:/tmp/xxx.iso):/tmp/rhel-server-6.4-x86_64-dvd.iso #输入iso文件的路径
[OK]====>the yum configure
3、安装数据库
点击(此处)折叠或打开
[root@testlihb tmp]# ./auto_install_oracle_server.sh
========>-------- seletion------------
========>1.install database
========>2.deinstall database
========>3.configure local yum
========>-----------------------------
========>Your choice:1 #安装数据库
[ok]====>begin install_db
[ok]====>current user is root #检查当前用户是否为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 #选择数据库字符集,此处只有两个选择
========>please input sid(less than 8 letters):oragbk #输入sid,sid必须少于8个字符
========>please input memory target(MB):4096 #输入内存,其中sga和pga比例为3:1
========>please input ORACLE_BASE(will auto create):/database/oragbk #oracle软件目录(如果目录不存在,会自动创建。如果目录存在,该目录必须为空)
========>please input host IP address:192.168.75.236 #输入本机ip地址
[ok]====>cpu #检查cpu
[ok]====>memory #检查内存
[ok]====>/tmp #检查/tmp目录
[ok]====>swap #检查交换分区
[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 #创建oracle用户,oinstall和dba组
[ok]====>the .bash_profile has been backup and change #备份和修改.bash_profile文件
[ok]====>the dir has been created #检查和创建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执行两个shell script文件
[ok]====>netca.rsp has been backup and change #备份和修改netca.rsp文件
[ok]====>waiting for netca install . #此处在创建listener,不需要等待太长时间,可查看/tmp/netca.rsp.log
[ok]====>netca has installed #listener创建完成
[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 #数据库创建完成
[ok]====>the install process success
4、检查数据库是否正常
点击(此处)折叠或打开
[root@testlihb tmp]# ps -ef|grep smon_ |grep -v grep
oracle 12863 1 0 07:34 ? 00:00:00 ora_smon_oragbk #进程存在
[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、卸载数据库
点击(此处)折叠或打开
[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用户执行脚本,然后在切到root用户执行脚本
[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、检查是否已经删除数据库
点击(此处)折叠或打开
[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
点击(此处)折叠或打开
#!/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 检查传入参数是否为空
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 检查数据库安装软件是否已经上传
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 判断执行用户是否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 获取输入数据库基本信息
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,内存,磁盘空间
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 创建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 创建ORACLE_BASE和ORACLE_HOME和数据文件目录并授权
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 解压数据库安装包
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 数据库软件安装配置文件
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 监听安装配置文件
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 开始安装监听软件
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 创建数据库配置文件
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 开始创建数据库
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 安装数据库
install_db(){
echo "[ok]====>begin install_db"
# check_dir $dir #检查文件夹是否可以作为ORACLE_BASE目录
# isnull $hah #检查传入参数是否为空
isroot #判断执行用户是否root
check_yum #检查yum源是否正常
check_installfile #检查数据库安装软件是否已经上传
get_information #获取输入数据库基本信息
check_cpu_mem_disk #检查cpu,内存,磁盘空间
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 #创建oracle用户和oinstall,dba用户组
bash_profile_set #修改/home/oracle/.bash_profile文件
create_dir #创建ORACLE_BASE和ORACLE_HOME和数据文件目录并授权
unzip_file #解压数据库安装包
hosts_set #修改/etc/hosts文件
db_install_set #修改db_install.rsp 数据库软件安装配置文件
install_software #开始安装oracle软件
netca_set #修改netca.rsp 监听安装配置文件
install_netca #开始安装监听软件
dbca_set #修改dbca.rsp 创建数据库配置文件
install_dbca #开始创建数据库
echo "[ok]====>the install process success"
}
##install_db
# deinstall_db 卸载数据库软件
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 #安装数据库
;;
2) deinstall_db #卸载数据库
;;
3) configure_yum #配置本地yum源
;;
*) exit 200
;;
esac
}
main
如下是db_install.rsp的内容:
点击(此处)折叠或打开
####################################################################
## 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