利用cobbler 实现系统自动化安装
建议通过搜狐epel源下载cobbler安装包
[root@centos ~]#cat /etc/yum.repos.d/epel.repo
[epel]
name=sohu-epel
baseurl=http://mirrors.sohu.com/fedora-epel/7/x86_64/
gpgcheck=0
[root@centos ~]#yum repolist
1、安装包、配置服务
[root@centos ~]#yum install cobbler dhcp -y
[root@centos ~]#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.
[root@centos ~]#systemctl start tftp httpd cobblerd
2、生成自动化安装系统的开机启动密码
[root@centos ~]#openssl passwd -1
Password:
Verifying - Password:
$1$JQDPVGcR$UopQ.pfS6P48TAC3ww07Z/
3、修改cobbler 配置文件
[root@centos ~]#vim /etc/cobbler/settings
[root@centos ~]#sed -n -e 101p -e 242p -e 272p -e 384p /etc/cobbler/settings
default_password_crypted: "$1$JQDPVGcR$UopQ.pfS6P48TAC3ww07Z/" # 默认口令
manage_dhcp: 1 # 自动配置dhcp服务器
next_server: 192.168.36.101 # TFTP地址
server: 192.168.36.101 # Cobbler服务器地址
[root@centos ~]#systemctl restart cobblerd
下载TFTP目录下的重要问你件
[root@centos ~]#cobbler get-loaders
task started: 2019-04-22_125917_get_loaders
task started (id=Download Bootloader Content, time=Mon Apr 22 12:59:17 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 ***
将TFTP文件拷贝到tftp目录中
[root@centos ~]#cobbler sync
task started: 2019-04-22_130210_sync
task started (id=Sync, time=Mon Apr 22 13:02:10 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
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 ***
4、配置dhcp服务
[root@centos ~]#vim /etc/cobbler/dhcp.template
[root@centos ~]#sed -n 21,28p /etc/cobbler/dhcp.template
subnet 192.168.36.0 netmask 255.255.255.0 {
option routers 192.168.36.254;
option domain-name-servers 1.1.1.1;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.36.100 192.168.36.254;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
[root@centos ~]#cobbler sync
task started: 2019-04-22_130606_sync
task started (id=Sync, time=Mon Apr 22 13:06:06 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 ***
重启dhcp服务发现dhcpd.conf配置文件已经自动同步
[root@centos ~]#systemctl restart dhcpd
[root@centos ~]#cat /etc/dhcp/dhcpd.conf
# ******************************************************************
# Cobbler managed dhcpd.conf file
# generated from cobbler dhcp.conf template (Mon Apr 22 05:06:07 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;
subnet 192.168.36.0 netmask 255.255.255.0 {
option routers 192.168.36.254;
option domain-name-servers 1.1.1.1;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.36.100 192.168.36.254;
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.36.101;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
if option pxe-system-type = 00:02 {
filename "ia64/elilo.efi";
} else if option pxe-system-type = 00:06 {
filename "grub/grub-x86.efi";
} else if option pxe-system-type = 00:07 {
filename "grub/grub-x86_64.efi";
} else if option pxe-system-type = 00:09 {
filename "grub/grub-x86_64.efi";
} else {
filename "pxelinux.0";
}
}
}
# group for Cobbler DHCP tag: default
group {
}
5、导入安装源文件
[root@centos ~]#cobbler import --path=/media/cdrom --name=CentOS7 --arch=x86_64
task started: 2019-04-22_130948_import
task started (id=Media import, time=Mon Apr 22 13:09:48 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/CentOS7-x86_64:
creating new distro: CentOS7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS7-x86_64 -> /var/www/cobbler/links/CentOS7-x86_64
creating new profile: CentOS7-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/CentOS7-x86_64 for CentOS7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS7-x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS7-x86_64
looking for /var/www/cobbler/ks_mirror/CentOS7-x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS7-x86_64/repodata
*** TASK COMPLETE ***
6、生成CentOS7最小化安装的ks7_mini.cfg文件
[root@centos ~]#vim /var/lib/cobbler/kickstarts/ks7_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$Tyo.RXcB$GcWeYoXa/uPKb/JlLeYkl/
# Use network installation
url --url=$tree # 修改成$tree变量,方便以后cobbler自动安装系统
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="ext4" --size=10240
part /boot --fstype="ext4" --size=500
part /home --fstype="ext4" --size=1024
part swap --fstype="swap" --size=2048
%packages
@core
%end
具体生成ks7_mini.cfg文件的方式请到应答文件中查看
7、查看菜单项
[root@centos ~]#cobbler profile list
CentOS7
CentOS7-x86_64
使用下面的命令可以删除指定的菜单项
[root@centos ~]#cobbler profile remove --name=CentOS7
[root@centos ~]#cobbler profile list
CentOS7-x86_64
8、将ks文件和系统关联,生成启动菜单
[root@centos ~]#cobbler profile add --name=CentOS7 --distro=CentOS7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks7_mini.cfg
9、创建虚拟机测试
菜单栏选择
读取内核文件
无需任何操作,真正的无人值守,自动安装系统
Cobbler Web管理
安装包
[root@centos ~]#yum install -y cobbler-web
[root@centos ~]#systemctl restart httpd
添加cobbler账号和密码
[root@centos ~]#htdigest -c /etc/cobbler/users.digest Cobbler cobbler1
Adding password for cobbler1 in realm Cobbler.
New password:
Re-type new password:
[root@centos ~]#cat /etc/cobbler/users.digest
cobbler1:Cobbler:6d3d694017aea7a8cb58c8ad284d8cb9
浏览器访问Cobbler管理页面
网址为https://192.168.36.101/cobbler_web 默认用户名、密码为:cobbler、cobbler