2020.09.11 PXE自动化部署作业(二)

2020.9.11 作业(二)

实验一:使用 kickstart 半自动化安装CentOS系统

1.centos8 安装基于HTTP的yum源并且添加centos6 和centos7的光盘

[11:13:56 root@localhost ~]#echo '- - -' > /sys/class/scsi_host/host2/scan 
[11:20:05 root@localhost ~]#echo '- - -' > /sys/class/scsi_host/host2/scan 
[11:20:06 root@localhost ~]#echo '- - -' > /sys/class/scsi_host/host2/scan 
​
[11:21:59 root@localhost ~]#lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sr0     11:0    1    7G  0 rom  #根据文件大小对应centos7
sr1     11:1    1  3.7G  0 rom  #centos6
sr2     11:2    1  7.7G  0 rom  #centos8

注意:以上相对路径都是相对于光盘的根,和工作目录无关

mkdir /var/www/html/centos/8/os/x86_64 -pv
mkdir /var/www/html/centos/7/os/x86_64 -pv
mkdir /var/www/html/centos/6/os/x86_64 -pv
mount /dev/sr0  /var/www/html/centos/8/os/x86_64
mount /dev/sr2  /var/www/html/centos/7/os/x86_64
mount /dev/sr1  /var/www/html/centos/6/os/x86_64


2.system-config-kickstart 生成应答文件

3.创建centos8的应答文件 并放在10.0.0.8的共享网站上

[15:52:13 root@localhost ~]#touch /var/www/html/ksdir/ks8.cfg
​
[16:23:24 root@localhost ~]#vim /var/www/html/ksdir/ks8.cfg
​
network  --bootproto=dhcp --device=ens160 --ipv6=auto --activate
network  --hostname=centos8.magedu.com
rootpw --iscrypted
$6$j9YhzDUnQVnxaAk8$qv7rkMcPAEbV5yvwsP666DXWYadd3jYjkA9fpxAo9qYotjGGBUclCGoP1TRv
gHBpqgc5n0RypMsPTQnVDcpO01
firstboot --enable
skipx
services --disabled="chronyd"
timezone Asia/Shanghai --isUtc --nontp
user --name=wang --
password=6oUfb/02CWfLb5l8f$sgEZeR7c7DpqfpmFDH6huSmDbW1XQNR4qKl2EPns.gOXqlnAIgv9p
TogtFVaDtEpMOC.SWXKYqxfVtd9MCwxb1 --iscrypted --gecos="wang"
​
part / --fstype="xfs" --ondisk=sda --size=102400
part /data --fstype="xfs" --ondisk=sda --size=51200
part swap --fstype="swap" --ondisk=sda --size=2048
part /boot --fstype="ext4" --ondisk=sda --size=1024
%packages
@^minimal-environment
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'                      
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
%post
useradd mage
echo magedu | passwd --stdin mage &> /dev/null
%end   
​
[16:25:50 root@localhost ksdir]#mkdir /data/iso
#centos8光盘中的isolinux文件夹拷贝到/data/iso中
[16:26:00 root@localhost ksdir]#cp -r /var/www/html/centos/8/os/x86_64/isolinux/   /data/iso
​
[16:27:33 root@localhost ksdir]#tree /data/iso/
/data/iso/
└── isolinux
    ├── boot.cat
    ├── boot.msg
    ├── grub.conf
    ├── initrd.img
    ├── isolinux.bin
    ├── isolinux.cfg #显示菜单风格
    ├── ldlinux.c32
    ├── libcom32.c32
    ├── libutil.c32
    ├── memtest
    ├── splash.png
    ├── TRANS.TBL
    ├── vesamenu.c32
    └── vmlinuz
    
[16:45:43 root@localhost ksdir]#vim /data/iso/isolinux/isolinux.cfg
label linux
  menu label ^Auto Install CentOS Linux 8
  kernel vmlinuz
  append initrd=initrd.img ks=http://10.0.0.8/ksdir/ks8.cfg 
​
​
​
label rescue
  menu label ^Auto Rescue a CentOS Linux system
  kernel vmlinuz
  append initrd=initrd.img inst.repo=http://10.0.0.8/centos/8/os/x86_64 rescue quiet
​
​
​
label local
    menu default
  menu label Boot from ^local drive
  localboot 0xffff
  
#文件刻录为光盘
[16:53:11 root@localhost ksdir]#dnf -y install mkisofs
​
[16:53:11 root@localhost ksdir]# mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "CentOS 8.0 x86_64 boot" -b isolinux/isolinux.bin -c isolinux/boot.cat -o /root/boot.iso /data/iso/
​
[16:53:11 root@localhost ksdir]#ll -h /root/boot.iso 
-rw-r--r-- 1 root root 68M Sep 10 16:52 /root/boot.iso
​
#新建虚拟机,将boot.iso作为启动光盘,进行安装centos7

实验二:实现pxe安装双系统centos6、centos7

#DHCP设置
[17:49:36 root@localhost ~]#yum -y install  dhcp-server
​
[17:49:13 root@localhost ~]#systemctl start dhcpd
option domain-name "example.org";
option domain-name-servers 180.76.76.76,223.5.5.5;
​
default-lease-time 68400;
max-lease-time 172800;
​
log-facility local7
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.50 10.0.0.100;
range 10.0.0.150 10.0.0.200;
option routers 10.0.0.2;
next-server 10.0.0.8;
filename "pxelinux.0";      
}
​
[18:59:35 root@localhost ~]#systemctl restart dhcpd
[19:00:14 root@localhost ~]#ss -nul
UNCONN  0        0                  0.0.0.0:67             0.0.0.0:*      
UNCONN  0        0           0.0.0.0%virbr0:67             0.0.0.0:*   
​
#实现TFTP服务
[20:10:56 root@localhost ~]#yum -y install  tftp-server
​
[20:16:15 root@localhost ~]#systemctl start tftp.service 
​
[20:16:35 root@localhost ~]#ss -ntul
udp   UNCONN  0       0                      *:69                 *:*  
​
#共享文件夹
[20:21:24 root@localhost ~]#cd /var/lib/tftpboot/
​
[20:28:19 root@localhost tftpboot]#updatedb 
​
[20:28:33 root@localhost tftpboot]#locate pxelinux.0
​
[20:28:38 root@localhost tftpboot]#yum provides  *pxelinux.0
​
[20:30:58 root@localhost tftpboot]#yum -y install syslinux-nonlinux-6.04-4.el8.noarch
​
[20:32:49 root@localhost tftpboot]#rpm -ql syslinux-nonlinux-6.04-4.el8.noarch|grep pxelinux.0 
/usr/share/syslinux/pxelinux.0
​
#pxelinux.0文件复制到/var/lib/tftpboot
[20:33:14 root@localhost tftpboot]#cp /usr/share/syslinux/pxelinux.0 .
​
[20:33:25 root@localhost tftpboot]#ll
total 48
-rw-r--r-- 1 root root 42791 Sep 10 20:33 pxelinux.0
​
#利用PXE实现自动化系统部署
#从光盘中拷贝vmlinuz initrd.img 到tftp共享文件夹中
[20:43:39 root@localhost tftpboot]#lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0   50G  0 part /data
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    2G  0 part [SWAP]
sr0     11:0    1    7G  0 rom  /var/www/html/centos/8/os/x86_64
sr1     11:1    1  3.7G  0 rom  /var/www/html/centos/6/os/x86_64
sr2     11:2    1  4.2G  0 rom  /var/www/html/centos/7/os/x86_64
​
[20:45:42 root@localhost tftpboot]#cp /misc/cd/isolinux/vmlinuz  .
​
[20:45:55 root@localhost tftpboot]#cp /misc/cd/isolinux/initrd.img  .
​
#寻找菜单文件背景图片文件 menu.c32菜单风格文件
[20:49:57 root@localhost tftpboot]#locate menu.c32
​
[20:50:09 root@localhost tftpboot]#updatedb
​
[20:50:16 root@localhost tftpboot]#locate menu.c32
​
[20:50:30 root@localhost tftpboot]#cp /usr/share/syslinux/menu.c32 .
​
#生成菜单内容文件
[20:58:12 root@localhost tftpboot]#mkdir prelinux.cfg
​
[21:01:46 root@localhost tftpboot]#cp /data/iso/isolinux/isolinux.cfg  pxelinux.cfg/default
​
[21:03:21 root@localhost tftpboot]#tree
.
├── initrd.img
├── menu.c32
├── pxelinux.cfg
│   └── default
├── pxelinux.0
└── vmlinuz
​
​
#准备centos6的应答文件
[21:23:06 root@localhost ksdir]#cat ks6.cfg
install
text
reboot
url --url=http://10.0.0.8/centos/6/os/x86_64/
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp  --noipv6
rootpw  --iscrypted
$6$b6C5mM/BwOMBoK8H$cYZFrHoNlOL0iDsxOTRhwnWJ3yfFmf7mRJBOxEqGoI56UMrT8J7qlrGwX7tS
nOf7wKxYR2hAvAREILDgOgsFe1
firewall --disabled
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb
quiet"
zerombr
clearpart --all --initlabel
part /boot --fstype=ext4 --size=1024
part / --fstype=ext4 --size=50000
part /data --fstype=ext4 --size=30000
part swap --size=2048
%packages
@core
@server-policy
@workstation-policy
autofs
vim-enhanced
%end
%post
useradd wang
echo magedu | passwd --stdin wang &> /dev/null
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/* /etc/yum.repos.d/bak
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=base
baseurl=file:///misc/cd
gpgcheck=0
EOF
%end
​
#准备centos6的应答文件
[21:23:06 root@localhost ksdir]#cat ks6.cfg
install
text
reboot
url --url=http://10.0.0.8/centos/6/os/x86_64/
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp  --noipv6
rootpw  --iscrypted
$6$b6C5mM/BwOMBoK8H$cYZFrHoNlOL0iDsxOTRhwnWJ3yfFmf7mRJBOxEqGoI56UMrT8J7qlrGwX7tS
nOf7wKxYR2hAvAREILDgOgsFe1
firewall --disabled
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb
quiet"
zerombr
clearpart --all --initlabel
part /boot --fstype=ext4 --size=1024
part / --fstype=ext4 --size=50000
part /data --fstype=ext4 --size=30000
part swap --size=2048
%packages
@core
@server-policy
@workstation-policy
autofs
vim-enhanced
%end
%post
useradd wang
echo magedu | passwd --stdin wang &> /dev/null
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/* /etc/yum.repos.d/bak
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=base
baseurl=file:///misc/cd
gpgcheck=0
EOF
%end
​
#修改菜单文件
[21:32:01 root@localhost tftpboot]#cat pxelinux.cfg/default
default menu.c32
timeout 60
​
menu title CentOS Linux 8
​
label linux 8
  menu label Auto Install CentOS Linux ^8
  kernel centos8/vmlinuz
  append initrd=centos8/initrd.img ks=http://10.0.0.8/ksdir/ks8.cfg              
​
label linux 7
  menu label Auto Install CentOS Linux ^7
    kernel centos7/vmlinuz
      append initrd=centos7/initrd.img ks=http://10.0.0.8/ksdir/ks7.1.cfg
​
label linux 6
  menu label Auto Install CentOS Linux ^6
    kernel centos6/vmlinuz
      append initrd=centos6/initrd.img ks=http://10.0.0.8/ksdir/ks6.cfg
​
​
​
label rescue
  menu label ^Rescue a CentOS Linux system
  kernel vmlinuz
  append initrd=initrd.img inst.repo=http://10.0.0.8/centos/8/os/x86_64 rescue quiet
​
label local
    menu default
  menu label Boot from ^local drive
  localboot 0xffff
  
  
[21:33:07 root@localhost tftpboot]#mkdir centos{6,7}
[21:33:25 root@localhost tftpboot]#cp vmlinuz  initrd.img 
[21:34:09 root@localhost tftpboot]#tree
.
├── centos6
├── centos7
├── initrd.img
├── menu.c32
├── pxelinux.0
├── pxelinux.cfg
│   └── default
└── vmlinuz
​
[21:34:57 root@localhost tftpboot]#cp /var/www/html/centos/7/os/x86_64/isolinux/vmlinuz  centos7/
[21:35:36 root@localhost tftpboot]#cp /var/www/html/centos/7/os/x86_64/isolinux/initrd.img  centos7/
[21:35:44 root@localhost tftpboot]#cp /var/www/html/centos/6/os/x86_64/isolinux/initrd.img  centos6/
[21:36:05 root@localhost tftpboot]#cp /var/www/html/centos/6/os/x86_64/isolinux/vmlinuz  centos6/
[21:36:36 root@localhost tftpboot]#tree
.
├── centos6
│   ├── initrd.img
│   └── vmlinuz
├── centos7
│   ├── initrd.img
│   └── vmlinuz
├── initrd.img
├── menu.c32
├── pxelinux.0
├── pxelinux.cfg
    └── default
​
#新建centos6、centos7虚拟机,断开光盘链接,自动使用网络连接,选择插入对应的操作系统
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值