操作系统1:CentOS 7(64位)
操作系统2:Windows 7(64位)
win64_11gR2_client.zip # Windows版 oracle 客户端,
# 推荐下载地址:Oracle官网
PLSQL Developer 12 (64 bit)
1.以oracle用户登陆系统启动图形界面
2.桌面上打开一个终端执行netca命令,启动配置助手。
[oracle@zm-centos7 ~]$ netca
3.选择 “Listener configuration”之后一路“Next”,直至完成。
4. 配置完成后,查看配置文件:
[oracle@zm-centos7 oracle]$ cat /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
# listener.ora Network Configuration File:/data/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /data/oracle
[oracle@zm-centos7 oracle]$
说明:
在配置完监听器后,可能由于重启电脑未启动数据库的原因,造成远程客户端访问该监听失败,错误提示:
正在连接...ORA-12545: 因目标主机或对象不存在, 连接失败测试未成功。
面对此问题,在网上查看了解决方法,有人提示在listener.ora中加入如下代码,后经过多次试验,在正确启动监听服务和数据库服务后,无需在listener.ora中加入下面代码,即可实现远程访问,提醒遇到上述问题的朋友。
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME =/data/oracle/product/11.2.0/db_1)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = test)
(ORACLE_HOME =/data/oracle/product/11.2.0/db_1)
(SID_NAME = testsid)
)
)
1. CentOS桌面上的终端窗口中执行以下命令,启动图形界面配置助手。
首先设置下当前语言环境为英文,防止乱码
[oracle@zm-centos7 ~]$ export LANG=enUS
[oracle@zm-centos7 ~]$ dbca
2. 选择“Create a Database”。
3. 选择“General Purpose or Transaction Processing”
4. 填入Database Name“test” 与 SID“testsid”
5.Enterprise Manager配置
如果没有配置监听,这里会提示配置监听后才可以使用EM。
6. Oracle系统用户密码配置,这里选择所有系统用户都使用同样的密码,求省事就“manager”吧。
7.存储类型,保持默认的文件系统
8. Flash Recovery Area位置和大小默认即可
9. 是否建立示便表,这里选是
10. 内存Memory配置
11. 字符集设置:使用Unicode.
Default Language: 选择Simplified Chinese
Default Territory: 选择China
Next
12. 确认没问题,则单击Next
13. 点击Finish,开始创建,直至完成。
14. 安装成功。
15. 在IE里可以输入服务器的IP,登陆Enterprise Manager进行数据库的管理。http://localhost:1158/em
用户名:sys 密码:manager 连接身份:SYSDBA
说明:如果在服务器端不使用oracle客户端软件(如pl/sql developer等)工具,该步可以省略。
在刚才的Net Configuration Assitant窗口中,选择第三个——Local Net Service Name Configuration,点击next
[oracle@zm-centos7 ~]$ netca
选择Add,点击Next,输入实例名test,点击next,选择TCP,点击next,然后输入Host name,这里一般输入本机IP地址,输入localhost或者127.0.0.1应该也可以,端口保持默认1521不变,然后next。
选择“Yes,perform a test”进行连接测试,点击next,会告诉你登录失败,一般都是这样,这时点击Change Login,使用system和之前创建实例时设置的password登录,点击OK,显示Test successful,接着点击next,输入test,再点击next,选择No,然后next,next,回到第一个界面,此时网络配置成功。
可以输入如下命令,查看刚才的配置。(因为这篇文章是接着上一篇写的,我的ORACLE_HOME是/data/oracle/product/11.2.0/db_1/。)
$ cat /data/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File:/data/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
TEST-127 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.201)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = test)
)
)
因为plsql客户端通过tns连接数据库服务器,在客户端需要安装oracle客户端。具体安装过程比较简单,这里不作说明。安装完成之后,需要配置。
在客户端安装路径的network/admin下,即
d:\oracle\product\10.2.0\client_1\NETWORK\ADMIN
有几个比较重要的文件,分别是sqlnet.ora,tnsnames.ora,listener.ora。
这是plsq客户端比较关键的配置文件。这里有几个建议,
(1)将linux服务器上的tnsnames.ora直接拷贝到此处。比手动编写要靠谱些,避免一些错误。当然也可以用客户端的net Configuration Assistant来配置。 (重要,必须配置)
(2)将linux服务器上的sqlnet.ora直接拷贝到此处。(该文件用途不清,不配置也可以进行客户端连接)
(3)使用NetCongratulation Assistant配置监听,配置完之后,会生成新的listener.ora文件。这个不用动。(该文件用途不清,不配置也可以进行客户端连接)
查看配置后的文件tnsnames.ora :
# tnsnames.ora Network Configuration File:E:\oracle_app\Administrator\product\11.2.0\client_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
TEST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.201)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = test)
)
)
1. 重启服务器后,以oracle用户身份登录系统,打开终端窗口,检查oracle用户的环境变量。
$ echo $ORACLE_HOME
/data/oracle/product/11.2.0/db_1
$ echo $ORACLE_SID
orcl
2.进入 cd $ORACLE_HOME/network/admin,检查listener.ora:
[oracle@zm-centos7 /]$ cat /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
# listener.ora Network Configuration File:/data/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT= 1521))
)
)
ADR_BASE_LISTENER = /data/oracle
重点检查其中的SID,HOST,PORT,ORACLE_HOME是否正确。
3.进入$ORACLE_HOME/bin,启动监听器:
[oracle@zm-centos7 /]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.1.0 -Production on 25-SEP-2017 22:48:15
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Starting /data/oracle/product/11.2.0/db_1/bin/tnslsnr:please wait...
TNSLSNR for Linux: Version 11.2.0.1.0 -Production
System parameter file is/data/oracle/product/11.2.0/db_1/network/admin/listener.ora
Log messages written to/data/oracle/diag/tnslsnr/zm-centos7/listener/alert/log.xml
Listening on:(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version11.2.0.1.0 - Production
Start Date 25-SEP-2017 22:48:15
Uptime 0 days 0 hr. 0 min. 10 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File /data/oracle/diag/tnslsnr/zm-centos7/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) forthis service...
Service "test" has 1 instance(s).
Instance "testsid",status UNKNOWN, has 1handler(s) for this service...
The command completed successfully
4. 监听启动正常,使用sqlplus启动数据库:
[oracle@zm-centos7 /]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.1.0 Production onMon Sep 25 22:50:15 2017
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORA-01078: failure in processing systemparameters
LRM-00109: could not open parameter file'/data/oracle/product/11.2.0/db_1/dbs/initorcl.ora'
此处错误是因为在oracle9i和oracle10g中,数据库默认将使用spfile启动数据库,如果spfile不存在,则就会出现上述错误。
解决方法:
将$ORACLE_BASE/admin/数据库名称/pfile目录下的init.ora.8252017165656形式的文件copy 到$ORACLE_HOME/dbs目录下initorcl.ora即可。(注:initorcl.ora中的oracle为你的实例名 ORACLE_SID)
比如我的就为:
[oracle@zm-centos7 /]$ cp /data/oracle/admin/test/pfile/init.ora.8252017165656 /data/oracle/product/11.2.0/db_1/dbs/initorcl.ora
[oracle@zm-centos7 /]$ sqlplus / as sysdba;
SQL*Plus: Release 11.2.0.1.0 Production onMon Sep 25 23:13:04 2017
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 613797888 bytes
Fixed Size 2215824 bytes
Variable Size 364904560 bytes
Database Buffers 239075328 bytes
Redo Buffers 7602176 bytes
Database mounted.
Database opened.
SQL>
5. 查看监听状态
[oracle@zm-centos7 ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.1.0 -Production on 26-SEP-2017 10:35:39
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version11.2.0.1.0 - Production
Start Date 26-SEP-2017 10:33:02
Uptime 0 days 0 hr. 2 min. 36 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File /data/oracle/diag/tnslsnr/zm-centos7/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
Services Summary...
Service "test" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "testsidXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@zm-centos7 ~]$
1. 关闭数据库服务
[oracle@zm-centos7 ~]$ sqlplus / as sysdba;
SQL*Plus: Release 11.2.0.1.0 Production onTue Sep 26 10:29:37 2017
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise EditionRelease 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Miningand Real Application Testing options
SQL> shut
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 11gEnterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Miningand Real Application Testing options
2. 关闭监听服务
[oracle@zm-centos7 ~]$ lsnrctl stop
LSNRCTL for Linux: Version 11.2.0.1.0 -Production on 26-SEP-2017 10:30:28
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
The command completed successfully
[oracle@zm-centos7 ~]$
3. 查看监听状态
[oracle@zm-centos7 ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.1.0 -Production on 26-SEP-2017 10:38:01
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
TNS-00511: No listener
Linux Error: 111: Connectionrefused
[oracle@zm-centos7 ~]$
centOS 7 里面修改hostname的方式有所改变,修改/etc/hosts和/etc/sysconfig/network两个文件已经不能生效。
使用的新命令是 :
#hostnamectl set-hostname zm-centos7
再次启动netca,OK
$ netca