采樣:
[oracle@sh02 ~]$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.4 (Santiago) [oracle@sh02 ~]$ uname -r 2.6.32-358.el6.x86_64 [oracle@shfpdb02 ~]$ uname -r 2.6.32-358.el6.x86_64 [oracle@shfpdb02 ~]$ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 80 On-line CPU(s) list: 0-79 Thread(s) per core: 2 Core(s) per socket: 10 Socket(s): 4 NUMA node(s): 4 Vendor ID: GenuineIntel CPU family: 6 Model: 62 Stepping: 7 CPU MHz: 2194.697 BogoMIPS: 4388.89 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 20480K NUMA node0 CPU(s): 0-9,40-49 NUMA node1 CPU(s): 10-19,50-59 NUMA node2 CPU(s): 20-29,60-69 NUMA node3 CPU(s): 30-39,70-79
查看監聽器是否啟用,查看監聽狀態:
//做兩個測試,因為節點是兩個,當前節點的監聽器停止
[grid@sh02 ~]$ srvctl status listener
Listener LISTENER is enabled
Listener LISTENER is running on node(s): shfpdb01
//啟動監聽器
[grid@sh02 ~]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-MAR-2022 16:30:59
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Starting /u01/app/11.2.0/grid/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.4.0 - Production
System parameter file is /u01/app/11.2.0/grid/network/admin/listener.ora
Log messages written to /u01/app/grid/diag/tnslsnr/shfpdb02/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date 11-MAR-2022 16:30:59
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/11.2.0/grid/network/admin/listener.ora
Listener Log File /u01/app/grid/diag/tnslsnr/sh02/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
Services Summary...
Service "ht" has 1 instance(s).
Instance "ht", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
//重新查看本地監聽器
[grid@sh02 ~]$ srvctl status listener
Listener LISTENER is enabled
Listener LISTENER is running on node(s): sh02,sh01
//查看進程
[grid@sh02 ~]$ ps -efww |grep lsnr//注意這里的所屬用戶,否則你設置了密碼保護之后,只能用所屬用戶登錄后才能進行更改
grid 12854 1 0 15:46 ? 00:00:00 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER_SCAN1 -inherit
grid 32735 1 0 16:30 ? 00:00:00 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER -inherit
grid 33921 31866 0 16:33 pts/0 00:00:00 grep lsnr
//我們進入oracle用戶,嘗試停止監聽
[grid@sh02 ~]$ exit
logout
[root@sh02 ~]# su - oracle
[oracle@sh02 ~]$ lsnrctl stop
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-MAR-2022 16:34:30
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
TNS-01190: The user is not authorized to execute the requested listener command
lsnrctl命令常用參數詳解:
1)start 啟動指定的監聽器 2)stop 關閉指定的監聽器 3)status 顯示監聽器的狀態。status命令顯示監聽器是不是活動的,日志與跟蹤文件的位置, 監聽器已經持續運行了多長時間,以及監聽器所監聽的任務。 4)services 列舉監聽器的服務信息,比如這些服務是否有任何專用的預生成服務器進程或與之相關的調度進程,以及每個服務已有多少連接被接受或拒絕。
這種方法用來檢查一個監聽器是否在監聽一個指定服務。 列出服務的一個匯總表及為每個協議服務處理程序所建立和拒絕的連接信息個數。 5)Version 顯示oracle net軟件與協議適配器的版本。 6)reload 重新裝入監聽器,重新讀取listener.ora文件,但不關閉監聽器。如果該文件發生了變化,重新刷新監聽器。 7)save_config 當從lsnrctl工具中對listener.ora文件進行了修改時,復制一個叫做listener.bak的listener.ora的文件。 8)trace 打開監聽器的跟蹤特性。 9)change_password 允許用戶修改關閉監聽器所需要的密碼。 10)quit 退出lsnrctl工具。 set* password 指定在lsnrctl命令行工具中執行管理任務所需要的密碼。
trc_file 指定監聽器跟蹤信息的位置。默認設置是$ORACLE_HOME\network\trace\listener.trc trc_directory trc_level 跟蹤級別 OFF – 未啟用跟蹤功能。OFF 為默認設置。 USER – 將跟蹤設置為用戶的相應級別。跟蹤以標識用戶導致的錯誤條件。 ADMIN – 將跟蹤設置為數據庫管理員的相應級別。跟蹤以標識特定的安裝問題。 SUPPORT – 將跟蹤設置為客戶支持人員的相應級別。 跟蹤文件可能會變得很大。 Oracle Corporation 建議在不進行網絡問題診斷時關閉跟蹤功能。 log_file 指定一個監聽器將把日志信息寫到哪里。這個參數在默認的情況下是ON,並默認為%oracle_home%\network\log\listener.log log_directory log_status current_listener inbound_connect_timeout 定義監聽器在一個會話得到啟動時將等待的有效響應時間。默認設置為10秒。 startup_waittime 定義監聽器在響應lsnrctl命令行工具中的一條status命令之前將等待多長時間。 save_config_on_stop 指定在一個lsnrctl會話期內所發生的修改在退出時是否應該被保存起來。
show命令

rawmode
顯示關於status和service的較詳細信息(當他們設置成on時)值為ON或OFF。
displaymode
把lsnrctl工具的顯示模式設置成raw、compact、normal或verbose
服務顯示模式為NORMAL
rules
trc_file
指定監聽器跟蹤信息的位置。默認設置是$ORACLE_HOME\network\trace\listener.trc
current_listener
目前的監聽器為 listener2
inbound_connect_timeout
定義監聽器在一個會話得到啟動時將等待的有效響應時間。默認設置為10秒。
startup_waittime
定義監聽器在響應lsnrctl命令行工具中的一條status命令之前將等待多長時間。
snmp_visible
save_config_on_stop
指定在一個lsnrctl會話期內所發生的修改在退出時是否應該被保存起來。
命令演示
LSNRCTL> help The following operations are available An asterisk (*) denotes a modifier or extended command: start stop status services version reload save_config trace spawn change_password quit exit set* show*
//change_password改變監聽密碼
//save_config 執行該命令后,會備份listenr.ora,同時設置到listenr.ora文件
LSNRCTL> version
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
TNSLSNR for Linux: Version 11.2.0.4.0 - Production
TNS for Linux: Version 11.2.0.4.0 - Production
Unix Domain Socket IPC NT Protocol Adaptor for Linux: Version 11.2.0.4.0 - Production
Oracle Bequeath NT Protocol Adapter for Linux: Version 11.2.0.4.0 - Production
TCP/IP NT Protocol Adapter for Linux: Version 11.2.0.4.0 - Production,,
The command completed successfully
LSNRCTL> status
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER //監聽器名為LISTENER
------------------------
Alias LISTENER //別名LISTENER
Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production //版本信息
Start Date 15-DEC-2021 11:18:18 //啟動時間
Uptime 86 days 2 hr. 30 min. 23 sec //正常運行
Trace Level off //跟蹤級別
Security ON: Local OS Authentication //安全性
SNMP OFF
Listener Parameter File /u01/app/11.2.0/grid/network/admin/listener.ora //監聽程序參數文件
Listener Log File /u01/app/grid/diag/tnslsnr/sh02/listener/alert/log.xml //監聽程序log文件
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.128.51.21)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.128.51.24)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM2", status READY, has 1 handler(s) for this service...
Service "fp" has 1 instance(s).
Instance "fp2", status READY, has 1 handler(s) for this service...
Service "ht" has 1 instance(s).
Instance "ht2", status UNKNOWN, has 1 handler(s) for this service...
LSNRCTL> show 或者 help show
The following operations are available after show //以下是有效的,跟在show命令之后,例如:show
An asterisk (*) denotes a modifier or extended command:
rawmode displaymode //
rules trc_file
trc_directory trc_level
log_file log_directory
log_status current_listener
inbound_connect_timeout startup_waittime
snmp_visible save_config_on_stop
dynamic_registration enable_global_dynamic_endpoint
oracle_home pid
connection_rate_limit valid_node_checking_registration
registration_invited_nodes registration_excluded_nodes
LSNRCTL> show trc_file
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
TNS-01190: The user is not authorized to execute the requested listener command
TNS-01190: 用戶無權執行所請求的監聽程序命令
LSNRCTL> show trc_directory
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
TNS-01190: The user is not authorized to execute the requested listener command
TNS-01190: 用戶無權執行所請求的監聽程序命令
Oracle lsnrctl設置密碼
1、設置監聽器的口令.默認口令為空.
LSNRCTL> change_password
2、設置session級別的密碼,如果密碼錯誤,不報錯,也顯示”命令執行成功”,但不能停止監聽器.
LSNRCTL> set password
3、保存到配置文件,否則下次登陸,以前設置的密碼無效.
LSNRCTL> save_config
lsnrctl 監聽命令
[grid@sh02 ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 10-MAR-2022 20:21:04 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.4.0 - Production Start Date 15-DEC-2021 11:18:18 Uptime 85 days 9 hr. 2 min. 46 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /u01/app/11.2.0/grid/network/admin/listener.ora Listener Log File /u01/app/grid/diag/tnslsnr/sh02/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.128.51.21)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.128.51.24)(PORT=1521))) Services Summary... Service "+ASM" has 1 instance(s). //有一個服務未+ASM,數據庫實例名為:+ASM2 Instance "+ASM2", status READY, has 1 handler(s) for this service... //狀態ready說明是目前處於動態注冊 Service "fp" has 1 instance(s). Instance "fp2", status READY, has 1 handler(s) for this service... Service "ht" has 1 instance(s). Instance "ht2", status UNKNOWN, has 1 handler(s) for this service... //狀態處於UNKNOWN表明處於靜態注冊
列舉監聽器的服務信息
[oracle@sh02 ~]$ lsnrctl services LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-MAR-2022 13:30:38 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) Services Summary... Service "+ASM" has 1 instance(s). Instance "+ASM2", status READY, has 1 handler(s) for this service... Handler(s): "DEDICATED" established:0 refused:0 state:ready LOCAL SERVER Service "fp" has 1 instance(s). Instance "fp2", status READY, has 1 handler(s) for this service... Handler(s): "DEDICATED" established:1791 refused:0 state:ready LOCAL SERVER
//htcmsdb服務 Service "ht" has 1 instance(s). Instance "ht2", status UNKNOWN, has 1 handler(s) for this service... Handler(s): "DEDICATED" established:0 refused:0 LOCAL SERVER The command completed successfully
三個監聽文件
[grid@sh02 ~]$ locate sqlnet.ora /u01/app/11.2.0/grid/network/admin/sqlnet.ora
[grid@sh02 ~]$ locate tnsnames.ora/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
[grid@sh02 ~]$ locate listener.ora /u01/app/11.2.0/grid/network/admin/listener.ora
//查看監聽文件
[oracle@sh02 ~]$ cat /u01/app/11.2.0/grid/network/admin/listener.ora
LISTENER_SCAN1=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1)))) # line added by Agent
LISTENER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))) #出一個監聽器定義的起始點
ENABLE_GLOBAL_DYNAMIC_ENDPOINT_LISTENER=ON # line added by Agent
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = htcmsdb)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1) //安裝位置
(SID_NAME =htcmsdb2) //oracle sid
)
)
監聽文件的各個參數的作用描述如下:
LISTENER 指出一個監聽器定義的起始點。它實際上是正被定義的當前監聽器的名稱。默認的名稱是LISTENER。
DESCRIPTION 描述每個監聽位置
ADDRESS_LIST 含有與監聽器正在監聽的那些位置有關的地址信息
PROTOCOL 指定用於本監聽位置的協議
HOST 保存監聽器所駐留在的那台計算機的名稱
PORT 含有監聽器正在上面監聽的地址
SID_LIST_LISTENER 定義配置監聽器所針對的ORACLE服務的列表
SID_DESC 描述每個Oracel SID
GLOBAL_DBNAME 標識全局數據庫名稱。本項應該與當前Oracle服務的 init.ora 文件中的SERVICE_NAMES項要一致
ORACLE_HOME 給出服務器上Oracle可執行程序的位置
SID_NAME 含有用於本Oracle實例的Oracle SID的名稱
如果你對監聽設置了密碼
[oracle@sh02 ~]$ lsnrctl stop LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 11-MAR-2022 14:29:51 Copyright (c) 1991, 2013, Oracle. All rights reserved. Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)) TNS-01190: The user is not authorized to execute the requested listener command
//不允許隨便關閉監聽
由於集群采用的scan 監聽器對外服務,所以這里要講這塊,遠程訪問時,如果關閉scan 監聽就會找不到監聽器,但是關閉本地監聽器沒有關系.
修改SCAN Listener的端口配置
[oracle@sh02 ~]$ ps -ef | grep -i tns
root 405 2 0 2021 ? 00:00:00 [netns]
grid 12854 1 0 15:46 ? 00:00:00 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER_SCAN1 -inherit
grid 32735 1 0 16:30 ? 00:00:00 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER -inherit
1、修改前,先檢查一下SCAN及SCAN Listener 的配置情況:
[oracle@sh02 ~]$ srvctl config scan
SCAN name: sh-cluster-scan, Network: 1/10.128.51.0/255.255.255.0/eth0
SCAN VIP name: scan1, IP: /sh-cluster-scan/10.128.51.22
2、關閉SCAN Listener
[oracle@sh02 ~]$ srvctl stop scan_listener
3、檢查是否被關閉
[oracle@sh02 ~]$ srvctl status scan_listener
SCAN Listener LISTENER_SCAN1 is enabled
SCAN listener LISTENER_SCAN1 is not running
客戶端連接出現

4、修改端口 srvctl modify scan_listener -p 1526
srvctl modify scan_listener -endpoints 1526
5、檢查修改是否生效
[oracle@sh02 ~]$ srvctl start scan
PRCC-1014 : scan1 was already running
PRCR-1004 : Resource ora.scan1.vip is already running
PRCR-1079 : Failed to start resource ora.scan1.vip
CRS-5702: Resource 'ora.scan1.vip' is already running on 'sh02'
[oracle@sh02 ~]$ srvctl config scan_listener
SCAN Listener LISTENER_SCAN1 exists. Port: TCP:1521
6、啟動SCAN Listener: [oracle@sh02 ~]$ srvctl start scan_listener
//啟動后,ps/sql能夠正常登錄 7、檢查下,確保成功 srvctl status scan_listener srvctl modify 命令除了能夠修改SCAN端口,還可以修改SCAN的名字: srvctl modify scan -n newname
停止和啟動scan listener時要注意下
//我在oracle用戶在執行啟動scan listener
[oracle@sh02 ~]$ srvctl start scan_listener
//查看進程看不到scan
[oracle@sh02 ~]$ ps -ef | grep -i tns
root 405 2 0 2021 ? 00:00:00 [netns]
grid 32735 1 0 16:30 ? 00:00:00 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER -inherit
//停止sacn_listener
[oracle@sh02 ~]$ srvctl stop scan_listener
//退出
[oracle@sh02 ~]$ exit
logout
//用grid用戶登錄
[root@sh02 ~]# su - grid
[grid@sh02 ~]$ srvctl stop scan_listener
PRCC-1016 : LISTENER_SCAN1 was already stopped
PRCR-1005 : Resource ora.LISTENER_SCAN1.lsnr is already stopped
//啟動scan_listener
[grid@sh02 ~]$ srvctl start scan_listener
[grid@sh02 ~]$ ps -efww |grep lsnr
grid 32735 1 0 16:30 ? 00:00:00 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER -inherit
grid 42083 1 0 16:50 ? 00:00:00 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER_SCAN1 -inherit
grid 42195 41859 0 16:50 pts/0 00:00:00 grep lsnr
[grid@sh02 ~]$ ps -efww |grep tns
root 405 2 0 2021 ? 00:00:00 [netns]
grid 32735 1 0 16:30 ? 00:00:00 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER -inherit
grid 42083 1 0 16:50 ? 00:00:00 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER_SCAN1 -inherit
grid 42224 41859 0 16:50 pts/0 00:00:00 grep tns
//再回到oracle用戶,這個時候就可以查看到
[oracle@sh02 ~]$ ps -ef | grep tns
root 405 2 0 2021 ? 00:00:00 [netns]
grid 32735 1 0 16:30 ? 00:00:00 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER -inherit
grid 42083 1 0 16:50 ? 00:00:00 /u01/app/11.2.0/grid/bin/tnslsnr LISTENER_SCAN1 -inherit
oracle 43393 43352 0 16:53 pts/0 00:00:00 grep tns
我們看看關閉本地監聽器對本地登錄是否有影響
//現在是關閉了本地和scan情況下
[oracle@sh02 ~]$ sqlplus sh/Sh12@10.128.51.22:1521/fp SQL*Plus: Release 11.2.0.4.0 Production on Fri Mar 11 17:05:45 2022 Copyright (c) 1982, 2013, Oracle. All rights reserved. ERROR: ORA-12541: TNS:no listener Enter user-name: ERROR: ORA-01017: invalid username/password; logon denied Enter user-name: ERROR: ORA-01017: invalid username/password; logon denied SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
//啟動scan
[oracle@sh02 ~]$ srvctl start scan_listener
[oracle@sh02 ~]$ sqlplus sh/Sh12@10.128.51.22:1521/fp
SQL*Plus: Release 11.2.0.4.0 Production on Fri Mar 11 17:08:23 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
SQL>
//關閉scan,啟動本地,報錯
所以一旦開啟scan模式,則本地監聽器是可有可無的.
