esxi 内核 linux,CentOS虚拟机配置PXE安装ESXi与RHEL、CentOS

PXE服务器用CentOS最小化安装即可,可以配置本地yum源来安装下面的服务。

此教程是手动安装,没有用到kickstart文件。

1.安装tftpserver和dhcpserver及syslinux。

使用yum安装。

yum install tftp-server dhcp syslinux -y

其中,tftp-server提供tftp服务,为pxe客户端提供文件。

dhcp提供dhcpd服务,为pxe客户端提供ip地址。

安装syslinux是为了使用pxelinux.0文件。

安装这些服务的服务器我设定其ip地址为192.168.16.180,这个地址要与第2步中的next-server对起来。

关闭系统的防火墙及selinux

service iptables stop

chkconfig iptables off

setenforce 0

vim /etc/selinux/config     # 修改文件永久关闭selinux

…前面省略

SELINUX=disabled                 # 设置SELINUX的值为disabled

…后面省略

设置服务开机启动

chkconfig dhcpd on

chkconfig xinetd on

2.配置dhcpd.conf

使用vim编辑/etc/dhcp/dhcpd.conf

下面配置中:

网关:192.168.16.1

网络:192.168.16.0/24

PXE SERVER:192.168.16.180

地址池:192.168.16.240-250

启动dhcp服务 service dhcpd start

ddns-update-style interim;

ignore client-updates;

allow booting;

allow bootp;

subnet 192.168.16.0 netmask 255.255.255.0

{

option routers 192.168.16.1;

option domain-name "s.un";

option domain-name-servers 192.168.16.252;

option subnet-mask 255.255.255.0;

option time-offset -18000;

default-lease-time 21600;

max-lease-time 43200;

range dynamic-bootp 192.168.16.240 192.168.16.250;

filename "pxelinux.0";

next-server 192.168.16.180;

}

3.配置TFTP服务器。

/etc/xinetd.d/tftp

service tftp

{

socket_type = dgram

protocol = udp

wait = yes

user = root

server = /usr/sbin/in.tftpd

server_args = -s /tftpboot

disable = no

per_source = 11

cps = 100 2

flags = IPv4

}

4.准备启动文件。

建立/tftpboot、/tftpboot/pxelinux.cfg目录。

并拷贝esxi镜像文件至/tftpboot目录。

假设将光盘挂载至/mnt/iso。

cp -r /mnt/iso/* /tftpboot/

从syslinux程序中复制pxelinux.0文件到这个目录;复制syslinux中的MENU.C32替换esxi中的同名文件

复制esxi镜像中的文件 ISOLINUX.CFG到pxelinux.cfg文件夹中

最后重启xinetd服务就好,别急,请往下看第5步写脚本

备注

如果你要为所有的服务器安装esxi6,请将ISOLINUX.CFG更名为default。如果你要为指定的服务器安装,请记下服务器的MAC地址(服务器上可能有多个网卡,需要记下通过网卡引导的网卡的MAC地址),并复制ISOLINUX.CFG文件,重命名为“序号+MAC地址”,其中序号用01、02、03代替,表示第1台、第2台服务器的顺序,在序号与MAC地址之间,用短横线代替,例如,第1台服务器的MAC地址是F48E38873878,则文件名为01-F4-8E-38-87-38-78

a1aacd8f925164cadb4a169eb4b1e6d3.png

5.写进一个脚本里

上面要建的目录好多,要复制的文件也好多,真是头大,可以写进脚本里

esxi的:

vi esxi_init.sh

umount /mnt/iso/

mount /dev/sr0 /mnt/iso/

mkdir -p /tftpboot/pxelinux.cfg

cp -r /mnt/iso/* /tftpboot/

cp /tftpboot/isolinux.cfg /tftpboot/pxelinux.cfg/default

cp /usr/share/syslinux/pxelinux.0 /tftpboot/

\cp /usr/share/syslinux/menu.c32 /tftpboot/

service xinetd restart

然后加上执行权限chmod 755 esxi_init.sh

执行./esxi_init.sh就把需要的文件复制好了

换esxi镜像的时候只需要把新的ISO挂到虚拟机里,rm -rf /tfptboot删除原来文件,重新执行脚本即可。

RHEL与CentOS的:

这个需要用到httpd服务器,索性装上吧,yum install -y httpd

vi normal.sh

umount /mnt/iso/

mount /dev/sr0 /mnt/iso/

mkdir -p /tftpboot/pxelinux.cfg

#cp -r /mnt/iso/* /tftpboot/

cp /tftpboot/isolinux.cfg /tftpboot/pxelinux.cfg/default

sed -i 's/quiet //g' /tftpboot/pxelinux.cfg/default

sed -i 's/inst.stage2=hd:LABEL=CentOS\\x207\\x20x86_64 //g' /tftpboot/pxelinux.cfg/default

sed -i 's/initrd.img/initrd.img method=http\:\/\/192.168.16.180 devfs=nomount/g' /tftpboot/pxelinux.cfg/default

cp /mnt/iso/isolinux/{initrd.img,vmlinuz,vesamenu.c32,aplash.jpg} /tftpboot/

cp /usr/share/syslinux/pxelinux.0 /tftpboot/

#\cp /usr/share/syslinux/menu.c32 /tftpboot/

service xinetd restart

service httpd restart

/tftpboot/

├── initrd.img #伪文件系统文件

├── vmlinuz #内核文件vesamenu.c32

├── splash.jpg #背景图片

├── menu.c32 #纯文本菜单

├── pxelinux.0 #引导文件,相当于grub

├── vesamenu.c32

└── pxelinux.cfg

└── default #启动菜单文件

最后要注意把虚拟机网络设置成桥接。

好了,有啥问题欢迎交流讨论。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值