写点什么

静默安装 Oracle 也没那么恐怖

发布于: 2021 年 02 月 01 日
静默安装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.x6411gR2database_1of2.zip

linux.x6411gR2database_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++-33elfutils-libelf-develelfutils-libelf-devel-staticgccgcc-c++libaio-devellibstdc++-develkshnumactl-develunixODBCunixODBC-devel
复制代码

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


创建组和用户

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

修改内核参数

# vi /etc/sysctl.conf
kernel.sem = 250 32000 100 128fs.file-max = 6815744net.ipv4.ip_local_port_range = 9000 65500net.core.rmem_default = 262144net.core.rmem_max = 4194304net.core.wmem_default = 262144net.core.wmem_max = 1048586fs.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-nrkernel.sem = 250        32000   100     128fs.file-max = 6815744net.ipv4.ip_local_port_range = 9000     65500net.core.rmem_default = 262144net.core.rmem_max = 4194304net.core.wmem_default = 262144net.core.wmem_max = 1048586fs.aio-max-nr = 1048576
复制代码

用户限制设置

# vi /etc/security/limits.conf
oracle soft nofile 1024oracle hard nofile 65536oracle soft nproc 2047oracle hard nproc 16384
vi /etc/pam.d/login
session required /lib64/security/pam_limits.sosession 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 fifi
复制代码

关闭 SELinux 及防火墙

查看SELinux状态:sestatus
永久关闭SELinux,需重启:# vi /etc/sysconfig/selinux
#SELINUX=enforcingSELINUX=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_profileORACLE_BASE=/u01/app/oracle; export ORACLE_BASEexport ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1ORACLE_SID=oral; export ORACLE_SIDexport ORACLE_OWNER=oracleexport PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/local/bin:/usr/sbin:/usr/binexport TNS_ADMIN=$ORACLE_HOME/network/adminexport LD_LIBRARY_PATH=$ORACLE_HOME/lib:$ORACLE_HOME/oracm/lib:/lib:/usr/lib:/usr/local/libexport NLS_LANG=AMERICAN_AMERICA.ZHS16GBKexport CLASSPATH=${CLASSPATH}:$ORACLE_HOME/JREexport CLASSPATH=${CLASSPATH}:$ORACLE_HOME/JRE/libexport CLASSPATH=${CLASSPATH}:$ORACLE_HOME/jlibexport CLASSPATH=${CLASSPATH}:$ORACLE_HOME/rdbms/jlibexport CLASSPATH=${CLASSPATH}:$ORACLE_HOME/network/jlibexport LIBPATH=${CLASSPATH}:$ORACLE_HOME/lib:$ORACLE_HOME/ctx/libexport SPFILE_PATH=$ORACLE_HOME/dbsexport ORA_NLS10=$ORACLE_HOME/nls/dataumask 022
复制代码

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

[oracle@ORATEST ~]$ env | more[oracle@ORATEST ~]$ umask
复制代码

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

# vi /etc/oraInst.loc

inventory_loc=/u01/app/oracle/oraInventoryinst_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]# lltotal 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]$ lltotal 2295604drwxr-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.rsp29c29< 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=AL32UTF8200c200< 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]$ lltotal 2295640drwxr-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.zipdrwxr-xr-x. 2 oracle oinstall       4096 Jan 22 14:56 oracledrwxr-xr-x. 2 oracle oinstall       4096 Jan 22 15:12 oradatadrwxr-xr-x. 2 oracle oinstall       4096 Jan 22 15:12 oradatabackup[oracle@ORATEST app]$ env | grep ORAORACLE_OWNER=oracleORA_NLS10=/u01/app/oracle/product/11.2.0/db_1/nls/dataORACLE_SID=oralORACLE_BASE=/u01/app/oracleORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
复制代码

执行安装命令

[oracle@ORATEST database]$ ./runInstaller -silent -force -noconfig -ignorePrereq -responseFile /u01/app/db_install.rspStarting Oracle Universal Installer...Checking Temp space: must be greater than 120 MB.   Actual 1628 MB    PassedChecking swap space: must be greater than 150 MB.   Actual 65535 MB    PassedPreparing ...   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.shTo 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.shCheck /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/oradataCHARACTERSET = "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 files1% complete3% complete37% completeCreating and starting Oracle instance40% complete45% complete50% complete55% complete56% complete60% complete62% completeCompleting Database Creation66% complete70% complete73% complete85% complete96% complete100% completeLook 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 bytesFixed Size 2214936 bytesVariable Size 5100274664 bytesDatabase Buffers 3221225472 bytesRedo Buffers 27435008 bytesDatabase mounted.Database opened.SQL>
复制代码

shutdown 和 startup 都成功执行,说明数据库正常启动了。

/u01/app/oradata/ORCL 目录下是刚建立数据库 ORCL 的数据文件

[oracle@ORATEST oradata]$ cd ORCL/[oracle@ORATEST ORCL]$ lltotal 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 aliasAttempting 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 LISTENERVersion TNSLSNR for Linux: Version 11.2.0.1.0 - ProductionStart Date 31-JAN-2021 13:55:20Uptime 0 days 0 hr. 0 min. 0 secTrace Level offSecurity ON: Local OS AuthenticationSNMP OFFListener Log File /u01/app/oracle/diag/tnslsnr/ORATEST/listener/alert/log.xmlListening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ORATEST)(PORT=1521)))The listener supports no servicesThe 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 namedb_name = orclshared_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.0compatible=11.2.0.0.0 #改成11版本
复制代码


错误:ORA-27504: IPC error creating OSD contextORA-27300: OS system dependent operation:unsupp_mtu failed with status: 0ORA-27301: OS failure message: Error 0ORA-27302: failure occurred at: skgxpvaddr10ORA-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 bytesFixed Size                  2214936 bytesVariable Size            4697621480 bytesDatabase Buffers         3623878656 bytesRedo Buffers               27435008 bytesDatabase 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 分区直接重来。


发布于: 2021 年 02 月 01 日阅读数: 37
用户头像

总结 分享 收获 2020.08.17 加入

公众号“MySQL从删库到跑路”作者 最纯粹的技术 最高级的享受

评论

发布
暂无评论
静默安装Oracle也没那么恐怖