2015-04-28 ywt200512... 摘自 csdn博客 阅 358 转 15
转藏到我的图书馆
微信分享:
1 安装前环境:
操作系统:CetnOS6.2x64 最小化安装,已配置好网络IP:172.16.2.182,物理内存8GB,硬盘100GB。
已下载: linux.x64_11gR2_database_1of2.zip linux.x64_11gR2_database_2of2.zip 位于目录/opt/ 2 准备工作 root用户登录后
#yum install vim //个人喜好vim编辑各种配置文件,所以先下一个 #yum install unzip //下载unzip,用来解压上述两个压缩文件 #cd /opt //切换当前目录到oracle压缩文件所在目录 #unzip linux.x64_11gR2_database_1of2.zip //解压 #unzip linux.x64_11gR2_database_2of2.zip
解压后新增一个/opt/database目录,里面是解压后的所有oracle安装文件。
在/etc/hosts文件中增加主机名(通过hostname获得)到回环IP的映射如下: 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 oracle11gcentos6.dlxg.gov.cn
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 oracle11gcentos6.dlxg.gov.cn
#vim /etc/selinux/config 设置 SELINUX=disabled #setenforce 0 //关闭selinux
#service iptables stop //临时关闭防火墙
3 安装必须的包 #yum install gcc #yum install make #yum install binutils #yum install gcc-c++
#yum install compat-libstdc++-33 #yum install elfutils-libelf-devel #yum install elfutils-libelf-devel-static #yum install ksh #yum install libaio #yum install libaio-devel #yum install numactl-devel #yum install sysstat #yum install unixODBC #yum install unixODBC-devel #yum install pcre-devel
4 准备安装用户及用户组 #groupadd oinstall #groupadd dba
#useradd -g oinstall -G dba -d /home/oracle oracle #passwd oracle //设置oracle密码 5 修改内核参数配置文件
#vim /etc/sysctl.conf 在文件最后增加 fs.aio-max-nr = 1048576 fs.file-max = 6553600 kernel.shmall = 2097152 kernel.shmmax = 2147483648 kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 1024 65000 net.core.rmem_default = 262144 net.core.rmem_max = 4194304 net.core.wmem_default = 262144 net.core.wmem_max = 1048586
保存文件。
#/sbin/sysctl -p //让参数生效
6 修改用户的限制文件
#vim /etc/security/limits.conf 在文件后增加 oracle soft nproc 2047 oracle hard nproc 16384 oracle soft nofile 1024 oracle hard nofile 65536 oracle soft stack 10240 保存文件。
修改/etc/pam.d/login文件,增加如下:
session required /lib64/security/pam_limits.so //64位系统时,千万别写成/lib/security/pam_limits.so,否则导致无法登录 session required pam_limits.so 修改/etc/profile,增加: if [ $USER = \"oracle\" ]; then 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/oracle/oradata //数据库数据安装目录 #mkdir /opt/oracle/oradata_back //数据备份目录 #mkdir /home/oracle/inventory //清单目录 #chown -R oracle:oinstall /opt/oracle
#chown -R oracle:oinstall /home/oracle/inventory #chmod -R 775 /opt/oracle
在oracle用户下设置环境变量: 修改/home/oracle/.bashrc文件,增加如下 ORACLE_BASE=/opt/oracle
ORACLE_HOME=/opt/oracle/11.2.0 PATH=$ORACLE_HOME/bin:$PATH NLS_LANG=American_America.AL32UTF8
export ORACLE_BASE ORACLE_HOME PATH ORACLE_SID NLS_LANG
8 编辑静默安装响应文件 #su - oracle
$cp -R /opt/database/response /home/oracle //复制一份模板 $cd /home/oracle/response
$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 -ignorePrereq
安装过程中,如果提示[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/response
$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_hello.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 = \"AL32UTF8\" //字符集,重要!!! 建库后一般不能更改,所以建库前要确定清楚。
TOTALMEMORY = \"5120\" //oracle内存5120MB 静默建库命令如下
$dbca -silent -responseFile /home/oracle/response/dbca_hello.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\ Service \"helloXDB.dlxg.gov.cn\" has 1 instance(s).
Instance \"hello\ 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\ Service \"helloXDB.dlxg.gov.cn\" has 1 instance(s).
Instance \"hello\ The command completed successfully
要想让oracle服务随着系统启动而自动启动,需要在/etc/rc.local文件中增加如下: su - oracle -c \"/opt/oracle/11.2.0/bin/dbstart /opt/oracle/11.2.0\"
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:1521/hello.dlxg.gov.cn 16 用新建的用户连接数据库,并建立一个表
$ export NLS_LANG=American_America.AL32UTF8
注意:UTF8是为了使得sqlplus和linux终端环境一致起来,此时发往数据库的是UTF8,
$ sqlplus test/test@172.16.2.182:1521/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 张三
17.导入数据库
将dmp文件放到data_pump_dir目录 执行导入命令:impdp system/test directory=data_pump_dir dumpfile=test.dmp remap_schema=src:dest full=y;
查询data_pump_dir目录:select * from dba_directories;
18.自动启动
####################################################################################################
## Automating Database Startup and Shutdown on Linux
####################################################################################################
## Once the instance is created, edit the \"/etc/oratab\" file setting the restart flag for each instance to 'Y'. vi /etc/oratab
hello:/opt/oracle/11.2.0:Y
## Next, create a file called \"/etc/init.d/oracle\" as the root user, containing the following.
vi /etc/init.d/oracle
#!-------------------------------------------------------------------------------------------------- #!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script. #
# Set ORA_HOME to be equivalent to the $ORACLE_HOME # from which you wish to execute dbstart and dbshut; #
# Set ORA_OWNER to the user id of the owner of the # Oracle database in ORA_HOME.
ORA_HOME=/opt/oracle/11.2.0 ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ] then
echo \"Oracle startup: cannot start\" exit fi
case \"$1\" in 'start')
# Start the Oracle databases:
# The following command assumes that the oracle login # will not prompt the user for any values
su - $ORA_OWNER -c \"$ORA_HOME/bin/dbstart $ORA_HOME\" touch /var/lock/subsys/oracle ;; 'stop')
# Stop the Oracle databases:
# The following command assumes that the oracle login # will not prompt the user for any values
su - $ORA_OWNER -c \"$ORA_HOME/bin/dbshut $ORA_HOME\" rm -f /var/lock/subsys/oracle ;; esac
#!-------------------------------------------------------------------------------------------------- chmod 750 /etc/init.d/oracle chkconfig --add oracle chkconfig oracle on
19.设置防火墙
编辑 vi /etc/sysconfig/iptables 文件,增加下列记录 -A INPUT -p tcp -m state --state NEW -m tcp --dport 1521 -j ACCEPT
保存新增的规则,以免下次重启机器后,配置规则失效:service iptables save 重启iptables服务:service iptables restart
因篇幅问题不能全部显示,请点此查看更多更全内容