Centos6.0 Oracle11gR2 静默命令行安装[转]
? if [ $SHELL = "/bin/ksh" ]; then
?? ulimit -p 16384
?? ulimit -n 65536
? else
?? ulimit -u 16384 -n 65536
? fi
?fi
7 创建安装目录和设置文件权限
?#mkdir /opt/oracle
?#mkdir /opt/oracle/11.2.0? //数据库系统安装目录
?#mkdir /opt/oradata??? //数据库数据安装目录
?#mkdir /opt/oradata_back? //数据备份目录
?#mkdir /home/oracle/inventory //清单目录
?#chown -R oracle:oinstall /opt/oracle
?#chown -R oracle:oinstall /home/oracle/inventory
?#chomod -R 775 /opt/oracle
8 编辑静默安装响应文件
?#su - oracle
?$cp -R /opt/database/response /home/oracle? //复制一份模板
?$cd /home/oracle
?$mv db_install.rsp db_install_swonly.rsp //因为下面的安装是只安装软件不安装启动数据库实例,所以改个名字以提示自己
?$vim db_install_swonly.rsp???? //开始修改这个安装响应文件
?
?需要设置的选项如下:
?oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0? //系统生成的,不要修改
?oracle.install.option=INSTALL_DB_SWONLY?????????????? //只安装软件,不安装启动数据库
?ORACLE_HOSTNAME=oracle11gcentos6.dlxg.gov.cn???????????? //通过hostname命令获得
?UNIX_GROUP_NAME=oinstall
?INVENTORY_LOCATION=/home/oracle/inventory
?SELECTED_LANGUAGES=en,zh_CN
?ORACLE_HOME=/opt/oracle/11.2.0
?ORACLE_BASE=/opt/oracle
?oracle.install.db.InstallEdition=EE
?oracle.install.db.isCustomInstall=false
?
?oracle.install.db.customComponents=oracle.server:11.2.0.1.0,???????? //保持系统默认值
? oracle.sysman.ccr:10.2.7.0.0,oracle.xdk:11.2.0.1.0,oracle.rdbms.oci:11.2.0.1.0,
? oracle.network:11.2.0.1.0,oracle.network.listener:11.2.0.1.0,oracle.rdbms:11.2.0.1.0,
? oracle.options:11.2.0.1.0,oracle.rdbms.partitioning:11.2.0.1.0,
? oracle.oraolap:11.2.0.1.0,oracle.rdbms.dm:11.2.0.1.0,
? oracle.rdbms.dv:11.2.0.1.0,orcle.rdbms.lbac:11.2.0.1.0,
? oracle.rdbms.rat:11.2.0.1.0
?
?oracle.install.db.DBA_GROUP=dba
?oracle.install.db.OPER_GROUP=dba
?DECLINE_SECURITY_UPDATES=true???????????????? //一定要设置为true
9 根据响应文件安装oracle
?$cd /opt/database
?$./runInstaller -silent -responseFile /home/oracle/response/db_install_swonly.rsp
?安装过程中,如果提示[WARNING]不必理会,此时安装程序仍在进行,如果出现[FATAL],则安装程序已经停止了。打开另一个终端,执行
?#tail -100f /home/oracle/inventory/logs/installActions......log
?可以实时跟踪查看安装日志,了解安装的进度。
?当出现
? 以下配置脚本需要以 "root" 用户的身份执行。
?? #!/bin/sh
?? #要运行的 Root 脚本
? /home/oracle/inventory/orainstRoot.sh
? /opt/oracle/11.2.0/root.sh
? 要执行配置脚本, 请执行以下操作:
???? 1. 打开一个终端窗口
???? 2. 以 "root" 身份登录
???? 3. 运行脚本
???? 4. 返回此窗口并按 "Enter" 键继续
? Successfully Setup Software.
?表示安装成功了。按照其提示操作。
?$exit? //退回到root
?#/home/oracle/inventory/orainstRoot.sh
?#/opt/oracle/11.2.0/root.sh
?
?
10 编辑静默建库响应文件
?$cd /home/oracle
?$mv dbca.rsp dbca_hello.rsp?? //改名为dbca_数据库名.rsp
?
11 静默配置监听
?$netca /silent /responsefile /home/oracle/response/netca.rsp
?正在对命令行参数进行语法分析:
?参数"silent" = true
?参数"responsefile" = /home/oracle/response/netca.rsp
?完成对命令行参数进行语法分析。
?Oracle Net Services 配置:
?完成概要文件配置。
?Oracle Net 监听程序启动:
? 正在运行监听程序控制:
??? /opt/oracle/11.2.0/bin/lsnrctl start LISTENER
? 监听程序控制完成。
? 监听程序已成功启动。
?监听程序配置完成。
?成功完成 Oracle Net Services 配置。退出代码是0
?成功运行后,在/opt/oracle/11.2.0/network/admin目录下生成sqlnet.ora和listener.ora两个文件。
?通过netstat -tlnp 命令,看到
?tcp? 0?? 0 :::1521??????? :::*????? LISTEN????? 5477/tnslsnr
?说明监听器已经在1521端口上开始工作了。
?
12 静默建立新库(同时也建立一个对应的实例)
? 修改/home/oracle/response/dbca.rsp,设置如下:
?RESPONSEFILE_VERSION = "11.2.0"? //不能更改
?OPERATION_TYPE = "createDatabase"
?GDBNAME = "hello.dlxg.gov.cn"? //数据库的名字
?SID = "hello"??? //对应的实例名字
?TEMPLATENAME = "General_Purpose.dbc" //建库用的模板文件
?SYSPASSWORD = "gnotsms"?? //SYS管理员密码
?SYSTEMPASSWORD = "gnotsms"? //SYSTEM管理员密码
?DATAFILEDESTINATION = /opt/oracle/oradata //数据文件存放目录
?RECOVERYAREADESTINATION=/opt/oracle/oradata_back //恢复数据存放目录
?CHARACTERSET = "ZHS16GBK"?? //字符集,重要!!! 建库后一般不能更改,所以建库前要确定清楚。
?TOTALMEMORY = "5120"??? //oracle内存5120MB
?静默建库命令如下
?$dbca -silent -responseFile /home/oracle/response/dbca.rsp
?复制数据库文件
?1% 已完成
?3% 已完成
?11% 已完成
?18% 已完成
?26% 已完成
?37% 已完成
?正在创建并启动 Oracle 实例
?40% 已完成
?45% 已完成
?50% 已完成
?55% 已完成
?56% 已完成
?60% 已完成
?62% 已完成
?正在进行数据库创建
?66% 已完成
?70% 已完成
?73% 已完成
?85% 已完成
?96% 已完成
?100% 已完成
?有关详细信息, 请参阅日志文件 "/opt/oracle/cfgtoollogs/dbca/hello/hello.log"。
?查看日志文件
?$ cat /opt/oracle/cfgtoollogs/dbca/hello/hello.log
?复制数据库文件
?DBCA_PROGRESS : 1%
?DBCA_PROGRESS : 3%
?DBCA_PROGRESS : 11%
?DBCA_PROGRESS : 18%
?DBCA_PROGRESS : 26%
?DBCA_PROGRESS : 37%
?正在创建并启动 Oracle 实例
?DBCA_PROGRESS : 40%
?DBCA_PROGRESS : 45%
?DBCA_PROGRESS : 50%
?DBCA_PROGRESS : 55%
?DBCA_PROGRESS : 56%
?DBCA_PROGRESS : 60%
?DBCA_PROGRESS : 62%
?正在进行数据库创建
?DBCA_PROGRESS : 66%
?DBCA_PROGRESS : 70%
?DBCA_PROGRESS : 73%
?DBCA_PROGRESS : 85%
?DBCA_PROGRESS : 96%
?DBCA_PROGRESS : 100%
?数据库创建完成。有关详细信息, 请查看以下位置的日志文件:
? /opt/oracle/cfgtoollogs/dbca/hello。
?数据库信息:
?全局数据库名:hello.dlxg.gov.cn
?系统标识符 (SID):hello
?建库后实例检查:
?$ ps -ef | grep ora_ | grep -v grep | wc -l
?21
?$ ps -ef | grep ora_ | grep -v grep
?oracle??? 5955???? 1? 0 07:03 ???????? 00:00:00 ora_pmon_hello
?oracle??? 5957???? 1? 0 07:03 ???????? 00:00:00 ora_vktm_hello
?oracle??? 5961???? 1? 0 07:03 ???????? 00:00:00 ora_gen0_hello
?oracle??? 5963???? 1? 0 07:03 ???????? 00:00:00 ora_diag_hello
?oracle??? 5965???? 1? 0 07:03 ???????? 00:00:00 ora_dbrm_hello
?oracle??? 5967???? 1? 0 07:03 ???????? 00:00:00 ora_psp0_hello
?oracle??? 5969???? 1? 0 07:03 ???????? 00:00:00 ora_dia0_hello
?oracle??? 5971???? 1? 0 07:03 ???????? 00:00:00 ora_mman_hello
?oracle??? 5973???? 1? 0 07:03 ???????? 00:00:00 ora_dbw0_hello
?oracle??? 5975???? 1? 0 07:03 ???????? 00:00:00 ora_lgwr_hello
?oracle??? 5977???? 1? 0 07:03 ???????? 00:00:00 ora_ckpt_hello
?oracle??? 5979???? 1? 0 07:03 ???????? 00:00:00 ora_smon_hello
?oracle??? 5981???? 1? 0 07:03 ???????? 00:00:00 ora_reco_hello
?oracle??? 5983???? 1? 0 07:03 ???????? 00:00:00 ora_mmon_hello
?oracle??? 5985???? 1? 0 07:03 ???????? 00:00:00 ora_mmnl_hello
?oracle??? 5987???? 1? 0 07:03 ???????? 00:00:00 ora_d000_hello
?oracle??? 5989???? 1? 0 07:03 ???????? 00:00:00 ora_s000_hello
?oracle??? 5999???? 1? 0 07:03 ???????? 00:00:00 ora_qmnc_hello
?oracle??? 6020???? 1? 0 07:03 ???????? 00:00:00 ora_cjq0_hello
?oracle??? 6022???? 1? 0 07:04 ???????? 00:00:00 ora_q000_hello
?oracle??? 6024???? 1? 0 07:04 ???????? 00:00:00 ora_q001_hello
?查看监听状态
?$ lsnrctl status
?LSNRCTL for?Linux: Version 11.2.0.1.0 - Production on 14-MAR-2012 07:09:03
?Copyright (c) 1991, 2009, Oracle.? All rights reserved.
?Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
?STATUS of the LISTENER
?------------------------
?Alias???????????????????? LISTENER
?Version?????????????????? TNSLSNR for Linux: Version 11.2.0.1.0 - Production
?Start Date??????????????? 14-MAR-2012 06:16:50
?Uptime??????????????????? 0 days 0 hr. 52 min. 15 sec
?Trace Level?????????????? off
?Security????????????????? ON: Local OS Authentication
?SNMP????????????????????? OFF
?Listener Parameter File?? /opt/oracle/11.2.0/network/admin/listener.ora
?Listener Log File???????? /opt/oracle/diag/tnslsnr/oracle11gcentos6/listener/alert/log.xml
?Listening Endpoints Summary...
?? (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
?? (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
?Services Summary...
?Service "hello.dlxg.gov.cn" has 1 instance(s).
?? Instance "hello", status READY, has 1 handler(s) for this service...
?Service "helloXDB.dlxg.gov.cn" has 1 instance(s).
?? Instance "hello", status READY, has 1 handler(s) for this service...
?The command completed successfully
?
13 修改数据库为归档模式(归档模式才能热备份,增量备份)
?$ export ORACLE_SID=hello
?$ sqlplus / as sysdba
?SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 14 07:18:16 2012
?Copyright (c) 1982, 2009,?Oracle.? All rights reserved.
?Connected to:
?Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
?With the Partitioning, OLAP, Data Mining and Real Application Testing options
?SQL> shutdown immediate;
?Database closed.
?Database dismounted.
?ORACLE instance shut down.
?SQL> startup mount
?ORACLE instance started.
?Total System Global Area 1603411968 bytes
?Fixed Size????????????????? 2213776 bytes
?Variable Size???????????? 402655344 bytes
?Database Buffers???????? 1191182336 bytes
?Redo Buffers??????????????? 7360512 bytes
?Database mounted.
?SQL> alter database archivelog;
?Database altered.
?SQL> alter database flashback on;
?Database altered.
?SQL> alter database open;
?Database altered.
?SQL> execute utl_recomp.recomp_serial();
?PL/SQL procedure successfully completed.
?SQL> alter system archive log current;
?System altered.
?SQL> exit
?Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
?With the Partitioning, OLAP, Data Mining and Real Application Testing options
?
14 修改oracle启动配置文件
?$vim /etc/oratab
?hello:/opt/oracle/11.2.0:Y
?这样就可以通过dbstart 启动此实例,也可以通过dbshut关闭此实例了。
?$ dbshut /opt/oracle/11.2.0/
?Processing Database instance "hello": log file /opt/oracle/11.2.0/shutdown.log
?此时所有oracle的进程关闭,监听器也停止。
?$dbstart /opt/oracle/11.2.0/
?Processing Database instance "hello": log file /opt/oracle/11.2.0/startup.log
?此时监听器工作,hello实例运行,再次查看监听器状态。
?$ lsnrctl status
?LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 14-MAR-2012 07:35:52
?Copyright (c) 1991, 2009, Oracle.? All rights reserved.
?Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
?STATUS of the LISTENER
?------------------------
?Alias???????????????????? LISTENER
?Version?????????????????? TNSLSNR for Linux: Version 11.2.0.1.0 - Production
?Start Date??????????????? 14-MAR-2012 07:35:38
?Uptime??????????????????? 0 days 0 hr. 0 min. 13 sec
?Trace Level?????????????? off
?Security????????????????? ON: Local OS Authentication
?SNMP????????????????????? OFF
?Listener Parameter File?? /opt/oracle/11.2.0/network/admin/listener.ora
?Listener Log File???????? /opt/oracle/diag/tnslsnr/oracle11gcentos6/listener/alert/log.xml
?Listening Endpoints Summary...
?? (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
?? (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
?Services Summary...
?Service "hello.dlxg.gov.cn" has 1 instance(s).
?? Instance "hello", status READY, has 1 handler(s) for this service...
?Service "helloXDB.dlxg.gov.cn" has 1 instance(s).
?? Instance "hello", status READY, has 1 handler(s) for this service...
?The command completed successfully
?
15 建立表空间及用户
?$export ORACLE_SID=hello; sqlplus / as sysdba
?进入SQL>后
?创建临时表空间
?create temporary tablespace user_temp tempfile '/opt/oracle/oradata/hello/user_temp.dbf' size 50m
?autoextend on
?next 50m maxsize 20480m
?extent management local;
?创建数据表空间
?create tablespace user_data?
?logging?
?datafile '/opt/oracle/oradata/hello/user_data.dbf'
?size 50m?
?autoextend on?
?next 50m maxsize 20480m?
?extent management local;
?创建用户并指定表空间
?create user test identified by test
?default tablespace user_data?
?temporary tablespace user_temp;
?给用户授予权限
?grant connect,resource to test;
?
?此时在其他机器上可以远程登录这个用户,命令为:
?$sqlplus test/test@172.16.2.182/hello.dlxg.gov.cn
16 用新建的用户连接数据库,并建立一个表
?$ export NLS_LANG=American_America.AL32UTF8
?注意:UTF8是为了使得sqlplus和linux终端环境一致起来,此时发往数据库的是UTF8,数据库存储前会转为ZHS16GBK.
?当读取时,Sqlplus会把收到的ZHS16GBK转换为UTF8发送到Linux终端。
?$ sqlplus test/test@172.16.2.182/hello.dlxg.gov.cn
?SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 14 08:22:11 2012
?Copyright (c) 1982, 2009, Oracle.? All rights reserved.
?Connected to:
?Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
?With the Partitioning, OLAP, Data Mining and Real Application Testing options
?SQL> create table STUDENT(ID int, NAME varchar(20));
?Table created.
?SQL> insert into STUDENT values(1, '张三');
?1 row created.
?SQL> select * from student;
?? ID NAME
?---------- ------------------------
??? 1 张三