个人工具

Ubuntu Server 10.10安装企业版Oracle 11g

来自Ubuntu中文

跳转至: 导航, 搜索

Ubuntu Server 10.10安装企业版Oracle 11g

最近在Ubuntu Server10.10版上装了两次Oracle 11g。主要参考了Wiki上的Ubuntu上Oracle10g安装指南 由于两遍下来,发现这篇文章还是有一些不足之处,而且内容有些老旧,所以在此基于原来的文章,添加一些自己安装过程中的经验,做一新文,以供各位参考。

第一步,获取Oracle

Oracle的官网上有下载,需要先注册帐号。注意32位和64位版本的区别。下载下来有两个zip文件,大小2G左右。可以用unzip直接解压缩。不建议解压到/tmp里,因为/tmp一般比较小,空间可能不够用。

第二步,安装必需的包

以root用户登录,安装如下软件包

apt-get install gcc make binutils lesstif2 libc6 libc6-dev rpm libmotif3 libaio1 libstdc++6 alien ksh

注意:
1. 使用Ubuntu 10.10安装oracle时,会报一个makefile到错误。这是因为新版本到ubuntu默认安装了libstdc++6,而oracle安装程序要使用的是libstdc++5,所以如果遇到这个错误可以执行 sudo apt-get install libstdc++5 然后在安装程序的报错对话框中点retry就可以继续了。

2. Oracle有很多的Shell使用ksh作为解释器。但是我发现Ubuntu Server没有默认安装这个古老且难用的解释器。所以在安装完之后的configuration过程中会导致shell无法正确执行而报错。

第三步,创建用户

# adduser oracle
正在添加用户"oracle"...
正在添加新组"oracle" (1001)...
正在添加新用户"oracle" (1002) 到组"oracle"...
创建主目录"/home/oracle"...
正在从"/etc/skel"复制文件...
输入新的 UNIX 密码: 
重新输入新的 UNIX 密码: 
passwd:已成功更新密码
Changing the user information for oracle
Enter the new value, or press ENTER for the default
	Full Name []: oracle
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 

adduser 命令系统会自动创建oracle用户的文件

第四步,修改设置

A.设置swap区

Oracle11g至少需要1G的内存和1.5G的交换空间。 具体要求如下:

内存大小 Swap大小
1G - 2G 1.5倍内存大小
2G - 16G 与内存大小相同
16G以上 16G

要查看swap区是否足够大小,用 fdisk -l 命令去查,如果不满足上述要求,那么就要增加swap的大小 重设交换分区可以使用如下操作(count 值是根据你需要调整的交换分区大小而定):

dd if=/dev/zero of=tmp_swap bs=1k count=900000
chmod 600 tmp_swap
mkswap tmp_swap
swapon tmp_swap

完成安装以後,可以释放这个空间:

swapoff tmp_swap
rm tmp_swap


B.修改 sysctl.conf

添加如下的行到/etc/sysctl.conf 中:

kernel.shmmax = 3147483648
kernel.shmmni = 4096
kernel.shmall = 2097152
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000

C.修改 limits.conf

添加如下的行到/etc/security/limits.conf中:

* soft nproc 2407
* hard nproc 16384
* soft nofile 1024
* hard nofile 65536

D.让修改生效

修改了以上文件後,必须让其生效,或重启系统,或切换到 root 用户下用以下的方式改变内核运行参数: sysctl -p

E.产生相应的软连接

创建一个文件如 kk,内容如下:

#!/bin/bash
ln -s /usr/bin/awk /bin/awk
ln -s /usr/bin/rpm /bin/rpm
ln -s /usr/bin/basename /bin/basename
mkdir /etc/rc.d
ln -s /etc/rc0.d /etc/rc.d/rc0.d
ln -s /etc/rc2.d /etc/rc.d/rc2.d
ln -s /etc/rc3.d /etc/rc.d/rc3.d
ln -s /etc/rc4.d /etc/rc.d/rc4.d
ln -s /etc/rc5.d /etc/rc.d/rc5.d
ln -s /etc/rc6.d /etc/rc.d/rc6.d
ln -s /etc/init.d /etc/rc.d/init.d

创建後,切换到 root 用户去执行一下。

F.创建RedHat的版本声明文件

在/etc/redhat-release中添加以下语句,以使安装程序认为正在一个RedHat的系统上安装:

Red Hat Linux release 3.1 (drupal)

G.修改环境变量

编辑 /home/oracle/.bashrc,增加以下export 的内容(注意替换ORACLE_HOME与ORACLE_SID为自己的配置):

export ORACLE_HOME=/opt/ora10
export ORACLE_OWNER=oracle
export ORACLE_SID=ora1
export ORACLE_TERM=xterm
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/Apache/Apache/bin:$PATH

H.修改Ubuntu的Run Level

由于是debian系的linux,Ubuntu Server默认在runlevel 2上运行系统。 但是由于Oracle的安装需要至少runlevel 3才可以完成安装(安装程序会自动检查)。 Ubuntu下可以运行runlevel命令来查看当前系统的runlevel。 telinit 命令用来切换运行级别。 以root 身份运行

telinit 3

第五步,开始安装

注销原来的用户,改用oracle用户登录。用env查看一下环境变量是否生效。 然后进入解压出来的安装文件目录中进行安装

cd /ora_ins_disk
./runInstaller

在安装过程中,请使用 Advanced Installation,然後一路按默认的设置进行往下设置,到窗单名为 “Specify Database Configuration Options”的时候,要修改以下设置: Database Character Set 中选择 Simplified Chinese ZHS16GBK。

当设置完各种路径,密码之后,Oracle安装程序会进行系统检查,这时候会说无法找到前面安装的各种包,并且Next按钮是灰色的无法点击。而在右上角有一个"Ignore All"的选项,用鼠标勾上这一项,然后Next按钮就可以点击了。但还是建议人工的看一下有没有除了Package之外的错误,如果有的话还是先处理之后再点Next。 然后Oracle安装程序就开始进行文件安装了。

文件安装之后,如果在前面一个步骤里没有安装ksh模块,configuration assistant 会提示说有一些shell程序运行失败(如果仔细看的话会发现错误信息是shell找不到ksh),失败的命令都保存在一个叫$ORACLE_HOME/cfgtoollogs/configToolFailedCommands的文件里。这时候不要慌张,只要Oracle安装结束后,用apt安装好ksh,重新运行$ORACLE_HOME/cfgtoollogs/configToolFailedCommands就可以完成配置过程。 在安装的後期,系统提示需要用 root 用户去运行两个脚本文件orainstRoot.sh和root.sh,安装完毕後,Oracle是正常启动着的,你可以试一下连接数据库,同时也可以使用浏览器去设置一下Oracle,(url:http: //localhost:1158/em/)(Oracle 11g与之前的版本都不一样,使用WEB页的企业管理器来代替以前的C/S版JAVA企业管理器)

第六步,设置自启动

创建自启动脚本 创建 oracledb 脚本到/etc/init.d/oracledb,内容如下: 记得把ORACLE_HOME路径换成自己的oracle安装路径,还有ORACLE_SID替换成安装时自己指定的SID

#!/bin/bash
#
# /etc/init.d/oracledb
#
# Run-level Startup script for the Oracle Instance, Listener, and
# Web Interface

export ORACLE_HOME='''/opt/ora10'''
export ORACLE_SID='''ora1'''
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/Apache/Apache/bin:$PATH

ORA_OWNR="oracle"
# if the executables do not exist -- display error
if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
echo "[Oracle Error] dbstart command does not exist, quitting..."
exit 1
else
echo "[Oracle Info] dbstart existance check OK"
fi

# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display
case "$1" in
start)
# Oracle listener and instance startup
echo "[Oracle Info] Starting oracle"
echo "[Oracle Info] su $ORA_OWNR -c ""$ORACLE_HOME/bin/lsnrctl start"
su $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl start"
if [ $? -ne 0 ] 
then
	echo "[Oracle Error] listener failed to start"
exit 1
else 
	echo "[Oracle Info] listener start OK"
fi

su $ORA_OWNR -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
echo "[Oracel Info] su $ORA_OWNR -c ""$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
if [ $? -ne 0 ] 
then
	echo "[Oracle Error] dbstart failed to start"
exit 1
else
	echo "[Oracle Info] dbstart OK"
fi
touch /var/lock/oracle
echo "[Oracle Info]su $ORA_OWNR -c ""$ORACLE_HOME/bin/emctl start dbconsole"
su $ORA_OWNR -c "$ORACLE_HOME/bin/emctl start dbconsole"
if [ $? -ne 0 ] 
then
	echo "[Oracle Error] dbconsole failed to start"
exit 1
else
	echo "[Oracle Info] dbconsole start OK"
fi
echo "[Oracle Info] Starting oracle ended OK"
;;
stop)
# Oracle listener and instance shutdown
echo "[Oracle Info] Shutdown Oracle: "
echo "[Oracle Info] su $ORA_OWNR -c ""$ORACLE_HOME/bin/lsnrctl stop"
su $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"
echo "[Oracle Info] su $ORA_OWNR -c ""$ORACLE_HOME/bin/dbshut $ORACLE_HOME"
su $ORA_OWNR -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME"
rm -f /var/lock/oracle
echo "[Oracle Info]su $ORA_OWNR -c ""$ORACLE_HOME/bin/emctl stop dbconsole"
su $ORA_OWNR -c "$ORACLE_HOME/bin/emctl stop dbconsole"
echo "[Oracle Info] Shutdown Oracle ended OK"
;;
reload|restart)
echo "[Oracle Info]: $1 oracle"
$0 stop
$0 start
;;
*)
echo "[Oracle Error] Unknown context: $1"
echo "[Oracle Info]  Usage: `basename $0` start|stop|restart|reload"
exit 1
esac
exit 0

设置权限,放到启动脚本中去

chmod 755 /etc/init.d/oracledb
update-rc.d oracledb defaults 99

还需要编辑一下/etc/oratab,把其中的N改成Y,不然上述脚本中所调用的$ORACLE_HOME/bin/dbstart在执行时不会自动启动相应的数据库实例(这里的数据库实例是ora1)。文件内容如下:

#
# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.

# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
ora1:/opt/ora10:Y