CentOS7下的PXE无人值守系统安装
为了满足同时安装上百台linux,而且不需要人工干预。这就需要PXE来通过网线自动安装linux
1.搭建yum源来下载必要的工具,yum源的配置见点击打开链接。
2.下载syslinux,dhcp,http,tftp-server。
[root@localhost etc]# yum -y install syslinux dhcp httpd tftp-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package syslinux-4.05-12.el7.x86_64 already installed and latest version
Package 12:dhcp-4.2.5-42.el7.centos.x86_64 already installed and latest version
Package httpd-2.4.6-40.el7.centos.x86_64 already installed and latest version
Package tftp-server-5.2-12.el7.x86_64 already installed and latest version
Nothing to do因为我是安装好了,所以报告Nothing to do 。那没安装的就执行那个命令
yum -y install syslinux dhcp httpd tftp-server
3.下载自动安装kickstart工具命令
yum -y install system-config-kickstart
同样,我也安装过了,才报告Nothing to do
[root@localhost ~]# yum -y install system-config-kickstart
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package system-config-kickstart-2.9.2-4.el7.noarch already installed and latest version
Nothing to do4.搭建一个http的安装源。
进入/var/www/html ,并创建一个目录CentOS用来挂载镜像
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
CentOS ks.cfg
[root@localhost html]# mount /dev/sr0 /var/www/html/CentOS注意:没那个CentOS目录的先创建一个目录。(那个ks.cfg先不用管,下步再教如何生成)。
命令是 mkdir /var/www/html/CentOS 。然后再挂载(sr0是镜像,也可以写成其他的镜像之类的)。
再执行以下命令
[root@localhost html]# systemctl start httpd
[root@localhost html]# systemctl stop firewalld可以在浏览器里。输入IP/CentOS.可以看到下图就代表成功
1.4.2 ks文件生成的三种方式
方法1
每安装好一台Centos机器,Centos安装程序都会创建一个kickstart配置文件,记录你的真实安装配置。如果你希望实现和某系统类似的安装,可以基于该系统的kickstart配置文件来生成你自己的kickstart配置文件。(生成的文件名字叫anaconda-ks.cfg位于/root/anaconda-ks.cfg)
方法2
Centos提供了一个图形化的kickstart配置工具。在任何一个安装好的Linux系统上运行该工具,就可以很容易地创建你自己的kickstart配置文件。kickstart配置工具命令为redhat-config-kickstart(RHEL3)或system-config-kickstart(RHEL4,RHEL5).网上有很多用CentOS桌面版生成ks文件的文章,如果有现成的系统就没什么可说。但没有现成的,也没有必要去用桌面版,命令行也很简单。
方法3
阅读kickstart配置文件的手册。用任何一个文本编辑器都可以创建你自己的kickstart配置文件。
----------------------------------------------------5.用system-config-kickstart工具来生成一个自动的安装的配置文件
运行命令,并弹出一个图形界面
[root@localhost ~]# system-config-kickstart按下列图形填
第二个:Installation Method(这个填自己IP,HTTP Directory就填自己那个光盘镜像的目录)
第三个。Boot Loader Options
第四个。Partition Information
分区自己操作吧。点下面那个Add(那个1代表占用剩余磁盘)
第五个 NetWork Configuration
第六个(我没说的选项不用改)
第七个
保存下来,(因为CentOS7下这个软件的问题。还需要在vim编辑一下ks.cfg这个文件)
打开这个ks.cfg这个文件。在最后面加上
%packages
@base
%end
保存后。使用如下命令检查一下是否有语法错误
[root@localhost ~]# ksvalidator ks.cfg
[root@localhost ~]#
将该文件移到/var/www/html/ks.cfg
[root@localhost html]# ls
CentOS ks.cfg
[root@localhost html]# pwd
/var/www/html再重启网络服务。
[root@localhost html]# systemctl restart httpd如果能够在浏览器下看到如下的话,证明上述过程好了(这次我用的火狐浏览器。不要在意这些细节。。)
6.配置tftp(这个文件的位置在左下角)
再执行命令
[root@localhost ~]#service tftp start
7.将必要文件放到tftpboot内
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux.cfg将镜像内的isolinux下的所有东西都考到tftpboot下
[root@localhost CentOS]# cp /var/www/html/CentOS/isolinux/* /var/lib/tftpboot/再将isolinux.cfg拷给pxelinux.cfg下命名为default
[root@localhost CentOS]# cp /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default8.配置dhcp服务器
在/etc/dhcp下编辑 dhcpd.conf 文件
这个文件下写如下内容
option domain-name "example.org";
option domain-name-servers 114.114.114.114;
default-lease-time 6000;
max-lease-time 72000;
log-facility local7;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.200;
option routers 192.168.1.1;
filename "pxelinux.0";
next-server 192.168.1.192;
}注意:
好了。最后一步!!修改文件。这个文件是/var/lib/tftpboot/pxelinux.cfg/default
(还有就是将63行 加上menu default ,删去69行的menu default)
最后。再重启一下服务吧!!!!!(关闭防火墙)
[root@localhost pxelinux.cfg]# systemctl restart httpd
[root@localhost pxelinux.cfg]# service tftp start
[root@localhost pxelinux.cfg]# systemctl restart dhcpd
[root@localhost pxelinux.cfg]# systemctl stop firewalld
注意事项:
1, 设置服务器端的时候需要注意:确保同一个局域网只有当前的这一台DHCP服务器;
否则会造成干扰,导致网络引导失败。
2, 为了确保安装客户机可以成功引导,客户机需要设置BIOS网络引导; Network boot;
且客户机和服务器一定要在同一个交换机下面,为保证传输速度建议使用千兆交换机。
3, 如果使用VMWare作客户端进行网络引导,失败率较高,目前没有测试成功。
注意:system-config-kickstart 这个程序只能在服务器本机运行,远程无法设置。
4, 关于DHCP服务的测试问题,可以使用windows客户端自动获取IP测试下,确保DHCP
服务正常运行方可。 可以使用wireshark在windows客户端抓包来验证DHCP。
查看dhcp日志: tail /var/lib/dhcpd/dhcpd.leases
编辑配置文件: vi /etc/dhcp/dhcpd.conf
重启DHCP服务: service dhcpd restart
==============================================================
centos7网络安装引导--服务启动顺序
service httpd restart
service dhcpd restart
service tftp restart
systemctl stop firewalld
查看是否可以访问网络引导文件ks.cfg
http://192.168.1.241:7071/ks.cfg