什么是自动化的安装部署操作系统?

在工作中我们可能经常部署很多台主机,手工的一台一台的安装只适合主机非常少的情况,但大的互联网公司在一些特殊的日子要部署大量的主机,以应对要到来的特大流量访问。这时候我们就不能,一台一台的安装主机了,一是效率太慢,二是太累,三是费时间。基于这个情况我们可以自动化的一起部署很多的主机,而不用我们人工一台一台的去安装部署,节约了大量的时间。

centos 6的启动流程

1.POST开机加电自检

2.MBR 读取硬盘mbr引导的前446字节,属于grub的stage1第一阶段

3.进入grub的stage1.5阶段,加载/boot分区所在的文件系统驱动

4.进入grub的stage2阶段,关键的文件已经在/boot/grub目录里面了,关键的文件 有/boot/grub.grub.conf文件,文件里面kernel /vmlinuz root=/dev/sda2,定义了内核文件所在的位置

5.加载vmlinuz内核,完成以后找/根目录,想要加载根文件系统,需要识别根所在的文件系统驱动,配合/boot/目录里面两个重要的文件,一个是vmlinuz内核文件和initramfs驱动文件完成加载根文件系统

6.加载完成根文件系统以后,启动根下面的第一个进程/sbin/init,这个进程要读取/etc/inittab配置文件,决定后续加载的一些脚本的启动顺序,也定义了运行模式

7.运行第一个初始化脚本/etc/rc.d/rc.sysinit这个是真正的os初始化脚本,任何根据/etc/inittab配置文件默认模式运行相应的/etc/rc.d/rc*.d 里面的脚本,当然里面的脚本都是软链接,真正的脚本在/etc/rc.d/init.d里面,在/etc/rc.d/rc*.d目录下是以K和S开头的文件,执行相应模式关闭或开启的服务

8.无论哪种模式运行都要运行/etc/rc.local

9.最后执行/bin/login程序,等待用户的登录

#############################################################################

在自动化安装系统之前我们可以先实现半自动化的安装,例如将系统放到U盘或者光盘中,这样我们插到主机上就可以实现自动化的安装,当然只适合小范围的安装

系统的安装程序叫anaconda

在安装完成操作系统以后会在root的目录里面自动出现一个文件anaconda-ks.cfg,这个文件就是anaconda安装向导在安装过程中生成的一个配置文件。

安装部署系统的时候在启动界面的一些基础设置

当我们安装一个新的操作系统的时候由于硬盘的MBR是空的系统任务硬盘不能引导所有自动切换到光盘引导

clip_image002

在图片中第一项是正常启动

在图片中第二项是加载最基本的显卡驱动

在图片中第三项是救援模式

在图片中第四项是直接在硬盘启动

在图片中第五项是检查内存

clip_image004

按esc会出现一个boot界面,这一项会根据你输入的什么指令进入什么模式下

clip_image006

输入rescue是进入救援模式

clip_image008

在boot后面输入Linux 就代表是正常进入安装界面

clip_image010

为什么输入Linux就是正常安装是因为它读取了光盘里面/misc/cd/isolinux/目录下的vmlinuz内核文件和initrd.img文件 ,在isolinux.cfg文件中定义了启动相关的命令。

clip_image012

#############################################################################

安装程序的启动流程

1.MBR 放在了光盘的isolinux目录下的boot.cat文件里面

2. stage2阶段放在了isolinux目录下的isolinux.bin 文件里面,相当于硬盘里面的/boot/grub/目录下的文件

3. 配置文件在光盘的isolinux目录的isolinux.cfg文件,定义了加载内核文件的路径

clip_image014

当进入光盘引导的时候会有一个60秒的选择时间,过了时间就会自动选择

clip_image016

当然在boot里面还可以加别的参数,例如test,test代表是字符界面安装,不是图形化界面安装,适合自动化安装

clip_image018

iso文件分为几类

一类是boot.iso文件,这个文件在哪用来引导不能用来安装

一类是netinstall.iso文件是网络安装

一类是bin-DVD1.iso文件是光盘安装

一类是minimal.iso最小化安装

#############################################################################

例如:在用boot,iso文件安装的时候只能看见引导界面不能后续安装,那么我们可以在第一项正常安装的地方按esc进入boot界面用网络安装,输入正常安装和yum源也就是光盘里面的文件 例输入:Linux askmethod

clip_image020

选择默认语言

clip_image022

选择默认键盘

clip_image024

选择URL网络安装

clip_image026

选择自动获取ip还是静态分配ip

clip_image028

输入远程http服务器的路径并按ok

clip_image030

按ctrl+F6 会看到安装界面

clip_image032

选择安装的存储

clip_image034

选择安装在硬盘,它提示是不是初始化,如果里面有数据建议慎重考虑

clip_image036

设置主机名

clip_image038

配置网络

clip_image040

clip_image042

选择自动获取还静态指定,完成以后点击APPly确定,并下一步

clip_image044

选择时区,选择上海

clip_image046

格林制时间和我们差8个时区,如果不是跨国企业,不建议选择

clip_image048

输入root密码,输两遍

clip_image050

如果密码输入的太简单就会提示

clip_image052

定制分区

clip_image054

创建LVM卷 ,选择分区,选择创建

clip_image056

由于boot不能创建逻辑卷,所以要单独分出来

clip_image058

clip_image060

所以空间用逻辑卷管理

clip_image062

clip_image064

clip_image066

创建卷组

clip_image068

clip_image070

clip_image072

clip_image074

clip_image076

clip_image078

创建完成

clip_image080

clip_image082

clip_image084

进入界面

clip_image086

其中有一项是给grub加密,这样进入grub单用户就会提示请输入密码

clip_image088

选择最小化安装

clip_image090

继续安装

clip_image092

重启完成安装

如果安装完最小化,想要图形化界面,配置好yum源以后可以安装图形化的桌面

yum groupinstall desktop -y

然后init 5 切换到图形化界面

#############################################################################

如何半自动化安装,把我们使用的设置写入应答文件,安装的时候告诉应答文件的路径,让从应答文件读取安装的时候设置,从而完成安装

制作应答文件

yum install system-config-kickstart -y 安装包

由于制作应答文件的是一个图形化工具,所以要到图形化桌面执行

启动前在最好调一下分辨率

system-config-kickstart 启动

clip_image094

clip_image096

clip_image098

clip_image100

clip_image102

clip_image104

clip_image106

clip_image108

clip_image110

clip_image112

clip_image114

clip_image116

clip_image118

clip_image120

clip_image122

clip_image124

clip_image126

clip_image128

clip_image130

clip_image132

ksvalidator ks6_minit.cfg 检查应答文件 ks6_minit.cfg 有没有格式错误

应答文件ks6_minit.cfg安装完成

如何调用应答文件呢?

1.可以放在网上,实现调用应答文件ks6_minit.cfg

2.把应答文件开始ks6_minit.cfg刻在光盘上

将应答文件放在http服务器或者ftp服务器上都可以,可以通过网络下载应答文件

1.建应答文件拷贝到/var/www/html 目录下,并启动http服务

clip_image134

在浏览器测试

clip_image136

如果在浏览器出现报错

clip_image138

关闭selinux

clip_image140

修改完配置文件要重新启动系统,如果不想去重新启动

setenforce 0 临时改变为permissive状态

用getenforce查看selinux的状态

现在开始半自动化的安装,因为现在启动还得靠光盘引导

在光盘引导界面的正常安装 按ESC

clip_image142

应答文件的路径有好几种

指明kickstart文件的位置: ks=

DVD drive: ks=cdrom:/PATH/TO/KICKSTART_FILE

Hard drive: ks=hd:device:/directory/KICKSTART_FILE

HTTP server: ks=http://host:port/path/to/KICKSTART_FILE

FTP server: ks=ftp://host:port/path/to/KICKSTART_FILE

HTTPS server: ks=https://host:port/path/to/KICKSTART_FILE

NFS server:ks=nfs:host:/path/to/KICKSTART_FILE

我们现在用的是http路径

在boot输入ip地址方便联到互联网,在写入应答文件的http路径,并回车确定

clip_image144

安装完成

如果应答文件的格式不小心写错了

在系统中有一个语法检查功能

ksvalidator ks6_minit.cfg 检查应答文件 ks6_minit.cfg 有没有格式错误

clip_image146

#############################################################################

制作应答文件还有一个更简单的办法,假如已经有了一个应答文件,我们可以导入原有的应答文件在它的基础上进行修改

在图形化桌面 输入system-config-kickstart

clip_image148

clip_image150

clip_image152

clip_image154

clip_image156

clip_image158

在原有的基础上修改

clip_image160

#############################################################################

在centos7 制作应答文件的过程和centos6的区别

yum install system-config-kickstart -y 安装制作应答文件的工具

system-config-kickstart 启动工具

clip_image162

clip_image164

和 centos6的一点区别就是包选择出不来

clip_image166

解决方法

更改yum源的名字为development

[root@contes7 ~]# cd /etc/yum.repos.d/

[root@contes7 yum.repos.d]# vim base.repo

clip_image168

重新启动工具

clip_image170

*************************************************************************************************************************

也可以用安装系统在root目录下生成的anaconda-ks.cfg文件,进行修改

例:在centos7.5系统

1.修改从光盘安装cdrom,还是网络安装

url --url="http://172.20.0.1/centos/7"

clip_image172

2.在随便一个地方写reboot ,代表安装完成自动重启

3.清除原有的分区表

# Partition clearing information

zerombr

clearpart --all --initlabel

clip_image174

4.把自定义的脚本写进去

%post

mkdir /etc/yum.repos.d/bak

mv /etc/yum.repos.d/C* /etc/yum.repos.d/bak

cat > /etc/yum.repos.d/base.repo <<EOF

[base]

name=base

baseurl=http://172.20.0.1/centos/7

gpgcheck=0

EOF

useradd zhouyafei

echo 123456 | passwd --stdin zhouyafei

systemctl set-default multi-user.target

%end

clip_image176

5.然后改名

mv anaconda-ks.cfg ks7_min.cfg

6.把应答文件放到http服务器的目录下

mv ks7_min.cfg /var/www/html/

7.启动http服务

systemctl start httpd

8.在浏览器测试

9.安装系统的时候进入光盘在第一项正常启动处按ESC

在boot下收入 Linux ks=http://ip/ks7_min.cfg

#############################################################################

系统光盘中的isolinux目录列表

boot.cat 代表MBR的角色

isolinux.bin 代表stage2阶段 光盘引导

vesamenu.c32 光盘启动的图形界面,就是下面的界面

clip_image178

menu.c32版本是纯文本的菜单

Memtest:内存检测,这是一个独立的程序

splash.jgp:光盘启动界面的背景图

vmlinuz是内核映像

initrd.img是ramfs (先cpio,再gzip压缩)

#############################################################################

centos6的应答文件

#platform=x86, AMD64, or Intel EM64T

#version=DEVEL

# Firewall configuration

firewall --disabled

reboot

# Install OS instead of upgrade

install

# Use network installation

url --url="http://172.20.0.1/centos/6"

# Root password

rootpw --iscrypted $1$3j39.X./$ja6TSZ6aG8nztWqi0hjUW0

# System authorization information

auth --useshadow --passalgo=sha512

# Use text mode install

text

firstboot --disable

# System keyboard

keyboard us

# System language

lang en_US

# SELinux configuration

selinux --disabled

# Installation logging level

logging --level=info

# Reboot after installation

reboot

# System timezone

timezone Asia/Shanghai

# Network information

network --bootproto=static --device=eth0 --gateway=172.20.0.1 --ip=172.20.0.197 --netmask=255.255.0.0 --onboot=on

# System bootloader configuration

bootloader --append="selinux=0" --location=mbr --password="123456"

# Clear the Master Boot Record

zerombr

# Partition clearing information

clearpart --all --initlabel

# Disk partitioning information

part /boot --fstype="ext4" --size=200

part / --fstype="ext4" --size=20000

part swap --fstype="swap" --size=2048

%post

mkdir /etc/yum.repos.d/bak

mv /etc/yum.repos.d/C* /etc/yum.repos.d/bak

cat > /etc/yum.repos.d/base.repo <<EOF

[base]

name=base

baseurl=http://172.20.0.1/centos/6

gpgcheck=0

EOF

useradd zhouyafei

echo 123456 | passwd --stdin zhouyafei

systemctl set-default multi-user.target

%end

%packages

@core

@server-policy

@workstation-policy

@base

@desktop

%end

#############################################################################

制作centos6启动光盘,实现半自动化安装,基于网络yum源

1.找一个空目录,并创建一个子目录叫/data/myiso

clip_image180

2.拷贝光盘下的isolinux目录到创建的/data/myiso目录

clip_image182

clip_image184

3.再在myiso目录下创建一个存放应答文件的目录

mkdir /data/myiso/ksdir

clip_image186

4.将已有的应答文件拷贝到新建的目录

clip_image188

cp /data/myiso/ksdir/ks6_minit.cfg /data/myiso/ksdir/ks6_desktop.cfg

clip_image190

在ks6_desktop.cfg 应答文件里面添加加一行包@desktop就实现了桌面化的安装,没有安装这个是最小化安装

clip_image192

clip_image194

5.修改启动菜单

cd /mnt/myiso/isolinux

vim isolinux.cfg

实现自动化安装一个带桌面,一个不带桌面,一个硬盘启动

可以修改title,改成你要的名字

clip_image196

删除内存检测

clip_image198

设置硬盘启动,并设置为默认启动menu default

clip_image200

删除救援模式

指定应答文件的位置ks=cdrom:/ksdir/ks6_destop.cfg 这个是指定本地文件

修改完成

clip_image202

最后在任何目录下执行这条命令,会自动生成一个boot.iso文件

mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "CentOS 6.9

x86_64 boot" -b isolinux/isolinux.bin -c isolinux/boot.cat -o /root/boot.iso /data/myiso/

最后的/data/myiso/ 是自己做启动光盘的时候创建的目录,其他都不用改

最后一步将这个boot.iso文件啦出来,安装系统的时候用这个boot.iso文件,做引导光盘。实现自动化安装

****************************************************************************************************************************

将生成的boot.iso文件拷入U盘

yum install syslinux -y

/usr/bin/isohybrid boot.iso 将boot.iso 转换一下格式,但是如果文件太大的话就会提示文件过大,不能转换。可以借助windows的工具,例如老毛桃。大白菜

1.将U盘插入主机 /dev/sdc

2.dd if=/root/boot.iso of=/dev/sdc

#############################################################################

单机实现自动化安装,不依赖网络,只适合主机不多的情况

把所有的文件都放到一个iso文件里面,不用添加网络yum源

制作完整版的iso文件

1.创建一个目录/data

mkdir /data

2.将光盘里面的所有的包都拷到目录里面并改名,提前挂载两个光盘(centos 6是两张光盘 DVD1 和 DVD2)

cp -rv /misc/cd/ /data/centos6

cp -rv /mnt/cdroot/* /data/centos6/

注:为什么不用(cp -r /misc/cd/* /data/centos)是因为这样拷贝不完整,里面有很多隐藏文件

3.创建一个目录专门放应答文件

mkdir /data/centos6/ksdir

4.将已有的应答文件拷贝到目录

[root@centos6 centos6]#cp /var/www/html/ks* /data/centos6/ksdir/

[root@centos6 centos6]#ls ksdir/

ks6_minit.cfg ks7_desktop.cfg

5.切换进源数据目录

cd /data/centos6/repodata/

clip_image204

6. 备份第2条到root目录下,这个文件记录的是rpm包的分组信息

cp 43d8fd068164b0f042845474d6a22262798b9f0d1f49ad1bf9f95b953089777d-c6-x86_64-comps.xml /root/

clip_image206

7.清空源数据目录里面的数据并将备份的拷贝回来,然后重新创建yum源数据

clip_image208

8.用命令createrepo -g 重新创建yum对应的信息

在/data/centos6目录的当前目录下创建yum仓库

createrepo -g repodata//43d8fd068164b0f042845474d6a22262798b9f0d1f49ad1bf9f95b953089777d-c6-x86_64-comps.xml .

clip_image210

9.删除/data/centos6/目录下一些不用的文件

用find过滤

find -name TRANS.TBL

clip_image212

删除找到的文件

find -name TRANS.TBL -exec rm {} \;

clip_image214

10.把/data/centos/ksdir/目录下的应答文件里面的网络路径改为光盘cdrom

cd /data/centos6/ksdir

[root@centos6 centos6]#cd /data/centos6/ksdir

[root@centos6 ksdir]#ls

ks6_minit.cfg ks7_desktop.cfg

[root@centos6 ksdir]#vim ks6_minit.cfg

clip_image216

clip_image218

11.修改isolinux.cfg文件里面的安装系统的时候的启动菜单

[root@centos6 isolinux]#cd /data/centos6/isolinux/

[root@centos6 isolinux]#vim isolinux.cfg

clip_image220

default vesamenu.c32

#prompt 1

timeout 600

display boot.msg

label desktop

menu label Install ^desktop system

kernel vmlinuz

append initrd=initrd.img ks=cdrom:/ksdir/ks6_desktop.cfg

label mini

menu label Install system with ^basic video driver

kernel vmlinuz

append initrd=initrd.img ks=cdrom:/ksdir/ks6_min.cfg

label local

menu default

menu label Boot from ^local drive

localboot 0xffff

clip_image222

12.最后在任何目录下执行这条命令,会自动生成一个/centos6-Everythig.iso文件

mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "CentOS 6.9

> x86_64 Everything" -b isolinux/isolinux.bin -c isolinux/boot.cat -o /root/centos6-Everythig.iso /data/centos6/

最后的/data/centos6/是自己做启动光盘的时候创建的目录,其他都不用改

#############################################################################

配置服务的大体流程

0.关闭selinux

getenforce 检查selinux的状态,在/etc/selinux/config文件里面修改为disabled

关闭防火墙

iptables -vnL 关闭防火墙的命令

1.安装包

2.起服务

3.根据生产需求更改配置文件;reload restart

4.测试

#############################################################################

当要批量部署大量的主机的时候要依赖网络

当然自动化的安装要依赖一些服务比如DHCP服务

DHCP获取ip主要四个包

clip_image224

 DHCP DISCOVER:客户端到服务器

 DHCP OFFER :服务器到客户端

 DHCP REQUEST:客户端到服务器

 DHCP ACK :服务器到客户端

dhclient 命令会自动去获取ip ,这个命令是默认后台执行

dhclient -d 前台执行自动获取获取dhcp地址,并会显示获取ip的过程

在 ls /var/lib/dhclient/ 目录下会看到获取到ip的信息文件

cat /var/lib/dhclient/dhclient.leases 文件里面有获取ip的服务器的信息

DHCP获取ip是先到先得

DHCP服务器端

1.DHCP的服务器端是静态地址

2.在虚拟机做实验的时候不能桥接

3.关闭selinux

getenforce 检查selinux的状态,在/etc/selinux/config文件里面修改为disabled

配置HDCP服务器

以centos7.5为DHCP服务器

以centos6为DHCP客户端

1. yum install dhcp -y 安装HDCP服务

2.查看DHCP包的文件列表

rpm -ql dhcp

3.启动DHCP服务 ,但是启动不了,因为DHCP服务的配置文件没有准备好一些基本的配置

systemctl start dhcpd.service

clip_image226

可以看见在/etc/dhcp/dhcpd.conf配置文件里面什么都没有

clip_image228

4.根据配置文件的提示将/usr/share/doc/dhcp*/dhcpd.conf.example文件里面的内容复制过来并修改

cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

4.修改查询生成的dhcp文件

vim /etc/dhcp/dhcpd.conf

clip_image230

clip_image232

systemctl restart dhcpd.service 启动DHCP服务

clip_image234

systemctl enable dhcpd.service 设为开机启动

clip_image236

可以绑定mac地址,让固定的一个ip分配给绑定的mac地址

vim /etc/dhcp/dhcpd.conf

clip_image238

然后重启dhcp服务

systemctl restart dhcpd.service

重启客户端的网卡

****************************************************************************************************************************

vim /etc/dhcp/dhcpd,conf 修改后的文件

# dhcpd.conf

#

# Sample configuration file for ISC dhcpd

#

# option definitions common to all supported networks...

option domain-name "magedu.org";

option domain-name-servers 114.114.114.114;

default-lease-time 86000;

max-lease-time 200000;

# Use this to enble / disable dynamic dns updates globally.

#ddns-update-style none;

# If this DHCP server is the official DHCP server for the local

# network, the authoritative directive should be uncommented.

#authoritative;

# Use this to send dhcp log messages to a different log file (you also

# have to hack syslog.conf to complete the redirection).

log-facility local7;

# No service will be given on this subnet, but declaring it helps the

# DHCP server to understand the network topology.

subnet 192.168.63.0 netmask 255.255.255.0 {

range 192.168.63.100 192.168.63.200;

option routers 192.168.63.1;

}

subnet 9.9.9.0 netmask 255.255.255.0 {

range 9.9.9.2 9.9.9.100;

}

# This is a very basic subnet declaration.

subnet 10.254.239.0 netmask 255.255.255.224 {

range 10.254.239.10 10.254.239.20;

option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;

}

# This declaration allows BOOTP clients to get dynamic addresses,

# which we don't really recommend.

subnet 10.254.239.32 netmask 255.255.255.224 {

range dynamic-bootp 10.254.239.40 10.254.239.60;

option broadcast-address 10.254.239.31;

option routers rtr-239-32-1.example.org;

}

# A slightly different configuration for an internal subnet.

subnet 10.5.5.0 netmask 255.255.255.224 {

range 10.5.5.26 10.5.5.30;

option domain-name-servers ns1.internal.example.org;

option domain-name "internal.example.org";

option routers 10.5.5.1;

option broadcast-address 10.5.5.31;

default-lease-time 600;

max-lease-time 7200;

}

# Hosts which require special configuration options can be listed in

# host statements. If no address is specified, the address will be

# allocated dynamically (if possible), but the host-specific information

# will still come from the host declaration.

host passacaglia {

hardware ethernet 0:0:c0:5d:bd:95;

filename "vmunix.passacaglia";

server-name "toccata.fugue.com";

}

# Fixed IP addresses can also be specified for hosts. These addresses

# should not also be listed as being available for dynamic assignment.

# Hosts for which fixed IP addresses have been specified can boot using

# BOOTP or DHCP. Hosts for which no fixed address is specified can only

# be booted with DHCP, unless there is an address range on the subnet

# to which a BOOTP client is connected which has the dynamic-bootp flag

# set.

host fantasia {

hardware ethernet 08:00:07:26:c0:a5;

fixed-address fantasia.fugue.com;

}

host testclient {

hardware ethernet 00:0c:29:3b:f1:3f;

fixed-address 192.168.63.88;

option routers 192.168.63.1;

option domain-name-servers 114.114.114.114;

}

# You can declare a class of clients and then do address allocation

# based on that. The example below shows a case where all clients

# in a certain class get addresses on the 10.17.224/24 subnet, and all

# other clients get addresses on the 10.0.29/24 subnet.

class "foo" {

match if substring (option vendor-class-identifier, 0, 4) = "SUNW";

}

shared-network 224-29 {

subnet 10.17.224.0 netmask 255.255.255.0 {

option routers rtr-224.example.org;

}

subnet 10.0.29.0 netmask 255.255.255.0 {

option routers rtr-29.example.org;

}

pool {

allow members of "foo";

range 10.17.224.10 10.17.224.250;

}

pool {

deny members of "foo";

range 10.0.29.10 10.0.29.230;

}

}

#############################################################################

在 /etc/dhcp/dhcpd.conf 文件和自动化部署系统相关的非常重要的两项

next-server 是和自动安装系统有关的,如果只是获取dhcp,不用加这一行

(next-server 的意思是当我们要网络批量的部署系统的时候,我们是没有经过光盘的,那我们怎么引导呢,我们通过网卡引导,但是我们又不能直接的启动网卡,网卡得获取一些引导文件,而网卡要通过一种网络服务获取引导文件,而这个网络服务叫 TFTP server 而这个TFTP server 上放了一些启动相关的引导文件例如:pxelinux 0 这个文件用来启动网卡,用网卡引导,进而实现安装。这个文件要放到TFTP server服务器上,我们要在HDCP服务器上指定谁是TFTP server 服务器 。这个就是next-server的指定。

filename :指定引导文件的名字)

subnet 192.168.63.0 netmask 255.255.255.0 { #获取地址的网段

range 192.168.63.100 192.168.63.200; #获取地址的范围

option routers 192.168.63.1; #获取的网关

option domain-name-servers 114.114.114.114; #获取的DNS

next-server 192.168.63.143; #TFTP server 的地址

filename "pxelinux.0"; #引导文件的名字

clip_image240

从网络中查找这个 next-server 192.168.63.143 ip的TFTP server主机,而TFTP server的主机的工作目录下面有pxelinux.0文件。通过连接TFTP server 服务器下的pxelinux.0引导文件,进而客户端就可以得到引导信息,进而启动网卡,启动起来网卡进而可以从DHCP 服务器得到一些信息,例如获取应答文件,获取内核等等,实现自动安装。

配置完成以后检查语法错误

centos6 : service dhcpd configtest

****************************************************************************************************************************

PXE

(pxe 是Intel公司研发的,基于client/server的网络模式,支持远程主机通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统。pxe可以引导和安装windows,linux等多种操作系统)

PXE工作原理

clip_image242

#############################################################################

ss -nutl 查看 ss -nutlp

DHCP的端口:服务端是67;客户端是68

TFTP 的端口: UDP的69

#############################################################################

TFTP 服务的配置和实现

实验:在centos7上搭建TFTP服务

yum install tftp-server -y 安装TFTP server

*********************************************************************************************************************

*(centos 6 安装TFTP server。在centos6上TFTP是非独立服务,用chkconfig --list查看 。在*centos6上启动TFTP服务的命令是 chkconfig tftp on;service xinetd restart)

* ******************************************************************************************************************

启动TFTP服务

centos7服务器端 systemctl start tftp.server 端口是69

systemctl is-enabled tftp 查看tftp的服务

systemctl enable tftp 开机启动

clip_image244

在客户端安装tftp客户端工具

yum install fttp -y

在客户端远程用tftp连接,tftp是轻量级的文件传输协议,相当于简化版的ftp,不过走的是UDP协议

tftp适合传输小文件

tfty 192.168.63.134 远程连接tftp服务器端,当然现在里面还没有存放文件,需要在tftp的服务器端的工作目录里面放入文件

/var/lib/tftpboot 目录是tftp服务器端工作的目录

拷贝一个文件到tftp工作目录

cd /var/lib/tftpboot

cp /etc/fstab . 将etc下的fstab文件拷贝到当前目录

clip_image246

在客户端下载拷贝的文件

用tftp 192.168.63.134 连接远程服务器

用get fstab 下载fstab文件

用quit 退出

clip_image248

具体步骤

1.yum install tftp-server -y

2. systemctl start tftp

3. systemctl enable tftp

#############################################################################

准备PXE 的文件

将准备的文件放在http的共享目录里面

1. yum install httpd -y

2. systemctl start httpd 启动httpd服务

3.systemctl enable httpd 设置为开机启动

cd /var/www/html/ 将一些准备好的文件放在这个目录下

第一步的yum源准备

在将来我们要安装系统有6版本和7版本的系统。所以预留一下目录

cd /var/www/html/

mkdir centos/{6,7} -pv

创建 centos目录,并在centos目录下面创建6和7子目录

clip_image250

我们要把光盘底下的内容拷到相关的目录下,但是文件太多,不方便拷贝,我们可以把光盘挂载到相关的目录

clip_image252

vim /etc/fstab

/dev/sr0 /var/www/html/centos/7 iso9660 defaults 0 0

mount -a 挂载

在浏览器测试能不能访问 http://192.168.63.134/centos/7

clip_image254

第二步准备应答文件

将系统自动生成的anaconda-ks.cfg应答文件拷贝新建的对应目录下并修改

mkdir /var/www/html/ksdir/{6,7} -pv

创建应答文件的目录ksdir 并在ksdir目录下创建用来存放应答文件系统版本6的和系统版本7的目录

clip_image256

将anaconda-ks.cfg拷贝到ksdir目录下的7目录里面并修改文件名为ks7_desktop.cfg,同时注意权限,应答文件的权限为644

cp -r /root/anaconda-ks.cfg /var/www/html/ksdir/7/ks7_desktop.cfg

cd /var/www/html/ksdir/7

chmod 644 ks7_desktop.cfg

clip_image258

修改应答文件

1.修改yum源的路径

url --url=http://192.168.63.134/centos/7/

2.以文本方式安装

# Use graphical install

text

reboot 开机自动重启

3.设置ip为自动获取

network --bootproto=dhcp --device=ens33 --onboot=on --ipv6=auto --activate

4.修改主机名

network --hostname=centos7.magedu.com

5.清除MBR信息

# Partition clearing information

zerombr

6.实现key验证

1.现在centos7上面生成秘钥文件,在拷贝到装好的系统中

ssh-keygen 生成秘钥文件

[root@Centos7.5 ~]#cd .ssh

[root@Centos7.5 .ssh]#ls

id_rsa id_rsa.pub

clip_image260

同时将秘钥拷贝到其他主机的时候会生成一个authorized_key文件,但是现在这个主机没有,我们可以把秘钥文件拷贝到主机的主机就会在自己的目录下生成authorized_key文件

ssh-copy-id 192.168.63.134

clip_image262

clip_image264

只需要把这个秘钥拷贝出来,放到ks7_desktop.cfg文件里面

clip_image266

7.配置好yum

clip_image268

8.开机进入字符界面

systemctl set-default multi-user.target #开机进入字符界面

9.检查应答文件

cat -A ks7_desktop.cfg

clip_image270

**************************************************************************************************************************

修改后的应答文件ks7_desktop.cfg

#version=DEVEL

# System authorization information

url --url=http://192.168.63.134/centos/7/ #yum源的网络路径,里面是光盘的文件

# Use graphical install

text #文本方式安装

reboot #开机自动重启

# Run the Setup Agent on first boot

firstboot --enable

ignoredisk --only-use=sda

# Keyboard layouts

keyboard --vckeymap=us --xlayouts='us'

# System language

lang en_US.UTF-8

# Network information #自动获取ip

network --bootproto=dhcp --device=ens33 --onboot=on --ipv6=auto --activate

network --hostname=centos7.magedu.com #主机名

# Root password

# System services

services --disabled="chronyd"

# System timezone

timezone Asia/Shanghai --isUtc --nontp

# System bootloader configuration

bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda

autopart --type=lvm

# Partition clearing information

zerombr #清除MBR信息

@core

@development

kexec-tools

autofs #这个包是安装临时挂载目录的包 /misc/cd

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda

pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty

pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok

pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty

%end

%post #安装后脚本

systemctl enable autofs # 启动autofs包

systemctl disable initial-setup.service

systemctl set-default multi-user.target #开机进入字符界面

mkdir /root/.ssh #在新建的系统中没有由于没有key验证,所以没有建.ssh

目录

cat > /root/.ssh/authorized_keys <<EOF #建创建好的key验证的秘钥拷贝到新建的主机

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5W2s0UvPRa0mrSAxTz28fwrupV33VtgSS6uICySRbJvRPfiR9FAR3xZ3GhCZfdGc814XizmJwqQ//Vft***ChL4wy9WA5wdaKLuCnDL1VYSt9zCmpRx6Jtdw+xlUxy+C+h3jeh3UkzGWSr+z1qTE4R4Bj3/pMvJwhXoWFGZlz3tFeTc2uv6Bb7E32Fg+fR6fri78JbqC7/Vtd8779m427ATayoHx4Iki2r2pz42xFY9jACsmjJ32HKnZUCtk9xLc2VgQbmVuuHqH6dbgSRG5yo2L+kiDfAq+MVLepj1M7rU1Wfn78oIzUNU+VaiSTr02E3B1BFIx1tU5HK7bcwjz7 root@localhost.localdomain

EOF

rm -rf /etc/yum.repos.d/*.repo #创建yum源

cat > /etc/yum.repos.d/base.repo <<EOF

[base]

name=base

baseurl=file:///misc/cd

gpgcheck=0

EOF

%end 结束脚本

****************************************************************************************************************************

第四步搭建DHCP服务

vim /etc/dhcp/dhcpd.conf

subnet 192.168.63.0 netmask 255.255.255.0 {

range 192.168.63.100 192.168.63.200;

option routers 192.168.63.1;

option domain-name-servers 114.114.114.114;

next-server 192.168.63.143;

filename "pxelinux.0";

}

clip_image272

重新启动DHCP服务

systemctl restart dhcpd

*********************************************************************************************************************

/etc/dhcp/dhcpd.conf 的文件

# dhcpd.conf

#

# Sample configuration file for ISC dhcpd

#

# option definitions common to all supported networks...

option domain-name "magedu.org";

option domain-name-servers 114.114.114.114;

default-lease-time 86000;

max-lease-time 200000;

# Use this to enble / disable dynamic dns updates globally.

#ddns-update-style none;

# If this DHCP server is the official DHCP server for the local

# network, the authoritative directive should be uncommented.

#authoritative;

# Use this to send dhcp log messages to a different log file (you also

# have to hack syslog.conf to complete the redirection).

log-facility local7;

# No service will be given on this subnet, but declaring it helps the

# DHCP server to understand the network topology.

subnet 192.168.63.0 netmask 255.255.255.0 {

range 192.168.63.100 192.168.63.200;

option routers 192.168.63.1;

option domain-name-servers 114.114.114.114;

next-server 192.168.63.143;

filename "pxelinux.0";

}

subnet 9.9.9.0 netmask 255.255.255.0 {

range 9.9.9.2 9.9.9.100;

}

# This is a very basic subnet declaration.

subnet 10.254.239.0 netmask 255.255.255.224 {

range 10.254.239.10 10.254.239.20;

option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;

}

# This declaration allows BOOTP clients to get dynamic addresses,

# which we don't really recommend.

subnet 10.254.239.32 netmask 255.255.255.224 {

range dynamic-bootp 10.254.239.40 10.254.239.60;

option broadcast-address 10.254.239.31;

option routers rtr-239-32-1.example.org;

}

# A slightly different configuration for an internal subnet.

subnet 10.5.5.0 netmask 255.255.255.224 {

range 10.5.5.26 10.5.5.30;

option domain-name-servers ns1.internal.example.org;

option domain-name "internal.example.org";

option routers 10.5.5.1;

option broadcast-address 10.5.5.31;

default-lease-time 600;

max-lease-time 7200;

}

# Hosts which require special configuration options can be listed in

# host statements. If no address is specified, the address will be

# allocated dynamically (if possible), but the host-specific information

# will still come from the host declaration.

host passacaglia {

hardware ethernet 0:0:c0:5d:bd:95;

filename "vmunix.passacaglia";

server-name "toccata.fugue.com";

}

# Fixed IP addresses can also be specified for hosts. These addresses

# should not also be listed as being available for dynamic assignment.

# Hosts for which fixed IP addresses have been specified can boot using

# BOOTP or DHCP. Hosts for which no fixed address is specified can only

# be booted with DHCP, unless there is an address range on the subnet

# to which a BOOTP client is connected which has the dynamic-bootp flag

# set.

host fantasia {

hardware ethernet 08:00:07:26:c0:a5;

fixed-address fantasia.fugue.com;

}

# You can declare a class of clients and then do address allocation

# based on that. The example below shows a case where all clients

# in a certain class get addresses on the 10.17.224/24 subnet, and all

# other clients get addresses on the 10.0.29/24 subnet.

class "foo" {

match if substring (option vendor-class-identifier, 0, 4) = "SUNW";

}

shared-network 224-29 {

subnet 10.17.224.0 netmask 255.255.255.0 {

option routers rtr-224.example.org;

}

subnet 10.0.29.0 netmask 255.255.255.0 {

option routers rtr-29.example.org;

}

pool {

allow members of "foo";

range 10.17.224.10 10.17.224.250;

}

pool {

deny members of "foo";

range 10.0.29.10 10.0.29.230;

}

}

***********************************************************************************************************************

第四步:在TFTP工作目录下创建一些启动相关的文件

1.先在tftp目录下创建一个文件夹

cd /var/lib/tftpboot/

mkdir pxelinux.cfg/

clip_image274

2.安装包,并将DHCP文件里面指定的文件pxelinux.0 放到 TFTP的工作目录下

yum install syslinux -y

在这个包里面有pxelinux.0文件

clip_image276

3.将找到的包复制到指定的目录

cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

clip_image278

4.将光盘下的制作菜单的文件拷贝过来,当然如果你不想用那么华丽的风格的菜单,还可以改成比较简素的风格

rpm -ql syslinux |grep "menu.c32"

这个menu.c32是非常朴素的风格

clip_image280

cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/

clip_image282

5.将光盘里面的内核文件拷贝过来

cp /var/www/html/centos/7/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/

clip_image284

6.将制作菜单的文件拷贝过来到pxelinux.cfg目录下并改名为default

cp /var/www/html/centos/7/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

clip_image286

7.修改default文件

修改菜单风格为 default menu.c32

default menu.c32

timeout 600

menu title CentOS 7

label desktop

menu label ^Install CentOS 7

kernel vmlinuz

append initrd=initrd.img http://192.168.63.134/ksdir/7/ks7_desktop.cfg

label mini

menu label Test this ^mini install CentOS 7

kernel vmlinuz

append initrd=initrd.img http://192.168.63.134/ksdir/7/ks7_desktop.cfg

label local

menu default

menu label Boot from ^local drive

localboot 0xffff

menu end

clip_image288

centos 7 PXE批量部署安装系统配置完成

#############################################################################

centos 6 PXE批量部署安装系统

yum install httpd dhcp tftp-server syslinux -y

chkconfig httpd on

chdconfig dhcp on

chdconfig tftf on

service httpd start

service xinetd restart

配置DHCP服务

cat /etc/dhcp/dhcpd.conf

cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.samole /etc/dhcp/dhcpd.conf

vim /etc/dhcp/dhcpd.conf

option domain-name-servers 114.114.114.114; 配置DNS

subnet 192.168.63.0 netmask 255.255.255.0 {

range 192.168.63.100 192.168.63.200;

option routers 192.168.63.1;

next-server 192.168.63.133; tftp服务器的地址

filename "pxelinux.0";

}

service dhcpd restart 启动dhcp服务

cd /var/www/html

mkdir /var/www/html/centos/6 -pv

mount /dev/sr0 /var/www/html/centos/6 并写到配置文件 /etc/fstab

mkdir /var/www/html/ksdir/6 -pv

cp /root/anaconda-ks.cfg /var/www/html/ksdir/ks_mini.cfg 拷贝并改名

vim /var/www/html/ksdir/6/ks_mini.cfg

url --url=http://192.168.63.133/centos/6

selinux --disabled

firewall --disabled

clearpart --none

zerombr

reboot

text

part /boot --fstype=ext4 --size=1024

part / --fstype=ext4 --size=50000

part /data --fstype=ext4 --size=30000

part swap --size=2048

%packages

@base

@core

vim

%end

%post

useradd zhouyafei

echo 123456 | passwd --stdin zhouyafei

%end

chmod 644 /var/www/html/ksdir/6/ks_mini.cfg 添加权限

配置TFTP

cd /var/lib/tftpboot/

mkdir pxelinux.cfg

cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

cp /misc/cd/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/

cp /misc/cd/isolinux/{boot.msg,splash.jpg,vwsamenu.c32} /var/lib/tftpboot/

cp /misc/cd/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default 复制并改名菜单

vim /var/lib/tftpboot/pxelinux.cfg/default

default vesamenu.c32

#prompt 1

timeout 600

display boot.msg

menu background splash.jpg

menu title Welcome to CentOS 6.9!

menu color border 0 #ffffffff #00000000

menu color sel 7 #ffffffff #ff000000

menu color title 0 #ffffffff #00000000

menu color tabmsg 0 #ffffffff #00000000

menu color unsel 0 #ffffffff #00000000

menu color hotsel 0 #ff000000 #ffffffff

menu color hotkey 7 #ffffffff #ff000000

menu color scrollbar 0 #ffffffff #00000000

label mini linux

menu label ^Install mini system

kernel vmlinuz

append initrd=initrd.img ks=http://192.168.63.133/ksdir/6/ks_mini.cfg

label local

menu default

menu label Boot from ^local drive

localboot 0xffff

测试

#############################################################################

在部署操作系统的时候可以选择安装centos6还是centos7

关闭防火墙和selinux

挂centos6和centos7的光盘

echo '- - -' > /sys/class/scsi_host/host0/scan

yum install httpd dhcp tftp-server syslinux -y

systemctl enable httpd dhcpd tftpd.socket 开机启动

systemctl start httpd tftp.socket

配置DHCP服务

option domain-name "example.org";

option domain-name-servers 114.114.114.114;

default-lease-time 86400;

max-lease-time 200000;

subnet 192.168.63.0 netmask 255.255.255.0 {

range 192.168.63.100 192.168.63.200;

option routers 192.168.63.1;

next-server 192.168.63.134;

filename "pxelinux.0";

}

systemctl restart dhcpd 启动服务

配置yum源

mkdir /var/www/html/centos/{6,7} -pv

/dev/sr0 /var/www/html/centos/7 iso9660 defaults 0 0

/dev/sr1 /var/www/html/centos/6 iso9660 defaults 0 0

~

配置应答文件

mkdir /var/www/html/ksdir

[root@localhost ksdir]# cp /root/ks7_desktop.cfg /var/www/html/ksdir/

[root@localhost ksdir]# cp /root/ks_mini.cfg /var/www/html/ksdir/

vim /var/www/html/ksdir/ks_mini.cfg

#platform=x86, AMD64, or Intel EM64T

#version=DEVEL

# Install OS instead of upgrade

install

# Keyboard layouts

keyboard 'us'

# Root password

rootpw --iscrypted $1$R3VaLZ60$6ivf/Qc89KVNf3SGYXP351

# Use network installation

url --url=http://192.168.63.134/centos/7

# System language

lang en_US

# Firewall configuration

firewall --disabled

# System authorization information

auth --useshadow --passalgo=sha512

# Use text mode install

text

# SELinux configuration

selinux --disabled

# Do not configure the X Window System

skipx

# Network information

network --bootproto=dhcp --device=ens33 --onboot=on --ipv6=auto --activate

# Reboot after installation

reboot

# System timezone

timezone Asia/Shanghai

# System bootloader configuration

bootloader --append="selinux=0" --location=mbr --password="123456"

# Clear the Master Boot Record

zerombr

# Partition clearing information

clearpart --all --initlabel

# Disk partitioning information

part swap --fstype="swap" --size=2048

part / --fstype="xfs" --size=20000

part /boot --fstype="xfs" --size=5048

part /home --fstype="xfs" --size=10000

%post

rm -rf /etc/yum.repos.d/*

mkdir /etc/yum.repos.d/bak

cat > /etc/yum.repos.d/base.repo <<EOF

[base]

name=base

baseurl=file:///mnt/cdroot

gpgcheck=0

EOF

mkdir /mnt/cdroot

mount /dev/sr0 /mnt/cdroot

%end

%packages

@base

@core

vim

%end

配置TFTP

cd /var/lib/tftpboot/

[root@localhost tftpboot]# mkdir pxelinux.cfg

[root@localhost tftpboot]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

[root@localhost tftpboot]# mkdir centos{6,7} 由于有两个内核,所以创建两个文件夹,一个放7的一个放6的

[root@localhost tftpboot]# cp /var/www/html/centos/6/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos6/

[root@localhost tftpboot]# cp /var/www/html/centos/7/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos7/

[root@localhost tftpboot]# cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/ 拷贝简单版菜单

[root@localhost tftpboot]# cp /var/www/html/centos/7/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default 拷贝菜单文件并改名

vim /var/lib/tftpboot/pxelinux.cfg/default

default menu.c32

timeout 600

menu title CentOS 7

label centos7

menu label ^Install Mini CentOS 7

kernel centos7/vmlinuz

append initrd=centos7/initrd.img ks=http://192.168.63.134/ksdir/ks7_mini.cfg

label centos6

menu label ^install Mini CentOS 6

kernel centos6/vmlinuz

append initrd=centos6/initrd.img ks=http://192.168.63.134/ksdir/ks_mini.cfg

label local

menu default

menu label Boot from ^local drive

localboot 0xffff

menu end

#############################################################################

cobbler系统批量部署

Cobbler:

快速网络安装linux操作系统的服务,支持众多的Linux发行版:Red Hat、

Fedora、 CentOS、 Debian、 Ubuntu和SuSE,也可以支持网络安装windows

PXE的二次封装,将多种安装参数封装到一个菜单

Python编写

提供了CLI和Web的管理形式

cobbler的实现

cobbler安装部署的时候需要外网

检查selinux 有没有关闭 /etc/selinux/conf

iptables 防火墙有没有关闭 iptables -vnL 查看防火墙 iptables -F 请客防火墙

1. yum install cobbler dhcp -y 安装cobbler和http的包,因为依赖会自动安装tftp syslinux

2. systemctl enable cobblerd dhcpd httpd tftp 开机启动

3. systemctl start cobblerd httpd tftp 启动服务

4. [root@localhost ~]# cd /var/lib/tftpboot/

[root@localhost tftpboot]# ls #cobbler会自动生成一些文件,不用自己去创建

boot etc grub images images2 ppc pxelinux.cfg s390x

clip_image290

5. 用命令检查cobbler里面缺什么文件,然后在一件一件的安装

命令: cobbler check

clip_image292

1.vim /etc/cobbler/settings 指定cobbler服务器的地址

查找server: 把127.0.0.1 改成本机的ip 更改完成以后重启服务systemctl restart cobblerd

server: 192.168.63.134

clip_image294

2. vim /etc/cobbler/settings 指定TFTP服务器的地址

查找 next_server: 把127.0.0.1 改成 TFTP服务器的地址,如果是本机的话改成本机地址

next_server: 192.168.63.134

clip_image296

3. 不用改,因为服务端口已经打开,

4. 执行这条 cobbler get-loaders 命令,自动下载需要的文件

在执行同步命令 cobbler sync

clip_image298

5. 第5步不是一个必要服务,不用管

6. 第六步不用安装

7. 用openssl passwd -1 命令生成一个加密的口令,替换系统自带的最小化应答文件的root口令

clip_image300

在 vim /etc/cobbler/settings 文件找到这一行并替换原有的加密口令

clip_image302

8.第八项是和电源有关的不用管

6. 重启cobbler 服务

systemctl restart cobblerd

7. 用cobbler 管理自动生成DHCP服务的文件

vim /etc/cobbler/settings

找到这manage_dhcp: 1 一行把0改成1

clip_image304

systemctl restart cobblerd 重启服务

8.修改DHCP的参考模板

vim /etc/cobbler/dhcp.template

subnet 192.168.63.0 netmask 255.255.255.0 {

option routers 192.168.63.1;

option domain-name-servers 114.114.114.114;

option subnet-mask 255.255.255.0;

range dynamic-bootp 192.168.63.100 192.168.63.200;

default-lease-time 21600;

max-lease-time 43200;

clip_image306

用cobbler sync 同步cobbler

用cat /etc/dhcp/dhcpd.conf 查看dhcp已经配置完成

9.准备yum源

导入对应的安装包

添加两个光盘一个centos6.9的一个centos7.5的

echo '- - -' > /sys/class/scsi_host/host0/scan

clip_image308

挂载光盘

mount /dev/sr0 /mnt/cdroot

mount /dev/sr1 /mnt/cdroot2

clip_image310

利用挂载的光盘导入对应的安装包

cobbler import --path=/mnt/cdroot2/ --name=Centos-6.9-x86_64 --arch=x86_64

cobbler import --path=/mnt/cdroot/ --name=Centos-7.5-x86_64 --arch=x86_64

-path=/mnt/cdroot2/ 挂载的路径

-name=Centos-6.9-x86_64 名字叫什么

--arch=x86_64 告诉系统支持的版本

9.可以工具生产情况修改TFTP发服务文件的菜单文件,当然也可以不改

vim /var/lib/tftpboot/pxelinux.cfg/default

10. 已经可以实现安装,但是可能不符合我们的要求

用 cobbler distro list 可以看到有两个系统,其中一个Centos-6.9-i386我们是没有的。里面是空的,可以删除

Centos-6.9-i386

Centos-6.9-x86_64

Centos-7.5-x86_64

clip_image312

但是删除的时候报错

[root@localhost Centos-6.9-x86_64]# cobbler distro remove --name=Centos-6.9-i386

exception on server: 'removal would orphan profile: Centos-6.9-i386'

clip_image314

提示要先删除菜单里面的菜单选项

cobbler profile remove --name=Centos-6.9-i386

再删除版本里面的

cobbler distro remove --name=Centos-6.9-i386

11.现在测试安装系统,已经可以看见菜单项,已经可以安装了

但是写入自己的应答文件的话,在url这一行要写入一个变量,会自动查找yum源的路径url --url=$tree

clip_image316

将自己应答文件拷贝到对应的目录 /var/lib/cobbler/kickstarts/

cp ks_mini_\(2\).cfg /var/lib/cobbler/kickstarts/

cp ks7_disktop.cfg /var/lib/cobbler/kickstarts/

.关联自己的应答文件

[root@localhost ~]# cobbler distro list 将应答文件的操作系统关联起来

Centos-6.9-x86_64

Centos-7.5-x86_64

cobbler profile add --name=Centos-6.9-x86_64_mini --distro=Centos-6.9-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks_mini_\(2\).cfg

-name=Centos-7.5-x86_64_dasktop 菜单的名字

--distro=Centos-7.5-x86_64 关联的操作系统

kickstart=/var/lib/cobbler/kickstarts/ks_mini_\(2\).cfg 应答文件对应的路径

****************************************************************************************************************************

基于WEB的cobbler

yum install cobbler-web -y 安装web包

systemctl restart httpd 启动dhcp服务

用浏览器测试,ip是服务器的ip

https://192.168.63.134/cobbler_web

创建cobbler_web 管理密码

htdigest -c /etc/cobbler/users.digest Cobbler test1 指定cobbler 的用户名为test1

cat /etc/cobbler/users.digest 查看创建的用户和加密的密码