静默安装oracle

如果Server段没有安装X界面,如何来安装Oracle呢?我们可以使用Oracle提供的静默安装来实现提示符下的Oracle安装。安装前的系统环境变量及内核参数的设置这里就不重复了,可以查看安装光盘中的安装文档。
假设Oracle安装文件已经解压至/u02 。
su - oracle
mkdir -p /u01/app/oracle/
1. 建立静默安装的配置文件
cd /u02/database/response
vi enterprise01.rsp
RESPONSEFILE_VERSION=2.2.1.0.0
FROM_LOCATION="../stage/products.xml"
ORACLE_HOME="/u01/app/oracle/product/10.2.0/db_1/"
ORACLE_HOME_NAME="OraDb10g_home1"
TOPLEVEL_COMPONENT={"oracle.server","10.2.0.1.0"}
DEINSTALL_LIST={"oracle.server","10.2.0.1.0"}
SHOW_SPLASH_SCREEN=false
SHOW_WELCOME_PAGE=false
SHOW_COMPONENT_LOCATIONS_PAGE=false
SHOW_CUSTOM_TREE_PAGE=false
SHOW_SUMMARY_PAGE=false
SHOW_INSTALL_PROGRESS_PAGE=false
SHOW_REQUIRED_CONFIG_TOOL_PAGE=false
SHOW_CONFIG_TOOL_PAGE=false
SHOW_RELEASE_NOTES=false
SHOW_ROOTSH_CONFIRMATION=false
SHOW_END_SESSION_PAGE=false
SHOW_EXIT_CONFIRMATION=false
NEXT_SESSION=false
NEXT_SESSION_ON_FAIL=false
SHOW_DEINSTALL_CONFIRMATION=false
SHOW_DEINSTALL_PROGRESS=false
ACCEPT_LICENSE_AGREEMENT=true
COMPONENT_LANGUAGES={"en"}
CLUSTER_NODES=
INSTALL_TYPE="EE"
s_nameForDBAGrp=dba
s_nameForOPERGrp=dba
b_oneClick=false
SHOW_DATABASE_CONFIGURATION_PAGE=false
b_createStarterDB=false
相关属性的值的意义,请参考Oracle提供的enterprise.rsp文档中的说明 。
2. 开始安装
cd /u02/database/
./runInstaller -silent -responseFile /u02/database/response/enterprise01.rsp
#注意-responseFile参数后的文件路径一定是绝对路径 ,并且enterprise01.rsp oracle用户可读。
执行过程如下:
Installation in progress (Mon May 12 20:27:18 CST 2008)
...............................................................  11% Done.
...............................................................  23% Done.
...............................................................  35% Done.
...............................................................  47% Done.
...........................................                      55% Done.
Install successful

Linking in progress (Mon May 12 20:30:01 CST 2008)
.                                                                55% Done.
Link successful

Setup in progress (Mon May 12 20:31:21 CST 2008)
....................                                            100% Done.
Setup successful

End of install phases.(Mon May 12 20:31:29 CST 2008)
Starting to execute configuration assistants
Configuration assistant "Oracle Net Configuration Assistant" succeeded
Configuration assistant "Oracle Database Configuration Assistant" failed
SEVEREOUI-10104:Some of the configuration assistants failed. It is strongly recommended that you retry the configuration assistants at this time. Not successfully running any "Recommended" assistants means your system will not be correctly configured. Select the failed assistants and click the 'Retry' button to retry them.
--------------------------------------
The "/u01/app/oracle/product/10.2.0/db_1/cfgtoollogs/configToolFailedCommands" . contains all commands that failed, were skipped or were cancelled. This file may be used to run these configuration assistants outside of OUI. Note that you may have to update this . with passwords (if any) before executing the same.
The "/u01/app/oracle/product/10.2.0/db_1/cfgtoollogs/configToolAllCommands" . contains all commands to be executed by the configuration assistants. This file may be used to run the configuration assistants outside of OUI. Note that you may have to update this . with passwords (if any) before executing the same.

--------------------------------------
The installation of Oracle Database 10g was successful, but some optional configuration assistants failed, were cancelled or skipped.
Please check '/u01/app/oracle/oraInventory/logs/silentInstall2008-05-12_08-26-55PM.log' for more details.

3. 运行安装所需脚本
vi /u01/app/oracle/oraInventory/logs/silentInstall2008-05-12_08-26-55PM.log
查看日志,提示我们用root用户运行如下两个脚本
/u01/app/oracle/oraInventory/orainstRoot.sh
/u01/app/oracle/product/10.2.0/db_1/root.sh
至此Oracle的产品已经安装完成,可是目前为止我们还没有建立数据库。
由于没有X界面无法启动dbca ,所以不能用dbca来帮我们建立数据库。这时候你可能会想到用create database 语句来建立数据库,可是语法实在是繁琐,并且还要运行许多的
oracle脚本 。
下面我们来利用oracle提供的种子数据库还原一个数据库出来。
假设我们要建立的数据库的名称为orcl 。

4.建立我们所需的目录。
mkdir -p /u01/app/oracle/admin/orcl/{a,b,u}dump
mkdir -p /u01/app/oracle/oradata/orcl
找到oracle为种子数据库提供的控制文件并copy至/u01/app/oracle/oradata/orcl 。
cd /u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates/
cp Seed_Database.ctl /u01/app/oracle/oradata/orcl

5.建立pfile文件
cd /u01/app/oracle/product/10.2.0/db_1/dbs
vi initorcl.ora
*.db_name=SEEDDATA #注:因为Seed_Database.ctl控制文件中记录的db_name为SEEDDATA。
control_files='/u01/app/oracle/oradata/orcl/Seed_Database.ctl'
compatible=10.2.0.1.0

6.启动数据库到mount状态
sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production . Mon May 12 21:48:47 2008
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.
Total System Global Area  117440512 bytes
Fixed Size                  1218004 bytes
Variable Size              58722860 bytes
Database Buffers           50331648 bytes
Redo Buffers                7168000 bytes
Database mounted.
使用默认的参数建立spfile
SQL> create spfile from pfile;
重新启动数据库
SQL> shutdown immediate
SQL> startup mount
更改sga_max_size,sga_target参数的值 。
SQL> alter system set sga_max_size=200M scope=spfile;
SQL> alter system set sga_target=160M scope=spfile;
然后再次重新启动数据库
SQL> shutdown immediate
SQL> startup mount


7.用rman连接数据库
rman target /
Recovery Manager: Release 10.2.0.1.0 - Production . Mon May 12 21:52:01 2008
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
connected to target database: SEEDDATA (DBID=3891038516, not open)
RMAN> list backup;

using target database control file instead of recovery catalog

List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1       Full    89.23M     DISK        00:00:36     30-JUN-05      
       BP Key: 1   Status: AVAILABLE  Compressed: YES  Tag:
       Piece Name: /ade/aime_10.2_lnx_push/oracle/oradata/Seed_Database.dfb
 List of Datafiles in backup set 1
 File LV Type Ckp SCN    Ckp Time  Name
 ---- -- ---- ---------- --------- ----
 1       Full 446074     30-JUN-05 /ade/aime_10.2_lnx_push/oracle/oradata/seeddata/system01.dbf
 2       Full 446074     30-JUN-05 /ade/aime_10.2_lnx_push/oracle/oradata/seeddata/undotbs01.dbf
 3       Full 446074     30-JUN-05 /ade/aime_10.2_lnx_push/oracle/oradata/seeddata/sysaux01.dbf
 4       Full 446074     30-JUN-05 /ade/aime_10.2_lnx_push/oracle/oradata/seeddata/users01.dbf

可以看到,我们可以利用/ade/aime_10.2_lnx_push/oracle/oradata/Seed_Database.dfb这个备份集来还原数据库。
但是很明显我们系统中并没有这样一个文件/ade/aime_10.2_lnx_push/oracle/oradata/Seed_Database.dfb ,但是查找发现路径/u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates下有Seed_Database.dfb文件 。
有两种方法,一个是建立一个软链接/ade/aime_10.2_lnx_push/oracle/oradata/Seed_Database.dfb 指向/u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates/Seed_Database.dfb 。另一个是创建目录/ade/aime_10.2_lnx_push/oracle/oradata/
并将Seed_Database.dfb copy至其下 。

8.还原数据库
run {
set newname for datafile '/ade/aime_10.2_lnx_push/oracle/oradata/seeddata/system01.dbf' to '/u01/app/oracle/oradata/orcl/system01.dbf';
set newname for datafile '/ade/aime_10.2_lnx_push/oracle/oradata/seeddata/sysaux01.dbf' to '/u01/app/oracle/oradata/orcl/sysaux01.dbf';
set newname for datafile '/ade/aime_10.2_lnx_push/oracle/oradata/seeddata/undotbs01.dbf' to '/u01/app/oracle/oradata/orcl/undotbs01.dbf';
set newname for datafile '/ade/aime_10.2_lnx_push/oracle/oradata/seeddata/users01.dbf' to '/u01/app/oracle/oradata/orcl/users01.dbf';
restore database;
switch datafile all;
}

cd /u01/app/oracle/oradata/orcl
[oracle@man /u01/app/oracle/oradata/orcl]$ ls
Seed_Database.ctl  sysaux01.dbf  system01.dbf  undotbs01.dbf  users01.dbf
可以看到我们所需要的数据文件都还原回来了,但是现在还缺少log file 。
我们现在打开数据库。
因为控制文件中记录的log file路径为 /ade/aime_10.2_lnx_push/oracle/oradata/seeddata 所以要先创建相应的目录。
SQL> alter database open resetlogs;
此时,在目录/ade/aime_10.2_lnx_push/oracle/oradata/seeddata 下创建了redo01.log,redo02.log,redo03.log,temp01.dbf文件。
我们要更改这几个文件的路径,所以先将数据库关闭,然后cp /ade/aime_10.2_lnx_push/oracle/oradata/seeddata/× /u01/app/oracle/oradata/orcl/
启动数据库到mount状态,并更改日志和临时文件的路径
SQL> alter database rename file '/ade/aime_10.2_lnx_push/oracle/oradata/seeddata/redo01.log' to '/u01/app/oracle/oradata/orcl/redo01.log';

Database altered.

SQL> alter database rename file '/ade/aime_10.2_lnx_push/oracle/oradata/seeddata/redo02.log' to '/u01/app/oracle/oradata/orcl/redo02.log';

Database altered.

SQL> alter database rename file '/ade/aime_10.2_lnx_push/oracle/oradata/seeddata/redo03.log' to '/u01/app/oracle/oradata/orcl/redo03.log';

Database altered.

SQL> alter database rename file '/ade/aime_10.2_lnx_push/oracle/oradata/seeddata/temp01.dbf' to '/u01/app/oracle/oradata/orcl/temp01.dbf';

Database altered.

SQL> alter database open;

到此数据库已经建立,并且数据文件也放到了我们期待的地方。但是还有一个问题,就是数据库名称不是我们事先期待的。
SQL> show parameter name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      SEEDDATA
db_unique_name                       string      SEEDDATA
global_names                         boolean     FALSE
instance_name                        string      orcl
lock_name_space                      string
log_file_name_convert                string
service_names                        string      SEEDDATA
下面我们将数据库名称SEEDDATA改成我们需要的orcl 。注意此时仅仅更改参数文件的值是不行的,因为控制文件中同样也记录着数据库的名称。

9.更改数据库名称
备份控制文件脚本
SQL> alter database backup controlfile to trace as '/tmp/ctl.txt';
SQL> create pfile from spfile;
将spfile删除,编辑pfile将db_name="SEEDDATA" 改成 db_name="orcl" 。

vi /tmp/ctl.txt 将其中如下一段
CREATE CONTROLFILE REUSE DATABASE "SEEDDATA" NORESETLOGS  NOARCHIVELOG
   MAXLOGFILES 16
   MAXLOGMEMBERS 3
   MAXDATAFILES 100
   MAXINSTANCES 8
   MAXLOGHISTORY 292
LOGFILE
 GROUP 1 '/u01/app/oracle/oradata/orcl/redo01.log'  SIZE 50M,
 GROUP 2 '/u01/app/oracle/oradata/orcl/redo02.log'  SIZE 50M,
 GROUP 3 '/u01/app/oracle/oradata/orcl/redo03.log'  SIZE 50M
-- STANDBY LOGFILE

DATAFILE
 '/u01/app/oracle/oradata/orcl/system01.dbf',
 '/u01/app/oracle/oradata/orcl/undotbs01.dbf',
 '/u01/app/oracle/oradata/orcl/sysaux01.dbf',
 '/u01/app/oracle/oradata/orcl/users01.dbf',
 '/u01/app/oracle/oradata/orcl/tt.dbf'
CHARACTER SET US7ASCII
;

修改为
CREATE CONTROLFILE REUSE DATABASE "SEEDDATA" set database "ORCL"  RESETLOGS  NOARCHIVELOG
   MAXLOGFILES 16
   MAXLOGMEMBERS 3
   MAXDATAFILES 100
   MAXINSTANCES 8
   MAXLOGHISTORY 292
LOGFILE
 GROUP 1 '/u01/app/oracle/oradata/orcl/redo01.log'  SIZE 50M,
 GROUP 2 '/u01/app/oracle/oradata/orcl/redo02.log'  SIZE 50M,
 GROUP 3 '/u01/app/oracle/oradata/orcl/redo03.log'  SIZE 50M

DATAFILE
 '/u01/app/oracle/oradata/orcl/system01.dbf',
 '/u01/app/oracle/oradata/orcl/undotbs01.dbf',
 '/u01/app/oracle/oradata/orcl/sysaux01.dbf',
 '/u01/app/oracle/oradata/orcl/users01.dbf',
 '/u01/app/oracle/oradata/orcl/tt.dbf'
CHARACTER SET US7ASCII
;
重新启动数据库到nomount状态 。
运行上面的建立控制文件的脚本,然后打开数据库 。
SQL> alter database open resetlogs;

10.控制文件更名并实现冗余。
修改参数文件initorcl.ora
*.control_files='/u01/app/oracle/oradata/orcl/control01.ctl','/u01/app/oracle/oradata/orcl/control02.ctl'
,'/u01/app/oracle/oradata/orcl/control03.ctl'

cd /u01/app/oracle/oradata/orcl
mv Seed_Database.ctl control01.ctl
cp control01.ctl control02.ctl
cp control01.ctl control03.ctl
重新启动数据库,大功告成!

你可能感兴趣的:(oracle,database,配置文件,product)