Centos7下静默安装Oracle 11g(无图形化界面)

Centos7下静默安装Oracle 11g(无图形化界面)

说明:

  • 因为是静默安装,所以我们不需要安装图形界面

前期准备

1. 准备Centos 7的系统环境

  • 系统版本:Centos X64 7.2.1511 (腾讯云)
  • 内核版本:3.10.0-514.26.2.el7.x86_64
  • 系统配置:1c,2G
  • 交换空间:
可用内存 需要交换空间
介于1 GB和2 GB之间 RAM大小的1.5倍
介于2 GB和16 GB之间 等于RAM的大小
超过16 GB 16 GB

默认是不提供swap分区的,这里需要自己动手加一下

dd if=/dev/zero of=/swap bs=1024 count=2048000
mkswap /swap
chmod 600 /swap
swapon /swap
echo "/swap swap swap default 0 0">>/etc/fstab  #设置成自动挂载

2. 配置hostname

hostnamectl set-hostname oracledb
echo "127.0.0.1     oracledb" >>/etc/hosts

3. 关闭selinux

sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config  
setenforce 0

2. 下载Oracle

官方网站:http://www.oracle.com/technetwork/database/enterprise-edition/downloads/
根据自己的服务器,下载相应的软件,我的系统是64位的,所以下载的是 Linux x86-64的,下载完的两个文件如下

  • linux.x64_11gR2_database_1of2.zip
  • linux.x64_11gR2_database_2of2.zip

3. 检查软件依赖环境

注意:从Oracle 11g 11.2.0.2版本开始,在Linux x86_64上安装时,只需要安装64位的软件包,但是,对于11.2.0.2之前的任何Oracle database 11g,下表中列出的32位和64位的安装包都必须安装

需要安装的依赖包(版本号只能大于规定的版本,不能小于)

binutils-2.23.52.0.1-12.el7.x86_64 
compat-libcap1-1.10-3.el7.x86_64 
compat-libstdc++-33-3.2.3-71.el7.i686
compat-libstdc++-33-3.2.3-71.el7.x86_64
gcc-4.8.2-3.el7.x86_64 
gcc-c++-4.8.2-3.el7.x86_64 
glibc-2.17-36.el7.i686 
glibc-2.17-36.el7.x86_64 
glibc-devel-2.17-36.el7.i686 
glibc-devel-2.17-36.el7.x86_64 
ksh
libaio-0.3.109-9.el7.i686 
libaio-0.3.109-9.el7.x86_64 
libaio-devel-0.3.109-9.el7.i686 
libaio-devel-0.3.109-9.el7.x86_64 
libgcc-4.8.2-3.el7.i686 
libgcc-4.8.2-3.el7.x86_64 
libstdc++-4.8.2-3.el7.i686 
libstdc++-4.8.2-3.el7.x86_64 
libstdc++-devel-4.8.2-3.el7.i686 
libstdc++-devel-4.8.2-3.el7.x86_64 
libXi-1.7.2-1.el7.i686 
libXi-1.7.2-1.el7.x86_64 
libXtst-1.2.2-1.el7.i686 
libXtst-1.2.2-1.el7.x86_64 
make-3.82-19.el7.x86_64 
sysstat-10.1.5-1.el7.x86_64
unixODBC-2.3.1-6.el7.i686
unixODBC-2.3.1-6.el7.x86_64
unixODBC-devel-2.3.1-6.el7.i686
unixODBC-devel-2.3.1-6.el7.x86_64

安装命令:

yum -y install binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel

安装完成后,检查依赖是否安装成功

rpm -q binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel | grep "not installed"

注:我使用的是腾讯云,腾讯云的yum源里已经有了,如果您用的是其它环境的,没有哪个依赖包,就手动装下即可。

4. 创建所需的操作系统组和用户

如果要安装Oracle数据库,则需要以下本地操作系统组和用户:

  • Oracle inventory组(通常为 oinstall)
  • OSDBA组 (通常为 dba)
  • OSOPER组 (通常为 oper)
  • Oracle软件所有者(通常为 oracle)
    添加命令:
groupadd oinstall
groupadd dba
groupadd oper
useradd -g oinstall -G dba oracle

修改oracle用户密码

passwd oracle

5. 配置内核参数和资源限制

  1. /etc/sysctl.conf添加如下参数,如果系统中某个参数高于下面的参数的值 ,保留较大的值,下面的数值只是官方要求的最小值,可以根据系统调整数值,以优化系统性能
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 536870912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
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
  1. 使内核参数生效
sysctl -p
  1. /etc/security/limits.conf中添加如下参数
oracle              soft    nproc   2047
oracle              hard    nproc   16384
oracle              soft    nofile  1024
oracle              hard    nofile  65536
  1. 在/etc/pam.d/login文件中,添加下面内容
session required /lib64/security/pam_limits.so
session required pam_limits.so
  1. /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
  1. 使用/etc/profile文件生效
source /etc/profile
  1. 禁用使用Transparent HugePages(启用Transparent HugePages,可能会导致造成内存在运行时的延迟分配,Oracle官方建议使用标准的HugePages)
  • 查看是否启用 如果显示 [always]说明启用了
cat /sys/kernel/mm/transparent_hugepage/enabled
  • 禁用Transparent HugePages,在/etc/grub.conf添加如下内容
echo never > /sys/kernel/mm/transparent_hugepage/enabled

重新启动系统以使更改成为永久更改

6. 创建oracle安装目录

如下目录,根据自己的实际情况可做修改

mkdir -p /data/app/
chown -R oracle:oinstall /data/app/
chmod -R 775 /data/app/

7. 配置oracle用户环境变量

在文件/home/oracle/.bash_profile里添加下面内容(具体值根据实际情况修改)

umask 022
export ORACLE_HOSTNAME=oracledb
export ORACLE_BASE=/data/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/
export ORACLE_SID=ORCL
export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH
export LC_ALL="en_US"
export LANG="en_US"
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"

8. 重启下系统

reboot

9. 解压下载好的两个Oracle数据库文件

unzip -q linux.x64_11gR2_database_1of2.zip -d /data
unzip -q linux.x64_11gR2_database_2of2.zip -d /data
mkdir -p /data/etc
cp /data/database/response/* /data/etc/

/data/etc/db_install.rsp修改以下变量的值

oracle.install.option=INSTALL_DB_SWONLY
DECLINE_SECURITY_UPDATES=true
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/data/app/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOSTNAME=oracledb
ORACLE_HOME=/data/app/oracle/product/11.2.0
ORACLE_BASE=/data/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=true
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba

10. 开始安装

su - oracle
cd /data/database
./runInstaller -silent -responseFile /data/etc/db_install.rsp -ignorePrereq

安装期间可以使用tail命令监看oracle的安装日志

#日志文件名称根据自己的实际执行时间变更
tail -f /data/app/oracle/inventory/logs/installActions2019-01-02_06-03-30PM.log

安装完成后有如下提示,如果有类似如下提示,说明安装完成

The following configuration scripts need to be executed as the "root" user. 
#!/bin/sh 
#Root scripts to run

/u01/app/oraInventory/orainstRoot.sh
/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

Successfully Setup Software.

11. 使用root用户执行脚本

su - root
sh /data/app/oracle/inventory/orainstRoot.sh
sh /data/app/oracle/product/11.2.0/root.sh

12. 配置监听程序

su - oracle
netca /silent /responsefile /data/etc/netca.rsp

#输出结果
[oracle@oracledb ~]$ netca /silent /responsefile /data/etc/netca.rsp

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

查看监听端口

netstat -tnpl | grep 1521

13. 静默创建数据库

  1. 编辑应答文件/data/etc/dbca.rsp
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/data/app/oracle/oradata
RECOVERYAREADESTINATION=/data/app/oracle/fast_recovery_area
CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "1638"
  1. 执行静默建库
su - oracle
dbca -silent -responseFile /data/etc/dbca.rsp

执行过程如下

[oracle@oracledb ~]$ dbca -silent -responseFile /data/etc/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 "/data/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.
  1. 查看进程
ps -ef | grep ora_ | grep -v grep

# 执行结果
[oracle@oracledb ~]$ ps -ef | grep ora_ | grep -v grep
oracle   19304     1  0 18:33 ?        00:00:00 ora_pmon_orcl
oracle   19306     1  0 18:33 ?        00:00:00 ora_vktm_orcl
oracle   19310     1  0 18:33 ?        00:00:00 ora_gen0_orcl
oracle   19312     1  0 18:33 ?        00:00:00 ora_diag_orcl
oracle   19314     1  0 18:33 ?        00:00:00 ora_dbrm_orcl
oracle   19316     1  0 18:33 ?        00:00:00 ora_psp0_orcl
oracle   19318     1  0 18:33 ?        00:00:00 ora_dia0_orcl
oracle   19320     1  0 18:33 ?        00:00:00 ora_mman_orcl
oracle   19322     1  0 18:33 ?        00:00:00 ora_dbw0_orcl
oracle   19324     1  0 18:33 ?        00:00:00 ora_lgwr_orcl
oracle   19326     1  0 18:33 ?        00:00:00 ora_ckpt_orcl
oracle   19328     1  0 18:33 ?        00:00:00 ora_smon_orcl
oracle   19330     1  0 18:33 ?        00:00:00 ora_reco_orcl
oracle   19332     1  0 18:33 ?        00:00:00 ora_mmon_orcl
oracle   19334     1  0 18:33 ?        00:00:00 ora_mmnl_orcl
oracle   19336     1  0 18:33 ?        00:00:00 ora_d000_orcl
oracle   19338     1  0 18:33 ?        00:00:00 ora_s000_orcl
oracle   19361     1  0 18:34 ?        00:00:00 ora_qmnc_orcl
oracle   19376     1  0 18:34 ?        00:00:00 ora_cjq0_orcl
oracle   19396     1  0 18:34 ?        00:00:00 ora_q000_orcl
oracle   19398     1  0 18:34 ?        00:00:00 ora_q001_orcl
  1. 查看监听状态
$ lsnrctl status

#结果
[oracle@oracledb ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 02-JAN-2019 18:36:15

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                02-JAN-2019 18:20:21
Uptime                    0 days 0 hr. 15 min. 54 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /data/app/oracle/product/11.2.0/network/admin/listener.ora
Listener Log File         /data/app/oracle/diag/tnslsnr/oracledb/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracledb)(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@oracledb ~]$

14. 至此数据库就安装成功了,下面我们登录下数据库

su - oracle
sqlplus / as sysdba
select status from v$instance;

执行select时,全出现以下情况

SQL> select status from v$instance;
select status from v$instance
*
ERROR at line 1:
ORA-01034: ORACLE not available
Process ID: 0
Session ID: 0 Serial number: 0

解决方式:

  1. 输入startup,
#startup的输出提示:
SQL> statup
SP2-0042: unknown command "statup" - rest of line ignored.
SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/data/app/oracle/product/11.2.0/dbs/initORCL.ora'
  1. 根据提示,将 O R A C L E B A S E / a d m i n / 数 据 库 名 称 / p f i l e 目 录 下 的 i n i t . o r a . x x x 形 式 的 文 件 c o p y 到 ORACLE_BASE/admin/数据库名称/pfile目录下的init.ora.xxx形式的文件copy到 ORACLEBASE/admin//pfileinit.ora.xxxcopyORACLE_HOME/dbs目录下initOracle.ora(根据startup提示)即可
cp /data/app/oracle/admin/orcl/pfile/init.ora.022019183329 initORCL.ora

查看数据库编码

select userenv('language') from dual;

# 输出结果:
SQL> select userenv('language') from dual;

USERENV('LANGUAGE')
--------------------------------------------------------------------------------
AMERICAN_AMERICA.AL32UTF8

SQL>

查看数据库版本

select * from v$version;

#结果
SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE	11.2.0.1.0	Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

激活scott用户

alter user scott account unlock;
alter user scott identified by tiger;
select username,account_status from dba_users;

15. 设置Oracle开机启动

修改/data/app/oracle/product/11.2.0/bin/dbstart

ORACLE_HOME_LISTNER=$ORACLE_HOME

修改/data/app/oracle/product/11.2.0/bin/dbshut

ORACLE_HOME_LISTNER=$ORACLE_HOME

修改vi /etc/oratab

orcl:/data/app/oracle/product/11.2.0:Y

新建文件/etc/rc.d/init.d/oracle

#! /bin/bash
# oracle: Start/Stop Oracle Database 11g R2
#
# chkconfig: 345 90 10
# description: The Oracle Database is an Object-Relational Database Management System.
#
# processname: oracle
. /etc/rc.d/init.d/functions
LOCKFILE=/var/lock/subsys/oracle
ORACLE_HOME=/data/app/oracle/product/11.2.0
ORACLE_USER=oracle
case "$1" in
'start')
   if [ -f $LOCKFILE ]; then
      echo $0 already running.
      exit 1
   fi
   echo -n $"Starting Oracle Database:"
   su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl start"
   su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
   su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl start dbconsole"
   touch $LOCKFILE
   ;;
'stop')
   if [ ! -f $LOCKFILE ]; then
      echo $0 already stopping.
      exit 1
   fi
   echo -n $"Stopping Oracle Database:"
   su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl stop"
   su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbshut"
   su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl stop dbconsole"
   rm -f $LOCKFILE
   ;;
'restart')
   $0 stop
   $0 start
   ;;
'status')
   if [ -f $LOCKFILE ]; then
      echo $0 started.
      else
      echo $0 stopped.
   fi
   ;;
*)
   echo "Usage: $0 [start|stop|status]"
   exit 1
esac
exit 0

/etc/init.d/oracle添加执行权限

chmod +x /etc/init.d/oracle

开机启动oracle

systemctl enable oracle
或
chkconfig oracle on

给启动文件加权限

cd /data/app/oracle/product/11.2.0/bin/
chmod 6751 oracle
cd /var/tmp
chown -R oracle:oinstall .oracle

16. 防火墙配置放开Oracle的端口

firewall-cmd --zone=public --add-port=1521/tcp --permanent
firewall-cmd --reload

参考文章:https://blog.csdn.net/kenny1993/article/details/75038670

你可能感兴趣的:(数据库)