在 Ubuntu 8.04 LTS (Hardy Heron) 上安装 Oracle 11g[翻译]

By Augusto Bott — May 6th, 2008 at 4:07 pm
http://www.pythian.com/blogs/968/installing-oracle-11g-on-ubuntu-804-lts-hardy-heron

转载请注明原作者,尊重版权从我做起

在我们发布《在 ubuntu 7.10 上安装 Oracle 10g 》(November, 6th)之后,考虑到4月21号 Ubuntu 8.04 LTS 的发布,我花了点时间回顾并整理出这个新的 安装向导: HOWTO 。
请注意:我使用的是 x86 server 版本的 Ubuntu 8.04 ,但是相同的步骤在desktop版本的 Ubuntu 上应该没有任何问题。另外提醒下,整个安装过程可能花费超过6个小时1的时间,别到时怪我没有告诉你哦。
那么,让我们开始吧~~

第一步
(安装ubuntu。当然,如果你还没有安装的话:D)
从这里获取 Ubuntu Linux 8.04 Hardy Heron (x86, 32-bit) 安装镜像,刻录到CD上,然后安装到任何一个你喜欢的主机上。安装系统的过程中,唯一的注意事项是,你应该让安装程序在系统安装的最后安装一个 OpenSSH 服务器到你的机器上,过一会儿我们的安装步骤都要通过ssh远程完成。
我不太确定这个服务器的最小配置需求,然而,在 ubuntu 上安装运行 Oracle 并没有被 Oracle 官方提供的支持。尽管你可能很惊讶,我使用的机器是512M内存的x86 奔腾系列的机器。(什么乱七八糟的。。)
第二步
(下载 Oracle 安装文件)
下载 Oracle 11g for Linux (x86, 32-bit)。
在刻录从网上下载回来的镜像文件之前,对它做一下哈西值验证是一个好主意(特别是ubuntu的安装镜像iso)。你可以在一个 Unix-like 主机上使用 md4sum filename, sha1sum filename, 或者 cksum filename 命令做这个验证。这些页面中列出了正确的哈西值:

(维基百科上有关于这些哈西功能的描述页面:MD5cksum。)
第三步
(设置Xserver,这一步有一个较简单的替代方案。请看文后的附录)
在这个 HOWTO 中,我们需要一个 X server,于是要在你的桌面电脑上,允许来自你的数据库服务器 X 连接到你的桌面。如果正好你的桌面电脑上也是使用 Ubuntu ,依次打开 系统->系统管理->登录窗口,选择“安全”标签页,然后取消选择“拒绝通过TCP连接Xserver”。你必须重新启动X服务器(使用 Ctrl+Alt+BackSpace)以便使刚才的更改生效。
我的桌面电脑系统是Ubuntu(我称之为”note”),所以我有一个X服务器并且已经处于运行中。如果你是在要安装数据库的电脑上运行的X服务器(使用了桌面版,并直接操作,而不是通过ssh),你可以跳过这一个步骤。把 192.168.x.y 改成你的oracle服务器(即将安装的)d的IP地址:
bott@note:~$ hostname
note
user@note:~$ xhost +192.168.x.y
192.168.x.y being added to access control list

第四步
通过ssh登录你的数据库服务器(即将安装的,以后就这样称呼),并更新所有软件包:
(中文用户请注意,我们还有先选择一个好用的源。参考 http://wiki.ubuntu.org.cn/Qref/ )

bott@note:~$ ssh user@192.168.x.y
user@192.168.x.y's password:
Linux hardy 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/
Last login: Thu May 1 21:45:05 2008 from 192.168.w.z
user@hardy:~$

确保你的网络连接正常(连接到国际互联网),升级所有的包到最新的版本,下面是我在Thursday, May 4th 2008的输出:
user@hardy:~$ hostname
hardy
user@hardy:~$ sudo su -
[sudo] password for pythian:
root@hardy:~# apt-get update
Hit http://security.ubuntu.com hardy-security Release.gpg
Ign http://security.ubuntu.com hardy-security/main Translation-en_US
Hit http://us.archive.ubuntu.com hardy Release.gpg
Ign http://us.archive.ubuntu.com hardy/main Translation-en_US
(...)
Fetched 7455kB in 2min36s (47.6kB/s)
Reading package lists... Done
root@hardy:~# apt-get dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
libldap-2.4-2 lshw
2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 498kB of archives.
After this operation, 0B of additional disk space will be used.
Do you want to continue [Y/n]?
Get:1 http://us.archive.ubuntu.com hardy-updates/main libldap-2.4-2 2.4.7-6ubuntu4.1 [181kB]
Get:2 http://us.archive.ubuntu.com hardy-updates/main lshw 02.12.01-2ubuntu1.1 [317kB]
Fetched 498kB in 2s (211kB/s)
(Reading database ... 18768 files and directories currently installed.)
Preparing to replace libldap-2.4-2 2.4.7-6ubuntu3 (using .../libldap-2.4-2_2.4.7-6ubuntu4.1_i386.deb) ...
Unpacking replacement libldap-2.4-2 ...
Preparing to replace lshw 02.12.01-2ubuntu1 (using .../lshw_02.12.01-2ubuntu1.1_i386.deb) ...
Unpacking replacement lshw ...
Setting up libldap-2.4-2 (2.4.7-6ubuntu4.1) ...
Setting up lshw (02.12.01-2ubuntu1.1) ...
Processing triggers for libc6 ...
ldconfig deferred processing now taking place
root@hardy:~#

可能你会奇怪,我们为什么要用sudo su – 代替 sudo -s (就像上一个版本的 HOWTO 中使用的那样): sudo su – 有效的开启一个空白的(干净的)root会话,然而 sudo -s 创建一个root权限的会话,但是保留了很多前一个会话的会话变量。我选择这样的方式就是试图使下面的整个过程更加的顺利而且不出现意外的小状况。
如果 ap-get dist-upgrade 安装了新版本的内核,那么重新启动电脑以使用最新的内核再进行以下的步骤会是一个好主意。
root@hardy:~# reboot

Broadcast message from user@hardy
(/dev/pts/0) at 0:04 ...

The system is going down for reboot NOW!
root@hardy:~# Connection to 192.168.x.y closed by remote host.
Connection to 192.168.x.y closed.
bott@note:~$

第五步
等电脑重新启动之后,再次登录进去安装一些Oracle安装需要的额外的包:build-essential, libaio1, gawk, ksh, libmotif3, alien, libtool, and lsb-rpm。请注意我们的内核已经被升级到了最新的版本:
bott@note:~$ ssh user@192.168.x.y
user@192.168.x.y's password:
Linux hardy 2.6.24-16-server #1 SMP Thu Apr 10 13:58:00 UTC 2008 i686

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/
Last login: Thu May 1 21:45:05 2008 from 192.168.w.z

user@hardy:~$ sudo su -
[sudo] password for pythian:
root@hardy:~# apt-get install build-essential libaio1 gawk ksh libmotif3 alien libtool lsb-rpm
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
autotools-dev binutils debhelper dpkg-dev g++ g++-4.2 gcc gcc-4.2 gettext html2text intltool-debian libbeecrypt6 libc6-dev libgomp1 libice6 libneon27
librpm4.4 libsm6 libstdc++6-4.2-dev libtimedate-perl libx11-6 libx11-data libxau6 libxcb-xlib0 libxcb1 libxdmcp6 libxext6 libxml2 libxmu6 libxp6 libxt6
linux-libc-dev make patch po-debconf rpm x11-common
Suggested packages:
lintian binutils-doc dh-make debian-keyring g++-multilib g++-4.2-multilib gcc-4.2-doc libstdc++6-4.2-dbg autoconf automake1.9 bison flex gcc-doc
gcc-multilib gdb manpages-dev gcc-4.2-locales gcc-4.2-multilib libgcc1-dbg libgomp1-dbg libmudflap0-4.2-dbg libmudflap0-4.2-dev cvs gettext-doc glibc-doc
libstdc++6-4.2-doc automaken gcj gfortran fortran95-compiler libtool-doc make-doc diff-doc
Recommended packages:
libltdl3-dev xml-core libmail-sendmail-perl libcompress-zlib-perl libmail-box-perl
The following NEW packages will be installed:
alien autotools-dev binutils build-essential debhelper dpkg-dev g++ g++-4.2 gawk gcc gcc-4.2 gettext html2text intltool-debian ksh libaio1 libbeecrypt6
libc6-dev libgomp1 libice6 libmotif3 libneon27 librpm4.4 libsm6 libstdc++6-4.2-dev libtimedate-perl libtool libx11-6 libx11-data libxau6 libxcb-xlib0
libxcb1 libxdmcp6 libxext6 libxml2 libxmu6 libxp6 libxt6 linux-libc-dev lsb-rpm make patch po-debconf rpm x11-common
0 upgraded, 45 newly installed, 0 to remove and 0 not upgraded.
Need to get 22.9MB of archives.
After this operation, 80.5MB of additional disk space will be used.
Do you want to continue [Y/n]?
(... again: downloads a bunch of packages ...)
(... again: installs a bunch of packages ...)
Processing triggers for libc6 ...
ldconfig deferred processing now taking place

root@hardy:~#

第六步
当以上所有的包都安装完成之后,我们要在系统上做一些调整。首先,要把sh从dash替换为bash。不要忘记这个步骤,否则我们可能会在安装过程中遇到各种各样的奇奇怪怪的错误:
root@hardy:~# cd /bin
root@hardy:/bin# ls -l /bin/sh
lrwxrwxrwx 1 root root 4 2008-04-28 19:59 /bin/sh -> dash
root@hardy:/bin# ln -sf bash /bin/sh
root@hardy:/bin# ls -l /bin/sh
lrwxrwxrwx 1 root root 4 2008-05-01 22:51 /bin/sh -> bash

如果你对于为什么Ubuntu使用dash作为默认shell感到好奇的话,这里有一个详细的解释:为什么使用dash作为默认系统shell程序,以及它和bash之间的不同。
第七步
接下来,我们对基本系统做一些改动(行号是后加的,为了显示清楚):
01 root@hardy:/bin# cd
02 root@hardy:~# pwd
/root
04 root@hardy:~# addgroup oinstall

Adding group `oinstall' (GID 1001) ...
Done.
07 root@hardy:~# addgroup dba
Adding group `dba' (GID 1002) ...
Done.
10 root@hardy:~# addgroup nobody
Adding group `nobody' (GID 1003) ...
Done.
13 root@hardy:~# usermod -g nobody nobody
14 root@hardy:~# useradd -g oinstall -G dba -p password -d /home/oracle -s /bin/bash oracle
15 root@hardy:~# passwd -l oracle
Password changed.
17 root@hardy:~# mkdir /home/oracle
18 root@hardy:~# chown -R oracle:dba /home/oracle
19 root@hardy:~# ln -s /usr/bin/awk /bin/awk
20 root@hardy:~# ln -s /usr/bin/rpm /bin/rpm
21 root@hardy:~# ln -s /usr/bin/basename /bin/basename
22 root@hardy:~# mkdir /etc/rc.d
23 root@hardy:~# for i in 0 1 2 3 4 5 6 S ; do ln -s /etc/rc$i.d /etc/rc.d/rc$i.d ; done
24 root@hardy:~# mkdir -p /u01/app/oracle
25 root@hardy:~# chown -R oracle:dba /u01
26 root@hardy:~#

  • 第 01-03 行:切换当前目录到 /root (root用户的家目录,这一步并非必须的)
  • 第 04-12 行:添加需要的组。
  • 第 13 行:修改 Ubuntu 的 nobody 用户,避免 Oracle 的安装程序产生疑惑。
  • 第 14-18 行:我们创建 oracle 用户,锁定这个用户,使没人能够用它登录系统,并且为这个用户创建一个家目录(和 ORACLE_HOME 是不同的)
  • 第 19-23 行:我们创建一些符号链接,在 Oracle 的安装程序试图查找的地方。
  • 最后,在第 24-25 行,我们创建了 ORACLE_BASE 目录。

第八步
我们还需要修改一些默认的系统设定,添加以下的代码到 /etc/sysctl.conf 文件的最后。这样可以扩展一个系统上的文件描述符总数,扩大共享内存的大小,并且对网络子系统的相关参数做相关的修改。(后面这句不懂: About the networking tweaks: it may bring benefits or it may not — your mileage may vary.)

fs.file-max = 65535
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 1024 65535
net.core.rmem_default = 1048576
net.core.rmem_max = 1048576
net.core.wmem_default = 262144
net.core.wmem_max = 262144

添加以下代码到 /etc/security/limits.conf 文件的最后:

oracle soft nproc 2047
oracle hard nproc 16383
oracle soft nofile 1023
oracle hard nofile 65535

添加以下代码到 /etc/pam.d/login 文件的最后,来强制在 /etc/security/limits.conf 所作更改的生效:

session required /lib/security/pam_limits.so
session required pam_limits.so

第一个版本的 HOWTO 那里有关于所有这些更改的解释:Installing Oracle 11g on Ubuntu Linux 7.04
在继续安装之前,你有两个选择:重启电脑使对 sysctl.conf 的更改生效,或者让系统重新载入 sysctl.conf 使用这样的命令: sysctl -p(我推荐使用后者。。):

root@hardy:~# sysctl -p
kernel.printk = 4 4 1 7
kernel.maps_protect = 1
fs.inotify.max_user_watches = 524288
vm.mmap_min_addr = 65536
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
fs.file-max = 65535
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 1024 65535
net.core.rmem_default = 1048576
net.core.rmem_max = 1048576
net.core.wmem_default = 262144
net.core.wmem_max = 262144
root@hardy:~#

第九步
在这个 HOWTO 中,我已经把第二步下载的 ZIP 文件解压在了 /home/oracle 下,所以我们, su 为 oracle 用户, export DISPLAY 变量(把 192.168.w.z 改为你自己 X 服务器的IP)2,然后开始安装。当执行 su – oracle 时,Ubuntu会提醒,这个帐号已经过期——这是没关系的,不用管它。当启动安装程序时,请注意我们添加的 -ignoreSysPrereqs 命令行开关。
(如果你的locale是中文的,可能出现乱码--中文为方块,请看这里

root@hardy:~# su - oracle
Your account has expired; please contact your system administrator
su: User account has expired
(Ignored)
oracle@hardy:~$ export DISPLAY=192.168.w.z:0.0
oracle@hardy:~$ pwd
/home/oracle
oracle@hardy:~$ ls -l
total 4
drwxr-xr-x 6 oracle dba 4096 2007-09-18 18:50 database
oracle@hardy:~$ cd database
oracle@hardy:~/database$ ls -l
total 28
drwxr-xr-x 11 oracle dba 4096 2007-08-06 16:02 doc
drwxr-xr-x 5 oracle dba 4096 2007-08-03 13:28 install
drwxr-xr-x 2 oracle dba 4096 2007-09-18 18:52 response
-rwxr-xr-x 1 oracle dba 2911 2007-08-03 13:28 runInstaller
drwxr-xr-x 14 oracle dba 4096 2007-08-03 13:27 stage
-rw-r--r-- 1 oracle dba 4835 2007-08-06 18:19 welcome.html
oracle@hardy:~/database$ ./runInstaller -ignoreSysPrereqs

片刻之后,Oracle 通用安装程序(OUI)会显示这样一个窗口(不用关心它在你的ssh窗口中显示那些乱七八糟的文字信息,除非它没有给你弹出这个窗口:D):
oracleOUIwindow1
点击Next之后,它将问你Oracle Inventory应该存放在哪里。我把组改成了dba,你完全可以保留默认组,如果你不想改的话
oracleOUIwindow2
点击Next, OUI 将会回顾都有什么产品包含在这个安装包里面:

在这个安装向导中(HOWTO),我将选择安装企业版(Enterprise Edition),你可以选择你需要的版本。

它会询问你安装的路径:

我选择默认选项,点击Next:

下一步——检查一些先决条件,有一些可能会失败:意料之中的情况——毕竟我们在官方不支持的系统平台上安装。哈哈
oracleOUIwindow7
你要做的只是,选中那些没有选中的复选框(就是那些没有检查通过的项目),当你点击的时候,它会自动改变为“用户验证”状态。

点击Next之后,它会询问是否创建一个数据库。我选择仅安装软件,新的数据库可以在晚些时候使用dbca创建。

我把所有的组都改为了dba:

在开始安装之前,它会向你显示一个摘要。点击Install之后,去泡一杯茶,休息一下,这个安装将会花上好一会儿功夫。

当安装进行到90%左右的时候,(linking stage) 会看起来像是卡死一样,但是它没有卡住:让它继续运行吧,再去喝点茶。

当安装程序显示这样的界面时,它要求你以root权限运行两个脚本:

这是我的输出:
root@hardy:~# /u01/app/oraInventory/orainstRoot.sh
Changing permissions of /u01/app/oraInventory to 770.
Changing groupname of /u01/app/oraInventory to dba.
The execution of the script is complete
root@hardy:~# /u01/app/oracle/product/11.1.0/db_1/root.sh
Running Oracle 11g root.sh script...

The following environment variables are set as:
ORACLE_OWNER= oracle
ORACLE_HOME= /u01/app/oracle/product/11.1.0/db_1

Enter the full pathname of the local bin directory: [/usr/local/bin]:
Copying dbhome to /usr/local/bin ...
Copying oraenv to /usr/local/bin ...
Copying coraenv to /usr/local/bin ...

Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root.sh script.
Now product-specific root actions will be performed.
Finished product-specific root actions.
root@hardy:~#

开香槟时间到!你成功完成了在 Ubuntu 8.04 LTS (Hardy Heron) 上安装 Oracle 11g 的整个过程。

然而我们的工作还没有完成:为了是你的生活更加轻松,还有几个操作需要完成。首先,添加这些行进入 /etc/profile:
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export PATH=$PATH:/u01/app/oracle/product/11.1.0/db_1/bin

还有,一个启动脚本是很有用的,不是吗?创建文件 /etc/init.d/oracledb 并把以下内容写进去:
#!/bin/bash
#
# /etc/init.d/oracledb
#
# Run-level Startup script for the Oracle Listener and Instances
# It relies on the information on /etc/oratab

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
export ORACLE_OWNR=oracle
export PATH=$PATH:$ORACLE_HOME/bin

if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi

case "$1" in
start)
# Oracle listener and instance startup
echo -n "Starting Oracle: "
su $ORACLE_OWNR -c "$ORACLE_HOME/bin/lsnrctl start"
su $ORACLE_OWNR -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
touch /var/lock/oracle
echo "OK"
;;
stop)
# Oracle listener and instance shutdown
echo -n "Shutdown Oracle: "
su $ORACLE_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"
su $ORACLE_OWNR -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME"
rm -f /var/lock/oracle
echo "OK"
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo "Usage: `basename $0` start|stop|restart|reload"
exit 1
esac

exit 0

保存之后,给它赋予执行的权限:
root@hardy:~# chmod a+x /etc/init.d/oracledb
如果你想让oracle在系统启动时自动启动,执行如下命令:

root@hardy:~# update-rc.d oracledb defaults 99
Adding system startup for /etc/init.d/oracledb ...
/etc/rc0.d/K99oracledb -> ../init.d/oracledb
/etc/rc1.d/K99oracledb -> ../init.d/oracledb
/etc/rc6.d/K99oracledb -> ../init.d/oracledb
/etc/rc2.d/S99oracledb -> ../init.d/oracledb
/etc/rc3.d/S99oracledb -> ../init.d/oracledb
/etc/rc4.d/S99oracledb -> ../init.d/oracledb
/etc/rc5.d/S99oracledb -> ../init.d/oracledb

注意:这个脚本依赖于这台机器上的数据库的存在,所以不要忘记使用 Oracle 用户运行 dbca 创建一个数据库,并将它配置为引导时启动(创建数据库之后,编辑/etc/oratab,将最后的一个值改为Y)。
使工作简单化,将你的用户加入到dba组,这样你的用户将能够以dba角色和oracle数据库交互。下列例子命令中,以user作为用户名:
root@hardy:~# usermod -G dba -a user
使用 dbca 创建数据库时,别忘了是使用 oracle 用户(还要定义DISPLAY环境变量)。创建之后,你应该试试你能不能正常连接它:
oracle@hardy:~$ export ORACLE_SID=heron
oracle@hardy:~$ sqlplus '/as sysdba'

SQL*Plus: Release 11.1.0.6.0 - Production on Mon May 5 02:39:27 2008

Copyright (c) 1982, 2007, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL>

当你看到这样的输出后,你就终于可以说一声:“安装彻底完成了!”。当然,最后我邀请您对我这篇想到的想法和感受。
[Augusto Bott 文]

附录

  1. 我反正没有花那么常的时间,可能作者的机器太蜗牛?:)
  2. 比设置DISPLAY变量和运行xhost命令更简单的方式是:
    ssh -X oracle@oraclehost
    这样的连接方式,不管是不是在本机上安装,都可以使用。不是么?
    我就是这样的:
    ssh -X oracle@localhost
    这样,ssh会自动创建DISPLAY环境变量的。
  3. LANG=en ./runInstaller -ignoreSysPrereqs 会比较好!

2 Responses to “在 Ubuntu 8.04 LTS (Hardy Heron) 上安装 Oracle 11g[翻译]”

  1. yaoms:

    我花了一天时间实践并翻译的

  2. 33bbb:

    恩 好东西 学习

Leave a Reply



Spam Protection by WP-SpamFree