说明:本文的所有步骤不适用于生产环境,仅用于个人测试环境的快速部署和学习,下述操作过程在Oracle Linux 7.9上安装Oracle 11.2.0.4单实例为例。
1 安装环境检查
安装环境的检查可以参考官方文档Oracle Database Quick Installation Guide for Linux x86-64。由于是测试环境,本文仅检查:
- 物理内存大于1G。使用
free -m
命令检查 - /tmp目录大于200MB。使用
df -h
命令检查,默认/tmp
目录在根
分区中,会大于200MB - hosts文件有对应的IP和主机名解析。使用
cat /etc/hosts
检查 - 安装和建库需要约10GB的空间。本文安装在
/u01
,未使用独立的分区,也隶属于根
分区中,有40GB的空间。
2 安装环境准备2.1 准备Oracle用户和目录
使用root用户创建软件安装目录/u01/app/oracle/product/11.2.0.4/db_1
,创建oinstall、dba、oper用户组,创建oracle用户,并且为oracle用户设置密码。
groupadd -g 1300 oinstallgroupadd -g 1301 dbagroupadd -g 1302 operuseradd -u 1300 -g oinstall -G dba,oper -s /bin/bash oraclemkdir -p /u01/app/oracle/product/11.2.0.4/db_1chown -R oracle.oinstall /u01passwd oracle
2.2 检查和安装所需的RPM包
- 使用rpm检查软件包是否已安装,如果未安装,则会提示
is not installed
。
rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n" binutils compat-db compat-libcap1 compat-libstdc++-33 control-center elfutils-libelf-devel gcc gcc-c++ glibc-common glibc glibc-devel glibc-headers ksh libgcc libstdc++ libstdc++-devel libaio libaio-devel libgomp libXp make sysstat unzip
- 配置本地yum源,确保
/etc/yum.repos.d/
目录下仅有oracle-linux-ol7.repo
配置文件
[root@oracle11g ~]# cat /etc/yum.repos.d/oracle-linux-ol7.repo [ol7_latest]name=Oracle Linux $releasever Latest ($basearch)baseurl=file:///media/OEL79gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oraclegpgcheck=1enabled=1[root@oracle11g ~]# df -h | grep OEL/dev/sr0 4.6G 4.6G 0 100% /media/OEL79[root@oracle11g ~]# yum makecacheLoaded plugins: ulninfool7_latest | 3.6 kB 00:00:00 Metadata Cache Created
- 使用yum安装软件包
yum install binutils compat-db compat-libcap1 compat-libstdc++-33 control-center elfutils-libelf-devel gcc gcc-c++ glibc-common glibc glibc-devel glibc-headers ksh libgcc libstdc++ libstdc++-devel libaio libaio-devel libgomp libXp make sysstat unzip -y
2.3 修改配置参数
- 修改pam认证机制,加载
pam_limits.so
模块来限制系统资源的使用
echo "session required pam_limits.so">>/etc/pam.d/login
- 配置oracle用户的资源限制,限制打开进程数量和文件数量
echo "oracle soft nproc 2047oracle hard nproc 16384oracle soft nofile 1024oracle hard nofile 65536">>/etc/security/limits.conf
- 修改profile,Linux中初始化shell时会使用该配置文件,当用户登录系统时,系统会首先加载/etc/profile文件,然后再加载用户个人的shell初始化文件,如~/.bash_profile等。
echo "if [ \$USER = "oracle" ]; thenif [ \$SHELL = "/bin/ksh" ]; thenulimit -p 16384ulimit -n 65536elseulimit -u 16384 -n 65536fiumask 022fi">>/etc/profile
- 修改内核参数,限制信号量、端口、文件数量等
echo "fs.aio-max-nr = 1048576fs.file-max = 6815744kernel.shmall = 15461882265 #16GBkernel.shmmax = 4294967295 #4GBkernel.shmmni = 4096kernel.sem = 250 32000 100 128net.ipv4.ip_local_port_range = 9000 65500net.core.rmem_default = 262144net.core.rmem_max = 4194304net.core.wmem_default = 262144net.core.wmem_max = 1048576">>/etc/sysctl.conf
内核参数介绍:
- fs.aio-max-nr = 1048576:控制系统异步输入输出操作(Asynchronous I/O)并发数的最大值,影响系统的数据传输效率和压力处理能力。
- fs.file-max = 6815744:表示系统最大文件打开数量,默认是1024,可能会造成系统资源不足或进程无法打开文件等问题。
- kernel.shmall = 15461882265:定义了系统使用的最大共享内存容量,以页面(4K)为单位,这里设置的是16GB。
- kernel.shmmax = 4294967295:定义了用户进程可使用的共享内存大小,以字节为单位,这里设置的是4GB。
- kernel.shmmni = 4096:定义了系统最大的共享内存区数量。
- kernel.sem = 250 32000 100 128:设置内核信号量的值。后面的数字分别表示“信号量数组的数量”、“每个信号量数组中信号量的数目”、“系统所允许的信号量总数”和“一个信号量能带有的最大值”。
- 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:表示系统中发送缓存区的最大数量,用来调节系统发送性能。
- 配置oracle用户的环境变量,设置实例名为
orcl
、安装路径为/u01/app/oracle/product/11.2.0.4/db_1
export ORACLE_SID=orclexport ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/db_1echo "export ORACLE_SID=$ORACLE_SIDexport ORACLE_BASE=/u01/app/oracleexport ORACLE_HOME=$ORACLE_HOMEexport LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:/usr/local/libexport PATH=$ORACLE_HOME/bin:$PATH:$ORACLE_HOME/OPatchexport CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlibumask 022export NLS_LANG=AMERICAN_AMERICA.ZHS16GBKexport SQLPATH=$ORACLE_HOME/sqlplus/admin">>/home/oracle/.bash_profile
2.4 关闭selinux和防火墙
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/configsystemctl disable firewalld --now
完成上述操作后,需要重启操作系统才生效
reboot
2.5 准备软件安装包
- 将安装包放在/tmp目录下
unzip p13390677_112040_Linux-x86-64_1of7.zipunzip p13390677_112040_Linux-x86-64_2of7.zip
- 更改安装包的属组和用户为oinstall和oracle
chown -R oracle.oinstall /tmp/database
2.6 创建响应文件
需要留意的是UNIX_GROUP_NAME、INVENTORY_LOCATION、ORACLE_HOME、ORACLE_BASE,保持和前文的创建的用户名、安装路径一致。
echo "oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0oracle.install.option=INSTALL_DB_SWONLYORACLE_HOSTNAME=DBProduceUNIX_GROUP_NAME=oinstallINVENTORY_LOCATION=/u01/app/oraInventorySELECTED_LANGUAGES=en,en_GBORACLE_HOME=/u01/app/oracle/product/11.2.0.4/db_1ORACLE_BASE=/u01/app/oracleoracle.install.db.InstallEdition=EEoracle.install.db.EEOptionsSelection=falseoracle.install.db.optionalComponents=oracle.install.db.DBA_GROUP=dbaoracle.install.db.OPER_GROUP=operoracle.install.db.CLUSTER_NODES=oracle.install.db.isRACOneInstall=falseoracle.install.db.racOneServiceName=oracle.install.db.config.starterdb.type=GENERAL_PURPOSEoracle.install.db.config.starterdb.globalDBName=oracle.install.db.config.starterdb.SID=oracle.install.db.config.starterdb.characterSet=oracle.install.db.config.starterdb.memoryOption=falseoracle.install.db.config.starterdb.memoryLimit=oracle.install.db.config.starterdb.installExampleSchemas=falseoracle.install.db.config.starterdb.enableSecuritySettings=trueoracle.install.db.config.starterdb.password.ALL=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_CONTROLoracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=oracle.install.db.config.starterdb.automatedBackup.enable=falseoracle.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=falseDECLINE_SECURITY_UPDATES=truePROXY_HOST=PROXY_PORT=PROXY_USER=PROXY_PWD=PROXY_REALM=COLLECTOR_SUPPORTHUB_URL=oracle.installer.autoupdates.option=SKIP_UPDATESoracle.installer.autoupdates.downloadUpdatesLoc=AUTOUPDATES_MYORACLESUPPORT_USERNAME=AUTOUPDATES_MYORACLESUPPORT_PASSWORD="/tmp/11gR2.rsp
3 执行静默安装
- 使用oracle用户,执行
./runInstaller
,注意-responseFile
要用绝对路径
cd /tmp/database./runInstaller -ignoreSysPrereqs -ignorePrereq -waitforcompletion -showProgress -silent -responseFile /tmp/11gR2.rsp
- 安装过程输出
Starting Oracle Universal Installer...Checking Temp space: must be greater than 120 MB. Actual 28865 MB PassedChecking swap space: must be greater than 150 MB. Actual 3967 MB PassedPreparing to launch Oracle Universal Installer from /tmp/OraInstall2023-05-06_03-53-30AM. Please wait ...You can find the log of this install session at: /u01/app/oraInventory/logs/installActions2023-05-06_03-53-30AM.logPrepare in progress................................................... 9% Done.Prepare successful.Copy files in progress................................................... 14% Done................................................... 20% Done................................................... 26% Done................................................... 31% Done................................................... 36% Done................................................... 41% Done................................................... 46% Done................................................... 51% Done................................................... 56% Done................................................... 63% Done................................................... 68% Done................................................... 73% Done................................................... 78% Done................................................... 83% Done...............................Copy files successful.Link binaries in progress...........Link binaries successful.Setup files in progress................................................... 88% Done................................................... 94% Done.Setup files successful.The installation of Oracle Database 11g was successful.Please check '/u01/app/oraInventory/logs/silentInstall2023-05-06_03-53-30AM.log' for more details.Execute Root Scripts in progress.As a root user, execute the following script(s):1. /u01/app/oraInventory/orainstRoot.sh2. /u01/app/oracle/product/11.2.0.4/db_1/root.sh.................................................. 100% Done.Execute Root Scripts successful.Successfully Setup Software.
4 安装后配置
使用root
用户来之执行配置脚本
/u01/app/oraInventory/orainstRoot.sh/u01/app/oracle/product/11.2.0.4/db_1/root.sh
5 执行静默建库5.1 创建监听
- 准备netca响应文件
echo 'RESPONSEFILE_VERSION="11.2"CREATE_TYPE="CUSTOM"INSTALLED_COMPONENTS={"server","net8″,"javavm"}INSTALL_TYPE=""typical""LISTENER_NUMBER=1LISTENER_NAMES={"LISTENER"}LISTENER_PROTOCOLS={"TCP;1521"}LISTENER_START=""LISTENER""NAMING_METHODS={"TNSNAMES","ONAMES","HOSTNAME"}NSN_NUMBER=1NSN_NAMES={"EXTPROC_CONNECTION_DATA"}NSN_SERVICE={"PLSExtProc"}NSN_PROTOCOLS={"TCP;HOSTNAME;1521"'>>/tmp/netca.rsp
- 执行静默安装,注意是
/responsefile
,而且响应文件要绝对路径
netca /silent /responsefile /tmp/netca.rsp
- 配置成功后,输出如下:
Parsing command line arguments: Parameter "silent" = true Parameter "responsefile" = /u01/install/netca.rspDone parsing command line arguments.Oracle Net Services Configuration:Profile configuration complete.Oracle Net Services configuration successful. The exit code is 0
- 启动监听程序
[oracle@oracle11g admin]$ lsnrctl startLSNRCTL for Linux: Version 11.2.0.4.0 - Production on 06-MAY-2023 04:28:25Copyright (c) 1991, 2013, Oracle. All rights reserved.Starting /u01/app/oracle/product/11.2.0.4/db_1/bin/tnslsnr: please wait...TNSLSNR for Linux: Version 11.2.0.4.0 - ProductionLog messages written to /u01/app/oracle/diag/tnslsnr/oracle11g/listener/alert/log.xmlListening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle11g)(PORT=1521)))Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))STATUS of the LISTENER------------------------Alias LISTENERVersion TNSLSNR for Linux: Version 11.2.0.4.0 - ProductionStart Date 06-MAY-2023 04:28:26Uptime 0 days 0 hr. 0 min. 0 secTrace Level offSecurity ON: Local OS AuthenticationSNMP OFFListener Log File /u01/app/oracle/diag/tnslsnr/oracle11g/listener/alert/log.xmlListening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle11g)(PORT=1521)))
5.2 执行静默建库
- 使用
oracle
用户执行dbca命令来完成静默建库,安装过程中会自动创建/u01/app/oracle/oradata
目录,并拷贝数据文件和生成控制文件、日志文件,将所有密码设置为oracle11g
。
dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname orcl -sid orcl -responseFile NO_VALUE -characterSet ZHS16GBK -memoryPercentage 75 -emConfiguration LOCAL -datafiledestination /u01/app/oracle/oradata -sysPassword oracle11g -systemPassword oracle11g -dbsnmpPassword oracle11g -sysmanPassword oracle11g
- 建库过程输出
Copying database files1% complete3% complete11% complete18% complete26% complete37% completeCreating and starting Oracle instance40% complete45% complete50% complete55% complete56% complete60% complete62% completeCompleting Database Creation66% complete70% complete73% complete85% complete96% complete100% completeLook at the log file "/u01/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.
6 安装完成后检查
- 数据库实例的监听注册状态,确定是READY
[oracle@oracle11g ~]$ lsnrctl statLSNRCTL for Linux: Version 11.2.0.4.0 - Production on 06-MAY-2023 04:35:48Copyright (c) 1991, 2013, Oracle. All rights reserved.Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))STATUS of the LISTENER------------------------Alias LISTENERVersion TNSLSNR for Linux: Version 11.2.0.4.0 - ProductionStart Date 06-MAY-2023 04:28:26Uptime 0 days 0 hr. 7 min. 22 secTrace Level offSecurity ON: Local OS AuthenticationSNMP OFFListener Log File /u01/app/oracle/diag/tnslsnr/oracle11g/listener/alert/log.xmlListening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle11g)(PORT=1521)))Services Summary...Service "orcl" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service...Service "orclXDB" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service...The command completed successfully
- 登录数据库,检查数据库状态为OPEN
[oracle@oracle11g ~]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.4.0 Production on Sat May 6 04:36:58 2023Copyright (c) 1982, 2013, Oracle. All rights reserved.Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> select name,open_mode from v$database;NAME OPEN_MODE--------- --------------------ORCL READ WRITE
至此,Oracle11gR2单实例静默安装和建库完成。
再次强调一遍,本文安装的环境仅适用于测试,生产环境的数据库安装,请遵循Oracle的最佳实践。