CentOS Oracle 報 Environment variable ORACLE_UNQNAME not defined 錯誤的解決辦法,environmentvariable
今天在 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 settingsDatabase ORACLE_HOME ................ /opt/oracle/11gLocal hostname ................ 192.168.64.61Listener ORACLE_HOME ................ /opt/oracle/11gListener port number ................ 1521Database SID ................ orclEmail 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 2015Copyright (c) 1982, 2009, Oracle. All rights reserved.Enter password: Connected to:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing optionsSQL> 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=yesNETWORKING_IPV6=noHOSTNAME=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 PMEM Configuration Assistant, Version 11.2.0.0.2 ProductionCopyright (c) 2003, 2005, Oracle. All rights reserved.Enter the following information:Database SID: orclListener port number: 1521Listener 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 dbconsoleOracle 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/aboutApplicationOracle 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
參考資料:
http://soulful.blog.51cto.com/468033/449934
http://czhwin.iteye.com/blog/1847366