RHEL5——指Redhat Enterprise Linux 5.0,本文档默认采用的是5.4版。同样适用于CentOS 5系列。已经测试过的版本RHEL5.4, CentOS5.6。

安装环境配置

Oracle 11g需要最少1G物理内存,建议>2G

在32位系统中进行安装时默认只认识3G内存,需要安装带有PAE的内核,在rhel的安装盘中有。

操作系统安装

使用默认安装选项(其实默认安装挺讨厌,安装了好多在这里用不到的软件,如:OpenOffice等)。如果是CentOS/Redhat 6请选择“Minimal”选项。

交换分区至少1G,使用如下命令检查

# grep MemTotal /proc/meminfo

网络配置

1)在/etc/hosts文件中添加一个完整的host记录,格式如下

<IP-address>    <fully-qualified-machine-name>  <machine-name/alias>
127.0.0.1       localhost.localdomain localhost
192.168.1.30    ora11g.dev.openzones.org        ora11g

注意:127.0.0.1不能缺少否则,lsnrctl start不能成功执行,hostname对应的ip要是正确的。Listener会在由主机名翻译到的地址上建立侦听。

2)修改主机名 修改/etc/sysconfig/network中的主机名为

HOSTNAME=ora11g.dev.openzones.org

使用hostname临时修改主机名(下次启动将从/etc/sysconfig/network读取)

# hostname ora11g.dev.openzones.org

注意:安装完oracle后不要修改主机名称。否则oracle将不能正常启动。

安全配置

1)更新操作系统

安装完成后,建议先对操作系统进行更新(如果不想更新或者没有外网可以跳过此步骤)

# yum update

2)selinux

修改/etc/selinux/config以关闭selinux,修改文件中的SELINUX=disabled(需要重新启动才可以生效),使用setenforce 0来临时关闭selinux(下次启动将从/etc/selinux/config读取)

3)防火墙设置

[CentOS/RHEL 5]

# iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 1521 -j ACCEPT
# iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 1158 -j ACCEPT
# iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT

[CentOS/RHEL 6]

# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 1521 -j ACCEPT
# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 1158 -j ACCEPT
# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT

保存防火墙配置

# /etc/init.d/iptables save

也可以人工修改文件/etc/sysconfig/iptables使用/etc/init.d/iptables restart使配置生效。

注意:添加的记录要放到COMMIT和下面内容之前,否则将不能连接到Oracle数据库 -A INPUT -j REJECT --reject-with icmp-host-prohibited

修改内核参数

需要设置如下linux参数,如果操作系统中已经设置的值大于如下设置请保留系统设置。 kernel.shmall、kernel.shmmni 和kernel.shmmax在rhel5中默认已经定义并且符合要求,如果你需要的值大于系统中默认的设置请修改,下面参数针对rhel5u4版本中的值。

cat >> /etc/sysctl.conf <<EOF
kernel.sem = 250 32000 100 128
kernel.shmmni = 4096
fs.file-max = 6815744
fs.aio-max-nr=1048576
net.ipv4.ip_local_port_range = 9000 65500
net.core.wmem_max = 1048576
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.rmem_default = 262144
EOF

使设置生效

/sbin/sysctl -p

确认设置

/sbin/sysctl -a | grep shm
/sbin/sysctl -a | grep sem
/sbin/sysctl -a | grep file-max
/sbin/sysctl -a | grep ip_local_port_range
/sbin/sysctl -a | grep rmem_default
/sbin/sysctl -a | grep rmem_max
/sbin/sysctl -a | grep wmem_default
/sbin/sysctl -a | grep wmem_max

依赖的软件包安装

Oracle将需要如下包的支持,如果方便的话建议使用Yum进行安装,这种方式比起CD方式要简单不易出错。

使用RPM命令从CD/DVD安装

可以是如下命令查看包的安装情况

# rpm -q compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel glibc glibc-devel glibc-common gcc gcc-c++ kernel-headers libgcc libaio libaio-devel libstdc++ libstdc++-devel unixODBC unixODBC-devel sysstat binutils make

如果是按照rhel5默认安装将还有如下包需要安装

  • compat-libstdc++-33
  • elfutils-libelf-devel
  • glibc-devel-2.5
  • gcc
  • gcc-c++
  • libaio-devel
  • libstdc++-devel
  • unixODBC
  • unixODBC-devel
  • sysstat

如果是使用CD盘来安装使用下面命令(在光盘的Server目录),如果是DVD盘,不用换盘,更为方便。

CD2:

# rpm -ivh elfutils-libelf*
# rpm -ivh kernel-headers* glibc-devel-2* glibc-headers-2* gcc-4* libgomp-4* gcc-c++-4* libstdc++-devel-4*

CD3:

# rpm -ivh unixODBC-2.2.11-7.1.i386.rpm unixODBC-devel-2.2.11-7.1.i386.rpm unixODBC-2.2.11-7.1.x86_64.rpm unixODBC-devel-2.2.11-7.1.x86_64.rpm 
# rpm -ivh libaio-devel* sysstat*

注:如果显示某些包已经安装,其命令行后面的安装将被终止,需要逐个安装或者添加--force参数。

可以是如下命令查看包的安装情况

# rpm -q compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel glibc glibc-devel glibc-common gcc gcc-c++ kernel-headers libgcc libaio libaio-devel libstdc++ libstdc++-devel unixODBC unixODBC-devel sysstat binutils make

[CentOS 5u4]

CentOS 5u4中默认安装还缺少compat-libstdc++-33 和pdksh-5.2.14-36需要添加:

# rpm -ivh compat-libstdc++-33-3.2.3-61.x86_64.rpm
# rpm -ivh pdksh-*.rpm

使用YUM安装

通过yum命令可以从网络或者光盘进行安装。

# yum install compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel glibc glibc-devel glibc-common gcc gcc-c++ kernel-headers libgcc libaio libaio-devel libstdc++ libstdc++-devel unixODBC unixODBC-devel sysstat binutils make

【CentOS 5】

# yum install libgomp pdksh

【CentOS 6】

# yum install libgomp mksh ksh

如果是从光盘安装而不是网络,如果光盘的挂载路径不是/media/CentOS或者/media/cdrom请挂载连接光盘到这两个路径之一如下:

# ln -s /media/CentOS_5.4_Final /media/CentOS

然后需要在yum中带上如下参数:

# yum --disablerepo=\* --enablerepo=c5-media <所需软件包>

用户配置

创建用户和组

/usr/sbin/groupadd oinstall
/usr/sbin/groupadd dba
/usr/sbin/groupadd oper
/usr/sbin/useradd -m -g oinstall -G dba,oper oracle
id oracle
passwd oracle

创建和初始化安装目录

注意:如果直接安装在oracle用户目录省略这个步骤。

Oracle Base目录

mkdir -p /u01/app/oracle
chown -R oracle:oinstall /u01/app/oracle
chmod -R 755 /u01/app/oracle

Oracle Home目录

Oracle Inventory目录

mkdir -p /u01/app/oraInventory
chown -R oracle:oinstall /u01/app/oraInventory
chmod -R 755 /u01/app/oraInventory

配置shell限制

配置用户资源限制策略

cat >> /etc/security/limits.conf <<EOF
# For Oracle User
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
EOF

使用户资源限制策略生效,32位系统中为/lib,64位系统中为/lib64目录或者不使用全路径,只写pam_limits.so;如果在64位系统中配置为32位系统模块路径会引起不能在本机登录的错误(远程SSH可以)。

cat >> /etc/pam.d/login <<EOF
session required pam_limits.so
EOF

Change the default profile for bash and ksh as well as the default login script for cshell.

cat >> /etc/profile <<EOF
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
cat >> /etc/csh.login <<EOF
if ( \$USER == "oracle" ) then
  limit maxproc 16384
  limit descriptors 65536
  umask 022
endif
EOF

设置环境变量

在.bash_profile添加环境设置

# su - oracle
$ vi ~/.bash_profile
# For Oracle11g
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=cbox
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
export LC_CTYPE=en_US.UTF-8

注意:不要使用cat来建立文件,它会展开变量。

安装步骤

1) 解压缩安装包

以oracle身份登录系统将压缩包放入/home/oracle目录,其他目录也可以,只要目录的拥有者为orale.oinstall即可。

$ su - oracle
$ unzip linux.x64_11gR2_database_1of2.zip
$ unzip linux.x64_11gR2_database_2of2.zip

2) 如果是远程安装环境配置

VNC方式

$ vncserver

注意:如果不使用Gnome界面可以不执行以下步骤。

$ vncserver -kill :1
$ vi ~/.vnc/xstartup
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
...
$ vncserver

X11-Forward方式

默认X11-Forward是开启的,只需要在客户机上安装X-Server即可返回服务器端界面,推荐使用Xming

3) 执行安装 注意:CentOS/Redhat 6.x中使用的是ksh而不是pdksh,安装过程中依赖检查时忽略就行了。

$ cd database

$ ./runInstaller
Step 1 Installation Option: Install database software only
Step 2 Grid Options: Single instance database  Installation
Step 3 Product Languages: Select Languages(English, Simplified Chinese)
Step 4 Database Edition: Enterprise Edition
Step 5 Installation Location: Oracle Base(/opt/usr/oracle/app), Software Location(/opt/usr/oracle/app/product/11.2.0/dbhome_1)
Step 6 Create Inventory: Inventory Directory(/opt/usr/oracle/oraInventory), oraInventory Group Name(oinstall)
Step 7 Operation System Groups: Database Administrator Group(dba), Database Operator Group(oinstall)

# /opt/usr/oracle/oraInventory/orainstRoot.sh
# /opt/usr/oracle/app/product/11.2.0/dbhome_1/root.sh

$ netca
Step 1 Choose the configuration you would like to do : Listener configuration
Step 2 Select you want to do : Add
Step 3 Listener Name: LISTENER
Step 4 Selected Protocols: TCP
Step 5 Use the standard port number of 1521

$ dbca
Step 1 Select the operation that you want to perform: Create a Database
Step 2 default
Step 3 Global Database Name(), SID()
Step 4 default
Step 5 Use the Same Administrative Password for All Accounts
Step 6 default
Step 7 default
Step 8 default
Step 9 Character Sets: Use Unicode(AL32UTF-8), National Character Set(UTF-8), Default Language(Simplified Chinese), Default Territory(China)

启动设置

设置为Oracle自动启动

检查/etc/oratab配置

# vi /etc/oratab
...
cbox:/opt/usr/oracle/app/product/11.2.0/dbhome_1:Y

编制启动脚本(方法一)

在rc.local中加入启动脚本

# vi /etc/rc.local
su - oracle -lc ${ORACLE_HOME}/bin/dbstart ${ORACLE_HOME}

建立系统服务(方法二)

# vi /etc/init.d/ora11g
#!/bin/bash
# chkconfig: 345 80 05
# description: starts the oracle dabase deamons
#
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
ORACLE_OWNER=oracle
ORACLE_DESC="Oracle 11g"
ORACLE_LOCK=/var/lock/subsys/ora11g
SU=/bin/su

case "$1" in
    'start')
        echo -n \"Starting ${ORACLE_DESC}:\"
        $SU - $ORACLE_OWNER -c '$ORACLE_HOME/bin/dbstart $ORACLE_HOME'
        $SU - $ORACLE_OWNER -c '$ORACLE_HOME/bin/emctl start dbconsole'
        touch ${ORACLE_LOCK}
        echo
        ;;
    'stop')
        echo -n "shutting down ${ORACLE_DESC}: "
        $SU - $ORACLE_OWNER -c '$ORACLE_HOME/bin/dbshut $ORACLE_HOME'
        rm -f ${ORACLE_LOCK}
        echo
        ;;
    'restart')
        echo -n "restarting ${ORACLE_DESC}:"
        $0 stop
        $0 start
        echo
        ;;
    *)
        echo "usage: $0 { start | stop | restart }"
        exit 1
        ;;
esac
exit 0

# chmod +x /etc/init.d/ora11g
# /sbin/chkconfig --level 345 ora11g on

安装测试

打开em控制台 https://192.168.1.30:1158/em 注意:建议安装完成后进行重启测试保证数据库可以自动启动。

常见问题

防火墙配置问题

如果你的防火墙配置文件/etc/sysconfig/iptables中存在如下条目请注释掉。

#-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited

内核参数配置问题

Oracle11g提供安装过程中的参数修复。

[root@xen-01 ~]# /tmp/CVU_11.2.0.1.0_oracle/runfixup.sh 
Response file being used is :/tmp/CVU_11.2.0.1.0_oracle/fixup.response
Enable file being used is :/tmp/CVU_11.2.0.1.0_oracle/fixup.enable
Log file location: /tmp/CVU_11.2.0.1.0_oracle/orarun.log
Setting Kernel Parameters...
kernel.shmmax = 536870912
The value for semopm in response file is not greater than value for semopm in /etc/sysctl.conf file. Hence not changing it.
kernel.sem = 250 32000 100 128
fs.file-max = 6815744
The value for file-max in response file is not greater than value for file-max in /etc/sysctl.conf file. Hence not changing it.
fs.file-max = 6815744
The upper limit of ip_local_port range in reponse file is not greater than value in /etc/sysctl.conf, hence not changing it.
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default=4194304
The value for rmem_default in response file is not greater than value for rmem_default in /etc/sysctl.conf file. Hence not changing it.
net.core.rmem_default = 262144
net.core.wmem_default=262144
The value for wmem_default in response file is not greater than value for wmem_default in /etc/sysctl.conf file. Hence not changing it.
net.core.wmem_default = 262144
net.core.rmem_max=4194304
The value for rmem_max in response file is not greater than value for rmem_max in /etc/sysctl.conf file. Hence not changing it.
net.core.rmem_max = 4194304
net.core.wmem_max=1048576
The value for wmem_max in response file is not greater than value for wmem_max in /etc/sysctl.conf file. Hence not changing it.
net.core.wmem_max = 1048576
fs.aio-max-nr=1048576
The value for aio-max-nr in response file is not greater than value for aio-max-nr in /etc/sysctl.conf file. Hence not changing it.
fs.aio-max-nr = 1048576

库依赖问题

CentOS 6库依赖

# yum install ksh mksh (用于解决pdksh依赖问题)

其余的忽略,因为已经有新的版本。

libXext.so.6: cannot open shared object file: No such file or directory

一般是在64位系统中安装时出现的32位库依赖问题问题。

[oracle@db01 databaes] ./runInstaller
[oracle@db01 database]$ Exception in thread "main" java.lang.UnsatisfiedLinkError: /tmp/OraInstall2012-12-21_04-18-54PM/jdk/jre/lib/i386/xawt/libmawt.so: libXext.so.6: cannot open shared object file: No such file or directory
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1647)
    at java.lang.Runtime.load0(Runtime.java:769)
    at java.lang.System.load(System.java:968)
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1668)
    at java.lang.Runtime.loadLibrary0(Runtime.java:822)
    at java.lang.System.loadLibrary(System.java:993)
    at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:50)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.awt.Toolkit.loadLibraries(Toolkit.java:1509)
    at java.awt.Toolkit.<clinit>(Toolkit.java:1530)
    at com.jgoodies.looks.LookUtils.isLowResolution(Unknown Source)
    at com.jgoodies.looks.LookUtils.<clinit>(Unknown Source)
    at com.jgoodies.looks.plastic.PlasticLookAndFeel.<clinit>(PlasticLookAndFeel.java:122)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:242)
    at javax.swing.SwingUtilities.loadSystemClass(SwingUtilities.java:1783)
    at javax.swing.UIManager.setLookAndFeel(UIManager.java:480)
    at oracle.install.commons.util.Application.startup(Application.java:758)
    at oracle.install.commons.flow.FlowApplication.startup(FlowApplication.java:164)
    at oracle.install.commons.flow.FlowApplication.startup(FlowApplication.java:181)
    at oracle.install.commons.base.driver.common.Installer.startup(Installer.java:265)
    at oracle.install.ivw.db.driver.DBInstaller.startup(DBInstaller.java:114)
    at oracle.install.ivw.db.driver.DBInstaller.main(DBInstaller.java:132)

解决办法:

# yum install libXext.i686

启动Lisnter问题

Lisnter配置文件位置:$ORACLE_HOME/network/admin/
配置文件名称:listener.ora,tnsnames.ora

启动超时

[oracle@gps ~]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 14-DEC-2011 05:28:54
Copyright (c) 1991, 2009, Oracle.  All rights reserved.
Starting /home/oracle/app/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /home/oracle/app/product/11.2.0/dbhome_1/network/admin/listener.ora
Log messages written to /home/oracle/app/diag/tnslsnr/gps/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=gps.railwaypolice.com)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=74.86.197.160-static.reverse.softlayer.com)(PORT=1521)))
TNS-12535: TNS:operation timed out
 TNS-12560: TNS:protocol adapter error
  TNS-00505: Operation timed out
   Linux Error: 110: Connection timed out
[oracle@gps ~]$ 

在/etc/hosts中添加主机名称的正确解析

ORA-12505、ORA-12514问题

修改$ORACLE_HOME/network/admin/listener.ora文件内容 添加如下服务:

LISTENER所侦听的数据库

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = cbox)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1)
      (SID_NAME = cbox)
    )
  )

LISTENER对应的服务器

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = ora11g.dev.iotlabs.com)(PORT = 1521))
    )
  )

重新加载侦听配置

$ lsnrctl reload

查看侦听状态

$ lsnrctl status

连接超时问题

当产生从本机可以连接,而从外部机器连接超时,一般有一下几项检查:

1)检查防火墙配置,看从外部是否可以telnet数据库主机的1521端口;

2)是否配置了不能访问到的DNS服务器,检查/etc/resolv.conf中的nameserver项(可以没有);建议对oracle主机在/etc/hosts中添加主机名称和ip对应关系。

3)主机的解析顺序是否正确,检查/etc/host.conf文件中的内容,正确一般为hosts优先。 order hosts,bind

其它问题

ORA-00845: MEMORY_TARGET not supported on this system

这个问题是由于设置SGA的大小超过了操作系统/dev/shm的大小,修改后就可解决:

1)查看修改前大小

# df -k /dev/shm

2)永久修改shm大小

# vi /etc/fstab
tmpfs /dev/shm tmpfs defaults,size=10G 0 0 
# umount /dev/shm && mount /dev/shm
or
#  mount -o remount /dev/shm

3)查看修改后大小

# df -k /dev/shm

4)临时修复大小

# mount -o remount,size=10G /dev/shm

[ 编辑 | 历史 ]
最近由“jilili”在“2015-07-22 14:51:43”修改