五、拷贝VM后,局域网能如何同时启动

king's blog
在工作中,可能会经常碰到在虚拟机中搭建环境,如果搭建环境很复杂得话,如果一个个去搭建则非常费时。此时,我们可以通过拷贝VM的方式进行快速搭建,但拷贝的VM,不能在同一局域网能启动,原因在于多个VM的IP,MAC等都是一样的。所以拷贝后的VM额外做如下事情方可同时使用。
备注:下面以VirtualBox创建的VM为例子:
1、修改Hostname和IP地址
2、修改Mac地址
步骤1:停止VM
步骤2:点击如下标识2按钮(更新一次MAC地址自动更新),这样能保证与原始VM的MAC地址不一样,此时会创建一个新的网卡
virtualbox

步骤3:用root登录图形界面->yast2->network,先删除原始的网卡,再给新创建的网卡(step2创建的)配置IP,重启网络服务即可,上面修改ip,更改mac都是针对Suse环境。

如果是Redhat,可通过命令的方式修改,步骤如下:
修改IP地址:修改/etc/sysconfig/network-scripts/ifcfg-eth0文件(如下),然后重启网络服务(service network restart)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@QA1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
UUID=df57bc21-b974-44c6-8d1d-6c1605fe686c
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR=08:00:27:67:D7:39-------------->MAc地址,一定要与步骤二界面的一致
IPADDR=10.80.18.1--------------------->IP地址
PREFIX=24
GATEWAY=10.80.18.1
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
[root@QA1 ~]#

修改Hostname:修改/etc/hosts和/etc/sysconfig/network两个文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#1.修改/etc/hosts文件
[root@QA1 ~]# cat /etc/hosts
127.0.0.1   localhost QA1.site localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.80.18.1  localhost QA1.site localhost4 localhost4.localdomain4
[root@QA1 ~]#

#2.修改/etc/sysconfig/network文件
[root@QA1 ~]# cat /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=QA1.site
GATEWAY=10.80.18.1

[root@QA1 ~]#

3、如果安装了oracle,则需要修改listener.ora和tnsnames.ora两个文件
备注:listener.ora和tnsnames.ora文件放置在类似/opt/oracle/product/11.2.0/dbhome_1/network/admin的目录下,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
oracle@QA1:~> cat /opt/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# listener.ora Network Configuration File: /opt/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = globe)
      (SID_NAME = globe)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = ETS157.site)(PORT = 1521)) ----------->ETS157需改为QA1
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

ADR_BASE_LISTENER = /opt/oracle

oracle@QA1:~>
1
2
3
4
5
6
7
8
9
10
11
12
13
oracle@QA1:~> cat /opt/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /opt/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

REAPSDB =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = ETS157.site)(PORT = 1521))----------->ETS157需改为QA1
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = REAPSDB)
    )
  )
oracle@QA1:~>
LEAVE A REPLY

loading