系统安装介绍
系统装机的三种引导方式
- 硬盘
- 光驱
-
网络
系统安装过程
- 加载 boot loader
- 加载启动安装菜单
- 加载内核和initrd系统
- 加载根系统
- 运行anaconda的安装向导
PXE
概念
PXE( Preboot eXecution Environment,预启动执行环境 )是由Inter公司开发的网络引导技术,工作在Client/Server模式,允许客户机通过网络从远程服务器下载引导镜像,并加载安装文件或整个操作系统。
PXE是通过网卡引导启动。
优点
- 规模化:同时装配多台服务器,无需每一台单独安装操作系统;
- 自动化:实现服务器的自动安装及自动配置各种服务;
- 远程实现:不需要光盘、U盘等安装介质,方便快捷的同时又可以保障服务器安全。
PXE网络装机操作过程
实验环境:
服务器内网IP地址:172.16.100.100。
DHCP、TFTP、FTP服务全都搭建在这一台服务器上。
实验步骤
服务器配置
步骤一:安装四个软件包:dhcp、tftp-server、vsftpd、syslinux。
[root@localhost ~]# yum install dhcp tftp-server.x86_64 vsftpd syslinux -y
步骤二:将虚拟机的网卡设置为仅主机模式,修改网卡配置文件,重启网络服务。模拟内网环境。
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=ed893cbb-1c79-49b5-bab3-47d3acaa9a79
DEVICE=ens33
ONBOOT=yes
IPADDR=172.16.100.100 //设置地址为172.16.100.100
NETMASK=255.255.255.0
GATEWAY=172.16.100.100 //设置网关为172.16.100.100
#DNS1=8.8.8.8 //注释掉DNS服务器
#DNS2=114.114.114.114
[root@localhost ~]# systemctl restart network
root@localhost ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.100.100 netmask 255.255.255.0 broadcast 172.16.100.255
inet6 fe80::3472:123c:a468:4387 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:2a:03:4e txqueuelen 1000 (Ethernet)
RX packets 115958 bytes 148892071 (141.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 42812 bytes 2686073 (2.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
步骤三:修改TFTP服务配置文件/etc/xinetd.d/tftp,将服务开启(默认是关闭状态)
[root@localhost ~]# rpm -qc tftp-server //查看tftp-server的配置文件位置
/etc/xinetd.d/tftp
[root@localhost ~]# vim /etc/xinetd.d/tftp //编辑配置文件
service tftp
{
socket_type = dgram
protocol = udp //使用UDP协议
wait = yes //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 start tftp //开启tftp服务
[root@localhost ~]# systemctl enable tftp //设置开机自启
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
步骤四:配置DHCP服务器,分配IP地址,指明tftp服务器的地址,开启服务
[root@localhost ~]# cd /usr/share/doc/dhcp-4.2.5/
[root@localhost dhcp-4.2.5]# ls
dhcpd6.conf.example dhcpd.conf.example ldap
[root@localhost dhcp-4.2.5]# cp dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp:是否覆盖"/etc/dhcp/dhcpd.conf"? y
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
next-server 172.16.100.100; //指定 TFTP 服务器的地址
filename"pxelinux.0"; //指定 PXE 引导程序的文件名
subnet 172.16.100.0 netmask 255.255.255.0 { //声明要分配的网段地址
range 172.16.100.20 172.16.100.90; //设置地址池
option routers 172.16.100.100; //默认网关地址指向TFTP服务器的IP地址
}
[root@localhost ~]# systemctl start dhcpd //开启dhcpd服务
[root@localhost ~]# systemctl enable dhcpd //设置开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
步骤五:将光盘挂载到/var/ftp的子目录centos7下,并将三大文件先拷入/var/lib/tftpboot/ 目录中:vmlinuz,initrd.img。pxelinux.0。
# 挂载光盘,先将光盘内的两个文件vmlinuz、initrd.img拷入/var/lib/tftpboot目录。
[root@localhost ~]# cd /var/ftp
[root@localhost ftp]# mkdir centos7
[root@localhost ftp]# mount /dev/sr0 centos7 //将光盘挂载到/var/ftp/centos7/目录下
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ftp]# cd centos7
[root@localhost centos7]# ls
CentOS_BuildTag GPL LiveOS RPM-GPG-KEY-CentOS-7
EFI images Packages RPM-GPG-KEY-CentOS-Testing-7
EULA isolinux repodata TRANS.TBL
[root@localhost centos7]# cd isolinux
[root@localhost isolinux]# ls
boot.cat grub.conf isolinux.bin memtest TRANS.TBL vmlinuz
boot.msg initrd.img isolinux.cfg splash.png vesamenu.c32
[root@localhost isolinux]# cp vmlinuz initrd.img /var/lib/tftpboot //将光盘内的2个文件拷入tftpboot目录
[root@localhost isolinux]# cd /var/lib/tftpboot
[root@localhost tftpboot]# ls
initrd.img vmlinuz
# 将pxelinux.0文件拷入/var/lib/tftpboot目录。
[root@localhost tftpboot]# rpm -ql syslinux |grep pxelinux.0 //查找pxelinux.0文件位置
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0
[root@localhost tftpboot]# cp /usr/share/syslinux/pxelinux.0 ./ //将pxelinux.0文件拷入tftpboot目录
[root@localhost tftpboot]# ls
initrd.img pxelinux.0 vmlinuz
步骤六:在/var/lib/tftpboot/ 目录下,创建子目录pxelinux.cfg,在pxelinux.cfg目录下编写引导程序的配置文件default。(可参考光盘 isolinux 目录下的 isolinux.cfg 文件)
[root@localhost tftpboot]# mkdir pxelinux.cfg 创建子目录pxelinux.cfg
[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# vim default
label auto
kernel vmlinuz
append initrd=initrd.img method=ftp://172.16.100.100/centos7 //使用ftp服务,指明安装路径
label linux text
kernel vmlinuz
append text initrd=initrd.img method=ftp://172.16.100.100/centos7
label linux rescue
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://172.16.100.100/centos7
步骤七:关闭防火墙和selinux
[root@localhost pxelinux.cfg]# systemctl stop firewalld
[root@localhost pxelinux.cfg]# setenforce 0
关闭防火墙和selinux
步骤一: 创建新的空白虚拟机
步骤二:开启虚拟机:
虚拟机自动获取IP地址、自动安装镜像文件系统,最后出现图形化界面,之后的参数需要手动设置。