今天本想在vcenter上建个分布式交换机,没想到在迁移主机端口时,由于主机只连了一个物理网卡,导致在迁移到分布式交换机而失去连接,几近周折,从网上找了几篇不错的文章,与众同乐

   

       假如一台ESX主机先通过标准虚拟交换机vSwitch0上的服务控制台IP(192.168.100.101)连接到vCenter Server。然后新建一个DVS,uplink仍然连接到同一子网(192.168.100.0/24)。此时将主机中空闲的物理网卡添加到uplink是没有问题的,但如果迁移和vSwitch0连接的物理网卡和上面的服务控制台,就会与ESX主机失去联系。登录ESX的控制台用/etc/init.d/network restart重启网络也连不到子网了。 
我恢复的办法如下 
(1)查看交换机状况,发现vmnic0(连接到vSwitch0的物理网卡)和vswif0(服务控制台)都出现在DVS中了 
esxcfg-vswitch -l 
(2)先将vmnic0从DVS中剥下来 
esxcfg-vswitch -Q vmnic0 -V xxx DVS_NAME 
参数-V填写DVport ID,可以从先前的命令看到,DVS_NAME填写DVS的名称(3)将vmnic0添加到vSwitch0中 
esxcfg-vswitch -L vmnic0 vSwitch0 
(4)删除原来的服务控制台 
esxcfg-vswif -d vswif0 
(5)在vSwitch0中添加服务控制台的端口组 
esxcfg-vswitch -A "Service Console" vSwitch0 
(6)重新添加服务控制台 
esxcfg-vswif -a -p "Service Console" -i 192.168.100.101 -n 255.255.255.0 -b 192.168.16.255 vswif0 
(7)用vsphere client直接登录ESX主机,选择主机,在“配置”标签页中找到“网络》分布式交换机”,删除即可


esxi 常用命令

一. VMware ESX Command

1. 看你的esx版本vmware –v

2. 查看显示ESX硬件,内核,存储,网络等信息esxcfg-info -a(显示所有相关的信息)esxcfg-info -w(显示esx上硬件信息)

3. 列出esx里知道的服务esxcfg-firewall –s

4. 查看具体服务的情况esxcfg-firewall -q sshclinet

5. 重新启动vmware服务service mgmt-vmware restart

6. 修改root的密码passwd root

7. 设置kernel高级选项esxcfg-advcfg -d(将系统内核恢复默认值)

8. 管理资源组esxcfg-resgrp -l(显示所有资源组)

9. 列出你当前的虚拟交换机esxcfg-vswitch -lesxcfg-vswitch -v 10 -p "Service Console" vSwitch0 (将vSwitch0上的Service Console划分到vLan 10上,如果vLan号为0则不设置vLan)

10. 查看控制台的设置esxcfg-vswif -l  (列出已添加的网卡)esxcfg-vswif -a (添加网卡)

11. 列出系统的网卡esxcfg-nics –l

12. 添加一个虚拟交换机,名字叫(internal)连接到两块物理网卡,(重新启动服务,vi就能看见了)esxcfg-vswitch -a vSwitch1esxcfg-vswitch -A internal vSwitch1esxcfg-vswitch -L vmnic1 vSwitch1esxcfg-vswitch -L vmnic2 vSwitch1

13.  删除交换机,(注意,别把控制台的交换机也删了)esxcfg-vswitch -D vSwitch1

14.  删除交换机上的网卡esxcfg-vswitch -u vmnic1 vswitch2

15.  删除portgroupesxcfg-vswitch -D internel vswitch1

16.  创建 vmkernel switch,如果你希望使用vmotion,iscsi的这些功能,你必须创建(通常是不需要添加网关的)esxcfg-vswitch -lesxcfg-vswitch -a vswitch2esxcfg-vswitch -A "vm kernel" vswitch2esxcfg-vswitch -L vmnic3 vswitch2esxcfg-vmknic -a "vm kernel" -i 172.16.1.141 -n 255.255.252.0 (添加一个vmkernel)

17.  防火墙设置esxcfg-firewall -e sshclient (打开防火墙ssh端口)esxcfg-firewall -d sshclient (关闭防火墙ssh端口)esxcfg-firewall -e veritasNetBackup(允许Veritas Netbackup服务)esxcfg-firewall -o 123,udp,out,ntp(为ntp服务打开UDP协议中的123端口的输出)

18.  路由管理esxcfg-route(VM生成网卡的路由管理)esxcfg-route(显示路由表)esxcfg-route 172.16.0.254(设置vmkernel网关)

19.  创建控制台esxcfg-vswitch -a vSwitch0esxcfg-vswitch -A "service console" vSwitch0esxcfg-vswitch -L vmnic0 vSwitch0esxcfg-vswif -a vswif0 -p "service console" -i 172.16.1.140 -n 255.255.252.0

20.  添加nas设备(a添加标签,-o,是nas服务器的名字或ip,-s是nas输入的共享名字)esxcfg-nas -a isos -o nas.vmwar.cn -s isos

21.  nas连接管理esxcfg-nas -r (强迫esx去连接nas服务器)esxcfg-nas -l   (用esxcfg-nas -l来看看结果)esxcfg-nas -a(添加NAS文件系统到/vmfs目录下)esxcfg-nas -d(删除NAS文件系统)

22.  扫描SCSI设备上的LUN信息esxcfg-rescan <vmkernel SCSI adapter name>

23.  连接iscsi设备(e:enable q:查询 d, disable s:强迫搜索)esxcfg-swiscsi -e

24.  设置targetipvmkiscsi-tool -D -a 172.16.1.133 vmhba40

25.  列出和target的连接vmkiscsi-tool -l -T vmhba40

26.  列出当前的磁盘ls -l /vmfs/devices/disks

27.  内核dump管理工具esxcfg-dumppart -l(显示当前dump分区配置信息)

28.  路径管理esxcfg-mpath -l(显示所有路径)esxcfg-mpath -a(显示所有HBA卡)

29.  ESX授权管理配置esxcfg-authesxcfg-auth --enablenis(运行NIS验证)

30.  管理启动设备esxcfg-bootesxcfg-boot -b(更新启动设备)

31.  执行initrd的初始化设置esxcfg-initesxcfg-init(初始化设备)

32.  esxcfg-linuxnet(在linux debug模式中,转换vswif设备命名为linux自带的eth命名规则)esxcfg-linuxnet --setup

33.  升级esxcfg-upgrade(ESX2.X升级到ESX3.X)

二. 使用命令更改Service Console IP在CLI下更改service console的ip地址,注意大小写,vmware是把物理nic虚拟成vmnic,在vmnic上创建虚拟交换机vswitch,是把网卡当成交换机来使用,不能对网卡进行ip地址的设置,只能在vswitch上创建interface就是vswif,对vswif进行ip设置 

1.  使用CLI创建Service Console[root@VI3 root]# esxcfg-vswitch -a vSwitch0                   

#创建vSwitch0[root@VI3 root]# esxcfg-vswitch -A "Service Console" vSwitch0  

#在vSwitch0上创建Portgroup,命名为Service Console[root@VI3 root]# esxcfg-vswitch -L vmnic0 vSwitch0              

#将vmnic0绑定在vSwitch0[root@VI3 root]# esxcfg-vswitch –l         

#可以看到service console已经绑定 vmnic0 

Switch Name   Num Ports  Used Ports Configured Ports MTU    Uplinks 

vSwitch0          64                5                64                        1500   vmnic0   

PortGroup Name   VLAN ID    Used Ports Uplinks

Service Console      0                1               vmnic0   

[root@VI3 root]# esxcfg-vswif -a vswif0 -p "Service Console" -i 192.168.1.1 -n 255.255.255.0               

#设备ID Service Consol 一定要加引号 #创建vswif0并与service console绑定,在ESX里ip地址只能跟vswif0绑定,也就是虚拟交换机的interface[root@VI3 root]# esxcfg-vswif –l     

#可以看到Service console的IP已经配置到vswif0 

Name    Port Group        IP Address       Netmask             Broadcast         Enabled  DHCP

vswif0  Service Console 192.168.1.50   255.255.255.0    192.168.1.255  true          false 

[root@VI3 root]# esxcfg-vswitch –lSwitch 

Name   Num Ports  Used     Ports Configured Ports MTU    Uplinks 

vSwitch0       64         5          64                               1500     vmnic0   

PortGroup Name   VLAN ID    Used Ports Uplinks

Service Console      0               1                vmnic0

[root@VI3 root]# service mgmt-vmware restart          

#重启服务,到这里正常情况下就可以使用VI连接到ESX

--------------↓如果不小心配置错了要删除,请看下面↓---------------

[root@VI3 root]# esxcfg-vswif –l   

#vswif0代表的虚拟网卡的interface0,service console对应vswif0 

Name   Port Group        IP Address    Netmask           Broadcast        Enabled  DHCP

vswif0 Service Console 192.168.1.1  255.255.255.0  192.168.1.255  true         false 

[root@VI3 root]# esxcfg-vswif -d vswif0                 

#删除vswif0

[root@VI3 root]# esxcfg-vswitch -l

Switch Name   Num Ports  Used Ports Configured Ports MTU    Uplinks 

vSwitch0           64               5                64                      1500     vmnic0   

PortGroup Name   VLAN ID    Used Ports Uplinks

Service Console      0              1                vmnic0         

[root@VI3 root]# esxcfg-vswitch –D “Service Console” vSwitch0    

#删除vSwitch0上面portgroup[root@VI3 root]# esxcfg-vswitch –D “VM Network” vSwitch0

[root@VI3 root]# esxcfg-vswitch -d vSwitch0                #删除vswitch0

[root@VI3 root]# esxcfg-vswitch –l                               #之前操作删除了vswitch信息,现在是空白

Switch Name   Num Ports  Used Ports Configured Ports MTU    Uplinks  PortGroup Name   VLAN ID    Used Ports Uplinks 

2.  如果不行检查一下以下配置文件.

[root@VI3 root]# vi /etc/sysconfig/network                 #这里纪录主机名字和网关

NETWORKING=yes

HOSTNAME=VI3     

GATEWAY=192.168.251.12         #网关

GATEWAYDEV=vswif0                #网关指定在vswif0

[root@VI3 root]# vi /etc/sysconfig/network-scripts/ifcfg-vswif0        #看看这里的信息是否跟之前配置吻合

DEVICE=vswif0                        #之前把service cosole与vswif0关联     

MACADDR=00:50:56:43:a3:52PORTGROUP=portgroup6     #这里的protgroup与service console一致

BOOTPROTO=static

BROADCAST=192.168.251.255

IPADDR=192.168.251.60                        #与service console一致NETMASK=255.255.255.0

ONBOOT=yes

如果以上不一致,可以手动更改在vi编辑器中,i键是插入模式,进行文本更改,esc键退出插入模式,:wq保存并退出.编辑完成reboot.可能启动后显示地址跟设置不同,但是可以使用VI连接到ESX

 

关于修改网卡ip整理资料

1.首先,你必须访问物理控制台。 2.把ESX主机设为维护模式并从Virtual Center中断开。 3.连接到ESX主机的控制台。 4.删除旧的IP(即删除vswif接口),"esxcfg-vswif -d vswif0" (vswif0 你的第一块网卡) 5.建立一个新的vswif接口及相应的IP地址,"esxcfg-vswif -a vswif0 -p “Service Console” -i 192.168.0.100 -n 255.255.255.0 -b 192.168.0.255″。这里: -i 是新的IP地址 -n 是子网掩码 -b 是广播地址 6.更新默认网关,”nano /etc/sysconfig/network file”按CTRL+O和回车,然后CTRL+Q退出。 7.重新启动接口。"esxcfg-vswif -s vswif0″ (禁用vswif0接口),然后"esxcfg-vswif -e vswif0″(开启该接口)。 8.更新DNS和HOSTS文件。接着在Virtual Center服务器上执行"ipconfig /flushdns"和"ipconfig /registerdns"。你可以通过VI图形界面来更改DNS及hostname信息: 1) 打开VI客户端并选择该ESX服务器,然后点击Configuration。 2) 点击DNS and Routing。 3) 点击Properties。 4) 若你想更改hostname, domain, 及DNS服务器,点击DNS Configuration并输入你期望的值。 5) 你可以点击Routing来更新默认网关。 6) 最后通过VI来重启该ESX服务器就可以了。