linux进阶-基于网络的PXE自动化安装详细步骤全get

基于网络的PXE自动化安装详细步骤

在这里插入图片描述

大家好我们又见面了!今天先搭建dhcp服务和tftp服务为后面的PXE实验做准备!
Go

搭建dhcp服务器

实验准备

一台没有ip地址的centos6主机,一台CentOS7虚拟机作为DHCP服务器;网卡设为NAT模式,设置固定IP地址,关闭虚拟机的DHCP功能。如图:

在这里插入图片描述

1.配置静态地址,关闭iptables,selinux服务

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

编辑网卡配置文件
······
TYPE=Ethernet
IPADDR0=192.168.2.7
BOOTPROTO=static
PREFIX=24
DEFROUTE=yes
NAME="eth0"
ONBOOT=yes
······
----------------------------------------------
[root@localhost ~]# iptables -F 
[root@localhost ~]# systemctl stop firewalld ✅
[root@localhost ~]# setenforce 0 ✅
----------------------------------------------
[root@localhost ~]# vim /etc/selinux/config 

编辑selinux配置文件
······
SELINUX=disabled
······

2.安装DHCP服务包并启动dhcp服务

[root@localhost ~]# yum -y install dhcp   #安装dhcp服务 ✅
[root@localhost ~]# systemctl start dhcpd.service   #直接启动dhcp服务会报错 ❌
[root@localhost ~]# systemctl status dhcpd.service   #查看状态,如下图

在这里插入图片描述

3.修改dhcp配置⽂件

系统⾃带的dhcp.conf是空⽂件,找到安装包⾃带的example进⾏修改

[root@localhost ~]# rpm -ql dhcp | grep example  ✅
-------------------------------------------------------------
[root@localhost ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf  ✅

在这里插入图片描述

重启dhcp服务,并设置开机⾃启动

[root@localhost ~]# systemctl start dhcpd.service   #开启dhcp服务 ✅
----------------------------------------------------- 
[root@localhost ~]# systemctl enable dhcpd.service   #设置开机自启 ✅

4.切换到另外⼀台CentOS6虚拟机,查看是否获取到ip地址

执⾏命令重新获取ip地址

[root@localhost ~]# dhclient -d  ✅
---------------------------------
[root@localhost ~]# ifconfig   #可以看到我们获取到的对应地址段的ip

再次查看获取到ip地址,表⽰dhcp服务已搭建成功
利⽤systemctl status dhcpd 命令可观察dhcp分发地址的全过程

[root@localhost ~]# systemctl status dhcpd.service ✅

在这里插入图片描述

tftp服务器

tftp在简单的文字模式FTP命令,常在嵌入式开发中下载文件

参数

-v运行时显示详细的处理信息
-c <命令>远程执行命令
-m <模式>选择传输模式
-V版本信息

【进入TFTP操作】

connect:连接到远程tftp服务器
模式:文件传输模式
put:上传文件
获取:下载文件
quit:退出
详细信息:显示详细的处理信息的
速度:显示包路径
状态:显示当前状态信息
二进制文件:二进制传输模式
ascii:ascii传送模式
rexmt:设置包传输的超时时间
超时:设置重传的超时时间
帮助:帮助信息
?:帮助信息

实验准备

centos 6 192.168.26.6 ---|
						 |---两台实验机器关防火墙、关selinux、chrony同步时间 ✅
centos 7 192.168.26.7 ---|

#centos 6 tftp客户端配置 
    安装 yum install tftp ✅
    安装 yum -y install xinetd ✅   #运行tftp可能会缺,提前装下吧!

#centos 7 为tftp服务器端 
    安装 yum install tftp-server ✅

[root@centos6 ~]# yum -y install tftp   #客户端 ✅

[root@centos7 ~]# yum -y install tftp-server   #服务器端 ✅

开启服务

centos 6:
    service xinetd restart   #开启tftp服务 ✅

centos 7:
    systemctl start tftp.socket   #开启tftp服务器 ✅
    systemctl enable tftp.socket   #设置开机启动 ✅

查看服务器端tftp服务是否启动,并创建测试文件上传共享目录

[root@centos7 ~]# systemctl status tftp.socket ✅
● tftp.socket - Tftp Server Activation Socket
   Loaded: loaded (/usr/lib/systemd/system/tftp.socket; enabled; vendor preset: disabled)
   Active: active (listening) since Wed 2019-11-13 20:52:12 CST; 12min ago
   Listen: [::]:69 (Datagram)

Nov 13 20:52:12 centos7 systemd[1]: Listening on Tftp Server Activation S...t.
Hint: Some lines were ellipsized, use -l to show in full.
[root@centos7 ~]# ss -unl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
UNCONN     0      0           *:48173                   *:*                  
UNCONN     0      0           *:68                      *:*                  
UNCONN     0      0           *:111                     *:*                  
UNCONN     0      0           *:5353                    *:*                  
UNCONN     0      0           *:809                     *:*                  
UNCONN     0      0        [::]:69                   [::]:*                  
UNCONN     0      0        [::]:111                  [::]:*                  
UNCONN     0      0        [::]:809                  [::]:* 
--------------------------------------------------------------------------
[root@centos7 ~]# touch test.txt   #创建测试文件 ✅
[root@centos7 ~]# mv test.txt /var/lib/tftpboot/   #tftp共享文件夹 ✅

使用tftp连接至服务器端,从共享目录下载共享文件

[root@centos6 ~]# tftp 192.168.26.8
tftp> get test.txt
^C
quit
tftp> quit
[root@centos6 ~]# ls
test.txt
tftp客户端、服务器端搭建结束,是不是很简单!那我们接下来的实验吧

搭建PXE环境

实验准备

可用服务器端:192.168.26.7
    老三样:关防火墙、关selinux、chrony同步时间 ✅

1.下载必要的软件包,开启对应的服务

[root@centos7 ~]# yum -y install dhcp tftp-server httpd syslinux   #下载包 ✅
-----------------------------------------------------------
[root@centos7 ~]# systemctl enable dhcpd httpd tftp.socket   #开启对应服务 ✅

2.创建本地yum源

编辑文件,添加开机自动挂载光盘

[root@centos7 ~]# mkdir -pv /var/www/html/centos/7  ✅
-----------------------------------------------------------
[root@centos7 ~]# vim /etc/fstab   

编辑文件添加
······
/dev/sr0        /var/www/html/centos/7  iso9660 default 0       0
······

在这里插入图片描述

挂载磁盘

[root@centos7 ~]# 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    3G  0 part [SWAP]
sr0     11:0    1 10.3G  0 rom  
[root@centos7 ~]# mount /dev/sr0 /var/www/html/centos/7 ✅
mount: /dev/sr0 is write-protected, mounting read-only
-----------------------------------------------------------
[root@centos7 ~]# mount -a
[root@centos7 ~]# 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    3G  0 part [SWAP]
sr0     11:0    1 10.3G  0 rom  /var/www/html/centos/7

3、制作ks.cfg⽂件

[root@centos7 ~]# mkdir -pv /var/www/html/ksdir/7   #先创建需要的目录 ✅
------------------------------------------------------------------

[root@centos7 ~]# cp /root/ks7_mini.cfg /var/www/html/ksdir/7/ ✅

# 应答文件因为之前我们做过,现在直接拷贝过来使用,没有的点击下方链接!
# 因为之前的制作ks.cfg也是采取http模式,所以要确保ks.cfg文件中的yum源可用,
  或者重新创建一个yum源,将ks.cfg文件里的yum源路径稍加修改即可。

------------------------------------------------------------------
[root@centos7 7]# chmod +r /var/www/html/ksdir/7/ks7_mini.cfg   #一定要保持ks.cfg文件的权限 ✅

可参考我的另一篇博客: llinux进阶-巧妙利用kickstart实现自动化安装全get

浏览器确认ks7.cfg能正常访问

在这里插入图片描述

4、修改制作ks.cfg⽂件

可参考我的另一篇博客: llinux进阶-巧妙利用kickstart实现自动化安装全get

5、配置dhcp服务

主要配置文件
在这里插入图片描述

重启服务

[root@centos7 ~]# systemctl  restart  dhcpd ✅

6、准备PXE相关⽂件

----------------------------------------------------------------------
[root@centos7 ~]# cd /var/lib/tftpboot/
[root@centos7 tftpboot]# mkdir pxelinux.cfg ✅
[root@centos7 tftpboot]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ ✅
---------------------------------------------------------------------- 
[root@centos7 tftpboot]# rpm -ql syslinux | grep menu.c32
/usr/share/syslinux/menu.c32
/usr/share/syslinux/vesamenu.c32
[root@centos7 tftpboot]# cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/ ✅
-----------------------------------------------------------------------
[root@centos7 ~]# cp /run/media/root/CentOS\ 7\ x86_64/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/ ✅
-----------------------------------------------------------------------
[root@centos7 ~]# 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    3G  0 part [SWAP]
sr0     11:0    1 10.3G  0 rom  /run/media/root/CentOS 7 x86_64

[root@centos7 ~]# cp /run/media/root/CentOS\ 7\ x86_64/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default ✅
------------------------------------------------------------------------
[root@centos7 ~]# cp /run/media/root/CentOS\ 7\ x86_64/isolinux/vesamenu.c32 /var/lib/tftpboot/pxelinux.cfg/default ✅
------------------------------------------------------------------------

最终目录树如下

在这里插入图片描述

7、制作菜单

[root@centos7 ~]# vim /var/lib/tftpboot/pxelinux.cfg/default  

在这里插入图片描述

8、创建一台新的centos7进行测试

选择基于网络安装

在这里插入图片描述

显示了我们制作的菜单项

在这里插入图片描述

安装成功,登录我们创建的用户

在这里插入图片描述

看到这条信息,首先谢谢您😘其次表示本次实验到这就完全结束了,欢迎下次光临!(~ ̄▽ ̄)~
  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值