基于pxe部署系统

一、前言

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

二、pxe原理

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

1.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文件

4.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功能

2.png

从pxe启动后,设置ks文件

3.png

安装

5.png

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

 

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

(0)
成吉思汗成吉思汗
上一篇 2015-09-14 09:23
下一篇 2015-09-14 09:31

相关推荐

  • DNS高级应用之ACL和View

    一、环境准备:     1、准备三台主机,要求如下      (1) DNS服务器双网卡:eth0:192.168.10.203  eth1: 172.16.2.10       (2)测试机1双网卡: eth0: 172.16.…

    Linux干货 2015-06-01
  • shutil,csv,ini

    序列化和反序列化笔记

    2017-10-29
  • MySQL应用管理

    这篇文章主要讲述基本的SQL语句,以供新手参考使用,不过最好的办法还是查阅官方文档和help命令。 进入正题 什么是SQL?        SQL结构化查询语言,是关系型数据库查询和管理语言,是一种数据库查询和程序设计语言,用于存取数据以及查询,更新和管理关系型数据库系统。 SQL的分类 &nbsp…

    Linux干货 2015-09-23
  • 第四周作业

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 [root@wlm ~]# useradd tuser1 [root@wlm ~]# cp -r etc/skel/ /home/tuser1/…

    Linux干货 2016-11-21
  • AWK小记

    gawk – pattern scanning and processing language 基本用法:gawk [options] ‘program’ FILE … program: PATTERN{ACTION STATEMENTS} 语句之间用分号分隔 print, printf 选项: -F:指明输入…

    2018-01-16
  • 重定向和管道

    重定向和管道 今天一起来学习一下重定向的一些相关命令及用法: 我们都知道程序=指令+数据 ,那么我们的数据的输入(Input)和输出(Output)是如何实现的呢?!跟小编君一起来看一下吧: 本博文小编君分成了四部分:1.重定向的讲解 2.管道符的讲解 3.涉及到的一些其他命令 4.练习题 一:重定向 重定向的本质是改变文件的默认位置,即换个地方存储数据。 …

    2017-08-04

评论列表(2条)

  • stanley
    stanley 2015-09-14 09:29

    有下篇吗,过程挺详细,只是步骤好顺利的样子,我们公司原来有同学在折腾这个过程没有预期顺利,总是卡在ip获取上

    • 成吉思汗
      成吉思汗 2015-09-15 08:49

      @stanley无下篇,自己电脑上做的实验,把虚拟机的dhcp功能关闭,只要服务器上dhcp配置好了,就能获取到ip。其实也没文章写的顺利,主要卡在kickstart文件上。