[toc]

适用范围

Centos 6 单机 ORACLE 11g 安装完成时候,需要修改修改主机名称,修改主机名称后,OEM 无法正常运行的问题处理。

问题概述

Centos 6 单机 修改主机名称

Centos 6 修改主机名称是需要修改配置文件的,跟 Centos/rhel 7 系列不一样,7 系列是可以通过 hostnamectl set-hostname namexx 来直接修改,不管是 6 系列还是 7 系列修改主机名称之后,都要手工修改/etc/hosts 下配置的 hostname

在修改主机名称这一块,对于是否需要重启主机来说,有些许争议,这里我搜索了官方文档,找到了 rhel 7 系列的修改主机名称的文档:https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/assembly_changing-a-hostname_configuring-and-managing-networking#proc_changing-a-hostname-using-hostnamectl_assembly_changing-a-hostname

    1. The hostnamectl utility automatically restarts the systemd-hostnamed to activate the new name. For the changes to take effect, reboot the host:

      1
      # reboot

      Alternatively, if you know which services use the hostname:

      1. Restart all services that only read the hostname when the service starts:

        1
        # systemctl restart <service_name>
      2. Active shell users must re-login for the changes to take effect.

这里有写需要重启reboot主机 生效,或者重启某个读到 hostname 的服务。

在这里生产环境建议重启下主机生效,也不知道那些服务用到了这个hostname。

Centos 6 修改主机的步骤:

1. Use the hostname utility

hostname myservernamehere

2. Alter the hostname in /etc/sysconfig/network

vi /etc/sysconfig/network

Change your old hostname by editing the text on the line after HOSTNAME=

3. Alter the hostname in /etc/hosts

vi /etc/hosts

If your old hostname is present here, edit it out and replace it with your new one.

4. reboot

由于已经安装了 单机的 ORACLE 11g,先关闭数据库及监听再修改主机名称,然后重启主机。

修改监听文件

在重启主机之后,如果 ORACLE 的监听配置的是 hostname,同时也需要修改监听的配置文件 /u01/app/oracle/product/19.3.0.0/dbhome_1/network/admin/listener.ora

1
2
3
4
5
6
LISTENER=
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.20.22.20)(PORT = 1521))
)
)

如果 host 里写的是 hostname,需要修改成新的hostname,或者直接写 IP地址。

OEM 无法启动问题处理

重启主机之后,启动监听、数据库都正常启动,但是 OEM 无法启动,会报 $ORACLE_HOME/oc4j/j2ee/OC4J_DBConsole_{new_hostname}_{db_name} not found. 这里想当然的是将这个目录重命名一下,将原来的 old_hostname 的目录重命名为now_hostname 的目录,但是又报 $ORACLE_HOME/now_hostname_dbname not found. 同样也通过重命名的方式处理,但是仍然不行,在启动的时候,https的url 仍然是 old_hostname,也就是并不是重命名文件夹能解决的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
oracle@now_hostname:/home/oracle $emctl start dbconsole
OC4J Configuration issue. /u01/app/oracle/product/11.2.0.4/dbhome_1/oc4j/j2ee/OC4J_DBConsole_{newhostname}_{db_name} not found.
oracle@now_hostname:/home/oracle $cd /u01/app/oracle/product/11.2.0.4/dbhome_1/oc4j/j2ee/
oracle@now_hostname:/u01/app/oracle/product/11.2.0.4/dbhome_1/oc4j/j2ee $ll
total 32
-rw-r--r-- 1 oracle dba 1015 Feb 24 2024 deploy_db_wf.ini
drwxr-xr-x 14 oracle dba 4096 Feb 24 2024 home
drwxr-xr-x 3 oracle dba 4096 Feb 24 2024 oc4j_applications
drwxr-x--- 6 oracle dba 4096 Feb 24 2024 OC4J_DBConsole
drwxr-xr-x 10 oracle dba 4096 Feb 26 2024 OC4J_DBConsole_old_hostname_dbname
drwxr-xr-x 5 oracle dba 4096 Feb 24 2024 OC4J_Workflow_Component_Container
drwxr-xr-x 5 oracle dba 4096 Feb 24 2024 OC4J_Workflow_Management_Container
drwxr-xr-x 2 oracle dba 4096 Feb 24 2024 utilities
oracle@now_hostname:/u01/app/oracle/product/11.2.0.4/dbhome_1/oc4j/j2ee $mv OC4J_DBConsole_old_hostname_dbname OC4J_DBConsole_dbname_dbname
oracle@now_hostname:/u01/app/oracle/product/11.2.0.4/dbhome_1/oc4j/j2ee $emctl start dbconsole
EM Configuration issue. /u01/app/oracle/product/11.2.0.4/dbhome_1/new_hostname_dbname not found.
oracle@now_hostname:/u01/app/oracle/product/11.2.0.4/dbhome_1/oc4j/j2ee $cd /u01/app/oracle/product/11.2.0.4/dbhome_1/

oracle@now_hostname:/u01/app/oracle/product/11.2.0.4/dbhome_1 $mv old_hostname_dbname/ new_hostname_dbname
oracle@now_hostname:/u01/app/oracle/product/11.2.0.4/dbhome_1 $emctl start dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.4.0
Copyright (c) 1996, 2013 Oracle Corporation. All rights reserved.
https://old hostname:1158/em/console/aboutApplication
Starting Oracle Enterprise Manager 11g Database Control ..................................^C

这里通过重建 OEM 的方式来解决,注意,重建OEM的时候,要把上面重命名的 文件夹进行删除,不然重建仍然不成功。

重建 OEM

1
emca -config dbcontrol db -repos recreate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

oracle@now_hostname:/home/oracle $emca -config dbcontrol db -repos recreate

STARTED EMCA at Sep 1, 2024 10:09:00 PM
EM Configuration Assistant, Version 11.2.0.3.0 Production
Copyright (c) 2003, 2011, Oracle. All rights reserved.

Enter the following information:
Database SID: ORACLE_SID
Listener port number: 1521
Listener ORACLE_HOME [ /u01/app/oracle/product/11.2.0.4/dbhome_1 ]:
Password for SYS user: xxxxxxx
Password for DBSNMP user: xxxxxx
Password for SYSMAN user: xxxxxx
Email address for notifications (optional):
Outgoing Mail (SMTP) server for notifications (optional):
-----------------------------------------------------------------

You have specified the following settings

Database ORACLE_HOME ................ /u01/app/oracle/product/11.2.0.4/dbhome_1

Local hostname ................ new_hostname
Listener ORACLE_HOME ................ /u01/app/oracle/product/11.2.0.4/dbhome_1
Listener port number ................ 1521
Database SID ................ ORACLE_SID
Email address for notifications ...............
Outgoing Mail (SMTP) server for notifications ...............

-----------------------------------------------------------------
----------------------------------------------------------------------
WARNING : While repository is dropped the database will be put in quiesce mode.
----------------------------------------------------------------------
Do you wish to continue? [yes(Y)/no(N)]: y
Sep 1, 2024 10:09:36 PM oracle.sysman.emcp.EMConfig perform
INFO: This operation is being logged at /u01/app/oracle/cfgtoollogs/emca/db_name/emca_2024_09_01_22_09_00.log.
Sep 1, 2024 10:09:36 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Dropping the EM repository (this may take a while) ...
Sep 1, 2024 10:10:09 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Repository successfully dropped
Sep 1, 2024 10:10:09 PM oracle.sysman.emcp.EMReposConfig createRepository
INFO: Creating the EM repository (this may take a while) ...
Sep 1, 2024 10:12:10 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Repository successfully created
Sep 1, 2024 10:12:11 PM oracle.sysman.emcp.EMReposConfig uploadConfigDataToRepository
INFO: Uploading configuration data to EM repository (this may take a while) ...
Sep 1, 2024 10:12:38 PM oracle.sysman.emcp.EMReposConfig invoke
INFO: Uploaded configuration data successfully
Sep 1, 2024 10:12:39 PM oracle.sysman.emcp.util.DBControlUtil secureDBConsole
INFO: Securing Database Control (this may take a while) ...
Sep 1, 2024 10:13:31 PM oracle.sysman.emcp.util.DBControlUtil secureDBConsole
INFO: Database Control secured successfully.
Sep 1, 2024 10:13:31 PM oracle.sysman.emcp.util.DBControlUtil startOMS
INFO: Starting Database Control (this may take a while) ...
Sep 1, 2024 10:13:51 PM oracle.sysman.emcp.EMDBPostConfig performConfiguration
INFO: Database Control started successfully
Sep 1, 2024 10:13:51 PM oracle.sysman.emcp.EMDBPostConfig performConfiguration
INFO: >>>>>>>>>>> The Database Control URL is https://new_hostname:1158/em <<<<<<<<<<<
Sep 1, 2024 10:14:07 PM oracle.sysman.emcp.EMDBPostConfig invoke
WARNING:
************************ WARNING ************************

Management Repository has been placed in secure mode wherein Enterprise Manager data will be encrypted. The encryption key has been placed in the file: /u01/app/oracle/productzhi_dbname/sysman/config/emkey.ora. Ensure this file is backed up as the encrypted data will become unusable if this file is lost.

***********************************************************
Enterprise Manager configuration completed successfully
FINISHED EMCA at Sep 1, 2024 10:14:07 PM
oracle@now_hostname:/home/oracle $emctl status dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.4.0
Copyright (c) 1996, 2013 Oracle Corporation. All rights reserved.
https://new_hostname:1158/em/console/aboutApplication
Oracle Enterprise Manager 11g is running.
------------------------------------------------------------------
Logs are generated in directory /u01/app/oracle/product/11.2.0.4/dbhome_1/now_hostname_dbname/sysman/log

解决方案

重建 OEM

1
emca -config dbcontrol db -repos recreate

参考文档

https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/assembly_changing-a-hostname_configuring-and-managing-networking#proc_changing-a-hostname-using-hostnamectl_assembly_changing-a-hostname

原文作者: liups.com

原文链接: http://liups.cn/posts/785e9465/

许可协议: 知识共享署名-非商业性使用 4.0 国际许可协议