脚本安装oracle19c

内容大多来自网络博客、贴吧,如果侵犯了你的权益,告诉我,我删掉。

这个脚本,我自己再centos7.8+oracle19.3是测试过了的。具体在各自环境上跑,可能有细节需要调整。

 

#!/bin/sh

SOFTDIR=/oracle/app/oracle/product/19.3.0/dbhome_1
LOGFILE=/tmp/install_oracle.log
BASE_DIR=$(pwd)
VG_NAME=centos

########################################
#check vg room

vgs | grep -w ${VG_NAME} > /dev/null
if [ $? -eq 1 ];then
echo "vg ${VG_NAME} does not exist,please check!"
exit 1
fi

_vg_left=$(vgs | grep -w ${VG_NAME} | grep [0-9]*g | awk '{print $NF}' | sed 's/\..*//')
if [ 40 -ge ${_vg_left:-0} ];then
echo "vg ${VG_NAME} useful room less than 40G "
exit 1
fi

###########################################################
##install software needed by oracle 19c
mv /etc/yum.repos.d/*.repo /tmp
echo "
[base]
name=CentOS-\$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
http://mirrors.aliyuncs.com/centos/\$releasever/os/\$basearch/
http://mirrors.cloud.aliyuncs.com/centos/\$releasever/os/\$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-\$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/\$releasever/updates/\$basearch/
http://mirrors.aliyuncs.com/centos/\$releasever/updates/\$basearch/
http://mirrors.cloud.aliyuncs.com/centos/\$releasever/updates/\$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-\$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/
http://mirrors.aliyuncs.com/centos/\$releasever/extras/\$basearch/
http://mirrors.cloud.aliyuncs.com/centos/\$releasever/extras/\$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7" > /etc/yum.repos.d/CentOS-Base.repo

yum clean all
yum makecache

##################
#begin install
yum install -y bc binutils elfutils-libelf elfutils-libelf-devel fontconfig-devel glibc glibc-devel ksh libaio libaio-devel libXrender libX11 libXau libXi libXtst libgcc librdmacm libstdc++ libstdc++-devel libxcb libibverbs make smartmontools sysstat compat-libcap1 compat-libstdc++-33 unzip

#Check software
####################################################
for _rpm in bc binutils elfutils-libelf elfutils-libelf-devel fontconfig-devel glibc glibc-devel ksh libaio libaio-devel libXrender libX11 libXau libXi libXtst libgcc librdmacm libstdc++ libstdc++-devel libxcb libibverbs make smartmontools sysstat compat-libcap1 compat-libstdc++-33 unzip
do
rpm -qa | grep -w ${_rpm} >/dev/null
if [ $? -ne 0 ]
then
echo "${_rpm} not installed"
exit 2
fi
done

########################################
#Create Oracle Filesystem
########################################
echo "Create Oracle Filesystem" >> $LOGFILE
lvcreate -L 20G -n oracle ${VG_NAME}
echo "lvcreate -L 20G -n oracle ${VG_NAME}.... OK=$?" >>$LOGFILE
vgs >> $LOGFILE
lvs >> $LOGFILE
df -h >> $LOGFILE
mkdir -p /oracle
mkfs.xfs /dev/${VG_NAME}/oracle
echo "mkfs.xfs /dev/${VG_NAME}/oracle...OK=$?" >> $LOGFILE
mount /dev/${VG_NAME}/oracle /oracle
echo "mount /dev/${VG_NAME}/oracle /oracle...OK=$?" >> $LOGFILE
mount >> $LOGFILE
echo "/dev/mapper/${VG_NAME}-oracle /oracle xfs defaults 0 0">> /etc/fstab

########################################
#Remove Default profile scripts
########################################
echo "Remove Default profile scripts" >> $LOGFILE
cd /etc/profile.d
mv oracle.sh oracle.sh.bak
mv oracle.csh oracle.csh.bak

########################################
#Delete Default User and Groups
########################################
echo "Delete Default User and Groups" >> $LOGFILE
/usr/sbin/userdel oracle
/usr/sbin/userdel grid
/usr/sbin/groupdel oinstall
/usr/sbin/groupdel dba
/usr/sbin/groupdel oper
/usr/sbin/groupdel backupdba
/usr/sbin/groupdel dgdba
/usr/sbin/groupdel kmdba
/usr/sbin/groupdel asmdba
/usr/sbin/groupdel asmoper
/usr/sbin/groupdel racdba

########################################
#Create User and Groups
########################################
echo "Create User and Groups" >> $LOGFILE
/usr/sbin/groupadd -g 54321 oinstall
/usr/sbin/groupadd -g 54322 dba
/usr/sbin/groupadd -g 54323 oper
/usr/sbin/groupadd -g 54324 backupdba
/usr/sbin/groupadd -g 54325 dgdba
/usr/sbin/groupadd -g 54326 kmdba
/usr/sbin/groupadd -g 54327 asmdba
/usr/sbin/groupadd -g 54328 asmoper
/usr/sbin/groupadd -g 54330 racdba
/usr/sbin/useradd -u 54321 -g oinstall -G dba,asmdba,backupdba,dgdba,kmdba,racdba,oper oracle
/usr/sbin/useradd -u 54331 -g oinstall -G dba,asmdba,backupdba,dgdba,kmdba,racdba grid

########################################
#Create Home directory and Software directory
########################################
echo "Create Home directory and Software directory" >> $LOGFILE
mkdir -p /home/oracle
mkdir -p /oracle/app/oracle/product/19.3.0/dbhome_1
##########################################
#当前测试环境为vmware,通过vm共享主机上的文件,因此路径是 /mnt/hgfs/Iso/V982063-01.zip
#如果不是,需要修改
unzip /mnt/hgfs/Iso/V982063-01.zip -d /oracle/app/oracle/product/19.3.0/dbhome_1
chown -R oracle:oinstall /oracle/app/oracle/product/19.3.0/dbhome_1
chmod -R 755 /home/oracle
chmod -R 755 /oracle
chown -R oracle:oinstall /home/oracle
chown -R oracle:oinstall /oracle
ls -l / >> $LOGFILE
########################################
#Set kernel parameters
########################################
echo "Set kernel parameters" >> $LOGFILE
MEMORY_SIZE=`grep MemTotal /proc/meminfo|awk -F ' ' '{print $2}'`
MEMORY_SIZE_BYTES=`echo $MEMORY_SIZE*1024|bc`

echo "
kernel.shmall = $MEMORY_SIZE_BYTES
kernel.shmmax = $MEMORY_SIZE_BYTES
kernel.shmmni = 4096
kernel.sem = 2500 32000 1024 1280
fs.file-max = 6815744
fs.aio-max-nr = 1048576
###net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
vm.hugetlb_shm_group = 302
" >>/etc/sysctl.conf
/sbin/sysctl -p

########################################
#Create oraInst.loc
########################################
echo "Create oraInst.loc" >> $LOGFILE
echo "
inventory_loc=/oracle/app/oraInventory
inst_group=oinstall
" >/etc/oraInst.loc

########################################
#Create .bash_profile
########################################
echo "Create .profile" >> $LOGFILE
echo "
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=\$PATH:\$HOME/bin

export PATH

if [ -t 0 ]; then
stty intr ^C
fi

stty erase '^H'
umask 022
export ORACLE_SID=
export ORACLE_BASE=/oracle/app/oracle
export ORACLE_HOME=\$ORACLE_BASE/product/19.3.0/dbhome_1
export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:\$ORACLE_HOME/oracm/lib:/lib:/usr/lib
export NLS_DATE_FORMAT=\"YYYY-MM-DD HH24:MI:SS\"
export TMP=/tmp
export TMPDIR=\$TMP
export PATH=\$ORACLE_HOME/bin:\$ORACLE_HOME/OPatch:\$PATH:
export TNS_ADMIN=\$ORACLE_HOME/network/admin
export ORACLE_PATH=.:\$ORACLE_BASE/dba_scripts/sql:\$ORACLE_HOME/rdbms/admin
export SQLPATH=\$ORACLE_HOME/sqlplus/admin
export NLS_LANG=\"AMERICAN_CHINA.ZHS16GBK\"
export ORA_NLS11=\$ORACLE_HOME/nls/data
export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib:\$ORACLE_HOME/network/jlib
#####################################
#下面三个需要rlwrap 支持,是可选的
#####################################
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
alias asmcmd='rlwrap asmcmd'
" >/home/oracle/.bash_profile

chown oracle:oinstall /home/oracle/.bash_profile

#Create Oracle Data Filesystem
########################################
echo "Create Oracle Filesystem" >> $LOGFILE
lvcreate -L 20G -n u01 ${VG_NAME}
echo "lvcreate -L 20G -n u01 ${VG_NAME}.... OK=$?" >>$LOGFILE
vgs >> $LOGFILE
lvs >> $LOGFILE
df -h >> $LOGFILE
mkdir -p /u01
mkfs.xfs /dev/${VG_NAME}/u01
echo "mkfs.xfs /dev/${VG_NAME}/u01...OK=$?" >> $LOGFILE
mount /dev/${VG_NAME}/u01 /u01
chown -R oracle:oinstall /u01
echo "mount /dev/${VG_NAME}/u01 /u01...OK=$?" >> $LOGFILE
mount >> $LOGFILE
echo "/dev/mapper/${VG_NAME}-u01 /u01 xfs defaults 0 0">> /etc/fstab

#################################################

cd $SOFTDIR
echo "$SOFTDIR/runInstaller -silent -force -noconfig -ignorePrereq \
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v19.0.0 \
oracle.install.option=INSTALL_DB_SWONLY \
UNIX_GROUP_NAME=oinstall \
INVENTORY_LOCATION=/oracle/app/oraInventory \
ORACLE_BASE=/oracle/app/oracle \
oracle.install.db.InstallEdition=EE \
oracle.install.db.OSDBA_GROUP=dba \
oracle.install.db.OSOPER_GROUP=oper \
oracle.install.db.OSBACKUPDBA_GROUP=backupdba \
oracle.install.db.OSDGDBA_GROUP=dgdba \
oracle.install.db.OSKMDBA_GROUP=kmdba \
oracle.install.db.OSRACDBA_GROUP=racdba \
oracle.install.db.rootconfig.executeRootScript=false \
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE \
oracle.install.db.config.starterdb.globalDBName=orcl \
oracle.install.db.config.starterdb.SID=orcl \
oracle.install.db.ConfigureAsContainerDB=true \
oracle.install.db.config.starterdb.managementOption=DEFAULT \
oracle.install.db.config.starterdb.omsPort=0 \
oracle.install.db.config.starterdb.enableRecovery=false \
oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE \
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/u01/app/oracle/oradata" >>$LOGFILE
mkdir -p /home/oracle
mkdir -p /oracle/app/oracle/product/19.3.0/dbhome_1
chmod -R 755 /home/oracle
chmod -R 755 /oracle
chown -R oracle:oinstall /home/oracle
chown -R oracle:oinstall /oracle
ls -l >> $LOGFILE
su - oracle -c "$SOFTDIR/runInstaller -silent -force -noconfig -ignorePrereq \
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v19.0.0 \
oracle.install.option=INSTALL_DB_SWONLY \
UNIX_GROUP_NAME=oinstall \
INVENTORY_LOCATION=/oracle/app/oraInventory \
ORACLE_BASE=/oracle/app/oracle \
oracle.install.db.InstallEdition=EE \
oracle.install.db.OSDBA_GROUP=dba \
oracle.install.db.OSOPER_GROUP=oper \
oracle.install.db.OSBACKUPDBA_GROUP=backupdba \
oracle.install.db.OSDGDBA_GROUP=dgdba \
oracle.install.db.OSKMDBA_GROUP=kmdba \
oracle.install.db.OSRACDBA_GROUP=racdba \
oracle.install.db.rootconfig.executeRootScript=false \
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE \
oracle.install.db.config.starterdb.globalDBName=orcl \
oracle.install.db.config.starterdb.SID=orcl \
oracle.install.db.ConfigureAsContainerDB=true \
oracle.install.db.config.starterdb.managementOption=DEFAULT \
oracle.install.db.config.starterdb.omsPort=0 \
oracle.install.db.config.starterdb.enableRecovery=false \
oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE \
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/u01/app/oracle/oradata "<<EOF
yuqq
EOF
#########################################################
#安装的时候需要输入root密码,记得改成你自己的root密码
#########################################################

#############################################
#sh /oracle/app/oracle/product/19.3.0/dbhome_1/root.sh <<EOF
sh /oracle/app/oracle/product/19.3.0/dbhome_1/root.sh

#########################
#oracle安装文件解压缩到 $ORACLE_HOME ,解压缩后是6.6G
#oracle安装完成后 7.1G
# /dev/mapper/${VG_NAME}-oracle 20G 7.1G 13G 36% /oracle

#####################################
#create db
su - oracle -c "dbca -silent -createDatabase -templateName General_Purpose.dbc -responseFile NO_VALUE \
-gdbname QQ -sid QQ \
-createAsContainerDatabase TRUE \
-numberOfPDBs 1 \
-pdbName lhrpdb2 \
-pdbAdminPassword lhr \
-sysPassword lhr -systemPassword lhr \
-datafileDestination '/u01/app/oracle/oradata' \
-recoveryAreaDestination '/u01/app/oracle/flash_recovery_area' \
-redoLogFileSize 50 \
-storageType FS \
-characterset AL32UTF8 -nationalCharacterSet AL16UTF16 \
-sampleSchema true \
-totalMemory 2048 \
-databaseType OLTP \
-emConfiguration NONE"

############################################
#create /tmp/netca.rsp
echo "
[GENERAL]

RESPONSEFILE_VERSION=\"19.3\"

CREATE_TYPE=\"CUSTOM\"

[oracle.net.ca]

INSTALLED_COMPONENTS=\{\"server\",\"net8\",\"javavm\"\}

INSTALL_TYPE=\"\"typical\"\"

LISTENER_NUMBER=1

LISTENER_NAMES=\{\"LISTENER\"\}

LISTENER_PROTOCOLS=\{\"TCP;1521\"\}

LISTENER_START=\"\"LISTENER\"\"

NAMING_METHODS=\{\"TNSNAMES\",\"ONAMES\",\"HOSTNAME\"\}

NSN_NUMBER=1

NSN_NAMES=\{\"EXTPROC_CONNECTION_DATA\"\}

NSN_SERVICE=\{\"PLSExtProc\"\}

NSN_PROTOCOLS=\{\"TCP;HOSTNAME;1521\"\} " >/tmp/netca.rsp

####################################
#create LISTENER
su - oracle -c "netca -silent -responsefile /tmp/netca.rsp"

 

########################################################################
安装完成后,务必修改oracle用户下的.bash_profile文件ORACLE_SID配置。
如果没有修改,直接登录,会报错:
Enter user-name:
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
########################################################################

上一篇:CorelDRAW 设计优秀品质的香水广告


下一篇:docker安装oracle19c记录