一、安装Oracle 11G前环境搭建

本次实验是基于Linux(CentOS6.7_64)下搭建oracle 11g环境,这里选择CentOS安装oracle并不是最佳选择,可以根据需要选择不同的Linux发行版,如Oracle Linux、SuSE Linux、Red Hat、IBM AIX等。


VM或物理机的配置要求:

在实验环境安装oracle11g最少需要2G内存、2个cpu、2G交换分区、磁盘空间不低于20G。

生产环境中,要保证oracle的性能,建议最低配置为8G内存、4个cpu、8G交换分区,如果生产环境比较繁忙,则需要更高的配置。


二、安装Oracle 11G前准备工作

上传oracle11g安装包,解压

linux.x64_11gR2_database_1of2.zip

linux.x64_11gR2_database_2of2.zip


配置/etc/hosts文件,添加ip与主机名的解析

127.0.0.1localhostlocalhost.localdomainlocalhost4localhost4.localdomain4::1localhostlocalhost.localdomainlocalhost6localhost6.localdomain6#eth010.11.12.88hm


创建oracle相关用户和组

[root@hm~]#groupadddba[root@hm~]#groupaddoinstall[root@hm~]#useradd-goinstall-Gdba-moracle[root@hm~]#idoracleuid=500(oracle)gid=501(oinstall)groups=501(oinstall),500(dba)


创建oracle软件安装目录

[root@hm~]#mkdir/u01/app/oracle-p[root@hm~]#chown-Roracle./u01/[root@hm~]#chmod775-R/u01/[root@hm~]#ls-ld/u01/drwxr-xr-x.3oracleoinstall4096Oct1422:58/u01/


oracle用户环境变量设置,su进入oracle用户下,修改~/.bash_profile文件,添加以下内容

exportTMP=/tmpexportTMPDIR=$TMPexportORACLE_TERM=xtermexportORACLE_BASE=/u01/app/oracleexportORACLE_HOME=$ORACLE_BASE/dbexportORACLE_SID=orclexportPATH=$ORACLE_HOME/bin:$PATHexportLD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:/usr/lib64if[$USER="oracle"];thenif[$SHELL="/bin/ksh"];thenulimit-p16384ulimit-n65536elseulimit-u16384-n65536fifi


修改内核参数,打开/etc/sysctl.conf文件,添加以下参数,并修改/etc/security/limits.conf文件

kernel.shmmax=68719476736kernel.shmall=4294967296net.core.rmem_default=262144net.core.rmem_max=4194304net.core.wmem_default=262144net.core.wmem_max=1048576fs.aio-max-nr=1048576net.ipv4.ip_local_port_range=900065500fs.file-max=6815744kernel.sem=25032000100128kernel.shmmni=4096[root@hm~]#sysctl-pnet.ipv4.ip_forward=0net.ipv4.conf.default.rp_filter=1net.ipv4.conf.default.accept_source_route=0kernel.sysrq=0kernel.core_uses_pid=1net.ipv4.tcp_syncookies=1kernel.msgmnb=65536kernel.msgmax=65536kernel.shmmax=68719476736kernel.shmall=4294967296kernel.shmmax=68719476736kernel.shmall=4294967296net.core.rmem_default=262144net.core.rmem_max=4194304net.core.wmem_default=262144net.core.wmem_max=1048576fs.aio-max-nr=1048576net.ipv4.ip_local_port_range=900065500fs.file-max=6815744kernel.sem=25032000100128kernel.shmmni=4096在/etc/security/limits.conf文件末尾添加如下内容oraclesoftnproc2047oraclehardnproc16384oraclesoftnofile4096oraclehardnofile65536并同时修改/etc/pam.d/login文件,添加以下内容sessionrequiredpam_limits.so


安装oracle依赖的软件包

[root@hm ~]# yum install gcc gcc-c++ libaio glibc compat-libstdc++-33 elfutils-libelf-devel libaio-devel libgcc libstdc++ libstdc++-devel unixODBC unixODBC-devel glibc-common ksh make sysstat pdksh

[root@hm ~]# yum install glibc-2.12-1.192.el6.i686

检查是否安装

[root@hm ~]# for i in gcc gcc-c++ libaio glibc compat-libstdc++-33 elfutils-libelf-devel libaio-devel libgcc libstdc++ libstdc++-devel unixODBC unixODBC-devel glibc-common ksh make sysstat pdksh;do rpm -q $i;done
gcc-4.4.7-17.el6.x86_64
gcc-c++-4.4.7-17.el6.x86_64
libaio-0.3.107-10.el6.x86_64
glibc-2.12-1.192.el6.x86_64
compat-libstdc++-33-3.2.3-69.el6.x86_64
elfutils-libelf-devel-0.164-2.el6.x86_64
libaio-devel-0.3.107-10.el6.x86_64
libgcc-4.4.7-17.el6.x86_64
libstdc++-4.4.7-17.el6.x86_64
libstdc++-devel-4.4.7-17.el6.x86_64
unixODBC-2.2.14-14.el6.x86_64
unixODBC-devel-2.2.14-14.el6.x86_64
glibc-common-2.12-1.192.el6.x86_64
ksh-20120801-33.el6.x86_64
make-3.81-23.el6.x86_64
sysstat-9.0.4-31.el6.x86_64
package pdksh is not installed


三、安装oracle11g软件

解压oracle11g软件包

[root@hm oracle]# unzip linux.x64_11gR2_database_1of2.zip

[root@hm oracle]# unzip linux.x64_11gR2_database_2of2.zip

[root@hmoracle]#chown-Roracle.database/[root@hmoracle]#ls-ldatabase/total36drwxr-xr-x.12oracleoinstall4096Aug172009docdrwxr-xr-x.4oracleoinstall4096Aug152009installdrwxrwxr-x.2oracleoinstall4096Aug152009responsedrwxr-xr-x.2oracleoinstall4096Aug152009rpm-rwxr-xr-x.1oracleoinstall3226Aug152009runInstallerdrwxrwxr-x.2oracleoinstall4096Aug152009sshsetupdrwxr-xr-x.14oracleoinstall4096Aug152009stage-rw-r--r--.1oracleoinstall5402Aug182009welcome.html


以orcle用户登录图形界面安装oracle,也可以使用vnc远程安装。这里直接用Xshell远程调用linux图形界面进行安装

[root@hm~]#su-oracle[oracle@hm~]$exportDISPLAY=10.11.12.1:0.0[oracle@hm~]$xhost+

进入database目录,执行runInstalle

[oracle@hm~]$cd/usr/local/src/oracle/database/[oracle@hmdatabase]$./runInstallerStartingOracleUniversalInstaller...CheckingTempspace:mustbegreaterthan120MB.Actual21645MBPassedCheckingswapspace:mustbegreaterthan150MB.Actual4095MBPassedCheckingmonitor:mustbeconfiguredtodisplayatleast256colors.Actual16777216PassedPreparingtolaunchOracleUniversalInstallerfrom/tmp/OraInstall2016-10-15_12-48-55PM.Pleasewait...

进入图形界面安装


[root@hm~]#/u01/app/oraInventory/orainstRoot.shChangingpermissionsof/u01/app/oraInventory.Addingread,writepermissionsforgroup.Removingread,write,executepermissionsforworld.Changinggroupnameof/u01/app/oraInventorytooinstall.Theexecutionofthescriptiscomplete.[root@hm~]#/u01/app/oracle/db/root.shRunningOracle11groot.shscript...Thefollowingenvironmentvariablesaresetas:ORACLE_OWNER=oracleORACLE_HOME=/u01/app/oracle/dbEnterthefullpathnameofthelocalbindirectory:[/usr/local/bin]:Copyingdbhometo/usr/local/bin...Copyingoraenvto/usr/local/bin...Copyingcoraenvto/usr/local/bin...Creating/etc/oratabfile...Entrieswillbeaddedtothe/etc/oratabfileasneededbyDatabaseConfigurationAssistantwhenadatabaseiscreatedFinishedrunninggenericpartofroot.shscript.Nowproduct-specificrootactionswillbeperformed.Finishedproduct-specificrootactions.

启动监听

[oracle@hm~]$lsnrctlstartLSNRCTLforLinux:Version11.2.0.1.0-Productionon15-OCT-201623:30:07Copyright(c)1991,2009,Oracle.Allrightsreserved.Starting/u01/app/oracle/db/bin/tnslsnr:pleasewait...TNSLSNRforLinux:Version11.2.0.1.0-ProductionLogmessageswrittento/u01/app/oracle/diag/tnslsnr/hm/listener/alert/log.xmlListeningon:(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hm)(PORT=1521)))Connectingto(ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))STATUSoftheLISTENER------------------------AliasLISTENERVersionTNSLSNRforLinux:Version11.2.0.1.0-ProductionStartDate15-OCT-201623:30:09Uptime0days0hr.0min.1secTraceLeveloffSecurityON:LocalOSAuthenticationSNMPOFFListenerLogFile/u01/app/oracle/diag/tnslsnr/hm/listener/alert/log.xmlListeningEndpointsSummary...(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hm)(PORT=1521)))ThelistenersupportsnoservicesThecommandcompletedsuccessfully

创建数据库实例,oracle用户下使用dbca工具创建

[oracle@hm ~]$ dbca

安装完成检查,查看oracle进程与监听状态

[oracle@hm~]$ps-ef|grepora_oracle66361023:41?00:00:00ora_pmon_orcloracle66381023:41?00:00:04ora_vktm_orcloracle66421023:41?00:00:00ora_gen0_orcloracle66441023:41?00:00:00ora_diag_orcloracle66461023:41?00:00:00ora_dbrm_orcloracle66481023:41?00:00:00ora_psp0_orcloracle66501023:41?00:00:05ora_dia0_orcloracle66521023:41?00:00:00ora_mman_orcloracle66541023:41?00:00:00ora_dbw0_orcloracle66561023:41?00:00:00ora_lgwr_orcloracle66581023:41?00:00:00ora_ckpt_orcloracle66601023:41?00:00:00ora_smon_orcloracle66621023:41?00:00:00ora_reco_orcloracle66641023:41?00:00:02ora_mmon_orcloracle66661023:41?00:00:02ora_mmnl_orcloracle66681023:41?00:00:00ora_d000_orcloracle66701023:41?00:00:00ora_s000_orcloracle67191023:41?00:00:00ora_qmnc_orcloracle67391023:41?00:00:01ora_cjq0_orcloracle68321023:41?00:00:00ora_q000_orcloracle68341023:41?00:00:00ora_q001_orcloracle68421023:42?00:00:00ora_smco_orcloracle68441023:42?00:00:00ora_w000_orcloracle158582208023:59pts/000:00:00grepora_[oracle@hm~]$lsnrctlstatusLSNRCTLforLinux:Version11.2.0.1.0-Productionon15-OCT-201623:59:58Copyright(c)1991,2009,Oracle.Allrightsreserved.Connectingto(ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))STATUSoftheLISTENER------------------------AliasLISTENERVersionTNSLSNRforLinux:Version11.2.0.1.0-ProductionStartDate15-OCT-201623:30:09Uptime0days0hr.29min.50secTraceLeveloffSecurityON:LocalOSAuthenticationSNMPOFFListenerLogFile/u01/app/oracle/diag/tnslsnr/hm/listener/alert/log.xmlListeningEndpointsSummary...(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hm)(PORT=1521)))ServicesSummary...Service"orcl"has1instance(s).Instance"orcl",statusREADY,has1handler(s)forthisservice...Service"orclXDB"has1instance(s).Instance"orcl",statusREADY,has1handler(s)forthisservice...Thecommandcompletedsuccessfully


登录oracle数据库,查看数据库实例状态、实例名、数据库文件、日志文件

SQL>selectstatusfromv$instance;STATUS------------OPENSQL>selectnamefromv$database;NAME---------ORCLSQL>selectnamefromv$datafile;NAME--------------------------------------------------------------------------------/u01/app/oracle/oradata/orcl/system01.dbf/u01/app/oracle/oradata/orcl/sysaux01.dbf/u01/app/oracle/oradata/orcl/undotbs01.dbf/u01/app/oracle/oradata/orcl/users01.dbfSQL>selectmemberfromv$logfile;MEMBER--------------------------------------------------------------------------------/u01/app/oracle/oradata/orcl/redo03.log/u01/app/oracle/oradata/orcl/redo02.log/u01/app/oracle/oradata/orcl/redo01.log


查看oracle数据库版本

SQL>select*fromv$version;BANNER--------------------------------------------------------------------------------OracleDatabase11gEnterpriseEditionRelease11.2.0.1.0-64bitProductionPL/SQLRelease11.2.0.1.0-ProductionCORE11.2.0.1.0ProductionTNSforLinux:Version11.2.0.1.0-ProductionNLSRTLVersion11.2.0.1.0-Production


关闭与启动

关闭数据库实例

SQL>shutdownimmediate;Databaseclosed.Databasedismounted.ORACLEinstanceshutdown.

关闭监听

[oracle@hm~]$lsnrctlstopLSNRCTLforLinux:Version11.2.0.1.0-Productionon16-OCT-201600:16:41Copyright(c)1991,2009,Oracle.Allrightsreserved.Connectingto(ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))Thecommandcompletedsuccessfully[oracle@hm~]$ps-ef|grepora_oracle169872208000:17pts/000:00:00grepora_

启动监听

[oracle@hm~]$lsnrctlstart

启动实例

[oracle@hm~]$sqlplus/assysdbaSQL*Plus:Release11.2.0.1.0ProductiononSunOct1600:19:392016Copyright(c)1982,2009,Oracle.Allrightsreserved.Connectedtoanidleinstance.SQL>startup;ORACLEinstancestarted.TotalSystemGlobalArea780824576bytesFixedSize2217424bytesVariableSize599788080bytesDatabaseBuffers171966464bytesRedoBuffers6852608bytesDatabasemounted.Databaseopened.SQL>selectstatusfromv$instance;STATUS------------OPEN