此脚本针对11.2.0,其他版本oracle类似。
脚本执行的所有步骤
-
定义Oracle安装所需的变量。
-
打印本机主机名、内存大小、Oracle SID以及为内核shmmax和shmall设置的值。
-
提示用户将Oracle数据库安装包放置在特定目录。
-
创建swap空间。
-
安装EPEL仓库和NTP服务,同步时间。
-
关闭SELinux和防火墙,禁用NetworkManager。
-
安装Oracle安装所需的依赖包。
-
创建Oracle用户和组。
-
创建Oracle数据库和实例所需的目录,并设置权限。
-
修改
/etc/hosts
文件以绑定hostname。 -
修改系统内存参数和网络参数。
-
修改系统用户限制(ulimit)设置。
-
修改登录配置文件以应用用户限制。
-
修改Oracle用户的bash配置文件。
-
备份和修改Oracle安装响应文件。
-
授权安装目录。
-
执行Oracle安装程序。
-
执行Oracle的root脚本。
-
配置Oracle监听器。
-
创建数据库实例。
-
解决Oracle sqlplus命令行乱码问题。
-
检查监听器状态和数据库端口。
脚本内容如下
#!/bin/sh
#到oracle官网下载压缩包
#https://updates.oracle.com/Orion/Services/download/p13390677_112040_Linux-x86-64_1of7.zip?aru=16716375&patch_file=p13390677_112040_Linux-x86-64_1of7.zip
#https://updates.oracle.com/Orion/Services/download/p13390677_112040_Linux-x86-64_2of7.zip?aru=16716375&patch_file=p13390677_112040_Linux-x86-64_2of7.zip
#将下载的p13390677_112040_Linux-x86-64_1of7.zip和p13390677_112040_Linux-x86-64_2of7.zip上到服务器的/data/install/目录下
#定义相关变量
oracle_directory=/data/u01/app
oracle_hostname=`hostname`
oracle_pass=Oracle#1230
sid=bapp
mem=`expr $(free -g |sed -n '2p' |awk '{print $2}') + 1`
kernel_shmmax=`expr $mem \* 1024 \* 1024 \* 1024 - 1`
kernel_shmall=`expr $mem \* 1024 \* 1024 / 4`
echo "本机主机名:" $oracle_hostname
echo "本机内存:" $mem "GB"
echo "Oracle SID:" $sid
echo "kernel_shmmax值设置为:" $kernel_shmmax
echo "kernel_shmall值设置为:" $kernel_shmall
echo "请放置database.tar.gz到/data/packet目录并解压"
#创建swap
dd if=/dev/zero of=/data/swapfile bs=1M count=10240
mkswap /data/swapfile
swapon /data/swapfile
echo '/swap/swapfile swap swap defaults 0 0' | tee -a /etc/fstab
#安装扩展yum源
yum install epel-release -y
yum -y install ntp ntpdate
#同步网络时间
ntpdate time.nist.gov
sleep 15s
#创建安装包存放目录
#mkdir -p $oracle_directory/install
cd /data/packet
#sleep 5m
#解压和授权
#unzip p13390677_112040_Linux-x86-64_1of7.zip
#unzip p13390677_112040_Linux-x86-64_2of7.zip
#关闭 SELinux
sed -i '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
#关闭防火墙
systemctl disable firewalld
systemctl stop firewalld
#禁用 NetworkManager
systemctl disable NetworkManager
systemctl stop NetworkManager
#安装依赖包
yum provides '*/applydeltarpm'
yum install -y deltarpm
yum install -y automake autotools-dev binutils bzip2 elfutils expat gawk gcc gcc-multilib g++-multilib lib32ncurses5 lib32z1 ksh less lib32z1 libaio1 libaio-dev libc6-dev libc6-dev-i386 libc6-i386 libelf-dev libltdl-dev libodbcinstq4-1 libodbcinstq4-1:i386 libpth-dev libpthread-stubs0-dev libstdc++5 make openssh-server rlwrap rpm sysstat unixodbc unixodbc-dev unzip x11-utils zlibc unzip cifs-utils libXext.x86_64 glibc.i686 expect
groupadd oinstall
groupadd dba
groupadd oper
useradd -g oinstall -G dba,oper oracle
#创建数据目录
mkdir -p $oracle_directory/oracle/product/11.2.0
mkdir -p $oracle_directory/oracle/oradata
mkdir -p $oracle_directory/oracle/fast_recovery_area
#mkdir -p $oracle_directory/oracle/inventory
mkdir -p $oracle_directory/oracle/oraInventory
mkdir -p $oracle_directory/admin/orcl/adump
mkdir -p $oracle_directory/flash_recovery_area
chown -R oracle:oinstall /data/u01
#绑定hosts
echo 127.0.0.1 $oracle_hostname >>/etc/hosts
#修改内存参数
cat << EOF >> /etc/sysctl.conf
fs.aio-max-nr = 1048576
fs.file-max = 6815744
#物理内存一半和4G中的较小者 值=内存G*1024*1024*1024,内存为 12G 时,该值为 12*1024*1024*1024-1 = 12884901887 ;内存为 16G 时,该值为 16*1024*1024*1024-1 = 17179869183 ;内存为 32G 时,该值为 32*1024*1024*1024-1 = 34359738367
#kernel.shmmax = 34359738367
#kernel.shmmax = 17179869184 #16G内存设置
kernel.shmmax = $kernel_shmmax #4G内存设置
#shmmax / 4k (getconf PAGESIZE)
#kernel.shmall = 1048576,共享内存的总页数,值=内存G/4KB,当内存为12G时,kernel.shmall = 3145728 ;当内存为 16G 时,
kernel.shmall=$kernel_shmall #6G内存设置,当内次为 32G 时, kernel.shmall = 8388608
#kernel.shmall=3774873
kernel.shmmni = 4096
kernel.sem = 250 32000 200 200
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
net.core.rmem_max = 4194304
EOF
sysctl -p
#修改 limits.conf
cat << EOF >> /etc/security/limits.conf
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
EOF
#修改 login
cat << EOF >> /etc/pam.d/login
session required /lib64/security/pam_limits.so
session required pam_limits.so
EOF
#修改 profile
cat << EOF >> /etc/profile
if [ \$USER = "oracle" ] ; then
if [ \$SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
umask 022
fi
EOF
#修改 oracle 用户的 .bash_profile
cat << EOF >> /home/oracle/.bash_profile
export ORACLE_BASE=$oracle_directory/oracle
export ORACLE_HOME=\$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=$sid
export ORACLE_UNQNAME=$ORACLE_SID
export PATH=\$PATH:\$ORACLE_HOME/bin
export NLS_LANG="AMERICAN_AMERICA.AL32UTF8 "
#export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"
#export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
EOF
#使修改生效
source /home/oracle/.bash_profile
#查看环境变量
env
#备份 response 文件
cd /data/packet/database
\cp -r response response_default
#修改 db_install.rsp :$oracle_directory/install/database/response/db_install.rsp,密码为Oracle#1230
cat << EOF > /data/packet/database/response/db_install.rsp
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=$oracle_hostname
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=$oracle_directory/oracle/oraInventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=$oracle_directory/oracle/product/11.2.0/dbhome_1
ORACLE_BASE=$oracle_directory/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.EEOptionsSelection=false
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
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oinstall
oracle.install.db.CLUSTER_NODES=
oracle.install.db.isRACOneInstall=
oracle.install.db.racOneServiceName=
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
oracle.install.db.config.starterdb.globalDBName=$sid
oracle.install.db.config.starterdb.SID=$sid
oracle.install.db.config.starterdb.characterSet=AL32UTF8
oracle.install.db.config.starterdb.memoryOption=true
oracle.install.db.config.starterdb.memoryLimit=$mem
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.enableSecuritySettings=true
oracle.install.db.config.starterdb.password.ALL=$oracle_pass
oracle.install.db.config.starterdb.password.SYS=
oracle.install.db.config.starterdb.password.SYSTEM=
oracle.install.db.config.starterdb.password.SYSMAN=
oracle.install.db.config.starterdb.password.DBSNMP=
oracle.install.db.config.starterdb.control=DB_CONTROL
oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=
oracle.install.db.config.starterdb.automatedBackup.enable=false
oracle.install.db.config.starterdb.automatedBackup.osuid=
oracle.install.db.config.starterdb.automatedBackup.ospwd=
oracle.install.db.config.starterdb.storageType=
oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=
oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=
oracle.install.db.config.asm.diskGroup=
oracle.install.db.config.asm.ASMSNMPPassword=
MYORACLESUPPORT_USERNAME=
MYORACLESUPPORT_PASSWORD=
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false
DECLINE_SECURITY_UPDATES=true
PROXY_HOST=
PROXY_PORT=
PROXY_USER=
PROXY_PWD=
PROXY_REALM=
COLLECTOR_SUPPORTHUB_URL=
oracle.installer.autoupdates.option=
oracle.installer.autoupdates.downloadUpdatesLoc=
AUTOUPDATES_MYORACLESUPPORT_USERNAME=
AUTOUPDATES_MYORACLESUPPORT_PASSWORD=
EOF
#无需修改 netca.rsp
#修改 /home/install/database/response/dbca.rsp,密码为Oracle#1230
cat << EOF > /data/packet/database/response/dbca.rsp
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "$sid"
SID = "$sid"
TEMPLATENAME = "General_Purpose.dbc"
SYSPASSWORD = "$oracle_pass"
SYSTEMPASSWORD = "$oracle_pass"
DATAFILEDESTINATION =$oracle_directory/oracle/oradata
CHARACTERSET = "AL32UTF8"
NATIONALCHARACTERSET= "AL16UTF16"
DATABASETYPE = "MULTIPURPOSE"
[createTemplateFromDB]
SOURCEDB = "myhost:1521:$sid"
SYSDBAUSERNAME = "system"
TEMPLATENAME = "My Copy TEMPLATE"
[createCloneTemplate]
SOURCEDB = "$sid"
TEMPLATENAME = "My Clone TEMPLATE"
[DELETEDATABASE]
SOURCEDB = "$sid"
[generateScripts]
TEMPLATENAME = "New Database"
GDBNAME = "$sid"
[CONFIGUREDATABASE]
[ADDINSTANCE]
DB_UNIQUE_NAME = "master"
NODELIST=
SYSDBAUSERNAME = "sys"
[DELETEINSTANCE]
INSTANCENAME = "orcl11g"
SYSDBAUSERNAME = "sys"
EOF
#目录授权
chown -R oracle:oinstall $oracle_directory/oracle
chmod -R 775 $oracle_directory/oracle
chown -R oracle.oinstall /data/packet/database
chmod -R 775 /data/packet/database
#安装 oracle 软件
date
chmod +x /data/packet/database/runInstaller
su - oracle -c "/data/packet/database/runInstaller -silent -ignorePrereq -responseFile /data/packet/database/response/db_install.rsp"
sleep 1m
date
#安装成功后,系统提示需要在 root 下执行两个脚本
sh $oracle_directory/oracle/oraInventory/orainstRoot.sh
sh $oracle_directory/oracle/product/11.2.0/dbhome_1/root.sh
#配置监听
su - oracle -c "netca /silent /responseFile /data/packet/database/response/netca.rsp"
#配置成功后,监听启动,查看监听状态
su - oracle -c "lsnrctl status"
#创建数据库
echo -e "正在创建数据库,请耐心等候!"
su - oracle -c "dbca -silent -createDatabase -responseFile /data/packet/database/response/dbca.rsp"
#查看屏幕输出的创建进度
#oracle_sqlplus命令行乱码问题解决
yum -y install readline* libtermcap-devel*
wget https://linux.linuxidc.com/linuxconf/download.php?file=Li9saW51eGZpbGVzL3B1Yi8yMDExLzA3LzA0L3Jsd3JhcC9ybHdyYXAtMC4zNy50YXIuZ3o= -O rlwrap-0.37.tar.gz
tar -zxvf rlwrap-0.37.tar.gz
cd rlwrap-0.37
./configure && make && make install
echo "alias sqlplus='rlwrap sqlplus'" >> /home/oracle/.bash_profile
echo "alias rman='rlwrap rman'" >> /home/oracle/.bash_profile
source /home/oracle/.bash_profile
#设置行宽
echo "set linesize 1000;" >>$oracle_directory/oracle/product/11.2.0/dbhome_1/sqlplus/admin/glogin.sql
#备份/data/oracle/product/11.2.0/dbhome_1/dbs目录
cp -r /data/oracle/product/11.2.0/dbhome_1/dbs /data/oracle/product/11.2.0/dbhome_1/dbs_default
su - oracle -c "lsnrctl status"
netstat -nulpt |grep 1521
哒哒哒哒!!!本脚本为shell脚本,如需要其他语言欢迎联系,遇到执行报错的大佬们评论区提供意见和建议。
标签:starterdb,运维,一键,db,data,oracle,install,Oracle,config From: https://blog.csdn.net/qq_22799793/article/details/142362396