zoukankan      html  css  js  c++  java
  • pxe自动化批量安装系统(Centos7)

    PXEpreboot execute environment

    环境实现:主服务器ip10.0.10.1

    tfpt

    trivial简单文件共享服务,基于udp协议工作;

    加载系统安装程序;

    69/udp

    [root@t2 ~]# yum list *tftp*

    [root@t2 ~]# yum install tftp tftp-server

    [root@t2 ~]# rpm -ql tftp-server

     1 /etc/xinetd.d/tftp
     2 /usr/lib/systemd/system/tftp.service
     3 /usr/lib/systemd/system/tftp.socket
     4 /usr/sbin/in.tftpd
     5 /usr/share/doc/tftp-server-5.2
     6 /usr/share/doc/tftp-server-5.2/CHANGES
     7 /usr/share/doc/tftp-server-5.2/README
     8 /usr/share/doc/tftp-server-5.2/README.security
     9 /usr/share/man/man8/in.tftpd.8.gz
    10 /usr/share/man/man8/tftpd.8.gz
    11 /var/lib/tftpboot           # 默认共享路径
    View Code

    [root@t2 ~]# systemctl start tftp.service

    dhcp

    dynamic host configuration protocol

    提供地址池(租约);不能跨路由器;

    能提供的信息包括:ip, netmask,  gateway,  dns server, dns search domain, nis server, lease time

    C/S

    Client 68/udp

    Server67/udp

        C           S           C          S

    dhcpdiscover-->dhcppoffer-->dhcprequest-->dhcpack

    VM虚拟机提供dhcp服务功能,故测试不能使用自带的三种用户模式,应自建虚拟网络。

    ifconfig eth1 10.0.10.1/24 up

    [root@t2 ~]# yum -y install dhcp

    [root@t2 ~]# rpm -ql dhcp

    cp -p /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

    [root@t2 ~]# cat /etc/dhcp/dhcpd.conf

    dhcpd.conf    

    [root@t2 ~]# systemctl start dhcpd.service

    通过另外一台服务器配置dhcp设置网卡后,在dhcp服务器上存在租赁记录:

    [root@t2 /etc/dhcp]# tail /var/lib/dhcpd/dhcpd.leases

    dhcpd.leases    
     1 lease 10.0.10.11 {
     2   starts 6 2017/08/19 14:46:16;
     3   ends 6 2017/08/19 14:56:16;
     4   cltt 6 2017/08/19 14:46:16;
     5   binding state active;
     6   next binding state free;
     7   rewind binding state free;
     8   hardware ethernet 00:0c:29:e3:ea:af;
     9   client-hostname "t3";
    10 }

    http

    [root@t2 ~]# yum -y install httpd

    [root@t2 ~]# cat /etc/httpd/conf/httpd.conf|grep IncludeOptional

    #IncludeOptional conf.d/*.conf

    [root@t2 ~]# systemctl start httpd.service

    mount /dev/sr0 /var/www/html/Centos7

    准备系统文件:

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

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

    [root@t2 ~]# cp /media/cdrom/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/

    [root@t2 ~]# cp /usr/share/syslinux/{chain.c32,mboot.c32,menu.c32,memdisk} /var/lib/tftpboot/

    [root@t2 ~]# mkdir -pv /var/lib/tftpboot/pxelinux.cfg

    [root@t2 ~]# cat pxelinux.cfg/default

    1 default menu.c32
    2 prompt 5 
    3 timeout 15
    4 MENU TITLE Hello , luomr
    5 
    6 LABEL linux
    7 MENU LABEL Install CentOS / x86_64
    8 KERNEL vmlinuz
    9 APPEND initrd=initrd.img inst.repo=http://10.0.10.1/Centos7 ks=http://10.0.10.1/ks.cfg
    default

    确认文件:

    [root@t2 /var/lib/tftpboot]# ls

    chain.c32   mboot.c32  menu.c32    pxelinux.cfg

    initrd.img  memdisk    pxelinux.0  vmlinuz

    ks.cfg

    注:以下为ks.cfg内容,可直接复制粘贴使用

    [root@t2 ~]# cp ks.cfg /var/www/html/

      1 #platform=x86, AMD64, 或 Intel EM64T
      2 #version=DEVEL
      3 # Install OS instead of upgrade
      4 install
      5 # Keyboard layouts
      6 keyboard 'us'
      7 # Root password
      8 rootpw --plaintext 000000
      9 # Use network installation
     10 url --url="http://10.0.10.1/Centos7"
     11 # System language
     12 lang zh_CN
     13 # Firewall configuration
     14 firewall --disabled
     15 # System authorization information
     16 auth  --useshadow  --passalgo=sha512
     17 # Use graphical install
     18 graphical
     19 # SELinux configuration
     20 selinux --disabled
     21 # Do not configure the X Window System
     22 skipx
     23 
     24 # Network information
     25 network  --bootproto=dhcp --device=eth0
     26 # Reboot after installation
     27 reboot
     28 # System timezone
     29 timezone Asia/Shanghai
     30 # System bootloader configuration
     31 bootloader --location=mbr
     32 # Partition clearing information
     33 clearpart --all --initlabel
     34 # Disk partitioning information
     35 part /boot --fstype="ext4" --ondisk=sda --size=200
     36 part /usr/local --fstype="ext4" --ondisk=sda --size=8000
     37 part swap --fstype="swap" --ondisk=sda --size=800
     38 part / --fstype="ext4" --grow --ondisk=sda --size=1
     39 
     40 %packages
     41 @development
     42 @remote-system-management
     43 ElectricFence
     44 ant
     45 babel
     46 bzr
     47 chrpath
     48 cmake
     49 cvs
     50 expect
     51 imake
     52 ksc
     53 lrzsz
     54 libstdc++-docs
     55 mercurial
     56 nasm
     57 net-tools
     58 perltidy
     59 rpmdevtools
     60 rpmlint
     61 vim
     62 systemtap-sdt-devel
     63 systemtap-server
     64 
     65 %end
     66 
     67 %post --interpreter=/bin/sh
     68 #!/bin/bash
     69 #by luomr
     70 
     71 #deploy yum 
     72 rm -rf /etc/yum.repos.d/*.repo
     73 cat>/etc/yum.repos.d/local.repo << EOF
     74 [Centos7]
     75 name=This is a local repo
     76 baseurl=http://10.0.10.1/Centos7
     77 enabled=1
     78 gpgcheck=0
     79 EOF
     80 yum clean all && yum list
     81 
     82 #network
     83 systemctl restart network.service
     84 
     85 ifconfig |grep inet|awk 'NR==1{print $2}' >/tmp/ip_local
     86 ip=`cat /tmp/ip_local`
     87 #nwn : network name
     88 nwn=`ifconfig |grep eno|awk -F: '{print $1}'`
     89 path_n=/etc/sysconfig/network-scripts/ifcfg-"$nwn"
     90 
     91 
     92 sed -i 's/BOOTPROTO=dhcp/BOOTPROTO=static/g' $path_n
     93 cat>>$path_n <<EOF
     94 IPADDR=$ip
     95 NETMASK=255.255.255.0
     96 EOF
     97 
     98 ifdown $nwn && ifup $nwn
     99 
    100 %end
    ks.cfg

    配置完毕,测试,本人实操成功!

  • 相关阅读:
    pom.xml报错web.xml is missing and <failOnMissingWebXml> is set to true
    JDK编译环境和运行环境版本不一致:unsupported major.minor version 52.0
    jdk与eclipse版本不一致导致:java was started but returned exit code=13
    Maven工程配置文件存放路径与读取配置文件路径配置
    maven官网下载bin.tar.gz和bin.zip以及src.tar.gz和src.zip的区别
    SpringBoot如何配置静态地址与访问路径
    好用免费的PPT网站
    executor可实现线程任务的提交与执行解耦的原因
    Maven配置阿里镜像库和本地库的方法
    SpringBoot热加载
  • 原文地址:https://www.cnblogs.com/kazihuo/p/7399646.html
Copyright © 2011-2022 走看看