cobbler
- cobbler是一个Linux服务器安装的服务,可以通过网络启动(PXE)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP,DNS等。cobbler可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web),还提供了API接口,可以方便二次开发使用。cobber是比较早前的kickstart的升级版,优点就是比较容易配置,还自带web界面比较易于管理。cobbler内置了一个轻量级配置管理系统,但它也支持和其他配置管理系统集成,如Puppet,暂不支持SaltStack。
部署步骤
//安装相关的依赖包
[root@hxdserver ~]# yum -y install epel-release
[root@hxdserver ~]# yum -y install httpd dhcp tftp python-ctypes cobbler xinetd cobbler-web pykickstart
//启动服务并设置开机自启
[root@hxdserver ~]# systemctl start httpd
[root@hxdserver ~]# systemctl start cobblerd
[root@hxdserver ~]# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@hxdserver ~]# systemctl enable cobblerd
Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
//修改server的ip地址为本机ip
[root@hxdserver ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.225.128/' /etc/cobbler/settings
//设置tftp的ip地址为本机ip
[root@hxdserver ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.225.128/' /etc/cobbler/settings
//开启tftp
[root@hxdserver ~]# sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp
//下载缺失文件
[root@hxdserver ~]# cobbler get-loaders
task started: 2018-10-29_093027_get_loaders
task started (id=Download Bootloader Content, time=Mon Oct 29 09:30:27 2018)
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 ***
//启动rsync并设置开机自启
[root@hxdserver ~]# systemctl start rsyncd
[root@hxdserver ~]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
//生成加密的密码
[root@hxdserver ~]# openssl passwd -salt "$RANDOM" '123'
55xZOgBciOWGE
[root@hxdserver ~]# vim /etc/cobbler/settings
default_password_crypted: "55xZOgBciOWGE"
//重启cobbler
[root@hxdserver ~]# systemctl restart cobblerd.service
//通过cobbler check核对当前设置是否有问题
[root@hxdserver ~]# 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配置文件,让cobbler控制dhcp
[root@hxdserver ~]# sed -i '/^manage_dhcp/s/0/1/g' /etc/cobbler/settings
[root@hxdserver ~]# sed -n '/^manage_dhcp/p' /etc/cobbler/settings
manage_dhcp: 1
//配置dhcp
[root@hxdserver ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.225.0 netmask 255.255.255.0 {
option routers 192.168.225.128;
option domain-name-servers 192.168.225.128;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.225.100 192.168.225.254;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
//重启服务并同步配置,改完dhcp必须要sync同步配置
[root@hxdserver ~]# systemctl restart cobblerd.service
[root@hxdserver ~]# cobbler sync
task started: 2018-10-29_095534_sync
task started (id=Sync, time=Mon Oct 29 09:55:34 2018)
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 ***
//检查dhcp是否正常
[root@hxdserver ~]# netstat -anulp|grep dhcp
udp 0 0 0.0.0.0:67 0.0.0.0:* 4102/dhcpd
//导入redhat7镜像
[root@hxdserver ~]# mount /dev/sr0 /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@hxdserver ~]# cobbler import --path=/mnt --name=rhel-7 --arch=x86_64
task started: 2018-10-29_100115_import
task started (id=Media import, time=Mon Oct 29 10:01:15 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
processing repo at : /var/www/cobbler/ks_mirror/rhel-7-x86_64/addons/HighAvailability
need to process repo/comps: /var/www/cobbler/ks_mirror/rhel-7-x86_64/addons/HighAvailability
looking for /var/www/cobbler/ks_mirror/rhel-7-x86_64/addons/HighAvailability/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/rhel-7-x86_64/addons/HighAvailability/repodata
processing repo at : /var/www/cobbler/ks_mirror/rhel-7-x86_64/addons/ResilientStorage
need to process repo/comps: /var/www/cobbler/ks_mirror/rhel-7-x86_64/addons/ResilientStorage
looking for /var/www/cobbler/ks_mirror/rhel-7-x86_64/addons/ResilientStorage/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/rhel-7-x86_64/addons/ResilientStorage/repodata
*** TASK COMPLETE ***
//查看cobbler镜像列表
[root@hxdserver ~]# cobbler list
distros:
rhel-7-x86_64
profiles:
rhel-7-x86_64
systems:
repos:
images:
mgmtclasses:
packages:
files:
//创建kickstarts自动安装脚本
[root@hxdserver ~]# 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.225.128/cobbler/ks_mirror/rhel-7-x86_64
$yum_repo_stanza
$SNIPPET('network_config')
reboot
rootpw --iscrypted 55xZOgBciOWGE
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@hxdserver ~]# cobbler validateks
task started: 2018-10-29_102356_validateks
task started (id=Kickstart Validation, time=Mon Oct 29 10:23:56 2018)
----------------------------
osversion: rhel7
checking url: http://192.168.225.128/cblr/svc/op/ks/profile/rhel-7-x86_64
running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.225.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@hxdserver ~]# cobbler profile list
rhel-7-x86_64
//修改profile,将我们新建的ks文件设为默认的kickstarts安装文件
[root@hxdserver ~]# cobbler profile edit --name rhel-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/rhel-7-x86_64.ks
//检查当前系统cobbler配置文件信息
[root@hxdserver ~]# 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 : {}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/rhel-7-x86_64.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@hxdserver ~]# cobbler sync
task started: 2018-10-29_103235_sync
task started (id=Sync, time=Mon Oct 29 10:32:35 2018)
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
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 files for distro: rhel-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/rhel-7-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/rhel-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/rhel-7-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/rhel-7-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: rhel-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/rhel-7-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/rhel-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/rhel-7-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/rhel-7-x86_64/initrd.img
Writing template files for rhel-7-x86_64
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: rhel-7-x86_64
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@hxdserver ~]# systemctl restart xinetd.service
[root@hxdserver ~]# systemctl restart cobblerd.service
[root@hxdserver ~]# systemctl restart httpd.service
- 客户端安装验证
选中第二个,即可开始安装
安装好后,使用我们设置的密码登录