1. cobbler简介
Cobbler 是一个系统启动服务(boot server),可以通过网络启动(PXE)的方式用来快速安装、重装物理服务器和虚拟机,支持安装不同的 Linux 发行版和 Windows。该工具使用python开发,小巧轻便(才15k行代码),使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP,DNS,以及yum包镜像。
Cobbler 使用命令行方式管理,也提供了基于 Web 的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。
即多安装树的pxe环境,是pxe的高级封装
Cobbler依赖:dhcp、tftp、rsync及dns
Cobbler是较早前的kickstart的升级版,优点是比较容易配置,还自带web界面比较易于管理。
Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。
cobbler集成的服务
- PXE服务支持
- DHCP服务管理
- DNS服务管理(可选bind,dnsmasq)
- 电源管理
- Kickstart服务支持
- YUM仓库管理
- TFTP(PXE启动时需要)
- Apache(提供kickstart的安装源,并提供定制化的kickstart配置)
cobbler配置文件详解
cobbler配置文件目录在/etc/cobbler
配置文件 | 作用 |
---|---|
/etc/cobbler/settings | cobbler主配置文件 |
/etc/cobbler/iso/ | iso模板配置文件 |
/etc/cobbler/pxe | pxe模板配置文件 |
/etc/cobbler/power | 电源配置文件 |
/etc/cobbler/user.conf | web服务授权配置文件 |
/etc/cobbler/users.digest | web访问的用户名密码配置文件 |
/etc/cobbler/dhcp.template | dhcp服务器的的配置模板 |
/etc/cobbler/dnsmasq.template | dns服务器的配置模板 |
/etc/cobbler/tftpd.template | tftp服务的配置模板 |
/etc/cobbler/modules.conf | 模块的配置文件 |
cobbler数据目录
目录 | 作用 |
---|---|
/var/lib/cobbler/config/ | 用于存放distros,system,profiles等信息配置文件 |
/var/lib/cobbler/triggers/ | 用于存放用户定义的cobbler命令 |
/var/lib/cobbler/kickstart/ | 默认存放kickstart文件 |
/var/lib/cobbler/loaders/ | 存放各种引导程序以及镜像目录 |
/var/www/cobbler/ks_mirror/ | 导入的发行版系统的所有数据 |
/var/www/cobbler/images/ | 导入发行版的kernel和initrd镜像用于远程网络启动 |
/var/www/cobbler/repo_mirror/ | yum仓库存储目录 |
cobbler日志文件
日志文件路径 | 说明 |
---|---|
/var/log/cobbler/installing | 客户端安装日志 |
/var/log/cobbler/cobbler.log | cobbler日志 |
cobbler命令详解
cobbler check //核对当前设置是否有问题
cobbler list //列出所有的cobbler元素
cobbler report //列出元素的详细信息
cobbler sync //同步配置到数据目录,更改配置最好都要执行下
cobbler reposync //同步yum仓库
cobbler distro //查看导入的发行版系统信息
cobbler system //查看添加的系统信息
cobbler profile //查看配置信息
2. cobbler服务端单机部署
配置yum源
[root@wyt1 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@wyt1 ~]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
[root@wyt1 ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@wyt1 ~]# yum -y install epel-release
安装cobbler相关软件
[root@wyt1 ~]# yum -y install httpd dhcp tftp python-ctypes cobbler xinetd cobbler-web pykickstart net-tools
启动服务并设置开机自启
[root@wyt1 ~]# systemctl enable --now httpd
[root@wyt1 ~]# systemctl enable --now cobblerd
[root@wyt1 ~]# systemctl enable --now xinetd
[root@wyt1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 5 127.0.0.1:25151 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 [::1]:25 [::]:*
LISTEN 0 128 [::]:443 [::]:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 [::]:22 [::]:*
修改server的ip地址为本机ip
[root@wyt1 ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.179.128/' /etc/cobbler/settings
设置tftp的ip地址为本机ip
[root@wyt1 ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.179.128/' /etc/cobbler/settings
开启tftp
[root@wyt1 ~]# sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp
[root@wyt1 ~]# vim /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no //修改此行
per_source = 11
cps = 100 2
flags = IPv4
下载缺失文件
[root@wyt1 ~]# cobbler get-loaders
task started: 2020-07-30_111104_get_loaders
task started (id=Download Bootloader Content, time=Thu Jul 30 11:11:04 2020)
path /var/lib/cobbler/loaders/README already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/COPYING.elilo already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/COPYING.yaboot already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/COPYING.syslinux already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/elilo-ia64.efi already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/yaboot already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/pxelinux.0 already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/menu.c32 already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/grub-x86.efi already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/grub-x86_64.efi already exists, not overwriting existing content, use --force if you wish to update
*** TASK COMPLETE ***
启动rsync并设置开机自启
[root@wyt1 ~]# systemctl enable --now rsyncd
[root@wyt1 ~]# ss -antl|grep 873
LISTEN 0 5 *:873 *:*
LISTEN 0 5 [::]:873 [::]:*
生成加密的密码
[root@wyt1 ~]# openssl passwd -1 -salt "$RANDOM" '123456'
$1$30823$mW29/wal2O2OYsyYLKXgp0
将新生成的加密密码加入到配置文件
[root@wyt1 ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$30823$mW29/wal2O2OYsyYLKXgp0''
重启cobbler
[root@wyt1 ~]# systemctl restart cobblerd
[root@wyt1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 5 127.0.0.1:25151 *:*
LISTEN 0 5 *:873 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 [::1]:25 [::]:*
LISTEN 0 128 [::]:443 [::]:*
LISTEN 0 5 [::]:873 [::]:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 [::]:22 [::]:*
通过cobbler check 核对当前设置是否有问题
[root@wyt1 ~]# cobbler check
The following are potential configuration items that you may want to fix:
1 : debmirror package is not installed, it will be required to manage debian deployments and repositories
2 : 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.
//以上两个是关于debian系统的错误,可忽略
配置cobbler dhcp
修改cobbler配置文件,让cobbler控制dhcp
[root@wyt1 ~]# sed -i '/^manage_dhcp/s/0/1/g' /etc/cobbler/settings
[root@wyt1 ~]# sed -n '/^manage_dhcp/p' /etc/cobbler/settings
manage_dhcp: 1
配置dhcp
[root@wyt1 ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.179.0 netmask 255.255.255.0 {
option routers 192.168.179.128;
option domain-name-servers 114.114.114.114; /此处为系统安装好后指定的dns地址
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.179.100 192.168.179.200;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
重启服务并同步配置,改完dhcp必须要sync同步配置
[root@wyt1 ~]# systemctl restart cobblerd
[root@wyt1 ~]# cobbler sync //同步
task started: 2020-07-30_111713_sync
task started (id=Sync, time=Thu Jul 30 11:17:13 2020)
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
.....
检查dhcp是否正常
[root@wyt1 ~]# netstat -anulp|grep dhcp
udp 0 0 0.0.0.0:67 0.0.0.0:* 2548/dhcpd
导入redhat7镜像
[root@wyt1 ~]# mount /dev/cdrom /mnt
[root@wyt1 ~]# cobbler import --path=/mnt --name=rhel-7 --arch=x86_64
task started: 2020-07-30_162444_import
task started (id=Media import, time=Tue Aug 21 16:24:44 2018)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/rhel-7-x86_64:
creating new distro: rhel-7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/rhel-7-x86_64 -> /var/www/cobbler/links/rhel-7-x86_64
creating new profile: rhel-7-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/rhel-7-x86_64 for rhel-7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/rhel-7-x86_64 //导入镜像的位置
need to process repo/comps: /var/www/cobbler/ks_mirror/rhel-7-x86_64
looking for /var/www/cobbler/ks_mirror/rhel-7-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/rhel-7-x86_64/repodata
*** TASK COMPLETE ***
说明:
--path //镜像路径
--name //为安装源定义一个名字
--arch //指定安装源平台
查看cobbler镜像列表
[root@wyt1 ~]# cobbler list
distros:
rhel-7-x86_64
profiles:
rhel-7-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
创建kickstarts自动安装脚本
[root@wyt1 ~]# cat > /var/lib/cobbler/kickstarts/rhel-7-x86_64.ks <<'EOF'
auth --enableshadow --passalgo=sha512
bootloader --location=mbr
clearpart --all --initlabel
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=4096
part / --fstype="ext4" --grow --size=15000
text
firewall --disabled
firstboot --disable
keyboard us
lang en_US
url --url=http://192.168.179.128/cobbler/ks_mirror/rhel-7-x86_64
$yum_repo_stanza
reboot
rootpw --iscrypted $1$30823$mW29/wal2O2OYsyYLKXgp0
selinux --disabled
skipx
timezone Asia/Shanghai --isUtc --nontp
install
zerombr
%packages
@^minimal
@core
kexec-tools
%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
EOF
检查ks文件语法是否有误
[root@wyt1 ~]# cobbler validateks
task started: 2020-07-30_113636_validateks
task started (id=Kickstart Validation, time=Thu Jul 30 11:36:36 2020)
----------------------------
osversion: rhel7
checking url: http://192.168.179.128/cblr/svc/op/ks/profile/rhel-7-x86_64
running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.179.128/cblr/svc/op/ks/profile/rhel-7-x86_64"
received on stdout:
received on stderr:
*** all kickstarts seem to be ok ***
*** TASK COMPLETE ***
查看当前cobbler有哪些配置文件
[root@wyt1 ~]# cobbler profile list
rhel-7-x86_64
修改profile,将我们新建的ks文件设为默认的kickstarts安装文件
[root@wyt1 ~]# cobbler profile edit --name rhel-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/rhel-7-x86_64.ks
配置网卡名称为传统网卡名称eth0
[root@wyt1 ~]# cobbler profile edit --name rhel-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'
检查当前系统cobbler配置文件信息
[root@wyt1 ~]# cobbler profile report
Name : rhel-7-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : rhel-7-x86_64 //仓库名字
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {'biosdevname': '0', 'net.ifnames': '0'} //网卡设为传统命名方式
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/rhel-7-x86_64.ks //使用的kickstarts配置文件的路径,必须为我们新建的ks文件的路径
Kickstart Metadata : {}
Management Classes : []
Management Parameters : <<inherit>>
Name Servers : []
Name Servers Search Path : []
Owners : ['admin']
Parent Profile :
Internal proxy :
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Repos : []
Server Override : <<inherit>>
Template Files : {}
Virt Auto Boot : 1
Virt Bridge : xenbr0
Virt CPUs : 1
Virt Disk Driver Type : raw
Virt File Size(GB) : 5
Virt Path :
Virt RAM (MB) : 512
Virt Type : kvm
同步cobbler
[root@wyt1 ~]# cobbler sync
task started: 2020-07-30_113745_sync
task started (id=Sync, time=Thu Jul 30 11:37:45 2020)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/rhel-7-x86_64
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/images/rhel-7-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
.....
为避免发生未知问题,先把服务端所有服务重启
[root@wyt1 ~]# systemctl restart cobblerd
[root@wyt1 ~]# systemctl restart xinetd
[root@wyt1 ~]# systemctl restart httpd
[root@wyt1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 5 127.0.0.1:25151 *:*
LISTEN 0 5 *:873 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 [::1]:25 [::]:*
LISTEN 0 128 [::]:443 [::]:*
LISTEN 0 5 [::]:873 [::]:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 [::]:22 [::]:*
3. 客户端安装
新建虚拟机从pxe启动
若出现以下界面则表示成功:
4.定制安装RedHat8
1.添加虚拟机统计服务器mac地址
2.在服务端配置cobbler
配置yum源
[root@wyt1 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@wyt1 ~]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
[root@wyt1 ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@wyt1 ~]# yum -y install epel-release
安装cobbler相关软件
[root@wyt1 ~]# yum -y install httpd dhcp tftp python-ctypes cobbler xinetd cobbler-web pykickstart net-tools
启动服务并设置开机自启
[root@wyt1 ~]# systemctl enable --now httpd
[root@wyt1 ~]# systemctl enable --now cobblerd
[root@wyt1 ~]# systemctl enable --now xinetd
[root@wyt1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 5 127.0.0.1:25151 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 [::1]:25 [::]:*
LISTEN 0 128 [::]:443 [::]:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 [::]:22 [::]:*
修改server的ip地址为本机ip
[root@wyt1 ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.179.128/' /etc/cobbler/settings
设置tftp的ip地址为本机ip
[root@wyt1 ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.179.128/' /etc/cobbler/settings
开启tftp
[root@wyt1 ~]# sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp
[root@wyt1 ~]# vim /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no //修改此行
per_source = 11
cps = 100 2
flags = IPv4
下载缺失文件
[root@wyt1 ~]# cobbler get-loaders
task started: 2020-07-30_111104_get_loaders
task started (id=Download Bootloader Content, time=Thu Jul 30 11:11:04 2020)
path /var/lib/cobbler/loaders/README already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/COPYING.elilo already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/COPYING.yaboot already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/COPYING.syslinux already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/elilo-ia64.efi already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/yaboot already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/pxelinux.0 already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/menu.c32 already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/grub-x86.efi already exists, not overwriting existing content, use --force if you wish to update
path /var/lib/cobbler/loaders/grub-x86_64.efi already exists, not overwriting existing content, use --force if you wish to update
*** TASK COMPLETE ***
启动rsync并设置开机自启
[root@wyt1 ~]# systemctl enable --now rsyncd
[root@wyt1 ~]# ss -antl|grep 873
LISTEN 0 5 *:873 *:*
LISTEN 0 5 [::]:873 [::]:*
生成加密的密码
[root@wyt1 ~]# openssl passwd -1 -salt "$RANDOM" '123456'
$1$30823$mW29/wal2O2OYsyYLKXgp0
将新生成的加密密码加入到配置文件
[root@wyt1 ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$30823$mW29/wal2O2OYsyYLKXgp0''
重启cobbler
[root@wyt1 ~]# systemctl restart cobblerd
[root@wyt1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 5 127.0.0.1:25151 *:*
LISTEN 0 5 *:873 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 [::1]:25 [::]:*
LISTEN 0 128 [::]:443 [::]:*
LISTEN 0 5 [::]:873 [::]:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 [::]:22 [::]:*
通过cobbler check 核对当前设置是否有问题
[root@wyt1 ~]# cobbler check
The following are potential configuration items that you may want to fix:
1 : debmirror package is not installed, it will be required to manage debian deployments and repositories
2 : 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.
//以上两个是关于debian系统的错误,可忽略
配置cobbler dhcp
修改cobbler配置文件,让cobbler控制dhcp
[root@wyt1 ~]# sed -i '/^manage_dhcp/s/0/1/g' /etc/cobbler/settings
[root@wyt1 ~]# sed -n '/^manage_dhcp/p' /etc/cobbler/settings
manage_dhcp: 1
配置dhcp
[root@wyt1 ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.179.0 netmask 255.255.255.0 {
option routers 192.168.179.128;
option domain-name-servers 114.114.114.114; /此处为系统安装好后指定的dns地址
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.179.100 192.168.179.200;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
重启服务并同步配置,改完dhcp必须要sync同步配置
[root@wyt1 ~]# systemctl restart cobblerd
[root@wyt1 ~]# cobbler sync //同步
task started: 2020-07-30_111713_sync
task started (id=Sync, time=Thu Jul 30 11:17:13 2020)
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
.....
检查dhcp是否正常
[root@wyt1 ~]# netstat -anulp|grep dhcp
udp 0 0 0.0.0.0:67 0.0.0.0:* 2548/dhcpd
导入redhat8镜像
[root@wyt1 ~]# mount /dev/cdrom /mnt
[root@wyt1 ~]# cobbler import --path=/mnt --name=rhel-8 --arch=x86_64
task started: 2020-07-31_000739_import
task started (id=Media import, time=Fri Jul 31 00:07:39 2020)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/rhel-8-x86_64:
creating new distro: rhel-8-x86_64
trying symlink: /var/www/cobbler/ks_mirror/rhel-8-x86_64 -> /var/www/cobbler/links/rhel-8-x86_64
creating new profile: rhel-8-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/rhel-8-x86_64 for rhel-8-x86_64
processing repo at : /var/www/cobbler/ks_mirror/rhel-8-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/rhel-8-x86_64
looking for /var/www/cobbler/ks_mirror/rhel-8-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/rhel-8-x86_64/repodata
*** TASK COMPLETE ***
说明:
--path //镜像路径
--name //为安装源定义一个名字
--arch //指定安装源平台
查看cobbler镜像列表
[root@wyt1 ~]# cobbler list
distros:
rhel-8-x86_64
profiles:
rhel-8-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
创建kickstarts自动安装脚本
[root@wyt1 ~]# cat > /var/lib/cobbler/kickstarts/rhel-8-x86_64.ks <<'EOF'
auth --enableshadow --passalgo=sha512
bootloader --location=mbr
clearpart --all --initlabel
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=4096
part / --fstype="ext4" --grow --size=15000
text
firewall --disabled
firstboot --disable
keyboard us
lang en_US
url --url=http://192.168.179.128/cobbler/ks_mirror/rhel-8-x86_64
$yum_repo_stanza
reboot
rootpw --iscrypted $1$30823$mW29/wal2O2OYsyYLKXgp0
selinux --disabled
skipx
timezone Asia/Shanghai --isUtc --nontp
install
zerombr
%packages
@^minimal
@core
kexec-tools
%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
EOF
检查ks文件语法是否有误
[root@wyt1 ~]# cobbler validateks
task started: 2020-07-31_003025_validateks
task started (id=Kickstart Validation, time=Fri Jul 31 00:30:25 2020)
----------------------------
osversion: rhel7
checking url: http://192.168.179.128/cblr/svc/op/ks/profile/rhel-8-x86_64
running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.179.128/cblr/svc/op/ks/profile/rhel-8-x86_64"
received on stdout:
received on stderr:
*** all kickstarts seem to be ok ***
*** TASK COMPLETE ***
查看当前cobbler有哪些配置文件
[root@wyt1 ~]# cobbler profile list
rhel-8-x86_64
修改profile,将我们新建的ks文件设为默认的kickstarts安装文件
[root@wyt1 ~]# cobbler profile edit --name rhel-8-x86_64 --kickstart=/var/lib/cobbler/kickstarts/rhel-8-x86_64.ks
配置网卡名称为传统网卡名称eth0
[root@wyt1 ~]# cobbler profile edit --name rhel-8-x86_64 --kopts='net.ifnames=0 biosdevname=0'
检查当前系统cobbler配置文件信息
[root@wyt1 ~]# cobbler profile report
Name : rhel-8-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : rhel-8-x86_64 //仓库名字
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {'biosdevname': '0', 'net.ifnames': '0'} //网卡设为传统命名方式
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/rhel-8-x86_64.ks //使用的kickstarts配置文件的路径,必须为我们新建的ks文件的路径
Kickstart Metadata : {}
Management Classes : []
Management Parameters : <<inherit>>
Name Servers : []
Name Servers Search Path : []
Owners : ['admin']
Parent Profile :
Internal proxy :
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Repos : []
Server Override : <<inherit>>
Template Files : {}
Virt Auto Boot : 1
Virt Bridge : xenbr0
Virt CPUs : 1
Virt Disk Driver Type : raw
Virt File Size(GB) : 5
Virt Path :
Virt RAM (MB) : 512
Virt Type : kvm
同步cobbler
[root@wyt1 ~]# cobbler sync
[root@wyt1 ~]# cobbler sync
task started: 2020-07-31_003112_sync
task started (id=Sync, time=Fri Jul 31 00:31:12 2020)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/rhel-8-x86_64
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/images/rhel-8-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
.....
为避免发生未知问题,先把服务端所有服务重启
[root@wyt1 ~]# systemctl restart cobblerd
[root@wyt1 ~]# systemctl restart xinetd
[root@wyt1 ~]# systemctl restart httpd
[root@wyt1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 5 127.0.0.1:25151 *:*
LISTEN 0 5 *:873 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 [::1]:25 [::]:*
LISTEN 0 128 [::]:443 [::]:*
LISTEN 0 5 [::]:873 [::]:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 [::]:22 [::]:*
3.在cobbler的web界面上配置
服务端同步配置并重启相关服务
[root@wyt1 ~]# cobbler sync
task started: 2020-07-31_005930_sync
task started (id=Sync, time=Fri Jul 31 00:59:30 2020)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/rhel-8-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/pxelinux.cfg/01-00-0c-29-1e-75-2b
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/grub/01-00-0C-29-1E-75-2B
removing: /var/lib/tftpboot/images/rhel-8-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
[root@wyt1 ~]# systemctl restart cobblerd
[root@wyt1 ~]# systemctl restart xinetd
[root@wyt1 ~]# systemctl restart httpd
[root@wyt1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 5 127.0.0.1:25151 *:*
LISTEN 0 5 *:873 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 [::1]:25 [::]:*
LISTEN 0 128 [::]:443 [::]:*
LISTEN 0 5 [::]:873 [::]:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 [::]:22 [::]:*
开机自动安装系统
5.使用配置文件安装CentOS7系统
添加虚拟机并统计mac地址
配置cobbler
前面配置方法与上面RedHat8操作一样无需重复操作,从导入镜像开始修改配置文件
导入CentOS7镜像
[root@wyt1 ~]# mount /dev/cdrom /mnt
[root@wyt1 ~]# cobbler import --path=/mnt --name=CentOS-7 --arch=x86_64
task started: 2020-07-31_000739_import
task started (id=Media import, time=Fri Jul 31 00:07:39 2020)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/CentOS-7-x86_64:
creating new distro: CentOS-7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS-7-x86_64 -> /var/www/cobbler/linksCentOS-7-x86_64
creating new profile: CentOS-7-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-x86_64 for rhel-8-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS-7-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS-7-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS-7-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS-7-x86_64/repodata
*** TASK COMPLETE ***
说明:
--path //镜像路径
--name //为安装源定义一个名字
--arch //指定安装源平台
查看cobbler镜像列表
[root@wyt1 ~]# cobbler list
distros:
CentOS-7-x86_64
profiles:
CentOS-7-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
创建kickstarts自动安装脚本
[root@wyt1 ~]# cat > /var/lib/cobbler/kickstarts/CentOS-7-x86_64.ks <<'EOF'
auth --enableshadow --passalgo=sha512
bootloader --location=mbr
clearpart --all --initlabel
part /boot --asprimary --fstype="ext4" --size=500
part swap --fstype="swap" --size=4096
part / --fstype="ext4" --grow --size=15000
text
firewall --disabled
firstboot --disable
keyboard us
lang en_US
url --url=http://192.168.179.128/cobbler/ks_mirror/CentOS-7-x86_64
$yum_repo_stanza
reboot
rootpw --iscrypted $1$30823$mW29/wal2O2OYsyYLKXgp0
selinux --disabled
skipx
timezone Asia/Shanghai --isUtc --nontp
install
zerombr
%packages
@^minimal
@core
kexec-tools
%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
EOF
检查ks文件语法是否有误
[root@wyt1 ~]# cobbler validateks
task started: 2020-07-31_003025_validateks
task started (id=Kickstart Validation, time=Fri Jul 31 00:30:25 2020)
----------------------------
osversion: rhel7
checking url: http://192.168.179.128/cblr/svc/op/ks/profile/CentOS-7-x86_64
running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.179.128/cblr/svc/op/ks/profile/CentOS-7-x86_64"
received on stdout:
received on stderr:
*** all kickstarts seem to be ok ***
*** TASK COMPLETE ***
查看当前cobbler有哪些配置文件
[root@wyt1 ~]# cobbler profile list
CentOS-7-x86_64
修改profile,将我们新建的ks文件设为默认的kickstarts安装文件
[root@wyt1 ~]# cobbler profile edit --name CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.ks
配置网卡名称为传统网卡名称eth0
[root@wyt1 ~]# cobbler profile edit --name CentOS-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'
检查当前系统cobbler配置文件信息
[root@wyt1 ~]# cobbler profile report
Name : CentOS-7-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : CentOS-7-x86_64 //仓库名字
Enable gPXE? : 0
Enable PXE Menu? : 1
Fetchable Files : {}
Kernel Options : {'biosdevname': '0', 'net.ifnames': '0'} //网卡设为传统命名方式
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/CentOS-7-x86_64.ks //使用的kickstarts配置文件的路径,必须为我们新建的ks文件的路径
Kickstart Metadata : {}
Management Classes : []
Management Parameters : <<inherit>>
Name Servers : []
Name Servers Search Path : []
Owners : ['admin']
Parent Profile :
Internal proxy :
Red Hat Management Key : <<inherit>>
Red Hat Management Server : <<inherit>>
Repos : []
Server Override : <<inherit>>
Template Files : {}
Virt Auto Boot : 1
Virt Bridge : xenbr0
Virt CPUs : 1
Virt Disk Driver Type : raw
Virt File Size(GB) : 5
Virt Path :
Virt RAM (MB) : 512
Virt Type : kvm
同步cobbler
[root@wyt1 ~]# cobbler sync
[root@wyt1 ~]# cobbler sync
task started: 2020-07-31_003112_sync
task started (id=Sync, time=Fri Jul 31 00:31:12 2020)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/CentOS-7-x86_64
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/images/CentOS-7-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
.....
为避免发生未知问题,先把服务端所有服务重启
[root@wyt1 ~]# systemctl restart cobblerd
[root@wyt1 ~]# systemctl restart xinetd
[root@wyt1 ~]# systemctl restart httpd
[root@wyt1 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 5 127.0.0.1:25151 *:*
LISTEN 0 5 *:873 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 [::1]:25 [::]:*
LISTEN 0 128 [::]:443 [::]:*
LISTEN 0 5 [::]:873 [::]:*
LISTEN 0 128 [::]:80 [::]:*
LISTEN 0 128 [::]:22 [::]:*
生成新的配置文件来安装系统
[root@wyt1 ~]# cd /var/lib/cobbler/config/systems.d/
[root@wyt1 systems.d]# vim CentOS7.json //编辑配置文件
[root@wyt1 systems.d]# cat CentOS7.json
{"comment": "", "status": "production", "kickstart": "/var/lib/cobbler/kickstarts/CentOS-7-x86_64.ks", "name_servers_search": [], "ks_meta": {}, "kernel_options_post": {}, "image": "", "redhat_management_key": "<<inherit>>", "virt_path": "<<inherit>>", "power_user": "", "kernel_options": {"biosdevname": "0", "net.ifnames": "0"}, "ctime": 1596128309.979551, "name_servers": ["114.114.114.114"], "mtime": 1596128309.979551, "enable_gpxe": false, "template_files": {}, "gateway": "192.168.179.2", "uid": "MTU5NjEyODMwOS45ODExOTEyNDEuNjYxNw", "virt_auto_boot": 0, "power_type": "ipmitool", "virt_cpus": "<<inherit>>", "mgmt_parameters": "<<inherit>>", "boot_files": {}, "hostname": "CentOS7", "repos_enabled": false, "mgmt_classes": [], "power_pass": "", "netboot_enabled": true, "ipv6_autoconfiguration": false, "profile": "CentOS-7-x86_64", "virt_type": "xenpv", "interfaces": {"eth0": {"ipv6_address": "", "interface_type": "", "static": true, "cnames": [], "mtu": "", "management": false, "interface_master": "", "mac_address": "00:50:56:21:1F:6C", "ipv6_prefix": "", "virt_bridge": "xenbr0", "netmask": "255.255.255.0", "bonding_opts": "", "ip_address": "192.168.179.210", "dhcp_tag": "", "static_routes": [], "ipv6_mtu": "", "ipv6_static_routes": [], "if_gateway": "", "dns_name": "", "bridge_opts": "", "connected_mode": false, "ipv6_secondaries": [], "ipv6_default_gateway": ""}}, "power_address": "", "proxy": "<<inherit>>", "fetchable_files": {}, "virt_file_size": "<<inherit>>", "ldap_enabled": false, "monit_enabled": false, "ipv6_default_device": "", "virt_pxe_boot": 0, "virt_disk_driver": "<<inherit>>", "owners": "<<inherit>>", "name": "CentOS7", "virt_ram": "<<inherit>>", "power_id": "", "server": "<<inherit>>", "redhat_management_server": "<<inherit>>", "depth": 2, "ldap_type": "authconfig", "template_remote_kickstarts": 0
修改配置放置文件 "kickstart": /var/lib/cobbler/kickstarts/CentOS-7-x86_64.ks
修改主机名 "hostname": "CentOS7"
修改配置文件 "profile": "CentOS-7-x86_64"
修改mac地址 "mac_address": "00:50:56:21:1F:6C"
修改ip地址 "ip_address": "192.168.179.210"
修改名字 "name": "CentOS7"
[root@wyt1 systems.d]# ls //配置文件名
CentOS7.json
同步配置文件
[root@wyt1 systems.d]# cobbler sync
task started: 2020-07-31_011827_sync
task started (id=Sync, time=Fri Jul 31 01:18:27 2020)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/rhel-8-x86_64
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/images/rhel-8-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
....