基于windows的PXE部署linux,基于pxe部署系统

一、前言

在生产环境中,我们经常遇到需要部署部署多台服务器。如果我们每部署一台服务器都要拿着系统盘到机房部署,守在服务器面前,那么我们的效率是十分低下的。况且有时候机房并不在我们身边。那么我们可以通过让机房值班人员为每台服务器配置好远程管理卡,运维人员通过远程管理卡,远程登入服务器进行操作。

二、pxe原理

pxe原理是通过服务器上网卡中支持的pxe启动,通过广播的方式获取ip地址与下一个服务器的ip地址,pxe客户端在tftp服务器上下载pxelinux.0文件,pxe客户端根据pxelinux.0的执行结果,通过tftp服务器加载kernel及ramdisk文件,从而引导系统。具体原理可查考下图

3c8ce6380daa33c267ccb0e2e66a02de.png

三、开始部署pxe服务器

3.1  部署dhcp服务

3.1.1 安装dhcp服务器并关闭selinux及iptables

[root@localhost ~]# yum install dhcp –y

[root@localhost ~]# setenforce 0            #设置selinux为permissive模式

[root@localhost ~]# getenforce

Permissive

[root@localhost ~]# service iptables stop   #关闭防火墙

3.1.2 配置dhcp服务器

[root@localhost ~]# mv /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

subnet 192.168.19.0 netmask 255.255.255.0 {

range 192.168.19.100 192.168.19.200;        #dhcp地址池

filename "pxelinux.0"                       #下一个寻找的文件

server-name "192.168.19.136"                #下一个寻找的服务器地址

}

3.1.3设置开机启动

[root@localhost ~]# chkconfig dhcpd on

[root@localhost ~]# chkconfig --list dhcpd

dhcpd           0:off         1:off         2:on 3:on 4:on 5:on 6:off

[root@localhost ~]# service dhcpd start

3.2 配置tftp服务器

[root@localhost ~]# yum install -y tftp-server

service tftp

{

socket_type        = dgram

protocol           = udp

wait               = yes

user               = root

server             = /usr/sbin/in.tftpd

server_args        = -s /var/lib/tftpboot

disable            = no                    #设置tftp-server开机自动启动

per_source         = 11

cps                = 100 2

flags              = IPv4

}

3.3配置pxe工作环境

3.3.1安装syslinux

[root@localhost ~]# yum install -y syslinux

[root@localhost tftpboot]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

3.3.2 安装httpd

[root@localhost tftpboot]# yum install -y httpd

[root@localhost tftpboot]# chkconfig httpd on

[root@localhost tftpboot]# service httpd start

3.3.3提供kernel,ramdisk等文件

[root@localhost tftpboot]# mount /dev/sr0 /mnt/cdrom

[root@localhost tftpboot]# mount --bind /mnt/cdrom /var/www/html/centos/x86_64

[root@localhost tftpboot]# cd /mnt/cdrom/images/pxeboot/

[root@localhost pxeboot]# cp vmlinuz initrd.img /var/lib/tftpboot/

[root@localhost isolinux]# cd /mnt/cdrom/isolinux/

[root@localhost isolinux]# cp vesamenu.c32 boot.msg splash.jpg  /var/lib/tftpboot/

[root@localhost isolinux]# mkdir /var/lib/tftpboot/pxelinux.cfg

[root@localhost isolinux]# cp isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

3.3.4提供kickstart文件

3c8ce6380daa33c267ccb0e2e66a02de.png

[root@localhost tftpboot]# yum install -y system-config-kickstart

[root@localhost tftpboot]# cp /root/ks.cfg /var/www/html/

#kickstart文件部分示例

# Firewall configuration

firewall --enabled --service=ssh

# Install OS instead of upgrade

install

# Use network installation

# Firewall configuration

firewall --enabled --service=ssh

# Install OS instead of upgrade

install

# Use network installation

url --url="http://192.168.19.136/centos/x86_64"        #指定安装源

# Root password

rootpw --plaintext centos                              #设置root密码

# System authorization information

auth  --useshadow  --passalgo=md5

# Use text mode install

text                                                   #文本模式安装                                  firstboot --disable

# System keyboard

keyboard us                                            #键盘类型

# System language

lang en_US                                             #语言

# SELinux configuration

selinux --enforcing                                    #selinux模式

# Installation logging level

logging --level=info

# Reboot after installation

reboot

# System timezone

timezone  Asia/Shanghai

# Network information

network  --bootproto=dhcp --device=eth0 --onboot=on    #连网方式

# System bootloader configuration

bootloader --append="crashkernel=auto rhgb quiet" --location=mbr --driveorder="sda"

# Clear the Master Boot Record

zerombr

# Partition clearing information

clearpart --all --initlabel

# Disk partitioning information

part /boot --fstype="ext4" --size=200                  #创建/boot分区

part / --fstype="ext4" --grow --size=1                 #创建/ 分区

四、测试

关闭vmware的dhcp功能

3c8ce6380daa33c267ccb0e2e66a02de.png

从pxe启动后,设置ks文件

3c8ce6380daa33c267ccb0e2e66a02de.png

安装

3c8ce6380daa33c267ccb0e2e66a02de.png

参考文献:http://www.cnblogs.com/mchina/p/centos-pxe-kickstart-auto-install-os.html

原创文章,作者:成吉思汗,如若转载,请注明出处:http://www.178linux.com/8000

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值