创建Oracle数据库
1. 以root用户的身份登录:
2. 检查硬件需求:
grep MemTotal /proc/meminfo(检查物理内存的大小,至少为1024M);
grep SwapTotal /proc/meminfo(检查交换分区的大小,至少为1.5G);
df –k /tmp(检查磁盘空间在/tmp分区的大小,至少为400M)
df –k (检查系统硬盘的空余空间)
下表显示不同安装类型所需的磁盘空间:
| Installation Type | Requirement for Software Files (GB) |
| Enterprise Edition | 1.5 |
| Standard Edition | 1.5 |
| Custom (maximum) | 1.5 |
grep "model name" /proc/cpuinfo(确定是否系统架构可以运行该软件)
补充:假如swap分区不够,我们需要扩展,需要使用下列命令:
fdisk –l
fdisk /dev/sda
partprobe
mkswap /dev/sda5
swapon /dev/sda5
grep SwapTotal /proc/meminfo(查看swap分区的大小)
假如家目录(因为逻辑卷挂载在home分区上,所以我们只需要扩展逻辑卷即可)的空间过小,我们也需要进行扩展:
umount /home
lvextend –L 10G /dev/vol0/home
e2fsck -f /dev/vol0/home
resize2fs /dev/vol0/home
mount /dev/vol0/home /home
df –h(查看目前磁盘空间和使用情况 以更易读的方式显示)
3.检查软件的需求:
操作系统必须是下列中的一种:
Red Hat Enterprise Linux AS/ES 3.0 (Update 4 or later)
Red Hat Linux 4.0(下面的实验我们就以4.0版本为例)
SUSE Linux Enterprise Server 9.0 with SP 2 or later
Asianux 1.0
Asianux 2.0
测试命令:cat /etc/issue
因为我们使用的是5.4的版本,所以系统检测时可能通不过,我们的将5.4改成4.4,系统检测完毕后再改过来。
内核版本:
Red Hat Enterprise Linux 3.0 and Asianux 1.0 : 2.4.21-27.E(默认版本)
Red Hat Enterprise Linux 4.0 and Asianux 2.0 : 2.6.9-5.EL(我们应该和相应的操作系统相对应,我们用的就是Red Hat Enterprise Linux 4.0版本的操作系统)
SUSE Linux Enterprise Server 9.0 :2.6.5-7.201
测试命令:uname -r
软件包:(下面我们只列出了Red Hat Enterprise Linux 4.0版本的包)
Red Hat Enterprise Linux 4.0 and Asianux 2.0:
binutils-2.15.92.0.2-13.EL4
compat-db-4.1.25-9
compat-libstdc++-296-2.96-132.7.2
control-center-2.8.0-12
gcc-3.4.3-22.1.EL4
gcc-c++-3.4.3-22.1.EL44
glibc-2.3.4-2.9
glibc-common-2.3.4-2.9
gnome-libs-1.4.1.2.90-44.1
libstdc++-3.4.3-22.1
libstdc++-devel-3.4.3-22.1
make-3.80-5
pdksh-5.2.14-30
sysstat-5.0.5-1
xscreensaver-4.18-5.rhel4.2
setarch-1.6-1
为了防止以后出错,最好也将下列的包安装了:
libXp,libXp-devel
Java Develoment(组包,yum groupinstall “Java Development”)
测试命令:rpm -q package_name
4.检查网络配置
Vim /etc/sysconfig/network
HOSTNAME=oracle.example.com
Vim /etc/hosts
192.168.0.117 oracle.example.com oracle
(这里的地址是你主机的静态地址)
注意:这里只是为了方便,我们可以用动态地址,并用DNS对主机名进行解析
5.创建系统组和用户
系统组:
OSDBA组 (如果你是首次创建的话,必须添加该组,它确定的操作系统用户帐户具有数据库(SYSDBA的权限)的管理权限。此组的默认名称是数据库管理员,此组的默认名为dba)
OSOPER组 (可选组,如果你想要一个独立的操作系统的用户群有一个有限的数据库(即SYSOPER权限)的管理权限,就需要添加。默认情况下,在OSDBA组的成员也有SYSOPER权限 注意:此种方式必须选用自定义安装Oracle通用安装程序提示你指定这个组的名称。通常为这一群体选择的组是oper)
the Oracle Inventory 组(当你在系统上首次安装Oracle软件时,Oracle通用安装程序创建oraInst.loc文件,该文件确定了Oracle库存组的名称和Oracle清单目录的路径。)
如果该文件存在自行命令:more /etc/oraInst.loc
显示结果为:
inventory_loc=/u01/app/oracle/oraInventory
inst_group=oinstall
inst_group参数显示了the Oracle Inventory group的名称
系统用户(the Oracle Software Owner User)
如果系统首次安装Oracle软件,则必须创建该用户,该用户拥有安装过程中所需的所有软件,并且该用户必须使the Oracle Inventory group作为其主组,让OSDBA和OSOPER作为其附加组。
groupad dba
groupadd dba
groupadd oper
useradd –g oinstall –G dba,oper oracle
passwd oracle(为oracle用户添加密码)
id oracle
id nobody(安装软件前必须确定该用户是否存在,若该用户不存在,则需创建)
6.配置内核参数
参数标准:
| Parameter | Value | |
| semmsl | 250 32000 100 128 | |
| shmall | 2097152 | |
| shmmax | Half the size of physical memory (in bytes) | |
| shmmni | 4096 | |
| file-max | 65536 | |
| ip_local_port_range | Minimum:1024 Maximum: 65000 | |
| rmem_default | 1048576 | |
| rmem_max | 1048576 | |
| wmem_default | 262144 | |
| wmem_max | 262144 |
使用命令查看这些参数:
| Parameter | Command |
| semmsl, semmns, semopm, and semmni | # /sbin/sysctl -a | grep sem This command displays the value of the semaphore parameters in the order listed. |
| shmall, shmmax, and shmmni | # /sbin/sysctl -a | grep shm This command displays the details of the shared memory segment sizes. |
| file-max | # /sbin/sysctl -a | grep file-max This command displays the maximum number of file handles. |
| ip_local_port_range | # /sbin/sysctl -a | grep ip_local_port_range This command displays a range of port numbers. |
| rmem_default | # /sbin/sysctl -a | grep rmem_default |
| rmem_max | # /sbin/sysctl -a | grep rmem_max |
| wmem_default | # /sbin/sysctl -a | grep wmem_default |
| wmem_max | # /sbin/sysctl -a | grep wmem_max |
vim /etc/sysctl.conf
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 1048576
net.core.rmem_max = 1048576
net.core.wmem_default = 262144
net.core.wmem_max = 262144
7.为Oracle用户设置内核限制
上线为:
| Shell Limit | Item in limits.conf | Hard Limit |
| Maximum number of open file descriptors | 65536 | |
| Maximum number of processes available to a single user | 16384 |
vim /etc/security/limits.conf
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
vim /etc/pam.d/login
session required /lib/security/pam_limits.so
session required pam_limits.so
以下根据用户的shell来限制:
vim /etc/profile
o if [ $USER = "oracle" ]; then
o if [ $SHELL = "/bin/ksh" ]; then
o ulimit -p 16384
o ulimit -n 65536
o else
o ulimit -u 16384 -n 65536
o fi
o fi
vim /etc/csh.login(如果用户的Shell为csh或者tcsh)
o if ( $USER == "oracle" ) then
o limit maxproc 16384
o limit descriptors 65536
o endif
8.创建oracle的基本目录,并进行挂载
类似结构:/mount_point/app/oracle_sw_owner(软件所属主)
| Requirement | Free Disk Space |
| Up to 3 GB | |
| The Oracle base directory will contain both software and database files (not recommended for production databases). | Up to 4 GB |
mkdir /u01(在这里,我们仅储存软件包文件,至于数据库文件我们将它放到oracle用户的家目录中)
fdisk –l
fdisk /dev/sda
partprobe
mkfs.ext3 /dev/sda6
vim /etc/fstab
【 /dev/sda6 /u01 ext3 defaults 0 0 】
mount –a
ls /u01 【若发现有lost+found,就说明挂载成功】
mkdir –pv /u01/app/oracle【递归创建oracle的基本目录,并显示过程】
chown –R oracle:oinstall /u01/app/oracle【修改oracle根目录的属主和属组】
chmod –R 755 /u01/app/oracle 【修改oracle根目录的权限】9.定义根目录和SID
su – oracle
vim .bash_profile
【PATH=$PATH:$HOME/bin:/u01/app/oracle/product/10.2.0/db_1/bin
umask 022
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
ORACLE_SID=orcl
export ORACLE_BASE ORACLE_SID ORACLE_HOME】
. .bash_profile
echo $ORACLE_BASE
注意:oracle用户必须重新登录才能生效
10.安装并创建数据库
在root用户下,先将光盘中的oracle数据库软件拷到根目录下,然后再执行: unzip 10201_database_linux32.zip
mv database/* /home/oracle
su – oracle(切换到oracle用户下)
du –sh ./database/ 【查看文件的大,因为文件正在传送】
cd database(当数据库从根目录都拷到oracle用户的家目录下时,再进入该目录)
ls
进行系统检测:
./runInstaller(请以KDE视窗模式下进入.否则无法执行runInstaller)
如果出现以下问题:
[oracle@oracle ~]$ ./runInstaller
Starting Oracle Universal Installer...
Checking installer requirements...
Checking operating system version: must be redhat-3, SuSE-9, redhat-4, UnitedLinux-1.0, asianux-1 or asianux-2
Passed
All installer requirements met.
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2009-06-07_12-13-22PM. Please wait ...[oracle@localhost database]$ Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using 'localhost:0.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(Unknown Source)
at java.awt.Window.init(Unknown Source)
at java.awt.Window.<init>(Unknown Source)
at java.awt.Frame.<init>(Unknown Source)
at oracle.ewt.popup.PopupFrame.<init>(Unknown Source)
at oracle.ewt.lwAWT.BufferedFrame.<init>(Unknown Source)
at oracle.sysman.oio.oioc.OiocOneClickInstaller.<init>(OiocOneClickInstaller.java:378)
at oracle.sysman.oio.oioc.OiocOneClickInstaller.main(OiocOneClickInstaller.java:2091)
解决办法:需要切换到root用户执行xhost +
如果还不成功,则在切换到oracle用户,并执行export DISPLAY=0.0
出现以下图形界面,我们选择高级安装模式:
根据提示,此时我们需要切换到两个目录下,分别执行程序:
cd /u01/app/oracle/oraInventory/
./orainstRoot.sh
cd /u01/app/oracle/product/10.2.0/db_1
./root.sh
然后点击ok即可,随即出现安装完成界面,点击退出即可。
在IE中输入http://192.168.0.117:1158/em,(注意:此处的192.168.0.117是你的安装oracle的机子的ip地址)即可出现以下登录界面:
以上会出现是否同意的信息,使管点击I aggress即可。
到此为止,安装已经全部结束,数据库也创建了。(有人可能会在安装数据库的时候没有创建数据库,这时就可以用dbca创建,注意:dbca是创建数据库帮手,可以帮你创建数据库)
如果上图中出现Java的错误提示信息,则需要编辑/u01/app/oracle/product/10.2.0/db_1/sysman/config,在此文件中加入
agentTZRegin=Asia/Shanghai
11.下面是对数据库的管理:
[oracle@oracle ~]$ emctl stop dbconsole(用于停止监听器)
TZ set to PRC
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation. All rights reserved.
http://oracle.example.com:1158/em/console/aboutApplication
Stopping Oracle Enterprise Manager 10g Database Control ...
... Stopped.
[oracle@oracle ~]$
[oracle@oracle ~]$ emctl start dbconsole(用于开启监听器)
TZ set to PRC
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation. All rights reserved.
http://oracle.example.com:1158/em/console/aboutApplication
Starting Oracle Enterprise Manager 10g Database Control ............... started.
------------------------------------------------------------------
Logs are generated in directory /u01/app/oracle/product/10.2.0/db_1/oracle.example.com_orcl/sysman/log
[oracle@oracle ~]$
如果监听程序没有开启,执行以下命令可以开启:
[oracle@oracle ~]$ lsnrctl start
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 21-MAR-2010 22:45:57
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Starting /u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 10.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle.example.com)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 21-MAR-2010 22:45:57
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle.example.com)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@oracle ~]$
文件/u01/app/oracle/product/10.2.0/db_1/install/portlist.ini中定义了监听的端口:
iSQL*Plus HTTP port number =5560
Enterprise Manager Console HTTP Port (orcl) = 1158
Enterprise Manager Agent Port (orcl) = 3938
查看监听端口:
[oracle@oracle install]$ netstat -tunlp|grep 1158
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:1158 0.0.0.0:* LISTEN 8934/java
[oracle@oracle install]$
[oracle@oracle ~]$ sqlplus / as sysdba(以sysdba的身份登录数据库)
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Mar 21 22:56:50 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> select * from v$instance;
INSTANCE_NUMBER INSTANCE_NAME
--------------- ----------------
HOST_NAME
----------------------------------------------------------------
VERSION STARTUP_T STATUS PAR THREAD# ARCHIVE LOG_SWITCH_WAIT
----------------- --------- ------------ --- ---------- ------- ---------------
LOGINS SHU DATABASE_STATUS INSTANCE_ROLE ACTIVE_ST BLO
---------- --- ----------------- ------------------ --------- ---
1 orcl
oracle.example.com
10.2.0.1.0 21-MAR-10 OPEN NO 1 STOPPED
ALLOWED NO ACTIVE PRIMARY_INSTANCE NORMAL NO
SQL> select INSTANCE_NAME from v$instance; (查看当前运行的实例)
INSTANCE_NAME
----------------
orcl
[oracle@oracle database]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Mar 22 08:01:33 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area 356515840 bytes
Fixed Size 1219400 bytes
Variable Size 113247416 bytes
Database Buffers 239075328 bytes
Redo Buffers 2973696 bytes
SQL> alter database mount;
Database altered.
SQL> alter database open;
Database altered.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
1706

被折叠的 条评论
为什么被折叠?



