剖析Oracle的网络结构轻松解决连接问题 发布时间:2007.09.26 05:01 来源:赛迪网 作者:xiaoqiao Oracle的网络结构: 首先我们来看以下三个配置文件: listener.ora、sqlnet.ora、tnsnames.ora (注释:都放在$ORACLE_HOME\network\admin目录下) 三个文件的
剖析Oracle的网络结构轻松解决连接问题
|
发布时间:2007.09.26 05:01 来源:赛迪网 作者:xiaoqiao |
Oracle的网络结构: 首先我们来看以下三个配置文件:
三个文件的作用和使用 #--- sqlnet.ora-----作用类似于linux或者其他unix的nsswitch.conf文件,通过这个文件来决定怎么样找一个连接中所出现的连接字符串。 例:在客户端输入
假如我的sqlnet.ora如下所示:
那么,客户端就会首先在tnsnames.ora文件中找orcl的记录.如果没有相应的记录则尝试把orcl当作一个主机名,通过网络的途径去解析它的ip地址然后去连接这个ip上GLOBAL_DBNAME=orcl这个实例,当然我这里orcl并不是一个主机名,示例:
那么客户端就只会从tnsnames.ora查找orcl的记录,括号中还有其他选项,如LDAP等并不常用。 #--- Tnsnames.ora------这个文件类似于unix 的hosts文件,提供的tnsname到主机名或者ip的对应,只有当sqlnet.ora中类似 NAMES.DIRECTORY_PATH= (TNSNAMES) 这样,也就是客户端解析连接字符串的顺序中有TNSNAMES是,才会尝试使用这个文件。 例子中有两个,ORCL 对应的本机,SALES对应的另外一个IP地址,里边还定义了使用主用服务器还是共享服务器模式进行连接。 #你所要连接的时候输入得TNSNAME
|
关于listener进程就不多说了,接受远程对数据库的接入申请并转交给oracle的服务器进程。所以如果不是使用的远程的连接,listener进程就不是必需的,同样的如果关闭listener进程并不会影响已经存在的数据库连接。
Listener.ora文件的例子
#listener.ora Network Configuration File: #E:\oracle\product\10.1.0\Db_2\NETWORK\ADMIN\listener.ora # Generated by Oracle configuration tools. |
#下面定义LISTENER进程为哪个实例提供服务
#这里是ORCL,并且它对应的ORACLE_HOME和GLOBAL_DBNAME
#其中GLOBAL_DBNAME不是必需的除非使用HOSTNAME做数据库连接
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = boway) (ORACLE_HOME = E:\oracle\product\10.1.0\Db_2) (SID_NAME = ORCL) ) ) |
#监听器的名字,一台数据库可以有不止一个监听器
#再向下面是监听器监听的协议,ip,端口等,这里使用的tcp1521端口,并且使#用的是主机名
LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = boway)(PORT = 1521)) ) |
上面的例子是一个最简单的例子,但也是最普遍的。一个listener进程为一个instance(SID)提供服务。
监听器的操作命令
$ORACLE_HOME/bin/lsnrctl start,其他诸如stop,status等。具体敲完一个lsnrctl后看帮助。
上面说到的三个文件都可以通过图形的配置工具来完成配置
$ORACLE_HOME/netca 向导形式的
$ORACLE_HOME/netmgr
本人比较习惯netmgr,
profile 配置的是sqlnet.ora也就是名称解析的方式
service name 配置的是tnsnames.ora文件
listeners配置的是listener.ora文件,即监听器进程
具体的配置可以尝试一下然后来看一下配置文件。
这样一来总体结构就有了,是
当你输入sqlplus sys/oracle@orcl的时候
1. 查询sqlnet.ora看看名称的解析方式,发现是TNSNAME
2. 则查询tnsnames.ora文件,从里边找orcl的记录,并且找到主机名,端口和service_name
3. 如果listener进程没有问题的话,建立与listener进程的连接。
4. 根据不同的服务器模式如专用服务器模式或者共享服务器模式,listener采取接下去的动作。默认是专用服务器模式,没有问题的话客户端就连接上了数据库的server process。
5. 这时候网络连接已经建立,listener进程的历史使命也就完成了。
#---------------
几种连接用到的命令形式
1.sqlplus / as sysdba 这是典型的操作系统认证,不需要listener进程
2.sqlplus sys/oracle 这种连接方式只能连接本机数据库,同样不需要listener进程
3.sqlplus sys/oracle@orcl 这种方式需要listener进程处于可用状态。最普遍的通过网络连接。
以上连接方式使用sys用户或者其他通过密码文件验证的用户都不需要数据库处于可用状态,操作系统认证也不需要数据库可用,普通用户因为是数据库认证,所以数据库必需处于open状态。
然后就是
#-------------
平时排错可能会用到的
1.lsnrctl status查看服务器端listener进程的状态
LSNRCTL>; help The following operations are available An asterisk (*) denotes a modifier or extended command: start stop status services version reload save_config trace change_password quit exit set* show* LSNRCTL>; status :em11: |
2.tnsping 查看客户端sqlnet.ora和tnsname.ora文件的配置正确与否,及对应的服务器的listener进程的状态。
C:\>;tnsping orcl TNS Ping Utility for 32-bit Windows: Version 10.1.0.2.0 - Production on 16-8月 - 2005 09:36:08 Copyright (c) 1997, 2003, Oracle. All rights reserved. Used parameter files: E:\oracle\product\10.1.0\Db_2\network\admin\sqlnet.ora Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = 127.0.0.1)(PORT = 1521))) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_ NAME = orcl))) OK (20 msec) |
3.
SQL>;show sga 查看instance是否已经启动
SQL>; select open_mode from v$database; 查看数据库是打开还是mount状态。 OPEN_MODE ---------- READ WRITE #----------------- |
使用hostname访问数据库而不是tnsname的例子
使用tnsname访问数据库是默认的方式,但是也带来点问题,那就是客户端都是需要配置tnsnames.ora文件的。如果你的数据库服务器地址发生改变,就需要重新编辑客户端这个文件。通过hostname访问数据库就没有了这个麻烦。
需要修改
服务器端listener.ora
#监听器的配置文件listener.ora #使用host naming则不再需要tnsname.ora文件做本地解析 # listener.ora Network Configuration File: d:\oracle\product\10.1.0\db_1\NETWORK\ADMIN\listener.ora # Generated by Oracle configuration tools. SID_LIST_LISTENER = (SID_LIST = (SID_DESC = # (SID_NAME = PLSExtProc) (SID_NAME = orcl) (GLOBAL_DBNAME = boway) (ORACLE_HOME = d:\oracle\product\10.1.0\db_1) # (PROGRAM = extproc) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC)) ) (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (HOST = boway)(PORT = 1521)) ) ) |
客户端sqlnet.ora 如果确认不会使用TNSNAME访问的话,可以去掉TNSNAMES。
# sqlnet.ora Network Configuration File: d:\oracle\product\10.1.0\db_1\NETWORK\ADMIN\sqlnet.ora # Generated by Oracle configuration tools. SQLNET.AUTHENTICATION_SERVICES= (NTS) NAMES.DIRECTORY_PATH= (HOSTNAME) |
Tnsnames.ora文件不需要配置,删除也可以。
下面需要解决的是网络和操作系统的配置问题。(解析我的主机名)
连接示例:
sqlplus sys/oracle@boway |
这样,就会连接boway服务器了。(listener来确定你所要连接的service_name)
参考:
在Oracle的网络结构中解决连接问题 谷歌

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
