前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Centos7静默安装Oracle11g

Centos7静默安装Oracle11g

作者头像
仙人技术
发布2020-11-05 14:37:05
9410
发布2020-11-05 14:37:05
举报

1、环境及准备工作

1.1 环境及配置调整

操作系统版本、内核版本、系统CPURAM、硬盘配置如下

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@localhost ~]# uname -r
3.10.0-1062.el7.x86_64
[root@localhost ~]# cat /proc/cpuinfo| grep "processor"| wc -l
8
[root@localhost ~]# cat /proc/meminfo| grep MemTotal
MemTotal:       131826144 kB
[root@localhost ~]# cat /proc/meminfo| grep SwapTotal
SwapTotal:       1835004 kB
[root@localhost ~]# fdisk -l|grep Disk
Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Disk label type: dos
Disk identifier: 0x000e4fd0
Disk /dev/vdb: 2199.0 GB, 2199023255552 bytes, 4294967296 sectors
Disk /dev/mapper/centos-root: 18.5 GB, 18513657856 bytes, 36159488 sectors
Disk /dev/mapper/centos-swap: 1879 MB, 1879048192 bytes, 3670016 sectors

如下表所示

项目

操作系统

CentOS Linux release 7.7.1908 (Core)

内核版本

3.10.0-1062.el7.x86_64

CPU

8C

RAM

128GB

SWAP

1GB

磁盘

/dev/vda 20G + /dev/vdb 2TB

数据盘未做格式化分区(这里仅格式化并挂载到单独目录,不做分区) 根据内存大小需要对此操作系统重新分配合适的swap空间(这里增加到16G),关于swap分区大小可参考红帽官方说明

[root@localhost ~]# mkfs.xfs /dev/vdb
[root@localhost ~]# mkdir /data && mount /dev/vdb /data
[root@localhost ~]# df -h | grep "data"
/dev/vdb                 2.0T   33M  2.0T   1% /data
[root@localhost ~]# blkid |grep vdb|awk '{print $2}'|cut -d '=' -f 2
"11eda493-b248-4ce0-91fb-e28e1b8164a9"
[root@localhost ~]# echo "UUID=11eda493-b248-4ce0-91fb-e28e1b8164a9 /data                   xfs     defaults        0 0" >> /etc/fstab  # 开机自动挂载数据盘
[root@localhost ~]# sed -ri '/^[^#]*swap/s@^@#@' /etc/fstab  # 关掉原来的swap开机自动挂载
[root@localhost ~]# dd if=/dev/zero of=/data/swapfile bs=1G count=16
[root@localhost ~]# mkswap /data/swapfile
[root@localhost ~]# chmod 600 /data/swapfile
[root@localhost ~]# swapon /data/swapfile
[root@localhost ~]# echo "/data/swapfile           swap                    swap    defaults        0 0" >> /etc/fstab  # 开机自动挂载swap分区

1.2 常用参数

修改主机名、关闭selinux、时间同步等

[root@localhost ~]# hostnamectl set-hostname oracledb-01
[root@localhost ~]# echo "127.0.0.1   oracledb-01" >> /etc/hosts
[root@oracledb-01 ~]# sestatus
SELinux status:                 disabled

1.3 其他准备

2、oracle安装

2.1 基本配置

2.2 解压安装包

[root@oracledb-01 ~]# cd linux.x64_11gR2_database_2of2/
[root@oracledb-01 linux.x64_11gR2_database_2of2]# ls
linux.x64_11gR2_database_1of2.zip  linux.x64_11gR2_database_2of2.zip
[root@oracledb-01 linux.x64_11gR2_database_2of2]# unzip -q linux.x64_11gR2_database_1of2.zip -d /data
[root@oracledb-01 linux.x64_11gR2_database_2of2]# unzip -q linux.x64_11gR2_database_2of2.zip -d /data
[root@oracledb-01 linux.x64_11gR2_database_2of2]# mkdir -p /data/etc
[root@oracledb-01 linux.x64_11gR2_database_2of2]# cp /data/database/response/* /data/etc/

2.3 正式安装

修改文件/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-01  # 修改成主机名
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

执行安装脚本

[root@oracledb-01 ~]# su - oracle
[oracle@oracledb-01 ~]$ cd /data/database/
[oracle@oracledb-01 database]$ ./runInstaller -silent -responseFile /data/etc/db_install.rsp -ignorePrereq

安装时可以根据安装提示查看日志

[root@oracledb-01 ~]# tail -f /data/app/oracle/inventory/logs/installActions2020-10-31_09-40-21PM.log

安装完成后会有如下提示

You can find the log of this install session at:
 /data/app/oracle/inventory/logs/installActions2020-10-31_09-40-21PM.log
The following configuration scripts need to be executed as the "root" user. 

 #!/bin/sh
 #Root scripts to run

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

按照上述提示进行操作,使用root用户运行脚本

[oracle@oracledb-01 ~]$ su - root
Password: 
[root@oracledb-01 ~]# sh /data/app/oracle/inventory/orainstRoot.sh 
Changing permissions of /data/app/oracle/inventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /data/app/oracle/inventory to oinstall.
The execution of the script is complete.
[root@oracledb-01 ~]# sh /data/app/oracle/product/11.2.0/root.sh 
Check /data/app/oracle/product/11.2.0/install/root_oracledb-01_2020-10-31_09-46-20.log for the output of root script

配置监听

[root@oracledb-01 ~]# su - oracle
[oracle@oracledb-01 ~]$ 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

查看监听端口

[oracle@oracledb-01 database]$ netstat -tnpl | grep 1521
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 :::1521                 :::*                    LISTEN      6064/tnslsnr

2.4 静默创建数据库

2.4.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 = "102400"  # 分配给Oracle的内存总量,根据服务器内存总量进行分配

2.4.2 执行静默建库

su - oracle
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.

2.4.3 检查

查看进程

[oracle@oracledb-01 ~]$ ps -ef | grep ora_ | grep -v grep
oracle     8113      1  0 12:03 ?        00:00:00 ora_pmon_orcl
oracle     8115      1  0 12:03 ?        00:00:00 ora_vktm_orcl
oracle     8119      1  0 12:03 ?        00:00:00 ora_gen0_orcl
oracle     8121      1  0 12:03 ?        00:00:00 ora_diag_orcl
oracle     8123      1  0 12:03 ?        00:00:00 ora_dbrm_orcl
oracle     8125      1  0 12:03 ?        00:00:00 ora_psp0_orcl
oracle     8127      1  0 12:03 ?        00:00:00 ora_dia0_orcl
oracle     8129      1  0 12:03 ?        00:00:00 ora_mman_orcl
oracle     8131      1  0 12:03 ?        00:00:00 ora_dbw0_orcl
oracle     8133      1  0 12:03 ?        00:00:00 ora_lgwr_orcl
oracle     8135      1  0 12:03 ?        00:00:00 ora_ckpt_orcl
oracle     8137      1  0 12:03 ?        00:00:00 ora_smon_orcl
oracle     8139      1  0 12:03 ?        00:00:00 ora_reco_orcl
oracle     8141      1  0 12:03 ?        00:00:00 ora_mmon_orcl
oracle     8143      1  0 12:03 ?        00:00:00 ora_mmnl_orcl
oracle     8145      1  0 12:03 ?        00:00:00 ora_d000_orcl
oracle     8147      1  0 12:03 ?        00:00:00 ora_s000_orcl
oracle     8161      1  0 12:03 ?        00:00:00 ora_qmnc_orcl
oracle     8178      1  0 12:03 ?        00:00:00 ora_cjq0_orcl
oracle     8188      1  0 12:03 ?        00:00:00 ora_q000_orcl
oracle     8190      1  0 12:03 ?        00:00:00 ora_q001_orcl

查看监听状态

[oracle@oracledb-01 ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 03-NOV-2020 12:06:10

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                03-NOV-2020 11:37:14
Uptime                    0 days 0 hr. 28 min. 56 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-01/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracledb-01)(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

2.5 登录数据库启动监听

[root@oracledb-01 ~]# su - oracle
[oracle@oracledb-01 ~]$ sqlplus / as sysdba
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'

按照提示操作

[oracle@oracledb-01 ~]$ cp /data/app/oracle/admin/orcl/pfile/init.ora.103202012323 /data/app/oracle/product/11.2.0/dbs/initORCL.ora

再次启动监听

SQL> shutdown immediate;
SQL> startup;
ORACLE instance started.

Total System Global Area  534462464 bytes
Fixed Size                  2215064 bytes
Variable Size             163578728 bytes
Database Buffers          360710144 bytes
Redo Buffers                7958528 bytes
Database mounted.
Database opened.

2.6 激活scott用户(可选)

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

3、设置开机启动

修改/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

添加执行权限和开机启动

[root@oracledb-01 ~]# chmod +x /etc/init.d/oracle
[root@oracledb-01 ~]# chkconfig oracle on
[root@oracledb-01 ~]# chkconfig --list|grep oracle

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

oracle          0:off   1:off   2:on    3:on    4:on    5:on    6:off

修改启动相关文件的权限

[root@oracledb-01 ~]# cd /data/app/oracle/product/11.2.0/bin/
[root@oracledb-01 bin]# chmod 6751 oracle
[root@oracledb-01 bin]# cd /var/tmp
[root@oracledb-01 tmp]# chown -R oracle:oinstall .oracle

关机重启测试

reboot

关机重启后登陆进入数据库后,再执行startup启动数据库。

参考:

https://blog.csdn.net/chenghuikai/article/details/85776622 https://www.cnblogs.com/hftian/p/6944133.html https://www.cnblogs.com/xiaofeng666/p/13702197.html

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-10-31,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1、环境及准备工作
    • 1.1 环境及配置调整
      • 1.2 常用参数
        • 1.3 其他准备
        • 2、oracle安装
          • 2.1 基本配置
            • 2.2 解压安装包
              • 2.3 正式安装
                • 2.4 静默创建数据库
                  • 2.4.1 编辑应答文件
                  • 2.4.2 执行静默建库
                  • 2.4.3 检查
                • 2.5 登录数据库启动监听
                  • 2.6 激活scott用户(可选)
                  • 3、设置开机启动
                  相关产品与服务
                  数据库
                  云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
                  领券
                  问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档