程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> CentOSOracle報EnvironmentvariableORACLE_UNQNAMEnotdefined錯誤的解決辦法

CentOSOracle報EnvironmentvariableORACLE_UNQNAMEnotdefined錯誤的解決辦法

編輯:Oracle教程

CentOSOracle報EnvironmentvariableORACLE_UNQNAMEnotdefined錯誤的解決辦法


今天在 CentOS 上安裝完 Oracle 後,通過命令 “emctl start dbconsole” 啟動管理控制台時,報了 “Environment variable ORACLE_UNQNAME not defined” 的錯誤。問題原因是因為 Oracle 總是獲取不到正確的 IP 地址(安裝 Oracle 時獲取的 IP 地址就是錯誤的),導致 em 出現問題,只需重新配置 emca 即可。折騰了好久,最後終於把問題給解決了。

環境描述

操作系統: CentOS 6.5
IP: 192.168.132.41
域: mycompany.com.cn
主機名: hemw-pc
Oracle:11gR2,安裝目錄為 /opt/oracle/11g

問題分析

剛開始按照網上的解決方案使用命令“emca -config dbcontrol db -repos create” 重新創建 em,輸入完對應的信息時,到最後確認時獲取到的 IP 地址總是不正確(Local hostname 應該是 192.168.132.41 才對):

 

-----------------------------------------------------------------

You have specified the following settings

Database ORACLE_HOME ................ /opt/oracle/11g

Local hostname ................ 192.168.64.61
Listener ORACLE_HOME ................ /opt/oracle/11g
Listener port number ................ 1521
Database SID ................ orcl
Email address for notifications ............... 
Outgoing Mail (SMTP) server for notifications ............... 

-----------------------------------------------------------------
因為獲取到的 hostname 值不正確,導致一直無法創建成功,提示如下錯誤

 

 

Could not complete the configuration. Refer to the log file at /opt/oracle/cfgtoollogs/emca/orcl/emca_2015_03_10_17_19_30.log for more details.

解決方案

經過各種嘗試和折騰後,最終還是把問題給搞定了,步驟如下:

1. 停止監聽器

 

$ lsnrctl stop

 

2. 停止 oracle 數據庫

 

$ sqlplus "sys / as sysdba"

SQL*Plus: Release 11.2.0.1.0 Production on Tue Mar 10 17:16:45 2015

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

Enter password: 

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown

 

3. 修改 $ORACLE_HOME/network/admin/listener.ora,將文件內容中 HOST 的值改為正確的 IP(192.168.132.41),如:

 

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.132.41)(PORT = 1521))
    )
  )
4. 修改 $ORACLE_HOME/network/admin/tnsnames.ora,將文件內容中 HOST 的值改為正確的 IP(192.168.132.41),如:
ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.132.41)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )
5. 修改 /etc/sysconfig/network,將文件內容改為:
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=hemw-pc

因為修改完這個文件後需要重啟操作系統才會生效,所以在不重啟操作系統的情況下需要同時執行一下:# hostname hemw-pc

6. 修改 /etc/hosts,在文件的最後新增如下內容:

192.168.132.41 hemw-pc hemw-pc.mycompany.com.cn

7. 啟動數據庫

SQL> startup

8. 啟動監聽

$ lsnrctl start
9. 刪除早期DBCONSOLE創建的用戶:
sql>drop role MGMT_USER;
sql>drop user MGMT_VIEW cascade;
sql>drop user sysman cascade;
10. 刪除早期DBCONSOLE創建的對象:
sql>drop PUBLIC SYNONYM MGMT_TARGET_BLACKOUTS;
sql>drop public synonym SETEMVIEWUSERCONTEXT;
11. 重新創建DBCONSOLE:(如果是在windows下,要先到注冊表刪除DBCONSOLE的服務,重啟電腦)
$emca -config dbcontrol db -repos create
如果提示創建失敗,輸出類似 “Could not complete the configuration. Refer to the log file at /opt/oracle/cfgtoollogs/emca/orcl/emca_*.log for more details.” 的錯誤信息,請查看對應的日志文件, 日志文件的最後一行內容如果是 “ORA-00955: name is already used by an existing object”,如:
CREATE PUBLIC SYNONYM MGMT_AVAILABILITY FOR MGMT_AVAILABILITY
                      *
ERROR at line 1:
ORA-00955: name is already used by an existing object
則需要執行一次重建的命令:
$emca -config dbcontrol db -repos recreate
在執行上面命令的過程中需要根據提示輸入對應的數據庫信息及 SYS、DBSNMP 和 SYSMAN 的登錄密碼,最後輸入 Y 進行確認,如:
STARTED EMCA at Mar 10, 2015 10:03:17 PM
EM Configuration Assistant, Version 11.2.0.0.2 Production
Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Enter the following information:
Database SID: orcl
Listener port number: 1521
Listener ORACLE_HOME [ /opt/oracle/11g ]: 
Password for SYS user:  
Password for DBSNMP user:  
Password for SYSMAN user:  
Email address for notifications (optional): 
Outgoing Mail (SMTP) server for notifications (optional):
12. 檢查 em 的狀態
$ emctl status dbconsole

Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0 
Copyright (c) 1996, 2009 Oracle Corporation.  All rights reserved.
https://hemw-pc:1158/em/console/aboutApplication
Oracle Enterprise Manager 11g is running. 
------------------------------------------------------------------
Logs are generated in directory /opt/oracle/11g/hemw-pc_orcl/sysman/log
至此,問題已經解決完畢。

 

附:emca 常用命令

創建一個 em 資料庫:emca -repos create
重建一個 em 資料庫:emca -repos recreate
刪除一個 em 資料庫:emca -repos drop

配置數據庫的 Database Control:emca -config dbcontrol db
刪除數據庫的 Database Control配置:emca -deconfig dbcontrol db

重新配置db control的端口,默認端口在1158
emca -reconfig ports
emca -reconfig ports -dbcontrol_http_port 1160
emca -reconfig ports -agent_port 3940

先設置 ORACLE_SID 環境變量後,啟動 em console服務:emctl start dbconsole
先設置 ORACLE_SID 環境變量後,停止em console服務:emctl stop dbconsole
先設置 ORACLE_SID 環境變量後,查看 em console服務的狀態:emctl status dbconsole

配置 dbconsole 的步驟
emca -repos create
emca -config dbcontrol db
emctl start dbconsole

重新配置 dbconsole 的步驟
emca -repos drop
emca -repos create
emca -config dbcontrol db

emctl start dbconsole

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved