码迷,mamicode.com
首页 > 数据库 > 详细

Linux下静默安装Oracle

时间:2020-04-11 20:32:47      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:desc   大小   app   listener   set   option   服务器   swap   cli   

相比Windows,在Linux安装Oracle的步骤可能略显繁琐,同时Oracle提供了静默安装方法在不适用图形界面的情况下进行安装,我们本次使用静默安装。为了避免以后忘记,因此我将本次安装过程记录,当日后需要的时候,可以再次回顾。

本人环境:CentOS 7.6 64位
安装版本:Oracle 11.2.0

准备安装包

关于 Oracle 11g 的安装包,我们可以直接到官网上下载。

下载链接:https://www.oracle.com/database/technologies/oracle-database-software-downloads.html

技术图片

下载完成之后,我们需要将安装包上传到Linux服务器上,Oracle 11g的安装包比较大,因此我借助了 WinSCP 文件传输软件来完成上传,最终,Linux服务器上得到的安装包如下。

技术图片

接着,将安装包依次解压,命令如下:

unzip linux.x64_11gR2_database_1of2.zip
unzip linux.x64_11gR2_database_2of2.zip

解压完成,会得到一个database的文件夹。

技术图片

安装依赖包

在这里,需要安装一些依赖包,命令如下:

yum -y install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel expat gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make pdksh sysstat unixODBC unixODBC-devel

安装之后,需要检查下依赖包是否安装完整,过滤出未安装完整的依赖,命令如下:

rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel expat gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make pdksh sysstat unixODBC unixODBC-devel | grep "not installed"

如果发现有未安装的,可以通过 yum 安装,或者通过 wget 命令下载rpm包,再手动安装。

[root@VM_0_8_centos database]# rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel expat gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make pdksh sysstat unixODBC unixODBC-devel | grep "not installed"
package pdksh is not installed
[root@VM_0_8_centos database]# 

如上,发现 pdksh 没有安装,通过 yum 安装。

[root@VM_0_8_centos database]# yum -y install pdksh
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
No package pdksh available.
Error: Nothing to do
[root@VM_0_8_centos database]# 

可以看到没有相关安装包可用,那么只能通过 wget 命令直接下载rpm包后手动安装,命令如下:

mkdir /software/temp
wget -O /software/temp/pdksh-5.2.14-37.el5_8.1.x86_64.rpm http://vault.centos.org/5.11/os/x86_64/CentOS/pdksh-5.2.14-37.el5_8.1.x86_64.rpm

下载完成,进入刚创建的临时目录 /software/temp ,通过命令 rpm -ivh 进行手动安装。

[root@VM_0_8_centos software]# cd /software/temp
[root@VM_0_8_centos temp]# ls
pdksh-5.2.14-37.el5_8.1.x86_64.rpm
[root@VM_0_8_centos temp]# rpm -ivh pdksh-5.2.14-37.el5_8.1.x86_64.rpm
warning: pdksh-5.2.14-37.el5_8.1.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID e8562897: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:pdksh-5.2.14-37.el5_8.1          ################################# [100%]
[root@VM_0_8_centos temp]# 

再次检查下依赖包是否完整,确保所需依赖包都已安装。

创建Oracle用户及安装目录

  • 创建和查看用户
# 创建用户
groupadd oinstall
groupadd dba
groupadd asmdba
useradd -g oinstall -G dba,asmdba oracle -d /home/oracle

# 查看用户
id oracle
  • 设置Oracle账户密码
[root@VM_0_8_centos software]# passwd oracle
Changing password for user oracle.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@VM_0_8_centos software]# 
  • 设置安装目录
[root@VM_0_8_centos software]# mkdir -p /software/app/oracle
[root@VM_0_8_centos software]# chown oracle:oinstall /software/app/oracle
[root@VM_0_8_centos software]# chmod -R 775 /software
[root@VM_0_8_centos software]# chown oracle:oinstall -R /software

修改系统文件参数配置

  • 配置hostname

可以将服务器名写入到hosts文件,这样以后就可以通过服务器名来进行连接。

vi /etc/hosts

在文件末加入 127.0.0.1 oracledb localhost localhost.localdomain,最后保存退出。

测试是否配置成功,则执行命令:ping -c 3 oracledb

[root@VM_0_8_centos temp]# ping -c 3 oracledb
PING oracledb (127.0.0.1) 56(84) bytes of data.
64 bytes from VM_0_8_centos (127.0.0.1): icmp_seq=1 ttl=64 time=0.018 ms
64 bytes from VM_0_8_centos (127.0.0.1): icmp_seq=2 ttl=64 time=0.021 ms
64 bytes from VM_0_8_centos (127.0.0.1): icmp_seq=3 ttl=64 time=0.020 ms

--- oracledb ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.018/0.019/0.021/0.005 ms
[root@VM_0_8_centos temp]# 
  • 修改内核参数

vi /etc/sysctl.conf

将 kernel.shmmax 与 kernel.shmall 注释掉,然后在文件末追加新配置内容。以下是从网上收集到的一些配置,需根据自己服务器内存选择追加的内容,仅供参考。


# 主机是4G内存选用
kernel.shmmax = 4294967296
kernel.shmall = 4294967296
kernel.shmmni = 4096
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=1048576
fs.aio-max-nr=1048576

# 主机是32G内存选用
kernel.shmmax = 17179869184
kernel.shmall = 17179869184
kernel.shmmni = 4096
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=1048576
fs.aio-max-nr=1048576

# 主机是64G内存选用
kernel.shmmax = 68719476736
kernel.shmall = 68719476736
kernel.shmmni = 4096
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=1048576
fs.aio-max-nr=1048576

修改参数之后,我们需要让参数生效,执行命令:sysctl -p

  • 检查selinux,确保SELINUX=disabled

cat /etc/selinux/config

技术图片

  • 修改资源使用配置文件

vi /etc/security/limits.conf

在文件末追加以下内容:

oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
  • 修改用户登录认证

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

为了让上面修改的环境变量立即生效,执行命令:source /etc/profile

设置oracle用户环境变量

  • 切换到oracle用户

su - oracle

  • 修改用户的环境变量

vi .bash_profile

在文件末追加以下内容:

umask 022
export ORACLE_HOSTNAME=oracledb
export ORACLE_BASE=/software/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export TNS_ADMIN=$ORACLE_HOME/network/admin
# export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
export NLS_LANG="AMERICAN_CHINA.ZHS16GBK"

OK,到这里我们的准备工作已经差不多,接下来就是静默安装配置和正式安装了,我们最好重启下服务器,执行命令:reboot

静默安装Oracle

  • 修改响应文件db_install.rsp

进入 /software/database (之前解压生成的目录),需要修改一下响应文件:vi /software/database/response/db_install.rsp,参考了网上文章,需要修改的内容如下:

# 选择安装类型:1.只装数据库软件 2.安装数据库软件并建库 3.升级数据库
oracle.install.option=INSTALL_DB_SWONLY
    
# 指定操作系统主机名,通过hostname命令获得
ORACLE_HOSTNAME=oracledb
          
# 指定oracle inventory目录的所有者,通常会是oinstall或者dba
UNIX_GROUP_NAME=oinstall
                         
# 指定产品清单oracle inventory目录的路径
INVENTORY_LOCATION=/software/app/oracle/inventory
        
# 指定数据库语言,可以选择多个,用逗号隔开
SELECTED_LANGUAGES=en,zh_CN
                
# 设置ORALCE_HOME的路径
ORACLE_HOME=/software/app/oracle/product/11.2.0/dbhome_1
  
# 设置ORALCE_BASE的路径
ORACLE_BASE=/software/app/oracle
                      
# 选择Oracle安装数据库软件的版本
oracle.install.db.InstallEdition=EE

# 是否自定义安装              
oracle.install.db.isCustomInstall=false

# 指定拥有OSDBA、OSOPER权限的用户组,通常会是dba组
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba

# 选择数据库的用途,一般用途/事物处理,数据仓库
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
       
# 指定SID
oracle.install.db.config.starterdb.SID=orcl
                
# 选择字符集,我这里选择有ZHS16GBK简体中文库
oracle.install.db.config.starterdb.characterSet=ZHS16GBK

# 是否设置安全更新,这里一定要设置为true
DECLINE_SECURITY_UPDATES=true

下面就是正式安装了,切换到oracle用户,命令:su - oracle,进入 /software/database 文件夹目录,执行以下命令,开始安装。

./runInstaller -silent -ignorePrereq -responseFile /software/database/response/db_install.rsp

技术图片

在安装过程中,界面会提示告诉我们,可以到具体的日志路径下查看安装日志,使用 tail -f 实时监控日志即可。

[oracle@VM_0_8_centos database]$ ./runInstaller -silent -ignorePrereq -responseFile /software/database/response/db_install.rsp
Starting Oracle Universal Installer...

Checking Temp space: must be greater than 120 MB.   Actual 87303 MB    Passed
Checking swap space: must be greater than 150 MB.   Actual 2047 MB    Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2020-04-11_03-59-06PM. Please wait ...[oracle@VM_0_8_centos database]$ [WARNING] [INS-32055] The Central Inventory is located in the Oracle base.
   CAUSE: The Central Inventory is located in the Oracle base.
   ACTION: Oracle recommends placing this Central Inventory in a location outside the Oracle base directory.
[WARNING] [INS-32055] The Central Inventory is located in the Oracle base.
   CAUSE: The Central Inventory is located in the Oracle base.
   ACTION: Oracle recommends placing this Central Inventory in a location outside the Oracle base directory.
You can find the log of this install session at:
 /software/app/oracle/inventory/logs/installActions2020-04-11_03-59-06PM.log
The following configuration scripts need to be executed as the "root" user. 
 #!/bin/sh 
 #Root scripts to run

/software/app/oracle/inventory/orainstRoot.sh
/software/app/oracle/product/11.2.0/dbhome_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 

Successfully Setup Software.

[oracle@VM_0_8_centos database]$ 

当在界面看到提示 Successfully Setup Software,则说明安装完成,同时根据提示,还需要新开一个窗口使用root用户登陆并执行以下命令:

/software/app/oracle/inventory/orainstRoot.sh
/software/app/oracle/product/11.2.0/dbhome_1/root.sh

最后,按回车键完成Oracle安装。

静默配置监听

切换到oracle用户,命令:su - oracle,进入 /software/database 文件夹目录,执行命令:netca /silent /responsefile /software/database/response/netca.rsp,开始配置监听。

[oracle@VM_0_8_centos database]$ netca /silent /responsefile /software/database/response/netca.rsp

Parsing command line arguments:
    Parameter "silent" = true
    Parameter "responsefile" = /software/database/response/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
    Running Listener Control: 
      /software/app/oracle/product/11.2.0/dbhome_1/bin/lsnrctl start LISTENER
    Listener Control complete.
    Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0

静默创建数据库

  • 修改文件dbca.rsp

vi /software/database/response/dbca.rsp

根据自己需要修改,比如这样:

GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/software/app/oracle/oradata
RECOVERYAREADESTINATION=/software/app/oracle/flash_recovery_area
# 根据实际情况设置字符集
CHARACTERSET = "ZHS16GBK"
  • 静默创建数据库

切换到oracle用户,命令:su - oracle,进入 /software/database 文件夹目录,执行命令:dbca -silent -responseFile /software/database/response/dbca.rsp,开始创建数据库。

[oracle@VM_0_8_centos database]$ dbca -silent -responseFile /software/database/response/dbca.rsp
Copying database files
1% complete
3% complete
11% complete
18% complete
26% 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 "/software/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.
[oracle@VM_0_8_centos database]$ 

我们可以使用Oracle用户,通过命令 lsnrctl status 查看监听状态。

[oracle@VM_0_8_centos ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 11-APR-2020 17:20:16

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                11-APR-2020 16:20:37
Uptime                    0 days 0 hr. 59 min. 39 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /software/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /software/app/oracle/diag/tnslsnr/VM_0_8_centos/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=VM_0_8_centos)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@VM_0_8_centos ~]$ 

OK,到这里已经成功在Linux下安装Oracle。

登录Oracle

接下来,我们用上面设置的密码 SYSPASSWORD = "oracle"来验证是否能正常登录。

[oracle@VM_0_8_centos ~]$ sqlplus sys/oracle@orcl as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Sat Apr 11 17:34:39 2020

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>

设置Oracle开机启动

最后,我们还需要配置一下,让Oracle能够在服务器开机时自动启动。

  • 配置/etc/oratab

vi /etc/oratab

使用root用户,修改 /etc/oratab 配置内容,设置如下:orcl:/software/app/oracle/product/11.2.0/dbhome_1:Y。其中,/software/app/oracle/product/11.2.0/dbhome_1为之前设置的 $ORACLE_HOME 路径。

技术图片

  • 配置/etc/rc.d/rc.local

vi /etc/rc.d/rc.local

su oracle -lc "/software/app/oracle/product/11.2.0/dbhome_1/bin/lsnrctl start"
su oracle -lc "/software/app/oracle/product/11.2.0/dbhome_1/bin/dbstart"
  • 给文件 /etc/rc.d/rc.local 增加执行权限

在CentOS7下,我们还需要检查文件 /etc/rc.d/rc.local 是否有执行权限,如果没有执行权限,则需执行命令:chmod +x /etc/rc.d/rc.local

完成以后操作后,需要验证一下,执行重启命令:reboot,重启之后先执行命令:su - oracle 切换到Oracle,再执行命令 lsnrctl status 查看监听状态,同时可以正常进行Oracle登录,说明开机自启动是没问题的。

[oracle@VM_0_8_centos ~]$ su - oracle
Password: 
Last login: Sat Apr 11 19:20:11 CST 2020 on pts/0
[oracle@VM_0_8_centos ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 11-APR-2020 19:23:44

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                11-APR-2020 19:17:31
Uptime                    0 days 0 hr. 6 min. 12 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /software/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /software/app/oracle/diag/tnslsnr/VM_0_8_centos/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=VM_0_8_centos)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
  Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@VM_0_8_centos ~]$ 

可能遇到的问题

  • Swap空间不够

在Oracle静默安装过程中,查看安装日志,发现出现错误并提示 swap空间 不够。

技术图片

使用 free -m 命令查看swap大小,发现大小为0,难怪会提示空间小于150M。因此,我们需要给服务器增加swap虚拟空间。

[root@VM_0_8_centos /]# free -m
              total        used        free      shared  buff/cache   available
Mem:          32009         312       31455           0         242       31377
Swap:             0           0           0

参考了网上资料,给Linux主机创建了2G的swap文件,创建过程如下:

[root@VM_0_8_centos /]# dd if=/dev/zero of=/software/swap bs=2048 count=1048576
1048576+0 records in
1048576+0 records out
2147483648 bytes (2.1 GB) copied, 3.23491 s, 664 MB/s
[root@VM_0_8_centos /]# mkswap /software/swap
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=ba7467e4-4d16-4c15-958a-9f03a8af5bc2
[root@VM_0_8_centos /]# chmod 600 /software/swap
[root@VM_0_8_centos /]# swapon /software/swap
[root@VM_0_8_centos /]# free -m
              total        used        free      shared  buff/cache   available
Mem:          32009         316       29324           0        2368       31336
Swap:          2047           0        2047
[root@VM_0_8_centos /]# 

为了让开机时自动启用,还需修改文件 /etc/fstab 添加一行:

/software/swap swap swap defaults 0 0
  • 提示 lsnrctl 命令找不到

我们使用oracle用户来操作,查看监听状态时,可能提示命令找不到。

[root@VM_0_8_centos ~]# su oracle
[oracle@VM_0_8_centos root]$ cd ~
[oracle@VM_0_8_centos ~]$ lsnrctl status
bash: lsnrctl: command not found
[oracle@VM_0_8_centos ~]$ ^C
[oracle@VM_0_8_centos ~]$ 

这是因为,在这里切换帐户一定要加 -,即使用 su - oracle,否则就会出现上面的错误。

Linux下静默安装Oracle

标签:desc   大小   app   listener   set   option   服务器   swap   cli   

原文地址:https://www.cnblogs.com/wintest/p/12681767.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!