基于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

相关推荐

  • 删除三天前备份的脚本

    [root@scm-dzm testfolder]# ll total 4 drwxr-xr-x. 2 root root   6 Jul 14 00:53 20160722 drwxr-xr-x. 2 root roo…

    Linux干货 2016-07-16
  • LAMP搭建wordpress博客站点

    使用WordPress可以搭建功能强大的网络信息发布平台,但更多的是应用于个性化的博客。针对博客的应用,WordPress能让您省却对后台技术的担心,集中精力做好网站的内容。本文将教您如何通过LAMP搭建自己的wordpress博客站点。 LAMP听起来很高大上,其实是集中技术合起来的称呼: L:linux A:apache httpd M:mysql、ma…

    2017-06-01
  • mariadb数据库的主从复制

    mariadb的主从复制

    2018-02-27
  • 安全和加密

    安全基础仿冒别人给某人发邮件telnet 127.0.0.1 25helo a.com 命令mail from:god@heaven.com 从某处发来的邮件rcpt to:root 给某人发邮件data 数据subject:hello 邮件名I miss you 邮件正文How old are you. 点代表结束quit redhat5普通用户提升管理员…

    Linux干货 2018-01-17
  • DNS和BIND配置(第二部分)

    接第一部分课后练习 三、课后练习: 2、配置反向解析: 步骤一:写主配置文件:改成与上个实验相同,也可以自己写一个简单的配置文件,如下: [root@localhost tmp]# cat named.conf.new options { directory  "/var/named&qu…

    Linux干货 2016-10-17
  • Linux的文本处理工具练习题

    练习一:     1、找出ifconfig命令结果中本机的所有IPv4地址 2、查出分区空间使用率的最大百分比值 3、查出用户UID最大值的用户名、UID及shell类型 4、查出/tmp的权限,以数字方式显示  练习二:       1、显示/proc/meminfo文件中以大…

    Linux干货 2016-08-08

评论列表(2条)

  • stanley
    stanley 2015-09-14 09:29

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

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

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