天高地厚

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

在ubuntu 下安装Oracle 11g

Posted on 2012-12-18 11:55  天高地厚-GNU  阅读(320)  评论(0编辑  收藏  举报
$ sudo su -
# apt-get install build-essential libaio1 gawk ksh libmotif3 alien libtool lsb-rpm

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

# echo "Red Hat Linux release 4" > /etc/redhat-release

root@hardy:/bin# cd
root@hardy:~# pwd
   /root
root@hardy:~# addgroup oinstall
   Adding group `oinstall' (GID 1001) ...
   Done.
root@hardy:~# addgroup dba
   Adding group `dba' (GID 1002) ...
   Done.
root@hardy:~# addgroup nobody
   Adding group `nobody' (GID 1003) ...
   Done.
root@hardy:~# usermod -g nobody nobody
root@hardy:~# useradd -g oinstall -G dba -p password -d /home/oracle -s /bin/bash oracle
root@hardy:~# passwd -l oracle
   Password changed.
root@hardy:~# mkdir /home/oracle
root@hardy:~# chown -R oracle:dba /home/oracle
root@hardy:~# ln -s /usr/bin/awk /bin/awk
root@hardy:~# ln -s /usr/bin/rpm /bin/rpm
root@hardy:~# ln -s /usr/bin/basename /bin/basename
root@hardy:~# mkdir /etc/rc.d
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
root@hardy:~# mkdir -p /u01/app/oracle
root@hardy:~# chown -R oracle:dba /u01
root@hardy:~#

修改etc/sysctl.conf文件,在末尾增加:

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文件末尾:
session required /lib/security/pam_limits.so
session required pam_limits.so
# sysctl -p

现在将oracle11g的安装包解压到/home/oracle/install/目录下。然后进入目录,设置DISPLAY参数(不设置Oracle装不上,可以一试),开始安装:
root@hardy:~# cd /home/oracle
root@hardy:/home/oracle# chown -R oracle:dba install
root@hardy:/home/oracle# su - oracle
Your account has expired; please contact your system administrator
su: User account has expired
(Ignored)
oracle@hardy:~$ export DISPLAY=127.0.0.1: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 install
oracle@hardy:~$ cd install
oracle@hardy:~/install$ ls -l

oracle@hardy:~$./runInstaller -ignoreSysPrereqs -jreLoc /usr/lib/jvm/java-6-sun/jre

在安装第二个界面,将用户组选择为dba,选择"Enterprise Edition",将检查到的所有非“Succeeded”的都打上勾,在创建完数据库后,先不点击OK.
进行如下操作:
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:~#

然后,在/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

创建一个Oracle 11g数据库的启动脚本,名字可以叫做:oracledb,在/u01/app/oracle/product/11.1.0/db_1/bin下建立文件: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 /u01/app/oracle/product/11.1.0/db_1/bin/oracledb

如果你希望开机自动启动Oracle 11g数据库,那么就作下面的工作:


root@hardy:~# ln -s /u01/app/oracle/product/11.1.0/db_1/bin/oracledb /etc/init.d/oracledb
root@hardy:~# sudo sysv-rc-conf --level 2345 oracledb on

如果没有sysv-rc-conf命令,就apt-get一个。

最后,增加你自己的用户名到dba组:


root@hardy:~# usermod -G dba -a user(注意user为你当前使用的用户,每个人的都不一定相同。)

好了,至此,Oracle 11g就安装完了。重新登录后,你就可以使用oracle的命令了。
你可以通过netca增加LISTENER,通过dbca增加数据库。测试一下是否安装成功:
(ORACLE_SID=heron 是你安装时候设置的值)


oracle@hardy:~$ export ORACLE_SID=orcl
oracle@hardy:~$ sqlplus '/as sysdba'

--startup nomount
startup open
--shutdown immediate

sql> select count(*) from dba_users;