pxe 快速部署自动安装_2018_lcf

——准备工作

1.http或ftp的系统安装源

安装源:192.168.2.254

ftp://192.168.2.254/centos7/

2.准备dhcp服务器,tftp引导文件服务器

pxe:192.168.2.100

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

[root@pxe ~]# vi /etc/dhcp/dhcpd.conf  //根据自己环境配置,要确保同网段中没有其它dhcp服务器!

subnet 192.168.2.0 netmask 255.255.255.0 {
        range 192.168.2.10 192.168.2.200;
        next-server 192.168.2.100;
        filename "pxelinux.0";
}

[root@pxe ~]# yum -y install tftp-server.x86_64  

[root@pxe ~]# yum -y install syslinux    //安装这个提取引导文件pxelinux.0

[root@pxe ~]# rpm -ql syslinux | grep pxelinux.0
/usr/share/syslinux/gpxelinux.0

/usr/share/syslinux/pxelinux.0

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

[root@pxe tftpboot]# pwd
/var/lib/tftpboot  

[root@pxe tftpboot]# mkdir pxelinux.cfg   //创建这个目录,固定目录位置

[root@pxe tftpboot]# wget -O pxelinux.cfg ftp://192.168.2.254/centos7/isolinux/isolinux.cfg

[root@pxe tftpboot]# ls   

initrd.img  isolinux.bin  pxelinux.0  pxelinux.cfg  splash.png  vesamenu.c32  vmlinuz

上面文件都从安装源那里拷贝


[root@pxe tftpboot]# vi pxelinux.cfg/default 

....

label linux
  menu default
  menu label ^Install CentOS 7-2018
  kernel vmlinuz

  append initrd=initrd.img inst.repo=ftp://192.168.2.254/centos7/

....

label rescue
  menu indent count 5
  menu label ^Rescue a CentOS system
  text help
        If the system will not boot, this lets you access files
        and edit config files to try to get it booting again.
  endtext
  kernel vmlinuz

  append initrd=initrd.img inst.repo=ftp://192.168.2.254/centos7/ rescue

.....

//改上面绿色部分就可以了,安装源卡死是要把inst.stage2 改成inst.repo就OK了

//kernel vmlinuz和append initrd=initrd.img这里如果你文件存在/var/lib/tftpboot下,就不用更改

//如果你有多个系统那就可以新建个目录abc,那就要写成abc/vmlinuz ,abc/initrd.img才行了

——开始安装


//前进开始安装就可以了。

——部署自动安装

可以安装system-config-kickstart软件包,制作应答文件。

制作完成后可以放到可访问的ftp或http空间里,这里是放在这个位置

ftp://192.168.2.254/ks7.cfg

然后修改下面一项就可以了,记得把int.repo改成kfs

[root@pxe tftpboot]# vi pxelinux.cfg/default 

....

label linux
  menu default
  menu label ^Install CentOS 7-2018
  kernel vmlinuz

  append initrd=initrd.img kfs=ftp://192.168.2.254/ks7.cfg

....

改好后和上面一样创建虚拟机就可以了,然后会自动安装和部署。

---ks7.cfg内容/生产环境下的最小化安装/高手写的

  #platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted rootadmin
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="ftp://192.168.2.254/centos7"
# System language
lang en_US.UTF-8
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
# Installation logging level
logging --level=warning
# Run the Setup Agent on first boot
firstboot --disable
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Network information
network --device=bootif --onboot=on --hostname=localhost --bootproto=bootp --noipv6
# Reboot after installation
reboot
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --asprimary --fstype=xfs --size=512
part /     --asprimary --fstype=xfs --size=1 --grow


%packages --nobase
@Core --nodefaults
-iwl3160-firmware
-iwl6000g2b-firmware
-iwl2030-firmware
-iwl7265-firmware
-iwl1000-firmware
-iwl4965-firmware
-iwl2000-firmware
-iwl3945-firmware
-alsa-tools-firmware
-aic94xx-firmware
-iwl135-firmware
-iwl7260-firmware
-iwl6050-firmware
-iwl6000g2a-firmware
-iwl5000-firmware
-ivtv-firmware
-iwl100-firmware
-iwl5150-firmware
-iwl105-firmware
-iwl6000-firmware
-alsa-firmware
-postfix
-audit
-tuned
chrony
psmisc
net-tools
screen
vim-enhanced
tcpdump
lrzsz
ltrace
strace
traceroute
whois
bind-utils
tree
mlocate
rsync
lsof
lftp
patch
diffutils
cpio
time
nmap
socat
man-pages
rpm-build
createrepo
%end


%pre
%end


%post --interpreter=/bin/bash
rm -f /etc/yum.repos.d/*.repo
cat >/etc/yum.repos.d/local.repo <<'EOF'
[local_repo]
name=CentOS-$releasever - Base
baseurl=ftp://192.168.2.254/centos7
enabled=1
gpgcheck=1
EOF
rpm -import ftp://192.168.2.254/centos7/RPM-GPG-KEY-CentOS-7
yum erase -y NetworkManager NetworkManager-libnm kexec-tools firewalld-filesystem polkit
sed 's,^CRONDARGS=.*,&"-m off",' -i /etc/sysconfig/crond
sed 's,^\(OPTIONS=\).*,\1"-4",'  -i /etc/sysconfig/chronyd
sed 's,^server .*,&\ncmdallow 127.0.0.1,' -i /etc/chrony.conf
sed 's,^#\(terminfo xterm \x27is.*\),\1\nterm xterm,' -i /etc/screenrc
cat >>/etc/sysconfig/network <<'EOF'
IPV6INIT="no"
NETWORKING="yes"
NOZEROCONF="yes"
EOF
echo -e "# ::1\t\tlocalhost localhost.localdomain localhost6 localhost6.localdomain6" >/etc/hosts
echo -e "127.0.0.1\tlocalhost localhost.localdomain localhost4 localhost4.localdomain4" >>/etc/hosts
echo -e 'export TZ='Asia/Shanghai' PYTHONSTARTUP="/usr/lib64/python2.7/pystartup.py" TMOUT=7200' >/etc/profile.d/environ.sh
echo -e "blacklist acpi_pad\nblacklist power_meter" >/etc/modprobe.d/blacklist.conf
cat >/usr/lib64/python2.7/pystartup.py <<'EOF'
#!/usr/bin/python
# -*- coding:utf_8 -*-
#from __future__ import print_function
from rlcompleter import readline
readline.parse_and_bind("tab: Complete")
EOF
cat >/etc/sysctl.d/70-system.conf <<'EOF'
net.ipv4.ip_forward = 1
net.ipv4.ip_default_ttl = 255
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 0


net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
kernel.sysrq = 16
vm.swappiness = 0
EOF
# config vimrc
cat >>/etc/vimrc<<'EOF'
set wrapscan
set noautoindent
set showmatch
set binary
set noswapfile
set ignorecase          " Do case insensitive matching
set foldmethod=syntax
set foldlevel=100
filetype plugin off
EOF
sed -e 's,^#\(Port\).*,\1 10022,' \
    -e 's,^#\(ListenAddress 0.0.0.0\),\1,' \
    -e 's,^#\(PermitRootLogin\).*,\1 yes,' \
    -e 's,^#\(MaxAuthTries\).*,\1 3,' \
    -e 's,^#\(UseDNS\).*,\1 no,' -i /etc/ssh/sshd_config
cat >/etc/sysconfig/network-scripts/ifcfg-eth0 <<'EOF'
# Generated by dracut initrd
DEVICE="eth0"
ONBOOT="yes"
IPV6INIT="no"
IPV4_FAILURE_FATAL="no"
NM_CONTROLLED="no"
TYPE="Ethernet"
BOOTPROTO="dhcp"
EOF
%end 

-----

错识一:安装源卡死


  append initrd=initrd.img inst.repo=ftp://192.168.2.254/centos7/ rescue

.....

//改上面绿色部分就可以了,安装源卡死是要把inst.stage2 改成inst.repo就OK了

------------------

错识二:因为内存给的不够,导致,centos7要给1.5G以上,把内存调大重新创建即可





猜你喜欢

转载自blog.csdn.net/cbuy888/article/details/81003860
PXE
今日推荐