基于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
下一篇 2015-09-14

相关推荐

  • 携程全站瘫痪引发的思考

       为今年5月冠上多事之夏的名头已是无可厚非的一件事,自支付宝光纤被挖断后,携程又暴出全站瘫痪的风波,从5/28 11:00开始,直到晚上11:29分才全面恢复.互联网也是谣言四起,纷纷猜测百度腾讯谁会是下一个灾难的受害者。暂切抛开这些玩笑言论,就携程本次事情引发的思考太多,前车之鉴后事之师,如果携程的事情发生到我们身上,我们该怎么办,…

    Linux干货 2015-06-03
  • for、while、until循环

    一、for循环          for 变量名 in 列表;do             循环体     &nbsp…

    Linux干货 2016-09-19
  • class8 文本处理工具sed和vim编辑器

    一、处理文本的工具sed     Stream EDitor,  行编辑器     sed是linux上一款比较重要的流编辑器。     特点:一次处理一行内容,处理完成后,把缓冲区的内容送往屏幕。这样不断重复,直到文件末尾。 &…

    Linux干货 2016-08-11
  • N_28文件类管理命令

    1.linux文件管理类命令有:mkdir ,rmdir,cp ,mv,rm,ls,vi,cat ,cut,sort,wc等 mkdir –make directories  (创建目录) 用法 :mkdir [OPTION]… DIRECTORY… -P  按需要创建目录的父目录; -v  显示创建的详细过程; -m M…

    2017-12-09
  • Nginx相关配置及其应用

    LB Cluster: 传输层:lvs、nginx、haproxy 应用层:nginx(http, https, smtp, pop, imap), haproxy(http), httpd(http/https), ats, perlbal, pound, … nginx load balancer: tcp/udp   nginx …

    Linux干货 2016-11-11

评论列表(2条)

  • stanley
    stanley 2015-09-14 09:29

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

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

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