作业二
重点 实验一:使用 kickstart 半自动化安装CentOS系统
1、系统默认未安装system-config-kickstart,先进行yum安装
[root@centos7 ~]# yum -y install system-config-kickstart
2、运行kickstart
[root@centos7 ~]# export DISPLAY=10.0.0.1:0.0
[root@centos7 ~]# system-config-kickstart
3、保存ks.cfg文件
[root@centos7 ~]# vim ks.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$aAqX2t/W$g4l6JD68KIc1hAGONXqSw1
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="xfs" --size=102400
part /boot --fstype="xfs" --size=1024
part swap --fstype="swap" --size=2048
part /data --fstype="xfs" --size=51200
%post
useradd zhao
echo magedu | passwd --stdin zhao >& /dev/null
%end
%packages
@web-server
%end
4、在本机打开httpd服务,并将fs.cfg文件上传到网页
[root@centos7 ~]# yum -y install httpd
[root@centos7 ~]# systemctl enable --now httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@centos7 ~]# mv ks.cfg /var/www/html/
5、开启一台新虚拟机
在进入光盘引导界面后,按ESC,出现下图界面,输入:boot:linux ip=dhcp ks=http://10.0.0.132/ks.cfg,回车后自动化安装,出现登录界面表示安装完成
重点 实验八:实现pxe安装双系统centos6、centos7
(1)安装相关软件包并启动
[root@centos7 ~]#yum -y install httpd tftp-server dhcp syslinux
[root@centos7 ~]#systemctl enable --now httpd tftp dhcpd
(2)配置DHCP服务
[root@centos7 ~]#cp /usr/share/doc/dhcp-server/dhcpd.conf.example
/etc/dhcp/dhcpd.conf
[root@centos7 ~]#vim /etc/dhcp/dhcpd.conf
option domain-name "example.com";
option domain-name-servers 180.76.76.76,223.6.6.6;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.50 10.0.0.100;
option routers 10.0.0.2;
next-server 10.0.0.132;
filename "pxelinux.0";
}
[root@centos8 ~]#systemctl start dhcpd
(3)准备yum源和相关目录
[root@centos7 ~]# mkdir -pv /var/www/html/centos/{6,7}/os/x86_64
mkdir: created directory ‘/var/www/html/centos’
mkdir: created directory ‘/var/www/html/centos/6’
mkdir: created directory ‘/var/www/html/centos/6/os’
mkdir: created directory ‘/var/www/html/centos/6/os/x86_64’
mkdir: created directory ‘/var/www/html/centos/7’
mkdir: created directory ‘/var/www/html/centos/7/os’
mkdir: created directory ‘/var/www/html/centos/7/os/x86_64’
[root@centos7 ~]# mount /dev/sr0 /var/www/html/centos/7/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos7 ~]# mount /dev/sr1 /var/www/html/centos/6/os/x86_64/
mount: no medium found on /dev/sr1
(4)准备kickstart文件
[root@centos7 ~]# mkdir /var/www/html/ks
[root@centos7 ~]# vim /var/www/html/ks/ks6.cfg
[root@centos7 ~]# vim /var/www/html/ks/ks7.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$agKAuTmT$7cU/l5zilSqfzxWq1J0pW0
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=etho
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://10.0.0.132/centos/7/os/x86_64"
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="xfs" --size=102400
part /boot --fstype="xfs" --size=1024
part swap --fstype="swap" --size=2048
part /data --fstype="xfs" --size=51200
%post
useradd zhao
echo magedu | passwd --stdin zhao >& /dev/null
%end
%packages
@web-server
%end
(5)准备PXE启动相关文件
[root@centos7 ~]#mkdir /var/lib/tftpboot/centos{6,7}
[root@centos7 ~]#cp /var/www/html/centos/6/os/x86_64/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos6
[root@centos7 ~]#cp /var/www/html/centos/7/os/x86_64/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos7
[root@centos7 ~]#cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/
#生成安装菜单文件
[root@centos7 ~]#mkdir /var/lib/tftpboot/pxelinux.cfg/
[root@centos7 ~]#cp /var/www/html/centos/7/os/x86_64/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
#最终目录结构如下
[root@centos7 ~]#tree /var/lib/tftpboot
.
├── centos6
│ ├── initrd.img
│ └── vmlinuz
├── centos7
│ ├── initrd.img
│ └── vmlinuz
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
└── default
(6)准备启动菜单文件
[root@centos7 ~]#vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 600
menu title Install CentOS Linux
label linux7
menu label Auto Install CentOS Linux ^7
kernel centos7/vmlinuz
append initrd=centos7/initrd.img ks=http://10.0.0.132/ks/ks7.cfg
label linux6
menu label Auto Install CentOS Linux ^6
kernel centos6/vmlinuz
append initrd=centos6/initrd.img ks=http://10.0.0.132/ks/ks6.cfg
label manual
menu label ^Manual Install CentOS Linux 7.8
kernel centos7/vmlinuz
append initrd=centos7/initrd.img
inst.repo=http://10.0.0.132/centos/7/os/x86_64/
label rescue
menu label ^Rescue a CentOS Linux system 7
kernel centos7/vmlinuz
append initrd=centos7/initrd.img
inst.repo=http://10.0.0.132/centos/7/os/x86_64/ rescue
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
(7)客户端测试安装
新准备一台主机,设置网卡引导,可看到看启动菜单,并实现自动安装

浙公网安备 33010602011771号