Oracle 监听器配置

Oracle数据库通过监听器与客户端建立连接,监听器程序由一个Oracle文件进行管理,文件名为listener.ora,Linux系统下存放于$ORACL_HOME/network/admin目录下。监听器必须运行在Oracle数据库服务器上,数据库服务通过动态注册或静态注册两种方式注册到监听器程序后,客户端即可通过监听器访问对应的数据库。

一、监听器配置

如下为一段监听文件的配置,有配置可以LISTENER采用TCP协议,数据库地址为192.168.0.9,默认端口为1521。如要新增监听器,可以直接修改该文件添加。

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.9)(PORT = 1521))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

监听器常用命令

Oralce使用lsnrct命令完成监听器程序的日常管理,常用命令有
lsnrctl status   #查看监听器状态 
lsnrctl start     #启动监听器
lsnrctl stop      #停止监听程序

二、动态注册

查看监听器状态:

[oracle@centos6 admin]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 11-SEP-2018 08:19:45

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.9)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                11-SEP-2018 08:19:39
Uptime                    0 days 0 hr. 0 min. 5 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/centos6/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.9)(PORT=1521)))
The listener supports no services
The command completed successfully

由上述信息可知监听器没有任何服务注册过来,可以通过修改local_listener参数让数据库动态注册到监听器上,例子如下:

SQL> alter system set
  2  local_listener='(address_list=(address=(protocol=tcp)(host=192.168.0.9)(port=1521)))';

System altered.

改参数已经修改立即生效,此时查看系统中的local_listener指和监听器状态如下:

SQL> show parameter local_listener;

NAME				     TYPE
------------------------------------ ---------------------------------
VALUE
------------------------------
local_listener			     string
(address_list=(address=(protoc
ol=tcp)(host=192.168.0.9)(port
=1521)))
[oracle@centos6 admin]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 11-SEP-2018 08:30:55

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.9)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                11-SEP-2018 08:19:39
Uptime                    0 days 0 hr. 11 min. 16 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/centos6/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.9)(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

由上述信息可知数据库服务已经注册过来了。

三、静态注册

先执行如下代码停止系统自动注册

SQL> alter system set 
  2  local_listener='';

System altered.

此时系统监听状态如下

[oracle@centos6 admin]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 11-SEP-2018 08:35:26

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.9)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                11-SEP-2018 08:19:39
Uptime                    0 days 0 hr. 15 min. 47 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/centos6/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.9)(PORT=1521)))
The listener supports no services
The command completed successfully

静态注册是间数据库信息直接写到监听器配置文件中,当监听器启动时就会自动注册数据库服务,达道静态注册的效果。需要注意的是,采用静态注册方式,在修改监听器配置文件后,需要重启监听器配置才能生效。具体配置参考如下例子:

[oracle@centos6 admin]$ cat listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.0.9)(PORT = 1521))
    )
  )
SID_LIST_LISTENER=
  (SID_LIST=
            (SID_DESC=
                 (SID_NAME=orcl)
                 (ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1)
                 (GLOBAL_DBNAME=orcl)
            )
  )
ADR_BASE_LISTENER = /u01/app/oracle

重启监听程序后,查看监听器状态:

[oracle@centos6 admin]$ lsnrctl stop

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 11-SEP-2018 08:39:34

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.9)(PORT=1521)))
The command completed successfully
[oracle@centos6 admin]$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 11-SEP-2018 08:39:44

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/centos6/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.9)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.9)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                11-SEP-2018 08:39:44
Uptime                    0 days 0 hr. 0 min. 0 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/centos6/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.9)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
  Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

由上述信息可知,监听器已正常启动起来。

CentOS 6.8 安装Oracle 11G

一、软件版本
操作系统:CentOS Linux release 6.8
Oracle 版本:linux.x64_11gR2_database
二、依赖包
binutils-2.20.51.0.2-5.11.el6.i686 compat-libcap1-1.10-1.i686 compat-libstdc++-33-3.2.3-69.el6.i686 gcc-4.4.4-13.el6.i686 gcc-c++-4.4.4-13.el6.i686 glibc-2.12-1.7.el6.i686 glibc-devel-2.12-1.7.el6.i686 ksh libgcc-4.4.4-13.el6.i686 libstdc++-4.4.4-13.el6.i686 libstdc++-devel-4.4.4-13.el6.i686 libaio-0.3.107-10.el6.i686 libaio-devel-0.3.107-10.el6.i686 make-3.81-19.el6.i686 sysstat-9.0.4-11.el6.i686
安装命令
# yum -y install binutils* compat-libcap1* compat-libstdc++* gcc* gcc-c++* glibc* glibc-devel* ksh* libaio* libaio-devel* libgcc* libstdc++* libstdc++-devel* libXi* libXtst* make* sysstat* elfutils* unixODBC*
三、安装前准备
1.创建用户组和用户
使用root用户登录,创建Oracle11g 数据所需的用户组与用户。
#创建用户组dba
#groupadd dba
#创建用户组oinstall
#groupadd oinstall
#创建软件用户
#useradd -g oinstall -G dba oracle
#创建用户密码
#passwd oracle
2.修改Oracle软件安装用户的Shell限制
在文件/etc/security/limits.conf中增加如下参数设置
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
3.修改内核参数
编辑文件/etc/sysctl.conf,增加如下参数
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.rp_filter = 1
fs.file-max = 6815744 #设置最大打开文件数
fs.aio-max-nr = 1048576
kernel.shmall = 2097152 #共享内存的总量,8G内存设置:2097152*4k/1024/1024
kernel.shmmax = 2147483648 #最大共享内存的段大小
kernel.shmmni = 4096 #整个系统共享内存端的最大数
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500 #可使用的IPv4端口范围
net.core.rmem_default = 262144
net.core.rmem_max= 4194304
net.core.wmem_default= 262144
net.core.wmem_max= 1048576
使配置文件生效
# sysctl -p

4.创建软件目录

Oracle Base为Oracle顶层目录,Oracle推荐的为/mount_point/app/software_owner,其中mount_point指挂节点目录,software_owner指软件用户,已Oracle用户为例,其目录为/u01/app/oracle
创建Oracle Base目录
#mkdir -p /u01/app/oracle
创建数据库文件目录
#mkdir /u01/app/oracle/oradata
修改权限
#chown -R oracle:oinstall /u01/app/oracle
#chmod -R 755 /u01/app/oracle
配置环境变量
切换oracle 用户,输入vi .bash_profile,增加一下内容
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:/usr/sbin:$PATH
export ORACLE_TERM=xterm #xterm窗口模式安装
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib #添加系统环境变量
export LANG=C #防止安装过程出现乱码
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK #设置Oracle客户端字符集,必须与Oracle安装时设置的字符集保持一致
5.修改系统名称
Oracle默认不支持CentOS系统安装,但是CentOS是RedHat开源版,只要将系统标识改为RedHat即可绕过。切换到root用户进行修改:
#vi /etc/redhat-release
修改为:Red Hat Enterprise Linux 6
6.上传文件
将文件上传到oracle用户目录
新建database目录
#mkdir database
解压缩文件
#unzip linux.x64_11gR2_database_1of2.zip -d ./database/
#unzip linux.x64_11gR2_database_2of2.zip -d ./database/
四、软件安装
使用oracle用户登录系统,
进入安装目录
[oracle@192 database]$ cd /home/oracle/database/database
执行安装程序
#[oracle@192 database]$ ./runInstaller

终于安装界面弹出来了,选择不自动更新,点next

选择只安装数据库软件
选择创建单实例数据库
语言选英文
这里选择企业版
确认文件目录
逐一确认安装包是否已经安装过,如果本地的版本更高,可以忽略
安装进行中
RDBMS软件安装完毕后,会要求用root用户执行两个脚本。
至此数据库安装完毕