手记

静默安装Oracle也没那么恐怖

几种必须静默安装的情况

  • 服务器为了减少资源占用,没安装图形组件
  • 不能进入机房,只能远程SSH
  • 想炫(Z)耀(B),静默安装显得有技术含量

磁盘分区要求

如没有特别要求,装机时可按如下分区比较好管理

/boot   ext3   100M  
Swap    swap   32G   #一般和内存一样大  
/u01    ext3   800G  #Oracle安装目录和数据库数据文件存放目录,大小要大于预估的全部数据量
/opt    ext3   5G  
/tmp    ext3   2G  
/       ext3   剩余空间  

安装步骤大纲

没明确指出操作账号的步骤,请仔细看命令前面是井号还是美元,井号就是用root做的,美元就是用oracle做的。

  1. 装前检查
  2. 创建组和用户
  3. 修改内核参数
  4. 修改用户限制
  5. 关闭SELinux及防火墙
  6. 创建安装目录
  7. 设置环境变量
  8. 执行runInstaller安装Oracle
  9. 执行dbca建立数据库
  10. 配置tnsnames.ora
  11. 执行lsnrctl启动监听,PLSQL连接

安装前检查

两个安装包
linux.x64_11gR2_database_1of2.zip
linux.x64_11gR2_database_2of2.zip
Oracle版本是11.2.0.1.0
Linux版本Red Hat Enterprise Linux Server release 6.6 (Santiago)

物理内存检查:
至少4G,查看物理内存命令:

# grep MemTotal /proc/meminfo

虚拟内存检查:
物理内存4-8G,虚拟内存为2倍物理内存;
物理内存8-32G,虚拟内存为1.5倍物理内存;
物理内存>32G,虚拟内存等于物理内存;

查看虚拟内存命令:

# grep SwapTotal /proc/meminfo

依赖包检查

rpm -q \
binutils \
compat-libstdc++-33 \
elfutils-libelf \
elfutils-libelf-devel \
elfutils-libelf-devel-static \
expat \
gcc \
gcc-c++ \
glibc \
glibc-common \
glibc-devel \
glibc-headers \
libaio \
libaio-devel \
libgcc \
libstdc++ \
libstdc++-devel \
make \
ksh \
sysstat \
numactl-devel \
kernel-headers \
libgomp        \
unixODBC \
unixODBC-devel | grep "not installed"|awk '{print $2;}'

输入下面几个包,说明系统没有

compat-libstdc++-33
elfutils-libelf-devel
elfutils-libelf-devel-static
gcc
gcc-c++
libaio-devel
libstdc++-devel
ksh
numactl-devel
unixODBC
unixODBC-devel

配好yum源,逐个yum install上面的包。

创建组和用户

[root@ORATEST]# groupadd oinstall
[root@ORATEST]# groupadd dba
[root@ORATEST]# useradd -g oinstall -G dba oracle
[root@ORATEST]# passwd oracle
Changing password for user oracle.
New password: 
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:      #此处密码输入oracle,BAD PASSWORD提示不用管
passwd: all authentication tokens updated successfully.

修改内核参数

# vi /etc/sysctl.conf

kernel.sem = 250 32000 100 128
fs.file-max = 6815744
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
fs.aio-max-nr = 1048576

使设置生效

#sysctl -p

检查设置是否成功

[root@ORATEST ~]# sysctl kernel.sem fs.file-max net.ipv4.ip_local_port_range net.core.rmem_default net.core.rmem_max net.core.wmem_default net.core.wmem_max fs.aio-max-nr
kernel.sem = 250        32000   100     128
fs.file-max = 6815744
net.ipv4.ip_local_port_range = 9000     65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
fs.aio-max-nr = 1048576

用户限制设置

# vi /etc/security/limits.conf

oracle    soft    nofile    1024
oracle    hard    nofile    65536
oracle    soft    nproc     2047
oracle    hard    nproc     16384

vi /etc/pam.d/login

session    required    /lib64/security/pam_limits.so
session    required    pam_limits.so

# vi /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

关闭SELinux及防火墙

查看SELinux状态:sestatus

永久关闭SELinux,需重启:
# vi /etc/sysconfig/selinux

#SELINUX=enforcing
SELINUX=disabled

即时关闭SELinux指令:
setenforce 0  或者  setenforce permissive

关闭防火墙:
Linux6及以下:
查看防火墙状态:service iptables status

重启后生效 
关闭: chkconfig iptables off 

即时关闭防火墙指令  
关闭: service iptables stop

创建安装目录

[root@ORATEST ~]# mkdir -p /u01/app/
[root@ORATEST ~]# chown -R oracle:oinstall /u01/app/
[root@ORATEST ~]# chmod -R 775 /u01/app/

配置环境变量

[root@ORATEST ~]# su - oracle
[oracle@ORATEST ~]$ vi /home/oracle/.bash_profile vi /home/oracle/.bash_profile
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
ORACLE_SID=oral; export ORACLE_SID
export ORACLE_OWNER=oracle
export PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/local/bin:/usr/sbin:/usr/bin
export TNS_ADMIN=$ORACLE_HOME/network/admin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/oracm/lib:/lib:/usr/lib:/usr/local/lib
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/JRE
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/JRE/lib
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/jlib
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/rdbms/jlib
export CLASSPATH=${CLASSPATH}:$ORACLE_HOME/network/jlib
export LIBPATH=${CLASSPATH}:$ORACLE_HOME/lib:$ORACLE_HOME/ctx/lib
export SPFILE_PATH=$ORACLE_HOME/dbs
export ORA_NLS10=$ORACLE_HOME/nls/data
umask 022

新开个会话,以Oracle账号登陆,检查环境是否生效

[oracle@ORATEST ~]$ env | more
[oracle@ORATEST ~]$ umask

以root账号,新建oraInst.loc,执行

# vi /etc/oraInst.loc


inventory_loc=/u01/app/oracle/oraInventory
inst_group=oinstall

[root@ORATEST ~]# chown oracle:oinstall /etc/oraInst.loc
[root@ORATEST ~]# chmod 664 /etc/oraInst.loc

执行runInstaller安装Oracle

修改host文件

[root@ORATEST ~]# vi /etc/hosts
...
127.0.0.1   ORATEST   #最后加上这行

将两个安装包上传到/u01/app,确保安装包属于oracle用户

[root@ORATEST app]# chown -R oracle:oinstall *.zip
[root@ORATEST app]# ll
total 2295600
-rw-r--r--. 1 oracle oinstall 1239269270 Jan 22 14:29 linux.x64_11gR2_database_1of2.zip
-rw-r--r--. 1 oracle oinstall 1111416131 Jan 22 14:29 linux.x64_11gR2_database_2of2.zip

如果已经属于oracle用户,上面步骤不用做。
在oracle账号下,按顺序解压

[oracle@ORATEST app]$unzip linux.x64_11gR2_database_1of2.zip  
[oracle@ORATEST app]$unzip linux.x64_11gR2_database_2of2.zip  

解压后文件都在database目录里

[oracle@ORATEST app]$ ll
total 2295604
drwxr-xr-x. 8 oracle oinstall       4096 Aug 21  2009 database
-rw-r--r--. 1 oracle oinstall 1239269270 Jan 22 14:29 linux.x64_11gR2_database_1of2.zip
-rw-r--r--. 1 oracle oinstall 1111416131 Jan 22 14:29 linux.x64_11gR2_database_2of2.zip

拷贝安装配置模板文件到当前目录(/u01/app)下

[oracle@ORATEST app]$ cp database/response/db_install.rsp  .

创建三个目录,oracle是安装目录,oradata是数据文件目录,oradatabackup,是数据文件备份目录

[oracle@ORATEST app]$ mkdir oracle   
[oracle@ORATEST app]$ mkdir oradata
[oracle@ORATEST app]$ mkdir oradatabackup

编辑db_install.rsp,编辑后和原始文件差异如下,

[oracle@ORATEST app]$ diff db_install.rsp database/response/db_install.rsp
29c29
< oracle.install.option=INSTALL_DB_AND_CONFIG
---
> oracle.install.option=
37c37
< ORACLE_HOSTNAME=localhost
---
> ORACLE_HOSTNAME=
42c42
< UNIX_GROUP_NAME=oinstall
---
> UNIX_GROUP_NAME=
47c47
< INVENTORY_LOCATION=/u01/app
---
> INVENTORY_LOCATION=
78c78
< SELECTED_LANGUAGES=en,zh_CN
---
> SELECTED_LANGUAGES=
83c83
< ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
---
> ORACLE_HOME=
88c88
< ORACLE_BASE=/u01/app/oracle
---
> ORACLE_BASE=
99c99
< oracle.install.db.InstallEdition=EE
---
> oracle.install.db.InstallEdition=
142c142
< oracle.install.db.DBA_GROUP=dba
---
> oracle.install.db.DBA_GROUP=
147c147
< oracle.install.db.OPER_GROUP=dba
---
> oracle.install.db.OPER_GROUP=
160c160
< oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
---
> oracle.install.db.config.starterdb.type=
165c165
< oracle.install.db.config.starterdb.globalDBName=orcl
---
> oracle.install.db.config.starterdb.globalDBName=
170c170
< oracle.install.db.config.starterdb.SID=orcl
---
> oracle.install.db.config.starterdb.SID=
184c184
< oracle.install.db.config.starterdb.characterSet=ZHS16GBK
---
> oracle.install.db.config.starterdb.characterSet=AL32UTF8
200c200
< oracle.install.db.config.starterdb.memoryLimit=1024
---
> oracle.install.db.config.starterdb.memoryLimit=
233c233
< oracle.install.db.config.starterdb.password.ALL=oracle
---
> oracle.install.db.config.starterdb.password.ALL=
278,279c278
< oracle.install.db.config.starterdb.dbcontrol.emailAddress=test@qq.com
< 
---
> oracle.install.db.config.starterdb.dbcontrol.emailAddress=
325c324
< oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE
---
> oracle.install.db.config.starterdb.storageType=
333c332
< oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/u01/app/oradata
---
> oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=
340c339
< oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/u01/app/oradatabackup
---
> oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=
386c385
< DECLINE_SECURITY_UPDATES=true
---
> DECLINE_SECURITY_UPDATES=

这些配置项也可以在安装命令参数里写,本文选择编辑db_install.rsp达到效果。
安装前文件和环境如下

[oracle@ORATEST app]$ ll
total 2295640
drwxr-xr-x. 8 oracle oinstall       4096 Aug 21  2009 database
-rw-r--r--. 1 oracle oinstall      22770 Jan 22 15:15 db_install.rsp
-rw-r--r--. 1 oracle oinstall 1239269270 Jan 22 14:29 linux.x64_11gR2_database_1of2.zip
-rw-r--r--. 1 oracle oinstall 1111416131 Jan 22 14:29 linux.x64_11gR2_database_2of2.zip
drwxr-xr-x. 2 oracle oinstall       4096 Jan 22 14:56 oracle
drwxr-xr-x. 2 oracle oinstall       4096 Jan 22 15:12 oradata
drwxr-xr-x. 2 oracle oinstall       4096 Jan 22 15:12 oradatabackup
[oracle@ORATEST app]$ env | grep ORA
ORACLE_OWNER=oracle
ORA_NLS10=/u01/app/oracle/product/11.2.0/db_1/nls/data
ORACLE_SID=oral
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

执行安装命令

[oracle@ORATEST database]$ ./runInstaller -silent -force -noconfig -ignorePrereq -responseFile /u01/app/db_install.rsp
Starting Oracle Universal Installer...
Checking Temp space: must be greater than 120 MB.   Actual 1628 MB    Passed
Checking swap space: must be greater than 150 MB.   Actual 65535 MB    Passed
Preparing ...
   CAUSE: ...
   ACTION: ....
[WARNING] [INS-30011] ...
The following configuration scripts need to be executed as the "root" user. 
 #!/bin/sh 
 #Root scripts to run
/u01/app/oracle/product/11.2.0/db_1/root.sh
To execute the configuration scripts:
         1. Open a terminal window 
         2. Log in as "root" 
         3. Run the scripts 
         4. Return to this window and hit "Enter" key to continue 
Configuration assistants have not been run. This can happen for following reasons - either root.sh is to be run before config or Oracle Universal Installer was invoked with the -noConfig option.
"/u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/configToolAllCommands" script 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 script with passwords (if any) before executing the same.
Successfully Setup Software.

输出Successfully Setup Software表示安装成功。同时提示以root账号执行/u01/app/oracle/product/11.2.0/db_1/root.sh脚本。

[root@ORATEST ~]# /u01/app/oracle/product/11.2.0/db_1/root.sh
Check /u01/app/oracle/product/11.2.0/db_1/install/root_ORATEST_2021-01-25_08-19-46.log for the output of root script

执行完Oracle软件安装完成。

建立数据库

oracle账号执行,拷贝建立数据库的配置文件dbca.rsp到app目录下

[oracle@ORATEST app]$ cp /u01/app/oracle/product/11.2.0/db_1/assistants/dbca/dbca.rsp .

编辑dbca.rsp,编写完各项目如下

[oracle@ORATEST app]$ cat dbca.rsp | grep -v ^# | grep -v ^$
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "ORCL"
SID = "orcl"
TEMPLATENAME = "General_Purpose.dbc"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
DATAFILEDESTINATION =/u01/app/oradata
CHARACTERSET = "ZHS16GBK"
TOTALMEMORY = "8000"
[createTemplateFromDB]
SOURCEDB = "myhost:1521:orcl"
SYSDBAUSERNAME = "system"
TEMPLATENAME = "My Copy TEMPLATE"
[createCloneTemplate]
SOURCEDB = "orcl"
TEMPLATENAME = "My Clone TEMPLATE"
[DELETEDATABASE]
SOURCEDB = "orcl"
[generateScripts]
TEMPLATENAME = "New Database"
GDBNAME = "orcl11.us.oracle.com"
[CONFIGUREDATABASE]
[ADDINSTANCE]
DB_UNIQUE_NAME = "orcl11g.us.oracle.com"
NODELIST=
SYSDBAUSERNAME = "sys"
[DELETEINSTANCE]
DB_UNIQUE_NAME = "orcl11g.us.oracle.com"
INSTANCENAME = "orcl11g"
SYSDBAUSERNAME = "sys"

同样这个文件的内容也可以在执行dbca命令时以参数形式输入,本文选择编辑dbca.rsp的方式。
app目录下执行命令建立数据库

[oracle@ORATEST app]$ dbca -silent -responseFile ./dbca.rsp 
Copying database files
1% complete
3% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
50% complete
55% complete
56% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
85% complete
96% complete
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/ORCL/ORCL.log" for further details.

此时数据库已经启动,可以访问了。下面指令测试是否成功

[oracle@ORATEST ~]$ sqlplus / as sysdba
...
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup;
ORACLE instance started.

Total System Global Area 8351150080 bytes
Fixed Size                  2214936 bytes
Variable Size            5100274664 bytes
Database Buffers         3221225472 bytes
Redo Buffers               27435008 bytes
Database mounted.
Database opened.
SQL> 

shutdown和startup都成功执行,说明数据库正常启动了。
/u01/app/oradata/ORCL目录下是刚建立数据库ORCL的数据文件

[oracle@ORATEST oradata]$ cd ORCL/
[oracle@ORATEST ORCL]$ ll
total 1433964
-rw-r----- 1 oracle oinstall   9748480 Jan 25 15:42 control01.ctl
-rw-r----- 1 oracle oinstall  52429312 Jan 25 15:23 redo01.log
-rw-r----- 1 oracle oinstall  52429312 Jan 25 15:41 redo02.log
-rw-r----- 1 oracle oinstall  52429312 Jan 25 15:23 redo03.log
-rw-r----- 1 oracle oinstall 513810432 Jan 25 15:38 sysaux01.dbf
-rw-r----- 1 oracle oinstall 702554112 Jan 25 15:36 system01.dbf
-rw-r----- 1 oracle oinstall  30416896 Jan 25 11:41 temp01.dbf
-rw-r----- 1 oracle oinstall  78651392 Jan 25 15:36 undotbs01.dbf
-rw-r----- 1 oracle oinstall   5251072 Jan 25 15:23 users01.dbf

配置tnsnames.ora

network/admin下新建ora文件

[oracle@ORATEST ~]$ vi /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora

webdb =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.6.2)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

远程客户端的tnsnames.ora写上相同的配置。如果远程在PC上,ora文件放在TNS_ADMIN环境变量对应的目录下。

执行lsnrctl启动监听,PLSQL连接

监听的配置文件不用编写,采用默认配置。检查webdb能否解析

[oracle@ORATEST ~]$ tnsping webdb
...
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.6.2)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl)))
TNS-12541: TNS:no listener

可以解析出地址和端口号,否则会报Failed to resolve name。no listerer提示监听程序没有启动,启动监听

[oracle@ORATEST ~]$ lsnrctl start
...
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ORATEST)(PORT=1521)))

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                31-JAN-2021 13:55:20
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Log File         /u01/app/oracle/diag/tnslsnr/ORATEST/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ORATEST)(PORT=1521)))
The listener supports no services
The command completed successfully

启动成功。
PLSQL连接,用户system,密码oracle,数据库下拉选择webdb,可以成功登陆。

如果一切顺利,到此大功告成。如果遇到一些报错请往下看。

一些报错的解决方法

错误:
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/db_1/dbs/initoral.ora'
解决:
[oracle@ORATEST dbs]$ cp /u01/app/oracle/product/11.2.0/db_1/srvm/admin/init.ora ./initoral.ora
错误:
ORA-00371: not enough shared pool memory, should be atleast 307023052 bytes
解决
[oracle@ORATEST dbs]$ vi initoral.ora
# replace "clustdb" with your database name
db_name = orcl
shared_pool_size =  307023052  #按提示大小改
错误:
ORA-00401: the value for parameter compatible is not supported by this release
解决:
[oracle@ORATEST dbs]$ vi initoral.ora
#compatible=9.2.0.0.0
compatible=11.2.0.0.0 #改成11版本
错误:
ORA-27504: IPC error creating OSD context
ORA-27300: OS system dependent operation:unsupp_mtu failed with status: 0
ORA-27301: OS failure message: Error 0
ORA-27302: failure occurred at: skgxpvaddr10
ORA-27303: additional information: requested interface 127.0.0.1 mtu not supported. Check output from ifconfig command
解决:
cd $ORACLE_HOME/rdbms/lib/
[oracle@ORATEST lib]$ make -f ins_rdbms.mk rac_off ioracle
错误:
ORA-00439: feature not enabled: Real Application Clusters  
解决:
cd $ORACLE_HOME/rdbms/lib/  
[oracle@ORATEST lib]$ make -f ins_rdbms.mk rac_on ioracle  
错误:  
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance   
ORA-00205: error in identifying control file, check alert log for more info  
解决:  
[root@ORATEST ~]# find / -name init.ora*  
/u01/app/oracle/admin/ORCL/pfile/init.ora.025202192615
[oracle@ORATEST dbs]$ sqlplus / as sysdba
...
SQL> startup pfile='/u01/app/oracle/admin/ORCL/pfile/init.ora.025202192615'
ORACLE instance started.
;
Total System Global Area 8351150080 bytes
Fixed Size                  2214936 bytes
Variable Size            4697621480 bytes
Database Buffers         3623878656 bytes
Redo Buffers               27435008 bytes
Database mounted.
Database opened.
SQL>   create spfile from pfile='/u01/app/oracle/admin/ORCL/pfile/init.ora.025202192615';
File created.

整库导入

如果新安装的库要导入老库的数据,
在老库服务器以oracle用户执行

exp system/oracle@orcl file=./exp.dmp full=y

新库建立完后,什么都不需要做,上传exp.dmp后,直接执行

[oracle@ORATEST app]$ imp system/oracle full=y file=./exp.dmp  #这里没写实例名@orcl 因为只有一个orcl实例可以省略

就可以成功导入老库所有数据和用户。
新老数据库的字符集相同即可,其它环节字符集不同也可以成功。

总结

终于搞定了传说中安装成功率只有50%的Oracle,还是静默安装,爽。
如果失败了,建议格式化u01分区直接重来。

0人推荐
随时随地看视频
慕课网APP