当前位置: 代码迷 >> 综合 >> CentOS 7 命令行安装 Oracle 11gR2
  详细解决方案

CentOS 7 命令行安装 Oracle 11gR2

热度:41   发布时间:2023-10-18 19:24:09.0

 

目的:在华为云买了个云服务器,是CentOs7.6的系统,打算在上面装一个Oracle11g的数据库,之前没有在Linux系统上装过Oracle数据库,所以各种百度和实验,终于搞成了,写一篇博客供大家参考,尽量少踩坑。

一、安装步骤

1、Oracle 11gR2 64位 Linux版安装包

下载地址:https://www.oracle.com/cn/database/enterprise-edition/downloads/oracle-db11g-linux.html

CentOS 7 命令行安装 Oracle 11gR2

2、安装依赖包

yum install -y automake autotools-dev binutils bzip2 elfutils expat \
gawk gcc gcc-multilib g++-multilib lib32ncurses5 lib32z1 \
ksh less lib32z1 libaio1 libaio-dev libc6-dev libc6-dev-i386 \
libc6-i386 libelf-dev libltdl-dev libodbcinstq4-1 libodbcinstq4-1:i386 \
libpth-dev libpthread-stubs0-dev libstdc++5 make openssh-server rlwrap \
rpm sysstat unixodbc unixodbc-dev unzip x11-utils zlibc unzip cifs-utils \
libXext.x86_64  glibc.i686

以上依赖包安装完成之后,执行

yum update

3、创建Oracle用户

操作用户:root

groupadd -g 502 oinstall
groupadd -g 503 dba
groupadd -g 504 oper
groupadd -g 505 asmadmin
useradd -u 502 -g oinstall -G oinstall,dba,asmadmin,oper -s /bin/bash -m oracle
passwd oracle

4、解压安装包

操作用户:oracle
操作目录:/home/oracle

将Oracle 11gR2安装文件上传(可以使用xftp工具上传)到该操作目录下面,然后顺序解压安装文件到该目录

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

5、修改安全设置

操作用户:root
操作文件:/etc/security/limits.conf

vi /etc/security/limits.conf

PS:如果不会使用Vi编辑器的话可以使用Xftp工具把limits.conf下载到本地使用NotePad++编辑完保存上传到服务器覆盖原来的。

在文件最后追加如下内容(vi使用方法略):

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

6、创建安装目录

操作用户:oracle

mkdir /home/oracle/tools/oracle11g

如果没有目录的操作权限可以使用chmod进行赋权,如果创建目录不报错这步可以不走

chmod 777 /home/oracle

7、修改环境变量

操作用户:oracle
操作目录:/home/oracle

vi ~/.bash_profile

在文件最后追加如下内容(vi使用方法略):

export ORACLE_BASE=/home/oracle/tools/oracle11g
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export ORACLE_UNQNAME=orcl
export NLS_LANG=.AL32UTF8
export PATH=${PATH}:${ORACLE_HOME}/bin/:$ORACLE_HOME/lib64

执行以下命令使其生效:

source ~/.bash_profile

以后每次重新登录不需要重新设置,环境变量将自动加载。

8、关闭防火墙

操作用户:root

systemctl stop firewalld.service

并设置其重新启动服务器后不再打开

systemctl disable firewalld.service

9、定义安装响应文件

操作用户:oracle
操作目录:/home/oracle

复制文件模板

cp /home/oracle/database/response/db_install.rsp .

模板内容修改如下(目录、用户等没有变化的情况下,可以直接使用),修改出使用粗体标出:


####################################################################
## Copyright(c) Oracle Corporation 1998,2008. All rights reserved.##
##                                                                ##
## Specify values for the variables listed below to customize    ##
## your installation.                                            ##
##                                                                ##
## Each variable is associated with a comment. The comment        ##
## can help to populate the variables with the appropriate        ##
## values.   ##
##                                                                ##
## IMPORTANT NOTE: This file contains plain text passwords and    ##
## should be secured to have read permission only by oracle user  ##
## or db administrator who owns this installation.                ##
##                                                                ##
####################################################################

#------------------------------------------------------------------------------

# Do not change the following system generated value.

#------------------------------------------------------------------------------

oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0

#------------------------------------------------------------------------------

# Specify the installation option.

# It can be one of the following:

# 1. INSTALL_DB_SWONLY

# 2. INSTALL_DB_AND_CONFIG

# 3. UPGRADE_DB

#-------------------------------------------------------------------------------

oracle.install.option=INSTALL_DB_AND_CONFIG

#-------------------------------------------------------------------------------

# Specify the hostname of the system as set during the install. It can be used

# to force the installation to use an alternative hostname rather than using the

# first hostname found on the system. (e.g., for systems with multiple hostnames

# and network interfaces)

#-------------------------------------------------------------------------------

ORACLE_HOSTNAME=localhost

#-------------------------------------------------------------------------------

# Specify the Unix group to be set for the inventory directory. 

#-------------------------------------------------------------------------------

UNIX_GROUP_NAME=oinstall

#-------------------------------------------------------------------------------

# Specify the location which holds the inventory files.

#-------------------------------------------------------------------------------

INVENTORY_LOCATION=/home/oracle/tools/oraInventory

#-------------------------------------------------------------------------------

# Specify the languages in which the components will be installed.           

#

# en  : English                  ja  : Japanese                 

# fr  : French                  ko  : Korean                   

# ar  : Arabic                  es  : Latin American Spanish   

# bn  : Bengali                  lv  : Latvian                 

# pt_BR: Brazilian Portuguese    lt  : Lithuanian               

# bg  : Bulgarian                ms  : Malay                   

# fr_CA: Canadian French          es_MX: Mexican Spanish         

# ca  : Catalan                  no  : Norwegian               

# hr  : Croatian                pl  : Polish                   

# cs  : Czech                    pt  : Portuguese               

# da  : Danish                  ro  : Romanian                 

# nl  : Dutch                    ru  : Russian                 

# ar_EG: Egyptian                zh_CN: Simplified Chinese       

# en_GB: English (Great Britain)  sk  : Slovak                   

# et  : Estonian                sl  : Slovenian               

# fi  : Finnish                  es_ES: Spanish                 

# de  : German                  sv  : Swedish                 

# el  : Greek                    th  : Thai                     

# iw  : Hebrew                  zh_TW: Traditional Chinese     

# hu  : Hungarian                tr  : Turkish                 

# is  : Icelandic                uk  : Ukrainian               

# in  : Indonesian              vi  : Vietnamese               

# it  : Italian                                                 

#

# Example : SELECTED_LANGUAGES=en,fr,ja

#------------------------------------------------------------------------------

SELECTED_LANGUAGES=en,zh_CN

#------------------------------------------------------------------------------

# Specify the complete path of the Oracle Home.

#------------------------------------------------------------------------------

ORACLE_HOME=/home/oracle/tools/oracle11g/product/11.2.0/dbhome_1

#------------------------------------------------------------------------------

# Specify the complete path of the Oracle Base.

#------------------------------------------------------------------------------

ORACLE_BASE=/home/oracle/tools/oracle11g

#------------------------------------------------------------------------------

# Specify the installation edition of the component.                       

#                                                           

# The value should contain only one of these choices.       

# EE    : Enterprise Edition                               

# SE    : Standard Edition                                 

# SEONE  : Standard Edition One

# PE    : Personal Edition (WINDOWS ONLY)

#------------------------------------------------------------------------------

oracle.install.db.InstallEdition=EE

#------------------------------------------------------------------------------

# This variable is used to enable or disable custom install.

#

# true  : Components mentioned as part of 'customComponents' property

#        are considered for install.

# false : Value for 'customComponents' is not considered.

#------------------------------------------------------------------------------

oracle.install.db.isCustomInstall=false

#------------------------------------------------------------------------------

# This variable is considered only if 'IsCustomInstall' is set to true.

#

# Description: List of Enterprise Edition Options you would like to install.

#

#              The following choices are available. You may specify any

#              combination of these choices.  The components you choose should

#              be specified in the form "internal-component-name:version"

#              Below is a list of components you may specify to install.

#       

#              oracle.rdbms.partitioning:11.2.0.1.0 - Oracle Partitioning

#              oracle.rdbms.dm:11.2.0.1.0 - Oracle Data Mining

#              oracle.rdbms.dv:11.2.0.1.0 - Oracle Database Vault

#              oracle.rdbms.lbac:11.2.0.1.0 - Oracle Label Security

#              oracle.rdbms.rat:11.2.0.1.0 - Oracle Real Application Testing

#              oracle.oraolap:11.2.0.1.0 - Oracle OLAP

#------------------------------------------------------------------------------

oracle.install.db.customComponents=oracle.server:11.2.0.1.0,oracle.sysman.ccr:10.2.7.0.0,oracle.xdk:11.2.0.1.0,oracle.rdbms.oci:11.2.0.1.0,oracle.network:11.2.0.1.0,oracle.network.listener:11.2.0.1.0,oracle.rdbms:11.2.0.1.0,oracle.options:11.2.0.1.0,oracle.rdbms.partitioning:11.2.0.1.0,oracle.oraolap:11.2.0.1.0,oracle.rdbms.dm:11.2.0.1.0,oracle.rdbms.dv:11.2.0.1.0,orcle.rdbms.lbac:11.2.0.1.0,oracle.rdbms.rat:11.2.0.1.0

###############################################################################

#                                                                            #

# PRIVILEGED OPERATING SYSTEM GROUPS                                        #

# ------------------------------------------                                  #

# Provide values for the OS groups to which OSDBA and OSOPER privileges      #

# needs to be granted. If the install is being performed as a member of the  #

# group "dba", then that will be used unless specified otherwise below.       #

#                                                                            #

###############################################################################

#------------------------------------------------------------------------------

# The DBA_GROUP is the OS group which is to be granted OSDBA privileges.

#------------------------------------------------------------------------------

oracle.install.db.DBA_GROUP=dba

#------------------------------------------------------------------------------

# The OPER_GROUP is the OS group which is to be granted OSOPER privileges.

#------------------------------------------------------------------------------

oracle.install.db.OPER_GROUP=oper

#------------------------------------------------------------------------------

# Specify the cluster node names selected during the installation.

#------------------------------------------------------------------------------

oracle.install.db.CLUSTER_NODES=

#------------------------------------------------------------------------------

# Specify the type of database to create.

# It can be one of the following:

# - GENERAL_PURPOSE/TRANSACTION_PROCESSING         

# - DATA_WAREHOUSE                               

#------------------------------------------------------------------------------

oracle.install.db.config.starterdb.type=GENERAL_PURPOSE

#------------------------------------------------------------------------------

# Specify the Starter Database Global Database Name.

#------------------------------------------------------------------------------

oracle.install.db.config.starterdb.globalDBName=orcl

#------------------------------------------------------------------------------

# Specify the Starter Database SID.

#------------------------------------------------------------------------------

oracle.install.db.config.starterdb.SID=orcl

#------------------------------------------------------------------------------

# Specify the Starter Database character set.

#                                             

# It can be one of the following:

# AL32UTF8, WE8ISO8859P15, WE8MSWIN1252, EE8ISO8859P2,

# EE8MSWIN1250, NE8ISO8859P10, NEE8ISO8859P4, BLT8MSWIN1257,

# BLT8ISO8859P13, CL8ISO8859P5, CL8MSWIN1251, AR8ISO8859P6,

# AR8MSWIN1256, EL8ISO8859P7, EL8MSWIN1253, IW8ISO8859P8,

# IW8MSWIN1255, JA16EUC, JA16EUCTILDE, JA16SJIS, JA16SJISTILDE,

# KO16MSWIN949, ZHS16GBK, TH8TISASCII, ZHT32EUC, ZHT16MSWIN950,

# ZHT16HKSCS, WE8ISO8859P9, TR8MSWIN1254, VN8MSWIN1258

#------------------------------------------------------------------------------

oracle.install.db.config.starterdb.characterSet=AL32UTF8

#------------------------------------------------------------------------------

# This variable should be set to true if Automatic Memory Management

# in Database is desired.

# If Automatic Memory Management is not desired, and memory allocation

# is to be done manually, then set it to false.

#------------------------------------------------------------------------------

oracle.install.db.config.starterdb.memoryOption=true

#------------------------------------------------------------------------------

# Specify the total memory allocation for the database. Value(in MB) should be

# at least 256 MB, and should not exceed the total physical memory available

# on the system.

# Example: oracle.install.db.config.starterdb.memoryLimit=512

#------------------------------------------------------------------------------

oracle.install.db.config.starterdb.memoryLimit=512

#------------------------------------------------------------------------------

# This variable controls whether to load Example Schemas onto the starter

# database or not.

#------------------------------------------------------------------------------

oracle.install.db.config.starterdb.installExampleSchemas=false

#------------------------------------------------------------------------------

# This variable includes enabling audit settings, configuring password profiles

# and revoking some grants to public. These settings are provided by default.

# These settings may also be disabled.   

#------------------------------------------------------------------------------

oracle.install.db.config.starterdb.enableSecuritySettings=true

###############################################################################

#                                                                            #

# Passwords can be supplied for the following four schemas in the       #

# starter database:            #

#  SYS                                                                      #

#  SYSTEM                                                                    #

#  SYSMAN (used by Enterprise Manager)                                      #

#  DBSNMP (used by Enterprise Manager)                                      #

#                                                                            #

# Same password can be used for all accounts (not recommended)       #

# or different passwords for each account can be provided (recommended)      #

#                                                                            #

###############################################################################

#------------------------------------------------------------------------------

# This variable holds the password that is to be used for all schemas in the

# starter database.

#-------------------------------------------------------------------------------

oracle.install.db.config.starterdb.password.ALL=Oracle#123456

#-------------------------------------------------------------------------------

# Specify the SYS password for the starter database.

#-------------------------------------------------------------------------------

oracle.install.db.config.starterdb.password.SYS=

#-------------------------------------------------------------------------------

# Specify the SYSTEM password for the starter database.

#-------------------------------------------------------------------------------

oracle.install.db.config.starterdb.password.SYSTEM=

#-------------------------------------------------------------------------------

# Specify the SYSMAN password for the starter database.

#-------------------------------------------------------------------------------

oracle.install.db.config.starterdb.password.SYSMAN=

#-------------------------------------------------------------------------------

# Specify the DBSNMP password for the starter database.

#-------------------------------------------------------------------------------

oracle.install.db.config.starterdb.password.DBSNMP=

#-------------------------------------------------------------------------------

# Specify the management option to be selected for the starter database.

# It can be one of the following:

# 1. GRID_CONTROL

# 2. DB_CONTROL

#-------------------------------------------------------------------------------

oracle.install.db.config.starterdb.control=DB_CONTROL

#-------------------------------------------------------------------------------

# Specify the Management Service to use if Grid Control is selected to manage

# the database.     

#-------------------------------------------------------------------------------

oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL=

#-------------------------------------------------------------------------------

# This variable indicates whether to receive email notification for critical

# alerts when using DB control. 

#-------------------------------------------------------------------------------

oracle.install.db.config.starterdb.dbcontrol.enableEmailNotification=false

#-------------------------------------------------------------------------------

# Specify the email address to which the notifications are to be sent.

#-------------------------------------------------------------------------------

oracle.install.db.config.starterdb.dbcontrol.emailAddress=test@163.com

#-------------------------------------------------------------------------------

# Specify the SMTP server used for email notifications.

#-------------------------------------------------------------------------------

oracle.install.db.config.starterdb.dbcontrol.SMTPServer=

###############################################################################

#                                                                            #

# SPECIFY BACKUP AND RECOVERY OPTIONS                                      #

# ------------------------------------                               #

# Out-of-box backup and recovery options for the database can be mentioned    #

# using the entries below.       #

#                                                                            #

###############################################################################

#------------------------------------------------------------------------------

# This variable is to be set to false if automated backup is not required. Else

# this can be set to true.

#------------------------------------------------------------------------------

oracle.install.db.config.starterdb.automatedBackup.enable=false

#------------------------------------------------------------------------------

# Regardless of the type of storage that is chosen for backup and recovery, if

# automated backups are enabled, a job will be scheduled to run daily at

# 2:00 AM to backup the database. This job will run as the operating system

# user that is specified in this variable.

#------------------------------------------------------------------------------

oracle.install.db.config.starterdb.automatedBackup.osuid=

#-------------------------------------------------------------------------------

# Regardless of the type of storage that is chosen for backup and recovery, if

# automated backups are enabled, a job will be scheduled to run daily at

# 2:00 AM to backup the database. This job will run as the operating system user

# specified by the above entry. The following entry stores the password for the

# above operating system user.

#-------------------------------------------------------------------------------

oracle.install.db.config.starterdb.automatedBackup.ospwd=

#-------------------------------------------------------------------------------

# Specify the type of storage to use for the database.

# It can be one of the following:

# - FILE_SYSTEM_STORAGE

# - ASM_STORAGE

#------------------------------------------------------------------------------

oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE

#-------------------------------------------------------------------------------

# Specify the database file location which is a directory for datafiles, control

# files, redo logs.       

#

# Applicable only when oracle.install.db.config.starterdb.storage=FILE_SYSTEM

#-------------------------------------------------------------------------------

oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/home/oracle/tools/oracle11g/oradata

#-------------------------------------------------------------------------------

# Specify the backup and recovery location.

#

# Applicable only when oracle.install.db.config.starterdb.storage=FILE_SYSTEM

#-------------------------------------------------------------------------------

oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/home/oracle/tools/oracle11g/fast_recovery_area

#-------------------------------------------------------------------------------

# Specify the existing ASM disk groups to be used for storage.

#

# Applicable only when oracle.install.db.config.starterdb.storage=ASM

#-------------------------------------------------------------------------------

oracle.install.db.config.asm.diskGroup=

#-------------------------------------------------------------------------------

# Specify the password for ASMSNMP user of the ASM instance.                 

#

# Applicable only when oracle.install.db.config.starterdb.storage=ASM_SYSTEM

#-------------------------------------------------------------------------------

oracle.install.db.config.asm.ASMSNMPPassword=

#------------------------------------------------------------------------------

# Specify the My Oracle Support Account Username.

#

#  Example  : MYORACLESUPPORT_USERNAME=metalink

#------------------------------------------------------------------------------

MYORACLESUPPORT_USERNAME=

#------------------------------------------------------------------------------

# Specify the My Oracle Support Account Username password.

#

# Example    : MYORACLESUPPORT_PASSWORD=password

#------------------------------------------------------------------------------

MYORACLESUPPORT_PASSWORD=

#------------------------------------------------------------------------------

# Specify whether to enable the user to set the password for

# My Oracle Support credentials. The value can be either true or false.

# If left blank it will be assumed to be false.

#

# Example    : SECURITY_UPDATES_VIA_MYORACLESUPPORT=true

#------------------------------------------------------------------------------

SECURITY_UPDATES_VIA_MYORACLESUPPORT=

#------------------------------------------------------------------------------

# Specify whether user wants to give any proxy details for connection.

# The value can be either true or false. If left blank it will be assumed

# to be false.

#

# Example    : DECLINE_SECURITY_UPDATES=false

#------------------------------------------------------------------------------

DECLINE_SECURITY_UPDATES=true

#------------------------------------------------------------------------------

# Specify the Proxy server name. Length should be greater than zero.

#

# Example    : PROXY_HOST=proxy.domain.com

#------------------------------------------------------------------------------

PROXY_HOST=

#------------------------------------------------------------------------------

# Specify the proxy port number. Should be Numeric and atleast 2 chars.

#

# Example    : PROXY_PORT=25

#------------------------------------------------------------------------------

PROXY_PORT=

#------------------------------------------------------------------------------

# Specify the proxy user name. Leave PROXY_USER and PROXY_PWD

# blank if your proxy server requires no authentication.

#

# Example    : PROXY_USER=username

#------------------------------------------------------------------------------

PROXY_USER=

#------------------------------------------------------------------------------

# Specify the proxy password. Leave PROXY_USER and PROXY_PWD 

# blank if your proxy server requires no authentication.

#

# Example    : PROXY_PWD=password

#------------------------------------------------------------------------------

PROXY_PWD=


如果怕麻烦,可以直接把文件下载到本地,把内容全部复制粘贴进去,把线上的覆盖更新。

10、静默安装Oracle 11gR2

操作用户:oracle
操作目录:/home/oracle/database

./runInstaller -silent -force -noconfig -ignorePrereq -responseFile /home/oracle/database/response/db_install.rsp

最终看到以下内容,表明Oracle已经安装成功了

The following configuration scripts need to be executed as the "root" user.
#!/bin/sh
#Root scripts to run/home/oracle/tools/oraInventory/orainstRoot.sh
/home/oracle/tools/oracle11g/product/11.2.0/dbhome_1/root.sh
To execute the configuration scripts:1. Open a terminal window2. Log in as "root"3. Run the scripts4. Return to this window and hit "Enter" key to continueSuccessfully Setup Software.

可能会报错:Checking swap space: 0 MB available, 150 MB required.    Failed 


解决方案:

1、检查 Swap 空间在设置 Swap 文件之前,有必要先检查一下系统里有没有既存的 Swap 文件。运行以下命令:

swapon -s

如果返回的信息概要是空的,则表示 Swap 文件不存在。

2、检查文件系统在设置 Swap 文件之前,同样有必要检查一下文件系统,看看是否有足够的硬盘空间来设置 Swap 。运行以下命令:

df -hal3、创建并允许 Swap 文件下面使用 dd 命令来创建 Swap 文件。检查返回的信息,还剩余足够的硬盘空间即可。
dd if=/dev/zero of=/swapfile bs=1024 count=512k

参数解读:if=文件名:输入文件名,缺省为标准输入。即指定源文件。< if=input file >of=文件名:输出文件名,缺省为标准输出。即指定目的文件。< of=output file >bs=bytes:同时设置读入/输出的块大小为bytes个字节count=blocks:仅拷贝blocks个块,块大小等于bs指定的字节数。

4、格式化并激活 Swap 文件上面已经创建好 Swap 文件,还需要格式化后才能使用。运行命令:

mkswap /swapfile激活 Swap ,运行命令:
swapon /swapfile

以上步骤做完,再次运行命令:

swapon -s 

11、完成安装

操作用户:root

根据上一步完成信息提示,执行以下两行命令,具体位置需要根据你的安装位置决定:

/home/oracle/tools/oraInventory/orainstRoot.sh
/home/oracle/tools/oracle11g/product/11.2.0/dbhome_1/root.sh

12、启动已经安装的数据库orcl

操作用户:oracle

sqlplus /nolog

使用dba权限连接Oralce

connect / as sysdba

可能遇到的错误:sqlplus: error while loading shared libraries: libnsl.so.1: cannot open shared object file: No such file or directory

解决方案:使用如下命令安装一下依赖包

yum install libaio

可能会遇到的错误:-bash: sqlplus: command not found

解决方案:

ln -s /home/oracle/tools/oracle11g/product/11.2.0/dbhome_1/sqlplus /usr/bin

13、启动数据库

startup

可能遇到的错误:ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/home/oracle/tools/oracle11g/product/11.2.0/dbhome_1/dbs/initorcl.ora'

解决方案

启动数据库时使用:

startup pfile='/home/oracle/initorcl.ora'

确认启动结果:

RACLE instance started.Total System Global Area  217157632 bytes
Fixed Size		    2211928 bytes
Variable Size		  159387560 bytes
Database Buffers	   50331648 bytes
Redo Buffers		    5226496 bytes
ORA-00205: error in identifying control file, check alert log for more info

报错:ORA-00205: error in identifying control file, check alert log for more info

解决方案:使用root账号,命令行输入:ipcs -s

CentOS 7 命令行安装 Oracle 11gR2

输入:ipcrm -s 1540096

再输入:ipcs -s

CentOS 7 命令行安装 Oracle 11gR2

输入:ipcs -m

CentOS 7 命令行安装 Oracle 11gR2

14、启动监听

操作用户:oracle

lsnrctl start

查看监听状态,可以确认各个数据库和实例监听服务的状态:

lsnrctl status

确认监听状态:

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 26-AUG-2020 16:14:15Copyright (c) 1991, 2009, Oracle.  All rights reserved.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                26-AUG-2020 16:12:27
Uptime                    0 days 0 hr. 1 min. 48 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Log File         /home/oracle/tools/oracle11g/product/11.2.0/dbhome_1/network/log/listener.log
Listening Endpoints Summary...(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ecs-x-large-4-linux-20200308120508)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).Instance "orcl", status BLOCKED, has 1 handler(s) for this service...
The command completed successfully

15、完成安装

数据库和监听成功启动之后,CentOS 7环境上的Oracle 11gR2就安装完成了。

如果想关掉数据库和监听使用如下命令:

关闭监听
lsnrctl stop关闭数据库
shutdown

16、远程连接

由于数据库是安装到华为云的服务器上的,所以远程连接还需要配置一下。

1)找到安装Oracle时的目录:/home/oracle/tools/oracle11g/product/11.2.0/dbhome_1/network/admin/samples

在这个目录下有两个文件:listener.ora和tnsnames.ora,把这两个文件使用Xftp下载到本地进行修改。

listener.ora修改内容如下:

# copyright (c) 1997 by the Oracle Corporation
# 
# NAME
#   listener.ora
# FUNCTION
#   Network Listener startup parameter file example
# NOTES
#   This file contains all the parameters for listener.ora,
#   and could be used to configure the listener by uncommenting
#   and changing values.  Multiple listeners can be configured
#   in one listener.ora, so listener.ora parameters take the form
#   of SID_LIST_<lsnr>, where <lsnr> is the name of the listener
#   this parameter refers to.  All parameters and values are
#   case-insensitive.# <lsnr>
#   This parameter specifies both the name of the listener, and
#   it listening address(es). Other parameters for this listener
#   us this name in place of <lsnr>.  When not specified,
#   the name for <lsnr> defaults to "LISTENER", with the default
#   address value as shown below.LISTENER =(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=121.36.6.106)(PORT=1521))(ADDRESS=(PROTOCOL=ipc)(KEY=PNPKEY)))	# SID_LIST_<lsnr>
#   List of services the listener knows about and can connect 
#   clients to.  There is no default.  See the Net8 Administrator's
#   Guide for more information.SID_LIST_LISTENER=(SID_LIST=(SID_DESC=#BEQUEATH CONFIG(GLOBAL_DBNAME=salesdb.mycompany)(SID_NAME=sid1)			(ORACLE_HOME=/home/oracle/tools/oracle11g/product/11.2.0/dbhome_1)#PRESPAWN CONFIG(PRESPAWN_MAX=20)(PRESPAWN_LIST=(PRESPAWN_DESC=(PROTOCOL=tcp)(POOL_SIZE=2)(TIMEOUT=1)))))# PASSWORDS_<lsnr>
#   Specifies a password to authenticate stopping the listener.
#   Both encrypted and plain-text values can be set.  Encrypted passwords
#   can be set and stored using lsnrctl.  
#     LSNRCTL> change_password
#       Will prompt for old and new passwords, and use encryption both
#       to match the old password and to set the new one.
#     LSNRCTL> set password
#	Will prompt for the new password, for authentication with 
#       the listener. The password must be set before running the next
#       command.
#     LSNRCTL> save_config
#       Will save the changed password to listener.ora. These last two
#       steps are not necessary if SAVE_CONFIG_ON_STOP_<lsnr> is ON.
#       See below.
#
# Default: NONE
#
# PASSWORDS_LISTENER = 20A22647832FB454      # "foobar"# SAVE_CONFIG_ON_STOP_<lsnr>
#   Tells the listener to save configuration changes to listener.ora when
#   it shuts down.  Changed parameter values will be written to the file,
#   while preserving formatting and comments.
# Default: OFF
# Values: ON/OFF
#
# SAVE_CONFIG_ON_STOP_LISTENER = ON# USE_PLUG_AND_PLAY_<lsnr>
#   Tells the listener to contact an Onames server and register itself
#   and its services with Onames.
# Values: ON/OFF
# Default: OFF
#
# USE_PLUG_AND_PLAY_LISTENER = ON# LOG_FILE_<lsnr>
#   Sets the name of the listener's log file.  The .log extension
#   is added automatically.
# Default=<lsnr>
#
# LOG_FILE_LISTENER = lsnr# LOG_DIRECTORY_<lsnr>
#   Sets the directory for the listener's log file.
# Default: <oracle_home>/network/log
#
# LOG_DIRECTORY_LISTENER = /private/app/oracle/product/8.0.3/network/log# TRACE_LEVEL_<lsnr>
#   Specifies desired tracing level.
# Default: OFF
# Values: OFF/USER/ADMIN/SUPPORT/0-16
#
# TRACE_LEVEL_LISTENER = SUPPORT# TRACE_FILE_<lsnr>
#   Sets the name of the listener's trace file. The .trc extension
#   is added automatically.
# Default: <lsnr>
#
# TRACE_FILE_LISTENER = lsnr# TRACE_DIRECTORY_<lsnr>
#   Sets the directory for the listener's trace file.
# Default: <oracle_home>/network/trace
#
# TRACE_DIRECTORY_LISTENER=/private/app/oracle/product/8.0.3/network/trace
# CONNECT_TIMEOUT_<lsnr>
#   Sets the number of seconds that the listener waits to get a 
#   valid database query after it has been started.
# Default: 10
#
# CONNECT_TIMEOUT_LISTENER=10

修改的内容:

CentOS 7 命令行安装 Oracle 11gR2

tnsnames.ora配置内容:

#ORCL是个别名
#这条信息记录了我们使用TCP协议,去连接IP地址为121.36.6.106,端口号为1521的数据库主机上服务名为orcl的数据库
ORCL =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 121.36.6.106)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = orcl)))

替换掉服务器上的文件。

2)重启服务器Oracle的服务

3)复制tnsnames.ora文件到访问端

4)配置tnsnames.ora文件到环境变量(假设当前电脑是客户端):TNS_ADMIN = D:\Config

 

 

 

 

 

 

 

 

  相关解决方案