静默安装Oracle也没那么恐怖(安裝執行文件)
/bootext3100MSwapswap32G#一般和内存一样大/u01ext3800G#Oracle安装目录和数据库数据文件存放目录,大小要大于预估的全部数据量/optext35G/tmpext32G/ext3剩余空间
安装步骤大纲
没明确指出操作账号的步骤,请仔细看命令前面是井号还是美元,井号就是用root做的,美元就是用oracle做的。
装前检查创建组和用户修改内核参数修改用户限制关闭SELinux及防火墙创建安装目录设置环境变量执行runInstaller安装Oracle执行dbca建立数据库配置tnsnames.ora执行lsnrctl启动监听,PLSQL连接安装前检查两个安装包linux.x64_11gR2_database_1of2.ziplinux.x64_11gR2_database_2of2.zipOracle版本是11.2.0.1.0Linux版本Red Hat Enterprise Linux Server release 6.6 (Santiago)
物理内存检查:至少4G,查看物理内存命令:
(图片来源网络,侵删)
#grepMemTotal/proc/meminfo
虚拟内存检查:物理内存4-8G,虚拟内存为2倍物理内存;物理内存8-32G,虚拟内存为1.5倍物理内存;物理内存>32G,虚拟内存等于物理内存;
查看虚拟内存命令:
#grepSwapTotal/proc/meminfo
依赖包检查
rpm-q\binutils\compat-libstdc++-33\elfutils-libelf\elfutils-libelf-devel\elfutils-libelf-devel-static\expat\gcc\gcc-c++\glibc\glibc-common\glibc-devel\glibc-headers\libaio\libaio-devel\libgcc\libstdc++\libstdc++-devel\make\ksh\sysstat\numactl-devel\kernel-headers\libgomp\unixODBC\unixODBC-devel|grep"notinstalled"|awk'{print$2;}'
输入下面几个包,说明系统没有
compat-libstdc++-33elfutils-libelf-develelfutils-libelf-devel-staticgccgcc-c++libaio-devellibstdc++-develkshnumactl-develunixODBCunixODBC-devel
配好yum源,逐个yum install上面的包。
创建组和用户
[root@ORATEST]#groupaddoinstall[root@ORATEST]#groupadddba[root@ORATEST]#useradd-goinstall-Gdbaoracle[root@ORATEST]#passwdoracleChangingpasswordforuseroracle.Newpassword:BADPASSWORD:itisbasedonadictionarywordBADPASSWORD:istoosimpleRetypenewpassword:#此处密码输入oracle,BADPASSWORD提示不用管passwd:allauthenticationtokensupdatedsuccessfully.
修改内核参数
#vi/etc/sysctl.confkernel.sem=25032000100128fs.file-max=6815744net.ipv4.ip_local_port_range=900065500net.core.rmem_default=262144net.core.rmem_max=4194304net.core.wmem_default=262144net.core.wmem_max=1048586fs.aio-max-nr=1048576
使设置生效
#sysctl-p
检查设置是否成功
[root@ORATEST~]#sysctlkernel.semfs.file-maxnet.ipv4.ip_local_port_rangenet.core.rmem_defaultnet.core.rmem_maxnet.core.wmem_defaultnet.core.wmem_maxfs.aio-max-nrkernel.sem=25032000100128fs.file-max=6815744net.ipv4.ip_local_port_range=900065500net.core.rmem_default=262144net.core.rmem_max=4194304net.core.wmem_default=262144net.core.wmem_max=1048586fs.aio-max-nr=1048576
用户限制设置
#vi/etc/security/limits.conforaclesoftnofile1024oraclehardnofile65536oraclesoftnproc2047oraclehardnproc16384vi/etc/pam.d/loginsessionrequired/lib64/security/pam_limits.sosessionrequiredpam_limits.so#vi/etc/profileif[$USER="oracle"];thenif[$SHELL="/bin/ksh"];thenulimit-p16384ulimit-n65536elseulimit-u16384-n65536fifi
关闭SELinux及防火墙
查看SELinux状态:sestatus永久关闭SELinux,需重启:#vi/etc/sysconfig/selinux#SELINUX=enforcingSELINUX=disabled即时关闭SELinux指令:setenforce0或者setenforcepermissive关闭防火墙:Linux6及以下:查看防火墙状态:serviceiptablesstatus重启后生效关闭:chkconfigiptablesoff即时关闭防火墙指令关闭:serviceiptablesstop
创建安装目录
[root@ORATEST~]#mkdir-p/u01/app/[root@ORATEST~]#chown-Roracle:oinstall/u01/app/[root@ORATEST~]#chmod-R775/u01/app/
配置环境变量
[root@ORATEST~]#su-oracle[oracle@ORATEST~]$vi/home/oracle/.bash_profilevi/home/oracle/.bash_profileORACLE_BASE=/u01/app/oracle;exportORACLE_BASEexportORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1ORACLE_SID=oral;exportORACLE_SIDexportORACLE_OWNER=oracleexportPATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/local/bin:/usr/sbin:/usr/binexportTNS_ADMIN=$ORACLE_HOME/network/adminexportLD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/oracm/lib:/lib:/usr/lib:/usr/local/libexportNLS_LANG=AMERICAN_AMERICA.ZHS16GBKexportCLASSPATH=${CLASSPATH}:$ORACLE_HOME/JREexportCLASSPATH=${CLASSPATH}:$ORACLE_HOME/JRE/libexportCLASSPATH=${CLASSPATH}:$ORACLE_HOME/jlibexportCLASSPATH=${CLASSPATH}:$ORACLE_HOME/rdbms/jlibexportCLASSPATH=${CLASSPATH}:$ORACLE_HOME/network/jlibexportLIBPATH=${CLASSPATH}:$ORACLE_HOME/lib:$ORACLE_HOME/ctx/libexportSPFILE_PATH=$ORACLE_HOME/dbsexportORA_NLS10=$ORACLE_HOME/nls/dataumask022
新开个会话,以Oracle账号登陆,检查环境是否生效
[oracle@ORATEST~]$env|more[oracle@ORATEST~]$umask
以root账号,新建oraInst.loc,执行
#vi/etc/oraInst.locinventory_loc=/u01/app/oracle/oraInventoryinst_group=oinstall[root@ORATEST~]#chownoracle:oinstall/etc/oraInst.loc[root@ORATEST~]#chmod664/etc/oraInst.loc
执行runInstaller安装Oracle修改host文件
[root@ORATEST~]#vi/etc/hosts...127.0.0.1ORATEST#最后加上这行
将两个安装包上传到/u01/app,确保安装包属于oracle用户
[root@ORATESTapp]#chown-Roracle:oinstall.zip[root@ORATESTapp]#lltotal2295600-rw-r--r--.1oracleoinstall1239269270Jan2214:29linux.x64_11gR2_database_1of2.zip-rw-r--r--.1oracleoinstall1111416131Jan2214:29linux.x64_11gR2_database_2of2.zip
如果已经属于oracle用户,上面步骤不用做。在oracle账号下,按顺序解压
[oracle@ORATESTapp]$unziplinux.x64_11gR2_database_1of2.zip[oracle@ORATESTapp]$unziplinux.x64_11gR2_database_2of2.zip
解压后文件都在database目录里
[oracle@ORATESTapp]$lltotal2295604drwxr-xr-x.8oracleoinstall4096Aug212009database-rw-r--r--.1oracleoinstall1239269270Jan2214:29linux.x64_11gR2_database_1of2.zip-rw-r--r--.1oracleoinstall1111416131Jan2214:29linux.x64_11gR2_database_2of2.zip
拷贝安装配置模板文件到当前目录(/u01/app)下
[oracle@ORATESTapp]$cpdatabase/response/db_install.rsp.
创建三个目录,oracle是安装目录,oradata是数据文件目录,oradatabackup,是数据文件备份目录
[oracle@ORATESTapp]$mkdiroracle[oracle@ORATESTapp]$mkdiroradata[oracle@ORATESTapp]$mkdiroradatabackup
编辑db_install.rsp,编辑后和原始文件差异如下,
[oracle@ORATESTapp]$diffdb_install.rspdatabase/response/db_install.rsp29c29<oracle.install.option=INSTALL_DB_AND_CONFIG--->oracle.install.option=37c37<ORACLE_HOSTNAME=localhost--->ORACLE_HOSTNAME=42c42<UNIX_GROUP_NAME=oinstall--->UNIX_GROUP_NAME=47c47<INVENTORY_LOCATION=/u01/app--->INVENTORY_LOCATION=78c78<SELECTED_LANGUAGES=en,zh_CN--->SELECTED_LANGUAGES=83c83<ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1--->ORACLE_HOME=88c88<ORACLE_BASE=/u01/app/oracle--->ORACLE_BASE=99c99<oracle.install.db.InstallEdition=EE--->oracle.install.db.InstallEdition=142c142<oracle.install.db.DBA_GROUP=dba--->oracle.install.db.DBA_GROUP=147c147<oracle.install.db.OPER_GROUP=dba--->oracle.install.db.OPER_GROUP=160c160<oracle.install.db.config.starterdb.type=GENERAL_PURPOSE--->oracle.install.db.config.starterdb.type=165c165<oracle.install.db.config.starterdb.globalDBName=orcl--->oracle.install.db.config.starterdb.globalDBName=170c170<oracle.install.db.config.starterdb.SID=orcl--->oracle.install.db.config.starterdb.SID=184c184<oracle.install.db.config.starterdb.characterSet=ZHS16GBK--->oracle.install.db.config.starterdb.characterSet=AL32UTF8200c200<oracle.install.db.config.starterdb.memoryLimit=1024--->oracle.install.db.config.starterdb.memoryLimit=233c233<oracle.install.db.config.starterdb.password.ALL=oracle--->oracle.install.db.config.starterdb.password.ALL=278,279c278<oracle.install.db.config.starterdb.dbcontrol.emailAddress=test@qq.com<--->oracle.install.db.config.starterdb.dbcontrol.emailAddress=325c324<oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE--->oracle.install.db.config.starterdb.storageType=333c332<oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/u01/app/oradata--->oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=340c339<oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/u01/app/oradatabackup--->oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=386c385<DECLINE_SECURITY_UPDATES=true--->DECLINE_SECURITY_UPDATES=
这些配置项也可以在安装命令参数里写,本文选择编辑db_install.rsp达到效果。安装前文件和环境如下
[oracle@ORATESTapp]$lltotal2295640drwxr-xr-x.8oracleoinstall4096Aug212009database-rw-r--r--.1oracleoinstall22770Jan2215:15db_install.rsp-rw-r--r--.1oracleoinstall1239269270Jan2214:29linux.x64_11gR2_database_1of2.zip-rw-r--r--.1oracleoinstall1111416131Jan2214:29linux.x64_11gR2_database_2of2.zipdrwxr-xr-x.2oracleoinstall4096Jan2214:56oracledrwxr-xr-x.2oracleoinstall4096Jan2215:12oradatadrwxr-xr-x.2oracleoinstall4096Jan2215:12oradatabackup[oracle@ORATESTapp]$env|grepORAORACLE_OWNER=oracleORA_NLS10=/u01/app/oracle/product/11.2.0/db_1/nls/dataORACLE_SID=oralORACLE_BASE=/u01/app/oracleORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
执行安装命令
[oracle@ORATESTdatabase]$./runInstaller-silent-force-noconfig-ignorePrereq-responseFile/u01/app/db_install.rspStartingOracleUniversalInstaller...CheckingTempspace:mustbegreaterthan120MB.Actual1628MBPassedCheckingswapspace:mustbegreaterthan150MB.Actual65535MBPassedPreparing...CAUSE:...ACTION:....[WARNING][INS-30011]...Thefollowingconfigurationscriptsneedtobeexecutedasthe"root"user.#!/bin/sh#Rootscriptstorun/u01/app/oracle/product/11.2.0/db_1/root.shToexecutetheconfigurationscripts:1.Openaterminalwindow2.Loginas"root"3.Runthescripts4.Returntothiswindowandhit"Enter"keytocontinueConfigurationassistantshavenotbeenrun.Thiscanhappenforfollowingreasons-eitherroot.shistoberunbeforeconfigorOracleUniversalInstallerwasinvokedwiththe-noConfigoption."/u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/configToolAllCommands"scriptcontainsallcommandstobeexecutedbytheconfigurationassistants.ThisfilemaybeusedtoruntheconfigurationassistantsoutsideofOUI.Notethatyoumayhavetoupdatethisscriptwithpasswords(ifany)beforeexecutingthesame.SuccessfullySetupSoftware.
输出Successfully Setup Software表示安装成功。同时提示以root账号执行/u01/app/oracle/product/11.2.0/db_1/root.sh脚本。
[root@ORATEST~]#/u01/app/oracle/product/11.2.0/db_1/root.shCheck/u01/app/oracle/product/11.2.0/db_1/install/root_ORATEST_2021-01-25_08-19-46.logfortheoutputofrootscript
执行完Oracle软件安装完成。
建立数据库oracle账号执行,拷贝建立数据库的配置文件dbca.rsp到app目录下
[oracle@ORATESTapp]$cp/u01/app/oracle/product/11.2.0/db_1/assistants/dbca/dbca.rsp.
编辑dbca.rsp,编写完各项目如下
[oracle@ORATESTapp]$catdbca.rsp|grep-v^#|grep-v^$[GENERAL]RESPONSEFILE_VERSION="11.2.0"OPERATION_TYPE="createDatabase"[CREATEDATABASE]GDBNAME="ORCL"SID="orcl"TEMPLATENAME="General_Purpose.dbc"SYSPASSWORD="oracle"SYSTEMPASSWORD="oracle"DATAFILEDESTINATION=/u01/app/oradataCHARACTERSET="ZHS16GBK"TOTALMEMORY="8000"[createTemplateFromDB]SOURCEDB="myhost:1521:orcl"SYSDBAUSERNAME="system"TEMPLATENAME="MyCopyTEMPLATE"[createCloneTemplate]SOURCEDB="orcl"TEMPLATENAME="MyCloneTEMPLATE"[DELETEDATABASE]SOURCEDB="orcl"[generateScripts]TEMPLATENAME="NewDatabase"GDBNAME="orcl11.us.oracle.com"[CONFIGUREDATABASE][ADDINSTANCE]DB_UNIQUE_NAME="orcl11g.us.oracle.com"NODELIST=SYSDBAUSERNAME="sys"[DELETEINSTANCE]DB_UNIQUE_NAME="orcl11g.us.oracle.com"INSTANCENAME="orcl11g"SYSDBAUSERNAME="sys"
同样这个文件的内容也可以在执行dbca命令时以参数形式输入,本文选择编辑dbca.rsp的方式。app目录下执行命令建立数据库
[oracle@ORATESTapp]$dbca-silent-responseFile./dbca.rspCopyingdatabasefiles1%complete3%complete37%completeCreatingandstartingOracleinstance40%complete45%complete50%complete55%complete56%complete60%complete62%completeCompletingDatabaseCreation66%complete70%complete73%complete85%complete96%complete100%completeLookatthelogfile"/u01/app/oracle/cfgtoollogs/dbca/ORCL/ORCL.log"forfurtherdetails.
此时数据库已经启动,可以访问了。下面指令测试是否成功
[oracle@ORATEST~]$sqlplus/assysdba...SQL>shutdownimmediate;Databaseclosed.Databasedismounted.ORACLEinstanceshutdown.SQL>startup;ORACLEinstancestarted.TotalSystemGlobalArea8351150080bytesFixedSize2214936bytesVariableSize5100274664bytesDatabaseBuffers3221225472bytesRedoBuffers27435008bytesDatabasemounted.Databaseopened.SQL>
shutdown和startup都成功执行,说明数据库正常启动了。/u01/app/oradata/ORCL目录下是刚建立数据库ORCL的数据文件
[oracle@ORATESToradata]$cdORCL/[oracle@ORATESTORCL]$lltotal1433964-rw-r-----1oracleoinstall9748480Jan2515:42control01.ctl-rw-r-----1oracleoinstall52429312Jan2515:23redo01.log-rw-r-----1oracleoinstall52429312Jan2515:41redo02.log-rw-r-----1oracleoinstall52429312Jan2515:23redo03.log-rw-r-----1oracleoinstall513810432Jan2515:38sysaux01.dbf-rw-r-----1oracleoinstall702554112Jan2515:36system01.dbf-rw-r-----1oracleoinstall30416896Jan2511:41temp01.dbf-rw-r-----1oracleoinstall78651392Jan2515:36undotbs01.dbf-rw-r-----1oracleoinstall5251072Jan2515:23users01.dbf
配置tnsnames.oranetwork/admin下新建ora文件
[oracle@ORATEST~]$vi/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.orawebdb=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.6.2)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))
远程客户端的tnsnames.ora写上相同的配置。如果远程在PC上,ora文件放在TNS_ADMIN环境变量对应的目录下。
执行lsnrctl启动监听,PLSQL连接监听的配置文件不用编写,采用默认配置。检查webdb能否解析
[oracle@ORATEST~]$tnspingwebdb...UsedTNSNAMESadaptertoresolvethealiasAttemptingtocontact(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.6.2)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))TNS-12541:TNS:nolistener
可以解析出地址和端口号,否则会报Failed to resolve name。no listerer提示监听程序没有启动,启动监听
[oracle@ORATEST~]$lsnrctlstart...Listeningon:(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ORATEST)(PORT=1521)))Connectingto(ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))STATUSoftheLISTENER------------------------AliasLISTENERVersionTNSLSNRforLinux:Version11.2.0.1.0-ProductionStartDate31-JAN-202113:55:20Uptime0days0hr.0min.0secTraceLeveloffSecurityON:LocalOSAuthenticationSNMPOFFListenerLogFile/u01/app/oracle/diag/tnslsnr/ORATEST/listener/alert/log.xmlListeningEndpointsSummary...(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ORATEST)(PORT=1521)))ThelistenersupportsnoservicesThecommandcompletedsuccessfully
启动成功。 PLSQL连接,用户system,密码oracle,数据库下拉选择webdb,可以成功登陆。
如果一切顺利,到此大功告成。如果遇到一些报错请往下看。
一些报错的解决方法
错误:LRM-00109:couldnotopenparameterfile'/u01/app/oracle/product/11.2.0/db_1/dbs/initoral.ora'解决:[oracle@ORATESTdbs]$cp/u01/app/oracle/product/11.2.0/db_1/srvm/admin/init.ora./initoral.ora
错误:ORA-00371:notenoughsharedpoolmemory,shouldbeatleast307023052bytes解决[oracle@ORATESTdbs]$viinitoral.ora#replace"clustdb"withyourdatabasenamedb_name=orclshared_pool_size=307023052#按提示大小改
错误:ORA-00401:thevalueforparametercompatibleisnotsupportedbythisrelease解决:[oracle@ORATESTdbs]$viinitoral.ora#compatible=9.2.0.0.0compatible=11.2.0.0.0#改成11版本
错误:ORA-27504:IPCerrorcreatingOSDcontextORA-27300:OSsystemdependentoperation:unsupp_mtufailedwithstatus:0ORA-27301:OSfailuremessage:Error0ORA-27302:failureoccurredat:skgxpvaddr10ORA-27303:additionalinformation:requestedinterface127.0.0.1mtunotsupported.Checkoutputfromifconfigcommand解决:cd$ORACLE_HOME/rdbms/lib/[oracle@ORATESTlib]$make-fins_rdbms.mkrac_offioracle
错误:ORA-00439:featurenotenabled:RealApplicationClusters解决:cd$ORACLE_HOME/rdbms/lib/[oracle@ORATESTlib]$make-fins_rdbms.mkrac_onioracle
错误:ORA-32004:obsoleteordeprecatedparameter(s)specifiedforRDBMSinstanceORA-00205:errorinidentifyingcontrolfile,checkalertlogformoreinfo解决:[root@ORATEST~]#find/-nameinit.ora/u01/app/oracle/admin/ORCL/pfile/init.ora.025202192615[oracle@ORATESTdbs]$sqlplus/assysdba...SQL>startuppfile='/u01/app/oracle/admin/ORCL/pfile/init.ora.025202192615'ORACLEinstancestarted.;TotalSystemGlobalArea8351150080bytesFixedSize2214936bytesVariableSize4697621480bytesDatabaseBuffers3623878656bytesRedoBuffers27435008bytesDatabasemounted.Databaseopened.SQL>createspfilefrompfile='/u01/app/oracle/admin/ORCL/pfile/init.ora.025202192615';Filecreated.
整库导入如果新安装的库要导入老库的数据,在老库服务器以oracle用户执行
expsystem/oracle@orclfile=./exp.dmpfull=y
新库建立完后,什么都不需要做,上传exp.dmp后,直接执行
[oracle@ORATESTapp]$impsystem/oraclefull=yfile=./exp.dmp#这里没写实例名@orcl因为只有一个orcl实例可以省略
就可以成功导入老库所有数据和用户。新老数据库的字符集相同即可,其它环节字符集不同也可以成功。
总结终于搞定了传说中安装成功率只有50%的Oracle,还是静默安装,爽。如果失败了,建议格式化u01分区直接重来。