系统安装介绍
系统装机的三种引导方式
- 硬盘
- 光驱
- 网络
系统安装过程
- 加载 boot loader
- 加载启动安装菜单
- 加载内核和initrd系统
- 加载根系统
- 运行anaconda的安装向导
PXE
概念
PXE( Preboot eXecution Environment,预启动执行环境 )是由Inter公司开发的网络引导技术,工作在Client/Server模式,允许客户机通过网络从远程服务器下载引导镜像,并加载安装文件或整个操作系统。
PXE是通过网卡引导启动。
优点
- 规模化:同时装配多台服务器,无需每一台单独安装操作系统;
- 自动化:实现服务器的自动安装及自动配置各种服务;
- 远程实现:不需要光盘、U盘等安装介质,方便快捷的同时又可以保障服务器安全。
PXE网络装机操作过程
服务器内网IP地址:192.168.177.150
步骤1 :关闭防火墙 ,安装tftp-server软件包,配置文件并开启服务
[root@localhost ~]# systemctl stop firewalld //关闭防火墙
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# yum -y install tftp-server xinetd //安装软件包
[root@localhost ~]# vim /etc/xinetd.d/tftp //配置文件
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp //#TFTP使用UDP协议
wait = no //no表示客户机可以多台一起连接,yes表示客户机只能一台一台连接
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot //指定TFTP根目录(文件存储路径)
disable = no //no表示开启TFTP服务
per_source = 11
cps = 100 2
flags = IPv4
}
[root@localhost ~]# systemctl enable --now xinetd tftp //启动服务
Created symlink from /etc/systemd/system/sockets.target.
wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
步骤2:安装dhcp软件包 配置文件并开启服务
[root@localhost ~]# yum -y install dhcp //安装dhcp软件包
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? yes
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
13 # Use this to enble / disable dynamic dns updates globally.
14 ddns-update-style none; //取消注释,禁止动态信息
15
16 next-server 192.168.177.150; //指定TFTP协议
17 filename "pxelinux.0"; //引导程序文件
18
19
20 # If this DHCP server is the official DHCP server for the local
21 # network, the authoritative directive should be uncommented.
22 #authoritative;
34 # This is a very basic subnet declaration.
35
36 subnet 192.168.177.0 netmask 255.255.255.0 {
37 range 192.168.177.160 192.168.177.240; //配置地址池
38 option routers 192.168.177.150; //配置网关
39 }
40
41 # This declaration allows BOOTP clients to get dynamic addresses,
42 # which we don't really recommend.
[root@localhost ~]# systemctl enable --now dhcpd //启动服务
步骤3:安装syslinux软件包,准备 PXE 引导程序
[root@localhost pxeboot]# cp vmlinuz initrd.img /var/lib/tftpboot/
[root@localhost pxeboot]# ls !$
ls /var/lib/tftpboot/
initrd.img vmlinuz
[root@localhost pxeboot]# yum install -y syslinux //安装syslinux软件包
[root@localhost pxeboot]# cd /usr/share/syslinux/
[root@localhost syslinux]# cp pxelinux.0 /var/lib/tftpboot/ 复制 PXE引导程序 到TFTP根目录下
[root@localhost syslinux]# cd /mnt/
[root@localhost mnt]# ls
CentOS_BuildTag LiveOS
EFI Packages
EULA repodata
GPL RPM-GPG-KEY-CentOS-7
images RPM-GPG-KEY-CentOS-Testing-7
isolinux TRANS.TBL
步骤4:安装FTP服务
[root@localhost mnt]# yum install -y vsftpd //安装vsftpd软件包
[root@localhost mnt]# cd /var/ftp/
[root@localhost ftp]# mkdir centos7
[root@localhost ftp]# mount /dev/sr0 /var/ftp/centos7/ //挂载
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ftp]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 37G 4.1G 33G 11% /
devtmpfs 975M 0 975M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 19M 972M 2% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 1014M 164M 851M 17% /boot
tmpfs 199M 4.0K 199M 1% /run/user/42
tmpfs 199M 48K 199M 1% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /mnt
[root@localhost ftp]# ls /mnt/
CentOS_BuildTag LiveOS
EFI Packages
EULA repodata
GPL RPM-GPG-KEY-CentOS-7
images RPM-GPG-KEY-CentOS-Testing-7
isolinux TRANS.TBL
[root@localhost ftp]# systemctl enable --now vsftpd 启动vsftpd服务
步骤5:准备CentOS 7 安装 源配置启动菜单文件
默认的启动菜单文件在TFTP根目录的 pxelinux.cfg子目录下,文件名为default
[root@localhost ftp]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# mkdir pxelinux.cfg
[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# vim default
default auto #指定默认入口名称
prompt 1 #设置是否等待用户选择,“1”表示等待用户控制
bel auto
kernel vmlinuz
append initrd=initrd.img method=ftp://192.168.177.150/centos7
label linux text #文本安装引导入口
kernel vmlinuz
append text initrd=initrd.img method=ftp://192.168.177.150/centos7
label linux rescue #救援模式引导入口
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://192.168.177.150/centos7
[root@localhost pxelinux.cfg]# cd ..
[root@localhost tftpboot]# ls -R
.:
initrd.img pxelinux.0 pxelinux.cfg vmlinuz
./pxelinux.cfg:
default
使用 VMware创建的虚拟机进行测试,虚拟机内存不少于 2GB,开启虚拟机,在提示字符串“boot:”后执行“auto”命令,将会自动通过网络下载安装文件,并进入默认的图形安装入口;
实现Kickstart无人值守安装
步骤1:安装Kickstart软件包
[root@localhost ~]# yum install -y system-config-kickstart
步骤2:配置kickstart选项并保存
步骤3: 配置需要安装的软件包
vim /root/anaconda-ks.cfg
[root@localhost ~]# cp /root/ks.cfg /var/ftp/ks.cfg
cp:是否覆盖"/var/ftp/ks.cfg"? yes
步骤4:导菜单文件default,添加ks引导参数
vim /var/lib/tftpboot/pxelinux.cfg/default