centos 6.5下安装oracle 11gR2与Oracle自动启动的配置
注意:以下命令使用root用户操作
安装依赖包
主要思路为配置oracleyum仓库,直接使用yum命令来安装依赖包,避免手工逐个的安装依赖包。
配置yum仓库以下载orcale依赖包
注意:这里是CentOS6.X的oracle依赖仓库,其他版本不同的。
导入GPGKeys
wgethttps://public-yum.oracle.com/RPM-GPG-KEY-oracle-ol6-O/etc/pki/rpm-gpg/RPM-GPG-KEY-oracle--no-check-certificate
安装oracle依赖
yuminstalloracle-rdbms-server-11gR2-preinstall
设置hostname
打开文件/etc/sysconfig/network,并修改HOSTNAME。
vi/etc/sysconfig/network NETWORKING=yes HOSTNAME=oracle.buzheng.org
打开/etc/host,添加服务器本机IP地址指向到HOSTNAME
vi/etc/hosts 192.168.1.15oracle.buzheng.orgoracle
oracle用户设置
当安装好oracle依赖之后,oracle用户已经创建好了,不需要手工创建oracle用户和相关的用户组。
修改oracle用户密码
[root@oracle~]#passwdoracle 更改用户oracle的密码。 新的密码: 重新输入新的密码: passwd:所有的身份验证令牌已经成功更新。
修改系统限制
在文件/etc/security/limits.d/90-nproc.conf中添加如下的最后一行
[root@oracle~]#vi/etc/security/limits.d/90-nproc.conf #Defaultlimitfornumberofuser'sprocessestoprevent #accidentalforkbombs. #Seerhbz#432903forreasoning. *softnproc1024 rootsoftnprocunlimited *-nproc16384
修改SELinux为permissive模式
修改文件/etc/selinux/config如下所示
[root@oracle~]#vi/etc/selinux/config #ThisfilecontrolsthestateofSELinuxonthesystem. #SELINUX=cantakeoneofthesethreevalues: #enforcing-SELinuxsecuritypolicyisenforced. #permissive-SELinuxprintswarningsinsteadofenforcing. #disabled-NoSELinuxpolicyisloaded. SELINUX=permissive #SELINUXTYPE=cantakeoneofthesetwovalues: #targeted-Targetedprocessesareprotected, #mls-MultiLevelSecurityprotection. SELINUXTYPE=targeted
重启机器
[root@oracle]#reboot
创建oracle安装目录,并授权
[root@oracle]#mkdir-p/u01/app/oracle/product/11.2.0/dbhome_1 [root@oracle]#chown-Roracle:oinstall/u01 [root@oracle]#chmod-R775/u01
授权oracle用户能够访问XServer
[root@oracle]#xhost+#要在主机上运行,不能是远程shell
注意:以下命令使用oracle用户操作
配置oracle安装环境变量
切换到oracle用户,编辑.bash_profile文件,如下所示,添加环境配置。
[root@oracle]#suoracle [oracle@oracle]#vi.bash_profile #OracleSettings TMP=/tmp;exportTMP TMPDIR=$TMP;exportTMPDIR ORACLE_HOSTNAME=oracle.buzheng.org;exportORACLE_HOSTNAME ORACLE_UNQNAME=orcl;exportORACLE_UNQNAME ORACLE_BASE=/u01/app/oracle;exportORACLE_BASE ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1;exportORACLE_HOME ORACLE_SID=orcl;exportORACLE_SID PATH=/usr/sbin:$PATH;exportPATH PATH=$ORACLE_HOME/bin:$PATH;exportPATH LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib;exportLD_LIBRARY_PATH CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;exportCLASSPATHexportPATH
下载oracle安装文件,解压缩后安装
下载oracle
打开oracle下载页面,http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html,下载下面两个文件到/home/oracle
linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip
解压缩文件并运行
unziplinux.x64_11gR2_database_1of2.zip unziplinux.x64_11gR2_database_2of2.zip cddatabase ./runInstaller
若为中文系统,安装界面会出现中文乱码,需要先将环境变为英文,在安装
exportLANG=en_US ./runInstaller
没有截图,安装步骤大致包括以下几步:
- Createandconfigureadatabase
- ServerClass
- Singleinstancedatabaseinstallation
- Advancedinstall
- Language:English
- EnterpriseEdition
- databasetype:GeneralPurpose/TransactionProcessing
- Memory:EnableAutomaticMemoryManagement
- Charactersets:UseUnicode(AL32UTF8)
图性界面安装最后会提示以ROOT执行下面两个脚本
[root@oracle~]#/u01/app/oraInventory/orainstRoot.sh Changingpermissionsof/u01/app/oraInventory. Addingread,writepermissionsforgroup. Removingread,write,executepermissionsforworld. Changinggroupnameof/u01/app/oraInventorytooinstall. Theexecutionofthescriptiscomplete.
[root@oracle~]#/u01/app/oracle/product/11.2.0/dbhome_1/root.sh RunningOracle11groot.shscript... Thefollowingenvironmentvariablesaresetas: ORACLE_OWNER=oracle ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 Enterthefullpathnameofthelocalbindirectory:[/usr/local/bin]: Copyingdbhometo/usr/local/bin... Copyingoraenvto/usr/local/bin... Copyingcoraenvto/usr/local/bin... Creating/etc/oratabfile... Entrieswillbeaddedtothe/etc/oratabfileasneededby DatabaseConfigurationAssistantwhenadatabaseiscreated Finishedrunninggenericpartofroot.shscript. Nowproduct-specificrootactionswillbeperformed. Finishedproduct-specificrootactions.
出现的问题
1,当环境变量中的ORACLE_SID与安装时实际配置不一致时,会导致startup出错,出错信息如下:
ORA-01078:failureinprocessingsystemparameters LRM-00109:couldnotopenparameterfile'/u01/app/oracle/product/11.2.0/dbhome_1/dbs/initDB11G.ora'
2,如果远程客户端连接是报错:ora-12514tns监听程序当前无法识别连接描述符中请求的服务,则需要配置listener.ora,添加如下节点:
SID_LIST_LISTENER= (SID_LIST= (SID_DESC= (SID_NAME=orcl) (ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1) ) )
好了,到此已经安装完成,通过访问web管理界面可验证。下面步骤也很重要,请继续。
注意:以下命令使用root用户操作
配置防火墙规则,开放侦听端口
将1521(你配置的oracle侦听端口)端口添加到防火墙规则,以便远程用户能顺利的访问到oracle服务。
iptables-IINPUT4-mstate--stateNEW-ptcp--dport1521-jACCEPT serviceiptablessave serviceiptablesreload
设置oracle自动启动
完成oracle安装后,我们可以通过命令启动停止数据库,但是当机器重启时并不能随机器启动,这也给我们带来了一些不便,下面记录了,如何将oralce加入服务中,并随机机器启动。
修改配置文件/etc/oratab
修改/etc/oratab的最后一行的最后一个字符,将N修改为Y。此举主要是为了使oracle的dbstart命令能在系统启动时能运行。如下所示:
[root@oracle~]#vi/etc/oratab # #ThisfileisusedbyORACLEutilities.Itiscreatedbyroot.sh #andupdatedbytheDatabaseConfigurationAssistantwhencreating #adatabase. #Acolon,':',isusedasthefieldterminator.Anewlineterminates #theentry.Linesbeginningwithapoundsign,'#',arecomments. # #Entriesareoftheform: #$ORACLE_SID:$ORACLE_HOME:<N|Y>: # #Thefirstandsecondfieldsarethesystemidentifierandhome #directoryofthedatabaserespectively.Thethirdfiledindicates #tothedbstartutilitythatthedatabaseshould,"Y",orshouldnot, #"N",bebroughtupatsystemboottime. # #Multipleentrieswiththesame$ORACLE_SIDarenotallowed. # # orcl:/u01/app/oracle/product/11.2.0/dbhome_1:Y
创建/etc/init.d/oracle
在/etc/init.d/下创建文件oracle,此为oracle自启动脚本。内容如下:
#!/bin/sh #chkconfig:3456161 #description:Oracle11gR2AutoRunServimces #/etc/init.d/oracle # #Run-levelStartupscriptfortheOracleInstance,Listener,and #WebInterface ORACLE_HOME="/u01/app/oracle/product/11.2.0/dbhome_1" ORA_OWNR="oracle" #iftheexecutablesdonotexist--displayerror if[!-f"$ORACLE_HOME/bin/dbstart"] then echo"Oraclestartup:cannotstart" exit1 fi #parameter:start,stop,restart case"$1"in start) #Oraclelistenerandinstancestartup su$ORA_OWNR-s/bin/bash$ORACLE_HOME/bin/dbstart$ORACLE_HOME echo"OracleStartSuccesful!OK." ;; stop) #Oraclelistenerandinstanceshutdown su$ORA_OWNR-s/bin/bash$ORACLE_HOME/bin/dbshut$ORACLE_HOME echo"OracleStopSuccesful!OK." ;; restart) $0stop $0start ;; *) echo$"Usage:`basename$0`{start|stop|restart}" exit1 esac exit0
赋予启动脚本执行权限并链接好:
#chmod750/etc/init.d/oracle #ln-s/etc/init.d/oracle/etc/rc1.d/K61oracle #ln-s/etc/init.d/oracle/etc/rc3.d/S61oracle
启动脚本设置好了之后,可以使用service命令来启动停止oracle了,这时候oracle已经是系统服务了。
serviceoraclestart serviceoraclestop serviceoraclerestart
设置oracle服务为自启动
#chkconfig--addoracle #chkconfig--level345oracleon
总结
好了,重启机器试试吧。以上就是这篇文章的全部内容了,希望本文的内容对大家学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流。