本文以CentOS 7 amd64为基础

安装环境配置

操作系统安装

请选择“Minimal”选项。

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

# grep MemTotal /proc/meminfo

网络配置

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

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)修改主机名 使主机名生效

# hostname ora11g.dev.openzones.org

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

安全配置

1)更新操作系统

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

# yum update

如果操作系统是离线安装的,后面还会用到安装包,需要挂载安装镜像并修改搜索路径,这样貌似不起作用,后面yum还得加参数^_^。

# mount -t auto /dev/cdrom /media/cdrom
# cd /etc/yum.repos.d
# for f in ./CentOS-*;do ( sed -i 's/enabled=1/enabled=0/g' $f ) done;
# sed -i 's/enabled=0/enabled=1/g' CentOS-Media.repo

2)selinux

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

3)防火墙设置

[CentOS7]

firewall-cmd --permanent --add-port=1521/tcp --add-port=1158/tcp --add-port=5901/tcp
firewall-cmd --reload

修改内核参数

需要设置如下linux参数,如果操作系统中已经设置的值大于如下设置请保留系统设置。

具体解释可参考:oracle 内核参数设置_I'm calvin-CSDN博客_oracle修改内核参数

CentOS7 中kernel.shmall、kernel.shmmni 和kernel.shmmax默认已经定义并且符合要求,只有wmem_max和rmem_max需要修改,添加如下即可:

cat >> /etc/sysctl.conf << 'EOF'
net.core.wmem_max = 1048576
net.core.rmem_max = 4194304
EOF

所有需要满足的参数如下:

kernel.sem = 250 32000 100 128
kernel.shmall = 18446744073692774399
kernel.shmmax = 18446744073692774399
kernel.shmmni = 4096
fs.file-max = 6815744
fs.aio-max-nr = 1048576
net.ipv4.ip_local_port_range = 32768 60999
net.core.wmem_default = 262144
net.core.rmem_default = 262144
net.core.wmem_max = 1048576
net.core.rmem_max = 4194304

使设置生效

/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命令可以从网络或者光盘进行安装。

# yum --disablerepo=\* --enablerepo=c7-media install -y 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 7】

# yum --disablerepo=\* --enablerepo=c7-media  install -y libgomp mksh ksh
# yum --disablerepo=\* --enablerepo=c7-media  install -y unzip

用户配置

创建用户和组

/usr/sbin/groupadd oinstall
/usr/sbin/groupadd dba
/usr/sbin/groupadd oper
/usr/sbin/useradd -m -g oinstall -G dba,oper 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 4096
oracle hard nproc 16384
oracle soft nofile 4096
oracle hard nofile 65536
EOF

注意:设置nofile的hard limit还有一点要注意的就是hard limit不能大于/proc/sys/fs/nr_open,假如hard limit大于nr_open,注销后将无法正常登录。

使用户资源限制策略生效

# 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
$ cat >> ~/.bash_profile << 'EOF'
### For Oracle11g ###
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0.4/dbhome_1
export ORACLE_SID=orcl
export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
export LC_CTYPE=zh_CN.UTF-8
EOF

安装步骤

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

$ su - oracle
$ unzip p13390677_112040_Linux-x86-64_1of7.zip
$ unzip p13390677_112040_Linux-x86-64_2of7.zip

静默安装

1、安装数据库软件

$ cd database
$ ./runInstaller -silent -force -noconfig \
    -IgnoreSysPreReqs -ignorePrereq -showProgress \
    oracle.install.option=INSTALL_DB_SWONLY \
    DECLINE_SECURITY_UPDATES=true \
    UNIX_GROUP_NAME=oinstall \
    INVENTORY_LOCATION=/u01/app/oraInventory \
    SELECTED_LANGUAGES=en,zh_CN \
    ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1 \
    ORACLE_BASE=/u01/app/oracle \
    oracle.install.db.InstallEdition=EE \
    oracle.install.db.isCustomInstall=false \
    oracle.install.db.DBA_GROUP=dba \
    oracle.install.db.OPER_GROUP=oper \
    oracle.install.db.isRACOneInstall=false \
    oracle.install.db.config.starterdb.type=GENERAL_PURPOSE \
    SECURITY_UPDATES_VIA_MYORACLESUPPORT=false \
    oracle.installer.autoupdates.option=SKIP_UPDATES

2、建立侦听网络

$ netca -silent -responsefile /u01/app/oracle/product/11.2.0.4/dbhome_1/assistants/netca/netca.rsp
$ lsnrctl stat

这里是在数据库未创建前建立的侦听服务,所以在后面完成数据库创建后还要编辑$ORACLE_HOME/network/admin/listener.ora文件,加入数据库配置。

3、建立数据库

dbca_install.rsp模板在安装文件的response文件夹中

$ cat > dbca_install_orcl.rsp << 'EOF'
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"  
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl"
SID = "orcl"
TEMPLATENAME = "General_Purpose.dbc"
STORAGETYPE = FS
DATAFILEDESTINATION =/u01/app/oracle/oradata
CHARACTERSET = "ZHS16GBK"
NATIONALCHARACTERSET = "AL16UTF16"
TOTALMEMORY = "4096"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle" 
EOF

$ dbca -silent -responseFile dbca_install_orcl.rsp

也可以直接用命令行建立

$ dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbName orcl -sysPassword oracle -systemPassword oracle

侦听补上,貌似11.2.0.4不需要在侦听中添加SID_LIST_LISTENER内容,他会自己发现实例。

vi $ORACLE_HOME/network/admin/listener.ora
...
SID_LIST_LISTENER =
(SID_LIST =
  (SID_DESC =
  (GLOBAL_DBNAME = orcl)
  (SID_NAME = orcl)
  )
)
...
ADR_BASE_LISTENER = /u01/app/oracle

重新启动侦听

$ lsnrctl stop
$ lsnrctl start

图形化安装

1、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

2、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(/u01/app/oracle/), Software Location(/u01/app/oracle/product/11.2.0.4/dbhome_1)
Step 6 Create Inventory: Inventory Directory(/u01/app/oraInventory), oraInventory Group Name(oinstall)
Step 7 Operation System Groups: Database Administrator Group(dba), Database Operator Group(oinstall)

# /u01/app/oraInventory/orainstRoot.sh
# /u01/app/oracle/product/11.2.0.4/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(orcl), SID(orcl)
Step 4 default, No Enterprise Manager
Step 5 Use the Same Administrative Password for All Accounts
Step 6 default
Step 7 default, Specify Fast Recovry Area, Enable Archiving
Step 8 default
Step 9 Memory; Sizing: Block Size, Processes; Character Sets: Use Unicode(AL32UTF-8), National Character Set(UTF-8), Default Language(Simplified Chinese), Default Territory(China)

启动设置

设置为Oracle自动启动,设置随操作系统自动启动。

检查/etc/oratab配置

# vi /etc/oratab
...
orcl:/u01/app/oracle/product/11.2.0.4/dbhome_1:Y
...

配置Systemd服务

cat > /etc/systemd/system/oracle.service << 'EOF'
[Unit]
Description=Oracle 11G
After=syslog.target network.target

[Service]
LimitMEMLOCK=infinity
LimitNOFILE=65535
Type=oneshot
RemainAfterExit=yes
User=oracle
Environment="ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/dbhome_1"
ExecStart=/u01/app/oracle/product/11.2.0.4/dbhome_1/bin/dbstart $ORACLE_HOME >> 2>&1 &
ExecStop=/u01/app/oracle/product/11.2.0.4/dbhome_1/bin/dbshut $ORACLE_HOME 2>&1 &

[Install]
WantedBy=multi-user.target
EOF

systemctl enable oracle

安装测试

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

数据库附加设置

默认数据库允许的最大的process数量是150个,包括系统的process,需要修改process数量,session数量不用修改,Oracle 11g会自己计算。

-- 修改参数
alter system set processes=500 scope=spfile;
commit;

-- 重启数据库才能生效
shudown immediate
startup

-- 查看参数
show parameter process;

默认的用户是180天过期,实际使用中有可能无法根据周期去变更

-- 修改为不限制
alter profile default limit PASSWORD_LIFE_TIME UNLIMITED;

-- 查看修改结果
select * from dba_profiles s where s.profile='DEFAULT' and resource_name='PASSWORD_LIFE_TIME';

常见问题

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;

11.2.0.4中貌似已经不需要人工配置,listener会自己发现Oracle实例。

启动超时

[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 = orcl)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0.4/dbhome_1)
      (SID_NAME = orcl)
    )
  )

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”在“2023-03-14 02:29:36”修改