關於oracle的網絡配置 之前一直很亂因爲其中的幾個名字對應有些上頭,在這裏我顏色標記和對應查詢的地方指明出來了,這些都是親自實驗過才說出來的。
網絡原理:
1 客戶端通過配置好的ip、端口、服務名 連接 監聽程序。
2 監聽程序通過sid名去連接數據實例。
3 數據庫實例創建一個服務器進程,然後把服務器進程的地址告訴監聽。
4 監聽在把服務器地址告訴客戶端。
5 客戶端拿着這個地址直接去連接數據庫實例,客戶端會把用戶名和密碼給服務器進程,服務器進程驗證通過後,正式建立鏈接,以後的客戶端和數據庫實例連接都不經過監聽了。
注意:
客戶端和數據庫實例一旦連接以後,及時監聽程序掛了以後,也沒任何影響。
我通常把監聽程序理解爲 紅娘,就是把客戶端和數據庫實例牽紅線的,一點雙方同意,他就退出不妨礙他們辦事了。
配置方式:
服務端: 配置監聽
cd $ORACLE_HOME/network/admin/listener.ora
-------------------------------------------------------------------
#監聽位置
LISTENER =
(DESCRIPTION = 對應本機地址|主機名
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.170)(PORT = 1522))
)
#數據庫服務
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = asmdb) --> show parameter db_unique_name
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(SID_NAME = asmdb) --> echo $ORACLE_SID
)
)
客戶端:只需要配置服務命名
cd $ORACLE_HOME/network/admin/tnsnames.ora
-------------------------------------------
170 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.170)(PORT = 1522))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = asmdb) --> lsnrctl status --> Service "asmdb" | show parameter service_names
)
)
實例操作驗證真理:
實驗環境介紹:
服務器系統版本:CentOS release 5.8 (Final)
數據庫版本:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
服務器1地址 主機名xcy1 ip:192.168.1.170
服務器2地址 主機名xcy2 ip:192.168.1.180
數據庫1 : 實例名 orcl
數據庫2:實例名 xcy
實驗目標:
數據庫1 通過網絡鏈接訪問數據庫2
服務器1操作步驟:
[oracle@xcy1 admin]$ vim /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(PROGRAM = extproc)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(SID_NAME = orcl)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.180)(PORT = 1521))
)
)
啓動監聽
[oracle@xcy1 admin]$ lsnrctl start
LSNRCTL for Linux: Version 10.2.0.1.0 - Production on 21-APR-2014 04:53:59
Copyright (c) 1991, 2005, Oracle. All rights reserved.
Starting /u01/app/oracle/product/10.2.0/db_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 10.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.180)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.1.0 - Production
Start Date 21-APR-2014 04:53:59
Uptime 0 days 0 hr. 0 min. 3 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/10.2.0/db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/product/10.2.0/db_1/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.1.190)(PORT=1521)))
Services Summary...
Service "xcy" has 1 instance(s).
Instance "xcy", status UNKNOWN, has 1 handler(s) for this service... ---這表明服務器已經啓用生效,服務進程在。
The command completed successfully
[oracle@xcy1 admin]$
服務器2操作步驟:
[oracle@xcy2 admin]$ vim /u01/app/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
XCY =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.180)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = xcy)
)
)
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
[oracle@xcy1 admin]$ sqlplus scott/tiger@xcy
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Apr 21 04:50:46 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL>
也可以進行直連方式:
[oracle@xcy1 admin]$ sqlplus scott/[email protected]:1521/xcy
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Apr 21 04:52:07 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL>
如果鏈接不上的情況出現,我在這裏提供一下簡單的排錯思路:
sqlplus scott/tiger@xcy
1 在服務器端 查看監聽程序是否啓動 命令: lsnrctl status
2 在服務器端配置tnsnames.ora 然後進行鏈接 命令:sqlplus scott/tiger@xcy 如果不可鏈接那麼說明服務器端配置有問題,反之客戶端的問題。
3 在客戶端進行 監聽文件是否可以讀取正常,命令:tnsping 【實例名】 比如: tnsping xcy 如果顯示OK (20 msec) 則表明正常,如果不能平通 請仔細檢查tnsnames.ora文件。
好了 先簡單描述這些吧,因爲我也是在學習當中,所以有很多地方不是很全面。
在上述描述中如果有不正確的地方,麻煩多多指出來。我會改正的。說了這麼多希望能對和我一樣剛入門的同學一些幫助,少走一些彎路。