PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装

一、PXE实现多系统可选择自动化安装系统

实现此种自动化安装,需要使用http,tftp,dhcp服务,实现环境,将http,tftp,dhcp服务端全部安装到一台服务器中,一台服务器兼顾多种服务(也可以将这三种服务,分别用三台服务器实现)

1、实验前提条件

为了不被教室环境所影响,网卡:仅主机,关闭wmware的dhcp服务


PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第1张图片
image.png
PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第2张图片
image.png

PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第3张图片
image.png
2、服务端安装httpd服务
[root@centos7 ~]#yum -y install httpd  注:安装httpd包
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
......
Complete!
[root@centos7 ~]#systemctl start httpd 注:启动服务端http服务
[root@centos7 ~]#systemctl enable httpd  注:设置开机启动
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第4张图片
image.png
  • 为使用http服务为自动安装提供源文件
[root@centos7 ~]#cd /var/www/html/
[root@centos7 html]#ls
[root@centos7 html]#mkdir centos/{6,7}/os/x86_64 -pv
[root@centos7 html]#tree
.
└── centos
    ├── 6
    │   └── os
    │       └── x86_64
    └── 7
        └── os
            └── x86_64

7 directories, 0 files

[root@centos7 html]#mkdir ksdir  注:在/var/www/html下创建应答文件目录
[root@centos7 html]#ls
centos  ksdir
[root@centos7 html]#tree -L 2
.
├── centos
│   ├── 6
│   └── 7
└── ksdir


PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第5张图片
image.png
  • 挂载 注:需要长久挂载,就写入/etc/fstab文件中
[root@centos7 html]#mount /dev/sr0 /var/www/html/centos/7/os/x86_64/
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos7 html]#mount /dev/sr1 /var/www/html/centos/6/os/x86_64/
mount: /dev/sr1 is write-protected, mounting read-only

通过http服务,可以访问源文件


PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第6张图片
image.png

PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第7张图片
image.png
2、 准备KS应答文件
  • 自作应答文件有两种:
    1. 通过system-config-kickstart 工具自作
    2. 通过参考/root/anaconda-ks.cfg 模板修改
      **通过system-config-kickstart自作应答文件
      注意:centos6系统应答文件制作在centos6系统主机制作;centos7系统应答文件制作在centos7系统主机制作
      本实验在centos6系统主机上通过system-config-kickstart做cnetos6系统的应答文件
  • 安装system-config-kickstart工具
[root@centos6 ~]#yum -y install system-config-kickstart
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
......
Complete!
PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第8张图片
image.png
  • 应答文件制作页面
    基本配置


    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第9张图片
    image.png

    安装方法


    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第10张图片
    image.png

    选项
    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第11张图片
    image.png

    分区!
    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第12张图片
    image.png

    网络设置
    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第13张图片
    image.png
    验证
    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第14张图片
    image.png
    防火墙设置
    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第15张图片
    image.png
    包的选择
    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第16张图片
    image.png
    安装前后运行的脚本
    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第17张图片
    image.png

    在http服务器上,设置基于KEY验证的登陆,将生产的authorized_keys写入到应答文件中
[root@centos7 ~]#ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:TgV76l4WdIalfV2e2rKQ4bq1TjKpW69wxA7l5tuIiGc [email protected]
The key's randomart image is:
+---[RSA 2048]----+
|        .   .   .|
|         o =   oo|
|        ..*.+ ..o|
|        +=.oo.o  |
|       .S=.+ o . |
|       +* o.. o  |
|       .oXoo .   |
|    .E..*o@ .    |
|   .o. +o=o=     |
+----[SHA256]-----+
[root@centos7 ~]#ls
172.22.149.240   Desktop    Downloads             Music     Public    Templates
anaconda-ks.cfg  Documents  initial-setup-ks.cfg  Pictures  reset.sh  Videos
[root@centos7 ~]#ssh-copy-id 192.168.16.7
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/bin/ssh-copy-id: ERROR: ssh: connect to host 192.168.16.7 port 22: Network is unreachable

[root@centos7 ~]#ssh-copy-id 192.168.18.7
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.18.7 (192.168.18.7)' can't be established.
ECDSA key fingerprint is SHA256:6hqGVGch7sXbceJJqmR1XxtQkJDBLjC8VGyzz9vcdKg.
ECDSA key fingerprint is MD5:41:6e:e7:36:24:37:8a:d5:5e:94:10:58:72:ae:da:21.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '192.168.18.7'"
and check to make sure that only the key(s) you wanted were added.

[root@centos7 ~]#cd .ssh
[root@centos7 .ssh]#ll
total 16
-rw-------  1 root root  406 Apr 20 15:39 authorized_keys
-rw-------  1 root root 1675 Apr 20 15:38 id_rsa
-rw-r--r--  1 root root  406 Apr 20 15:38 id_rsa.pub
-rw-r--r--. 1 root root 1142 Apr 20 15:39 known_hosts
[root@centos7 .ssh]#cat authorized_keys 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6DfXuaYccUtGgMh2wy3fuBz3IVxC19oIacJvMWPnKb/JnPbgrcT8efPt7aTVeGqReWZD6HH+vQ9HSq50W9gktC+fNeeJd/UVrVLgw6iFpUc+UYvShfMpyknEYOhotYrrT2Izojz0l3MIR/uuaE/guW+T6P+8oGmCbAS97bn3ofwlGUhWya+2v4YkiW1RvpSqY9AIxFf+BH2GyLysCVNC6QfwSLnB2PLGnTxAgCREKbRzawG1sF55vXoiPRwtQgBLRfkM99C6kpsJTFkkZX+pG3jhLdKlsdFCjbf+g1+WLho8YtdmDTEuQO+g/dN7xz1JZJQ8vT1Nn2fVgULHKsO+x [email protected]
[root@centos7 .ssh]#ll -d
drwx------. 2 root root 80 Apr 20 15:39 .
PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第18张图片
image.png

ks.cfg应答文件配置好之后,保存
PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第19张图片
image.png
生成的自动安装centos6的应答文件
[root@centos6 ~]#cat ks.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled  注:防火墙关闭
# Install OS instead of upgrade
install    
# Use network installation
url --url="http://192.168.18.7/centos/6/os/x86_64/" 注:安装源路径
# Root password
rootpw --iscrypted $1$zqF4W.uR$6RYTN1HKSNP2aVU8/tb/D1  注:基于加密后的root口令
# 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  注:selinux关闭
# Installation logging level
logging --level=info
# Reboot after installation
reboot      注:系统安装完之后重启
# System timezone
timezone  Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr    注:bootloader安装进磁盘mbr中
# Clear the Master Boot Record
zerombr    注:清除原来设备的mbr
# Partition clearing information
clearpart --all --initlabel     注:清除原来磁盘分区
# Disk partitioning information  注:创建新的磁盘分区文件系统
part /boot --fstype="ext4" --size=500
part / --fstype="ext4" --size=20480
part swap --fstype="swap" --size=2048

%post      注:安装后运行脚本
mkdir /root/.ssh
chmod 700 /root/.ssh
cat > /root/.ssh/authorized_keys << EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6DfXuaYccUtGgMh2wy3fuBz3IVxC19oIacJvMWPnKb/JnPbgrcT8efPt7aTVeGqReWZD6HH+vQ9HSq50W9gktC+fNeeJd/UVrVLgw6iFpUc+UYvShfMpyknEYOhotYrrT2Izojz0l3MIR/uuaE/guW+T6P+8oGmCbAS97bn3ofwlGUhWya+2v4YkiW1RvpSqY9AIxFf+BH2GyLysCVNC6QfwSLnB2PLGnTxAgCREKbRzawG1sF55vXoiPRwtQgBLRfkM99C6kpsJTFkkZX+pG3jhLdKlsdFCjbf+g1+WLho8YtdmDTEuQO+g/dN7xz1JZJQ8vT1Nn2fVgULHKsO+x [email protected]
EOF
chmod 600 /root/.ssh/authorized_keys
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
cat > /etc/yum.repos.d/base.repo <

将centos6系统上生产的应答文件ks.cfg拷到centos7http服务端主机上

[root@centos6 ~]#scp ks.cfg 192.168.18.7:/
The authenticity of host '192.168.18.7 (192.168.18.7)' can't be established.
RSA key fingerprint is 87:44:f5:d3:fe:a9:23:11:4e:56:64:9b:d9:6c:4d:92.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.18.7' (RSA) to the list of known hosts.
[email protected]'s password: 
ks.cfg                                                     100% 1712     1.7KB/s   00:00
[root@centos7 /]#ls ks.cfg 
ks.cfg

重新命名centos6自动安装系统的应答文件

[root@centos7 /]#mv ks.cfg /var/www/html/ksdir/ks6_mini.cfg
  • 通过参考/root/anaconda-ks.cfg 模板修改
#注:先以刚刚生成的 ks6_mini.cfg为模板制作 ks7_mini.cfg应答文件
[root@centos7 /]#mv ks.cfg /var/www/html/ksdir/ks6_mini.cfg
[root@centos7 /]#cd /var/www/html/ksdir/
[root@centos7 ksdir]#ls
ks6_mini.cfg
[root@centos7 ksdir]#cp ks6_mini.cfg ks7_mini.cfg 
[root@centos7 ksdir]#ls
ks6_mini.cfg  ks7_mini.cfg
[root@centos7 ksdir]#vim ks7_mini.cfg 

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
# 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
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation         注:6该为7
# 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=dhcp --device=ens33 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel 
# Disk partitioning information
part /boot --fstype="ext4" --size=500
part / --fstype="ext4" --size=20480
part swap --fstype="swap" --size=2048

%post
mkdir /root/.ssh
chmod 700 /root/.ssh
cat > /root/.ssh/authorized_keys << EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6DfXuaYccUtGgMh2wy3fuBz3IVxC19oIacJvMWPnKb/JnPbgrcT8efPt7aTVeGqReWZD6HH+vQ9HSq50W9gktC+fNeeJd/UVrVLgw6iFpUc+UYvShfMpyknEYOhotYrrT2Izojz0l3MIR/uuaE/guW+T6P+8oGmCbAS97bn3ofwlGUhWya+2v4YkiW1RvpSqY9AIxFf+BH2GyLysCVNC6QfwSLnB2PLGnTxAgCREKbRzawG1sF55vXoiPRwtQgBLRfkM99C6kpsJTFkkZX+pG3jhLdKlsdFCjbf+g1+WLho8YtdmDTEuQO+g/dN7xz1JZJQ8vT1Nn2fVgULHKsO+x [email protected]
EOF
chmod 600 /root/.ssh/authorized_keys
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
cat > /etc/yum.repos.d/base.repo <
PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第20张图片
image.png
[root@centos7 html]#tree -L 5
.
├── centos
│   ├── 6
│   │   └── os
│   │       └── x86_64
│   │           ├── CentOS_BuildTag
│   │           ├── EFI
│   │           ├── EULA
│   │           ├── GPL
│   │           ├── images
│   │           ├── isolinux
│   │           ├── Packages
│   │           ├── RELEASE-NOTES-en-US.html
│   │           ├── repodata
│   │           ├── RPM-GPG-KEY-CentOS-6
│   │           ├── RPM-GPG-KEY-CentOS-Debug-6
│   │           ├── RPM-GPG-KEY-CentOS-Security-6
│   │           ├── RPM-GPG-KEY-CentOS-Testing-6
│   │           └── TRANS.TBL
│   └── 7
│       └── os
│           └── x86_64
│               ├── CentOS_BuildTag
│               ├── EFI
│               ├── EULA
│               ├── GPL
│               ├── images
│               ├── isolinux
│               ├── LiveOS
│               ├── Packages
│               ├── repodata
│               ├── RPM-GPG-KEY-CentOS-7
│               ├── RPM-GPG-KEY-CentOS-Testing-7
│               └── TRANS.TBL
└── ksdir
    ├── ks6_mini.cfg
    └── ks7_mini.cfg

19 directories, 17 files

  • ks应答文件做好之后,进行ks文件的语法错误:ksvalidator
[root@centos7 ksdir]#ksvalidator ks6_mini.cfg 
[root@centos7 ksdir]#ksvalidator ks7_mini.cfg
4、服务端安装tfcp-sever
  • 在centos7主机上安装服务端tftp-sever包
注:安装包
[root@centos7 ksdir]#yum -y install tftp-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
......
Complete!

[root@centos7 ksdir]#systemctl start tftp; systemctl enable tftp
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
[root@centos7 ksdir]#systemctl status tftp
● tftp.service - Tftp Server
   Loaded: loaded (/usr/lib/systemd/system/tftp.service; indirect; vendor preset: disabled)
   Active: active (running) since Sat 2019-04-20 16:36:04 CST; 14s ago
     Docs: man:in.tftpd
 Main PID: 12483 (in.tftpd)
   CGroup: /system.slice/tftp.service
           └─12483 /usr/sbin/in.tftpd -s /var/lib/tftpboot

Apr 20 16:36:04 centos7.localdomain systemd[1]: Started Tftp Server.
[root@centos7 ksdir]#rpm -ql tftp-server
/etc/xinetd.d/tftp
/usr/lib/systemd/system/tftp.service
/usr/lib/systemd/system/tftp.socket
/usr/sbin/in.tftpd
/usr/share/doc/tftp-server-5.2
/usr/share/doc/tftp-server-5.2/CHANGES
/usr/share/doc/tftp-server-5.2/README
/usr/share/doc/tftp-server-5.2/README.security
/usr/share/man/man8/in.tftpd.8.gz
/usr/share/man/man8/tftpd.8.gz
/var/lib/tftpboot  注:tftp服务器端工作目录,tftp客户端下载,查看等所需文件都放在该目录下

5、 服务端安装DHCP包
  • 安装dhcp安装包
[root@centos7 ksdir]#yum -y install dhcp
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package dhcp.x86_64 12:4.2.5-68.el7.centos.1 will be installed
......
Complete!

[root@centos7 ksdir]#rpm -ql dhcp
/etc/NetworkManager
/etc/NetworkManager/dispatcher.d
/etc/NetworkManager/dispatcher.d/12-dhcpd
/etc/dhcp/dhcpd.conf  注:dhcp配置文件
/etc/dhcp/dhcpd6.conf
/etc/dhcp/scripts
/etc/dhcp/scripts/README.scripts
/etc/openldap/schema/dhcp.schema
/etc/sysconfig/dhcpd
/usr/bin/omshell
/usr/lib/systemd/system/dhcpd.service
/usr/lib/systemd/system/dhcpd6.service
/usr/lib/systemd/system/dhcrelay.service
/usr/sbin/dhcpd
/usr/sbin/dhcrelay
/usr/share/doc/dhcp-4.2.5
/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example  注:dhcp服务配置文件样本,参照此文件编辑配置文件
/usr/share/doc/dhcp-4.2.5/dhcpd6.conf.example
/usr/share/doc/dhcp-4.2.5/ldap
/usr/share/doc/dhcp-4.2.5/ldap/README.ldap
/usr/share/doc/dhcp-4.2.5/ldap/dhcp.schema
/usr/share/doc/dhcp-4.2.5/ldap/dhcpd-conf-to-ldap
/usr/share/man/man1/omshell.1.gz
/usr/share/man/man5/dhcpd.conf.5.gz
/usr/share/man/man5/dhcpd.leases.5.gz
/usr/share/man/man8/dhcpd.8.gz
/usr/share/man/man8/dhcrelay.8.gz
/usr/share/systemtap/tapset/dhcpd.stp
/var/lib/dhcpd
/var/lib/dhcpd/dhcpd.leases  注:dhcp分配的地址数据文件
/var/lib/dhcpd/dhcpd6.leases
[root@centos7 ksdir]#
  • 编辑dhcp配置文件
注:复制模板文件,修改模板文件
[root@centos7 ksdir]#cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf 
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? yes
[root@centos7 dhcp]#vim dhcpd.conf 

# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "magedu.com";
option domain-name-servers 114.114.114.114, 225.5.5.5;  #注:设定给分配的ip地址的主机同时自动分配dns地址,

default-lease-time 86400;    注:dhcp分配地址使用的时间设定
max-lease-time 864000;  注:客户端使用的分配的ip地址,申请最长使用的时间设定

# 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;

#ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
# 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.

# This is a very basic subnet declaration.

subnet 192.168.18.0 netmask 255.255.255.0 { 
  range 192.168.18.10 192.168.18.200;  注:dhcp服务器分配的网段地址范围设定
  option routers 192.168.18.199;   注:网关的设定
  next-server 192.168.18.7;  注:提供引导文件的服务器IP地址,此处地址即为tftp服务端主机地址
  filename "pxelinux.0";  注:指明引导文件名称,pxelinux.0是引导计算机启动的文件
}
注:解析:通过dhcp服务端服务器指定tftp服务器服务端地址,进而将来服务器可以连到tftp服务端服务器下载一些自动安装的一些必要文件;
客户端通过网卡的PXE功能通过dhcp服务端获得tftp服务端ip地址,获取ip地址之后,再通过dhcp服务端给的next-server 192.168.36.7(tfcp服务器地址)地址,
去tftp服务端服务器去下载与引导计算机启动的相关文件filename "pxelinux.0"中的pxelinux.0是引导计算机启动的文件,pxelinux.0相当于在linux里默认支持linux系统的引导程序

# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.

  • 启动dhcp服务,同时设置开机启动
[root@centos7 dhcp]#systemctl start dhcpd; systemctl enable dhcpd
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
[root@centos7 dhcp]#systemctl status dhcpd
● dhcpd.service - DHCPv4 Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2019-04-20 17:44:57 CST; 9s ago
     Docs: man:dhcpd(8)
           man:dhcpd.conf(5)
 Main PID: 13478 (dhcpd)
   Status: "Dispatching packets..."
   CGroup: /system.slice/dhcpd.service
           └─13478 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --...

Apr 20 17:44:57 centos7.localdomain dhcpd[13478]: No subnet declaration for virbr0 (192....).
Apr 20 17:44:57 centos7.localdomain dhcpd[13478]: ** Ignoring requests on virbr0.  If th...at
Apr 20 17:44:57 centos7.localdomain dhcpd[13478]:    you want, please write a subnet dec...on
Apr 20 17:44:57 centos7.localdomain dhcpd[13478]:    in your dhcpd.conf file for the net...nt
Apr 20 17:44:57 centos7.localdomain dhcpd[13478]:    to which interface virbr0 is attach...**
Apr 20 17:44:57 centos7.localdomain dhcpd[13478]: nt
Apr 20 17:44:57 centos7.localdomain dhcpd[13478]: Listening on LPF/eth0/00:0c:29:ad:6f:7...24
Apr 20 17:44:57 centos7.localdomain dhcpd[13478]: Sending on   LPF/eth0/00:0c:29:ad:6f:7...24
Apr 20 17:44:57 centos7.localdomain dhcpd[13478]: Sending on   Socket/fallback/fallback-net
Apr 20 17:44:57 centos7.localdomain systemd[1]: Started DHCPv4 Server Daemon.
Hint: Some lines were ellipsized, use -l to show in full.
[root@centos7 dhcp]#

注:dhcp服务端监听端口是:67
tftp服务端端口是:69

[root@centos7 dhcp]#ss -nul
State       Recv-Q Send-Q Local Address:Port                Peer Address:Port              
UNCONN      0      0      192.168.122.1:53                             *:*                  
UNCONN      0      0                  *:67                             *:*                  
UNCONN      0      0           *%virbr0:67                             *:*                  
UNCONN      0      0                  *:47188                          *:*                  
UNCONN      0      0                  *:111                            *:*                  
UNCONN      0      0                  *:5353                           *:*                  
UNCONN      0      0                  *:42726                          *:*                  
UNCONN      0      0          127.0.0.1:816                            *:*                  
UNCONN      0      0                  *:866                            *:*                  
UNCONN      0      0                 :::69                            :::*                  
UNCONN      0      0                 :::111                           :::*                  
UNCONN      0      0                 :::36333                         :::*                  
UNCONN      0      0                 :::866                           :::*          
  • 配置文件语法检查
[root@centos7 dhcp]#service dhcpd configtest
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

6、准备支持多系统启动文件
  • 安装syslinux包
    syslinux包提供pxelinux.0,pxelinux.0是linux系统启动文件,可以引导计算机启动的文件
[root@centos7 dhcp]#yum -y install syslinux
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
base    
......
Installed:
  syslinux.x86_64 0:4.05-15.el7                                                              

Complete!                                 
[root@centos7 dhcp]#rpm -ql syslinux |grep pxelinux.0
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0   注:引导linux系统启动文件

[root@centos7 dhcp]#rpm -ql syslinux | grep menu.c32
/usr/share/syslinux/menu.c32  启动菜单风格文件
/usr/share/syslinux/vesamenu.c32  
  • 将sysLinux包生成的pxelinux.0、menu.c32拷贝到tftp工作目录下/var/lib/tftpboot,以及将
[root@centos7 dhcp]#cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@centos7 dhcp]#cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/
  • 在/var/lib/tftpboot目录下创建2个目录,分别放各自的centos6,centos7系统的内核文件vmlinuz与伪根文件系统initrd.img
[root@centos7 dhcp]#cd /var/lib/tftpboot/
[root@centos7 tftpboot]#mkdir kernel{6,7}
[root@centos7 tftpboot]#cp /var/www/html/centos/6/os/x86_64/isolinux/vmlinuz kernel6
[root@centos7 tftpboot]#cp /var/www/html/centos/6/os/x86_64/isolinux/initrd.img kernel6
[root@centos7 tftpboot]#cp /var/www/html/centos/7/os/x86_64/isolinux/vmlinuz kernel7
[root@centos7 tftpboot]#cp /var/www/html/centos/7/os/x86_64/isolinux/initrd.img kernel7
[root@centos7 tftpboot]#tree
.
├── kernel6
│   ├── initrd.img
│   └── vmlinuz
├── kernel7
│   ├── initrd.img
│   └── vmlinuz
├── menu.c32
└── pxelinux.0

2 directories, 6 files
  • 在/var/lib/tftpboot目录下创建pxelinux.cfg菜单文件目录
[root@centos7 tftpboot]#mkdir pxelinux.cfg
[root@centos7 tftpboot]#ls
kernel6  kernel7  menu.c32  pxelinux.0  pxelinux.cfg
  • 将光盘的启动菜单文件拷贝到pxelinux.cfg目录下,并且重命名为default文件
[root@centos7 tftpboot]#cp /var/www/html/centos/7/os/x86_64/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@centos7 tftpboot]#tree
.
├── kernel6
│   ├── initrd.img
│   └── vmlinuz
├── kernel7
│   ├── initrd.img
│   └── vmlinuz
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
    └── default

3 directories, 7 files


7、准备启动菜单文件
[root@centos7 tftpboot]#vim pxelinux.cfg/default 

default menu.c32  注:启动菜单风格文件
timeout 1000      注:设定启动菜单超时时间10秒
menu title Auto Install CentOS
label centos7
  menu label Install CentOS ^Mini 7
  kernel kernel7/vmlinuz   注:centos7内核文件
  append initrd=kernel7/initrd.img ks=http://192.168.18.7/ksdir/ks7_mini.cfg                          
label centos6    
  menu label Install CentOS Mi^ni 6
  kernel kernel6/vmlinuz
  append initrd=kernel6/initrd.img ks=http://192.168.18.7/ksdir/ks6_mini.cfg
label local
    menu default  注:默认从本地驱动器启动
    menu label Boot from ^local drive  注:默认从本地驱动器启动
    localboot 0xffff

[root@centos7 tftpboot]#tree
.
├── kernel6
│   ├── initrd.img
│   └── vmlinuz
├── kernel7
│   ├── initrd.img
│   └── vmlinuz
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
    └── default

3 directories, 7 files
[root@centos7 tftpboot]#

二、实验:利用cobbler 实现系统自动化安装

  • cobbler快速网络安装linux操作系统的服务,支持众多的Linux发行版:Red Hat、Fedora、CentOS、Debian、Ubuntu和SuSE,也可以支持网络安装
    windows
  • PXE的二次封装,将多种安装参数封装到一个菜单
  • 提供了CLI和Web的管理形式


    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第21张图片
    image.png
1、安装包和配置服务

cobbler包依赖于epel,需要服务端能连接外网,但是最好不要使用最新epel源,不稳定,容易出现bug,cobbler在安装过程中,其中依赖的包httpd,tftp,syslinux都自动安装了,唯独dhcp包没有安装,因此需要单独安装。

  • 安装cobbler、dhcp这2个包
[root@centos7 yum.repos.d]#yum -y install cobbler dhcp
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
......
Installed:
  cobbler.x86_64 0:2.8.3-2.el7                       dhcp.x86_64 12:4.2.5-68.el7.centos.1                      

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7_4.1                      apr-util.x86_64 0:1.5.2-6.el7                               
  httpd.x86_64 0:2.4.6-88.el7.centos                httpd-tools.x86_64 0:2.4.6-88.el7.centos                    
  mailcap.noarch 0:2.1.41-2.el7                     mod_wsgi.x86_64 0:3.4-18.el7                                
  python-cheetah.x86_64 0:2.4.4-4.el7               python-markdown.noarch 0:2.4.1-2.el7                        
  python-netaddr.noarch 0:0.7.5-9.el7               python-pillow.x86_64 0:2.0.0-19.gitd1c6db8.el7              
  python-pygments.noarch 0:1.4-10.el7               python2-simplejson.x86_64 0:3.10.0-1.el7                    
  syslinux.x86_64 0:4.05-15.el7                     tftp-server.x86_64 0:5.2-22.el7                             

Complete!

  • 设置tftp、dhcpd、httpd、cobblerd这四个程序开机自启
[root@centos7 yum.repos.d]#systemctl enable tftp dhcpd httpd cobblerd
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.

  • 启动 tftp、httpd、cobblerd
[root@centos7 yum.repos.d]#systemctl start tftp httpd cobblerd
  • 检查cobbler环境,解决报错问题
[root@centos7 yum.repos.d]#cobbler check
The following are potential configuration items that you may want to fix:

1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work.  This should be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
注:这一项需设定cobblerd主机ip地址
2 : For PXE to be functional, the 'next_server' field in /etc/cobbler/settings must be set to something other than 127.0.0.1, and should match the IP of the boot server on the PXE network.
注:设定tftp主机ip地址
3 : change 'disable' to 'no' in /etc/xinetd.d/tftp
4 : Some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
注:提示用cobbler get-loaders命令,下载自动化安装的相关文件
5 : enable and start rsyncd.service with systemctl
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
7 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still set to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one
注:cobblerd自动安装系统,默认设置的root密码为cobblerd,不安全,在配置文件中修改
8 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

Restart cobblerd and then run 'cobbler sync' to apply changes.
以上8个问题需要解决
2、修改cobbler 配置文件
[root@centos7 yum.repos.d]# vim /etc/cobbler/settings
PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第22张图片
image.png
PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第23张图片
image.png

设置自动安装root密码,cobblerd默认的root账户密码时cobblerd

[root@centos7 ~]#openssl passwd -1
Password: 
Verifying - Password: 
$1$LuGacovO$HzzGyYZ47R8d6da/dbYqj1
注:生成的这个加密口令替换cobblerd设置的默认root登录口令
PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第24张图片
image.png

PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第25张图片
image.png
  • 修改好以上几项,重启下cobblerd
[root@centos7 yum.repos.d]#cobbler check
The following are potential configuration items that you may want to fix:

1 : change 'disable' to 'no' in /etc/xinetd.d/tftp
2 : Some network boot-loaders are missing from /var/lib/cobbler/loaders, you may run 'cobbler get-loaders' to download them, or, if you only want to handle x86/x86_64 netbooting, you may ensure that you have installed a *recent* version of the syslinux package installed and can ignore this message entirely.  Files in this directory, should you want to support all architectures, should include pxelinux.0, menu.c32, elilo.efi, and yaboot. The 'cobbler get-loaders' command is the easiest way to resolve these requirements.
3 : enable and start rsyncd.service with systemctl
4 : debmirror package is not installed, it will be required to manage debian deployments and repositories
5 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

Restart cobblerd and then run 'cobbler sync' to apply changes
  • 通过cobbler get-loaders自动化安装需要的相关文件
[root@centos7 yum.repos.d]#cobbler get-loaders
task started: 2019-04-21_153144_get_loaders
task started (id=Download Bootloader Content, time=Sun Apr 21 15:31:44 2019)
downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README
downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo
downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot
downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux
downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi
downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot
downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0
downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32
downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi
downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi
*** TASK COMPLETE ***

[root@centos7 yum.repos.d]#cd /var/lib/cobbler/loaders/
[root@centos7 loaders]#tree
.
├── COPYING.elilo
├── COPYING.syslinux
├── COPYING.yaboot
├── elilo-ia64.efi
├── grub-x86_64.efi
├── grub-x86.efi
├── menu.c32
├── pxelinux.0
├── README
└── yaboot

0 directories, 10 files

  • 同步配置好的数据目录
    通过cobbler sync命令,同步配置好的数据到相关服务文件中,更改配置文件都要执行下该命令
[root@centos7 loaders]#tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── boot
├── etc
├── grub
├── images
├── images2
├── ppc
├── pxelinux.cfg
└── s390x

8 directories, 0 files

[root@centos7 loaders]#cobbler sync
task started: 2019-04-21_153802_sync
task started (id=Sync, time=Sun Apr 21 15:38:02 2019)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout: 
received on stderr: 
running: service dhcpd restart
received on stdout: 
received on stderr: Redirecting to /bin/systemctl restart dhcpd.service
Job for dhcpd.service failed because the control process exited with error code. See "systemctl status dhcpd.service" and "journalctl -xe" for details.

Exception occured: 
Exception value: 'cobbler trigger failed: cobbler.modules.sync_post_restart_services'
Exception Info:
  File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 82, in run
    rc = self._run(self)
   File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 181, in runner
    return self.remote.api.sync(self.options.get("verbose",False),logger=self.logger)
   File "/usr/lib/python2.7/site-packages/cobbler/api.py", line 763, in sync
    return sync.run()
   File "/usr/lib/python2.7/site-packages/cobbler/action_sync.py", line 144, in run
    utils.run_triggers(self.api, None, "/var/lib/cobbler/triggers/sync/post/*", logger=self.logger)
   File "/usr/lib/python2.7/site-packages/cobbler/utils.py", line 928, in run_triggers
    raise CX("cobbler trigger failed: %s" % m.__name__)

!!! TASK FAILED !!!

[root@centos7 loaders]#tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── boot
│   └── grub
│       └── menu.lst
├── etc
├── grub
│   ├── efidefault
│   ├── grub-x86_64.efi
│   ├── grub-x86.efi
│   └── images -> ../images
├── images
├── images2
├── memdisk
├── menu.c32
├── ppc
├── pxelinux.0
├── pxelinux.cfg
│   └── default
├── s390x
│   └── profile_list
└── yaboot

10 directories, 10 files

3、配置dhcp服务
  • 借助cobbler里的dhcp模板文件,修改dhcp配置文件
[root@centos7 loaders]#vim /etc/cobbler/dhcp.template

# ******************************************************************
# Cobbler managed dhcpd.conf file
#
# generated from cobbler dhcp.conf template ($date)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
#
# ******************************************************************

ddns-update-style interim;

allow booting;
allow bootp;

ignore client-updates;
set vendorclass = option vendor-class-identifier;

option pxe-system-type code 93 = unsigned integer 16;

subnet 192.168.18.0 netmask 255.255.255.0 {
     option routers             192.168.18.199;   注:网关地址                                                               
     option domain-name-servers 1.1.1.1; 注:DNS地址
     option subnet-mask         255.255.255.0; 注:子网
     range dynamic-bootp        192.168.18.10 192.168.18.200; 注:dhcp分配IP地址的范围
     default-lease-time         21600;注:分配的ip地址使用时间
     max-lease-time             43200; 注:客户端可以申请使用的ip地址最长使用时间
     next-server                $next_server; 注:$next_server代表的是tftp服务端ip地址
     class "pxeclients" {
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
          if option pxe-system-type = 00:02 {
                  filename "ia64/elilo.efi";

修改括号括起来的几项即可


PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第26张图片
image.png
  • 同步dhcp模板文件
[root@centos7 loaders]#cobbler sync
task started: 2019-04-21_155713_sync
task started (id=Sync, time=Sun Apr 21 15:57:13 2019)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
cleaning link caches
running post-sync triggers
running python triggers from /var/lib/cobbler/triggers/sync/post/*
running python trigger cobbler.modules.sync_post_restart_services
running: dhcpd -t -q
received on stdout: 
received on stderr: 
running: service dhcpd restart
received on stdout: 
received on stderr: Redirecting to /bin/systemctl restart dhcpd.service

running shell triggers from /var/lib/cobbler/triggers/sync/post/*
running python triggers from /var/lib/cobbler/triggers/change/*
running python trigger cobbler.modules.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***

[root@centos7 loaders]#vim /etc/dhcp/dhcpd.conf 

# ******************************************************************                                            
# Cobbler managed dhcpd.conf file
# generated from cobbler dhcp.conf template (Sun Apr 21 07:57:14 2019)
# Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes
# in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be
# overwritten.
# ******************************************************************

ddns-update-style interim;

allow booting;
allow bootp;

ignore client-updates;
set vendorclass = option vendor-class-identifier;

option pxe-system-type code 93 = unsigned integer 16;
注:cobbler模板dhcp文件同步到dhcp的配置文件中
subnet 192.168.18.0 netmask 255.255.255.0 {
     option routers             192.168.18.199;
     option domain-name-servers 1.1.1.1;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.18.10 192.168.18.200;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                192.168.18.8;
     class "pxeclients" {
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";

4、导入安装源文件

本实验导入centos7,centos6两个系统的安装源文件

  • 先将centos6,centos7光盘分别挂载到/mnt/centos6/,/mnt/centos7/目录下
[root@centos7 ~]#mkdir /mnt/centos{6,7}
[root@centos7 ~]#mount /dev/sr0 /mnt/centos7
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos7 ~]#mount /dev/sr1 /mnt/centos6
mount: /dev/sr1 is write-protected, mounting read-only

  • 导入安装源文件
    安装源文件导入之后,都放入在/var/www/cobbler目录下
[root@centos7 ~]#ls /var/www/cobbler
images  ks_mirror  links  localmirror  misc  pub  rendered  repo_mirror  svc
[root@centos7 ~]#du /var/www/cobbler
0   /var/www/cobbler/images
0   /var/www/cobbler/ks_mirror/config
0   /var/www/cobbler/ks_mirror
0   /var/www/cobbler/links
0   /var/www/cobbler/localmirror
16  /var/www/cobbler/misc
0   /var/www/cobbler/pub
0   /var/www/cobbler/rendered
0   /var/www/cobbler/repo_mirror
8   /var/www/cobbler/svc
24  /var/www/cobbler

  • 导入centos6安装源文件
    注:--path=/mnt/centos6:导入源文件路径
    --name=Centos-6.10:导入之后命名的系统名称
    --arch=x86_64:系统架构
[root@centos7 ~]#cobbler import --path=/mnt/centos6 --name=Centos-6.10 --arch=x86_64
task started: 2019-04-21_161430_import
task started (id=Media import, time=Sun Apr 21 16:14:30 2019)
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path /var/www/cobbler/ks_mirror/Centos-6.10-x86_64:
creating new distro: Centos-6.10-x86_64
trying symlink: /var/www/cobbler/ks_mirror/Centos-6.10-x86_64 -> /var/www/cobbler/links/Centos-6.10-x86_64
creating new profile: Centos-6.10-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/Centos-6.10-x86_64 for Centos-6.10-x86_64
processing repo at : /var/www/cobbler/ks_mirror/Centos-6.10-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/Centos-6.10-x86_64
looking for /var/www/cobbler/ks_mirror/Centos-6.10-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/Centos-6.10-x86_64/repodata
*** TASK COMPLETE ***
  • cobbler distro list 查看导入的发行版系统信息
  • cobbler profile list 查看菜单中操作系统名字
[root@centos7 ~]#cobbler distro list
   Centos-6.10-x86_64
[root@centos7 ~]#cobbler profile list 
   Centos-6.10-x86_64    注:本信息是根据导入的发行行版信息对应生成的

[root@centos7 ~]#du -h /var/www/cobbler 
44M /var/www/cobbler/images/Centos-6.10-x86_64
44M /var/www/cobbler/images
4.0K    /var/www/cobbler/ks_mirror/config
264K    /var/www/cobbler/ks_mirror/Centos-6.10-x86_64/EFI/BOOT
268K    /var/www/cobbler/ks_mirror/Centos-6.10-x86_64/EFI
3.5G    /var/www/cobbler/ks_mirror/Centos-6.10-x86_64/Packages
4.0K    /var/www/cobbler/ks_mirror/Centos-6.10-x86_64/images/pxeboot
184M    /var/www/cobbler/ks_mirror/Centos-6.10-x86_64/images
44M /var/www/cobbler/ks_mirror/Centos-6.10-x86_64/isolinux
27M /var/www/cobbler/ks_mirror/Centos-6.10-x86_64/repodata
3.8G    /var/www/cobbler/ks_mirror/Centos-6.10-x86_64
3.8G    /var/www/cobbler/ks_mirror
0   /var/www/cobbler/links
0   /var/www/cobbler/localmirror
16K /var/www/cobbler/misc
0   /var/www/cobbler/pub
0   /var/www/cobbler/rendered
0   /var/www/cobbler/repo_mirror
8.0K    /var/www/cobbler/svc
3.8G    /var/www/cobbler

  • 导入centos7安装源文件
    注:方法同上
[root@centos7 ~]#cobbler import --path=/mnt/centos7 --name=Centos-7.6 --arch=x86_64
task started: 2019-04-21_163041_import
task started (id=Media import, time=Sun Apr 21 16:30:41 2019)
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path /var/www/cobbler/ks_mirror/Centos-7.6-x86_64:
creating new distro: Centos-7.6-x86_64
trying symlink: /var/www/cobbler/ks_mirror/Centos-7.6-x86_64 -> /var/www/cobbler/links/Centos-7.6-x86_64
creating new profile: Centos-7.6-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/Centos-7.6-x86_64 for Centos-7.6-x86_64
processing repo at : /var/www/cobbler/ks_mirror/Centos-7.6-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/Centos-7.6-x86_64
looking for /var/www/cobbler/ks_mirror/Centos-7.6-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/Centos-7.6-x86_64/repodata
*** TASK COMPLETE ***

[root@centos7 ~]#du -h /var/www/cobbler 
44M /var/www/cobbler/images/Centos-6.10-x86_64
57M /var/www/cobbler/images/Centos-7.6-x86_64
100M    /var/www/cobbler/images
8.0K    /var/www/cobbler/ks_mirror/config
264K    /var/www/cobbler/ks_mirror/Centos-6.10-x86_64/EFI/BOOT
268K    /var/www/cobbler/ks_mirror/Centos-6.10-x86_64/EFI
3.5G    /var/www/cobbler/ks_mirror/Centos-6.10-x86_64/Packages
4.0K    /var/www/cobbler/ks_mirror/Centos-6.10-x86_64/images/pxeboot
184M    /var/www/cobbler/ks_mirror/Centos-6.10-x86_64/images
44M /var/www/cobbler/ks_mirror/Centos-6.10-x86_64/isolinux
27M /var/www/cobbler/ks_mirror/Centos-6.10-x86_64/repodata
3.8G    /var/www/cobbler/ks_mirror/Centos-6.10-x86_64
2.5M    /var/www/cobbler/ks_mirror/Centos-7.6-x86_64/EFI/BOOT/fonts
8.3M    /var/www/cobbler/ks_mirror/Centos-7.6-x86_64/EFI/BOOT
8.3M    /var/www/cobbler/ks_mirror/Centos-7.6-x86_64/EFI
433M    /var/www/cobbler/ks_mirror/Centos-7.6-x86_64/LiveOS
9.5G    /var/www/cobbler/ks_mirror/Centos-7.6-x86_64/Packages
4.0K    /var/www/cobbler/ks_mirror/Centos-7.6-x86_64/images/pxeboot
8.6M    /var/www/cobbler/ks_mirror/Centos-7.6-x86_64/images
57M /var/www/cobbler/ks_mirror/Centos-7.6-x86_64/isolinux
29M /var/www/cobbler/ks_mirror/Centos-7.6-x86_64/repodata
10G /var/www/cobbler/ks_mirror/Centos-7.6-x86_64
14G /var/www/cobbler/ks_mirror
0   /var/www/cobbler/links
0   /var/www/cobbler/localmirror
16K /var/www/cobbler/misc
0   /var/www/cobbler/pub
0   /var/www/cobbler/rendered
0   /var/www/cobbler/repo_mirror
8.0K    /var/www/cobbler/svc
14G /var/www/cobbler

[root@centos7 ~]#cobbler distro list
   Centos-6.10-x86_64
   Centos-7.6-x86_64
[root@centos7 ~]#cobbler profile list
   Centos-6.10-x86_64
   Centos-7.6-x86_64

5、生成ks文件

cobbler生成的应答文件是最小安装的,可能不满足我们生成要求,我们可以把自己自定义制作好的应答文件拷贝到该 /var/lib/cobbler/kickstarts/目录下。
注:应答文件权限为644

[root@centos7 ~]#cd /var/lib/cobbler/kickstarts/
[root@centos7 kickstarts]#ls
default.ks    install_profiles  sample_autoyast.xml  sample_esxi4.ks  sample.ks
esxi4-ks.cfg  legacy.ks         sample_end.ks        sample_esxi5.ks  sample_old.seed
esxi5-ks.cfg  pxerescue.ks      sample_esx4.ks       sample_esxi6.ks  sample.seed

[root@centos7 ~]#ls
anaconda-ks.cfg  Documents  initial-setup-ks.cfg  ks7_mini.cfg      Music     Public    Templates
Desktop          Downloads  ks6_mini.cfg.bak      ks7_mini.cfg.bak  Pictures  reset.sh  Videos
[root@centos7 ~]#mv ks6_mini.cfg.bak ks6_mini.cfg
[root@centos7 ~]#ls
anaconda-ks.cfg  Documents  initial-setup-ks.cfg  ks7_mini.cfg      Music     Public    Templates
Desktop          Downloads  ks6_mini.cfg          ks7_mini.cfg.bak  Pictures  reset.sh  Videos
[root@centos7 kickstarts]#ll
total 64
-rw-r--r-- 1 root root  115 May  4  2018 default.ks
-rw-r--r-- 1 root root   22 May  4  2018 esxi4-ks.cfg
-rw-r--r-- 1 root root   22 May  4  2018 esxi5-ks.cfg
drwxr-xr-x 2 root root   56 Apr 21 14:50 install_profiles
-rw-r--r-- 1 root root 1712 Apr 21 16:42 ks6_mini.cfg
-rw-r--r-- 1 root root 2719 Apr 21 16:42 ks7_mini.cfg
-rw-r--r-- 1 root root 1424 May  4  2018 legacy.ks
-rw-r--r-- 1 root root  292 May  4  2018 pxerescue.ks
-rw-r--r-- 1 root root 2825 May  4  2018 sample_autoyast.xml
-rw-r--r-- 1 root root 1856 May  4  2018 sample_end.ks
-rw-r--r-- 1 root root    0 May  4  2018 sample_esx4.ks
-rw-r--r-- 1 root root  324 May  4  2018 sample_esxi4.ks
-rw-r--r-- 1 root root  386 May  4  2018 sample_esxi5.ks
-rw-r--r-- 1 root root  386 May  4  2018 sample_esxi6.ks
-rw-r--r-- 1 root root 1913 May  4  2018 sample.ks
-rw-r--r-- 1 root root 3419 May  4  2018 sample_old.seed
-rw-r--r-- 1 root root 6658 May  4  2018 sample.seed

  • 拷贝的应答文件需要修改里面的url源
  • 修改ks6_mini.cfg应答文件
[root@centos7 kickstarts]#vim ks6_mini.cfg 

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url=$tree     注:修改此处即可,$tree是一个变量指定cobbler安装源的路径                                                                                         
# Root password
rootpw --iscrypted $1$zqF4W.uR$6RYTN1HKSNP2aVU8/tb/D1

  • 修改ks6_mini.cfg应答文件
[root@centos7 kickstarts]#vim ks7_mini.cfg 

#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
url --url=$tree      注:修改此处安装源路径为$tree                                                                                           
# Use graphical install
text
selinux --disabled
firewall --disabled
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

6、将ks文件和系统关联,生成启动菜单

注:--name=Centos-6.10-x86_64_mini :自定义菜单中操作安装的操作系统名称
--distro=Centos-6.10-x86_64:与之匹配的操作系统版本
--kickstart=/var/lib/cobbler/kickstarts/ks6_mini.cfg: 与之匹配的应答文件

[root@centos7 kickstarts]#cobbler distro list 注:查看导入的发行版信息
   Centos-6.10-x86_64
   Centos-7.6-x86_64

[root@centos7 kickstarts]#cobbler profile add --name=Centos-6.10-x86_64_mini --distro=Centos-6.10-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks6_mini.cfg
[root@centos7 kickstarts]#cobbler profile add --name=Centos-7.6-x86_64_mini --distro=Centos-7.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7_mini.cfg

[root@centos7 kickstarts]#cobbler profile list
   Centos-6.10-x86_64
   Centos-6.10-x86_64_mini  
   Centos-7.6-x86_64
   Centos-7.6-x86_64_mini

  • 删除自动生成的最小安装的操作系统菜单项Centos-6.10-x86_64,Centos-7.6-x86_64
[root@centos7 kickstarts]#cobbler profile remove --name=Centos-6.10-x86_64
[root@centos7 kickstarts]#cobbler profile remove --name=Centos-7.6-x86_64
[root@centos7 kickstarts]#cobbler profile list
   Centos-6.10-x86_64_mini
   Centos-7.6-x86_64_mini

7、自动化安装实验
  • 设置好虚拟机配置


    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第27张图片
    image.png
  • 开启此虚拟机


    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第28张图片
    image.png
  • 选择安装系统版本


    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第29张图片
    image.png

    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第30张图片
    image.png

    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第31张图片
    image.png

    自动安装成功
    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第32张图片
    image.png

三、实验:cobbler web管理实现自动化配置

注:基于cobbler web的管理需要在上面实验上面额外加一个包cobbler-web

1、安装包cobbler-web
[root@centos7 network-scripts]#yum -y install cobbler-web
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package cobbler-web.noarch 0:2.8.3-2.el7 will be installed
--> Processing Dependency: Django > 1.6 for package: cobbler-web-2.8.3-2.el7.noarch
--> Processing Dependency: mod_ssl for package: cobbler-web-2.8.3-2.el7.noarch
--> Running transaction check
---> Package mod_ssl.x86_64 1:2.4.6-88.el7.centos will be installed
......
Complete!

  • 重启httpd服务
[root@centos7 network-scripts]#systemctl restart httpd
2、给登录cobbler web页面添加一个用户
注:给Cobbler服务创建一个jiangxiong的账户和设置密码
[root@centos7 ~]#htdigest   /etc/cobbler/users.digest Cobbler jiangxiong
Adding user jiangxiong in realm Cobbler
New password: 
Re-type new password:
3、通过网页登录cobbler_web服务端
image.png
  • 输入账户,密码登录


    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第33张图片
    image.png

    PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装_第34张图片
    image.png

你可能感兴趣的:(PXE实现多系统可选择自动化安装系统与利用cobbler 实现系统自动化安装)