环境准备
[root@cobbler-server ~]# free -h total used free shared buff/cache available Mem: 2.9G 194M 79M 9.1M 2.7G 2.6G Swap: 3.0G 0B 3.0G [root@cobbler-server ~]# cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 44 model name : Intel(R) Xeon(R) CPU X5650 @ 2.67GHz stepping : 2 microcode : 0x1f cpu MHz : 2660.000 cache size : 12288 KB physical id : 0 siblings : 1 core id : 0 cpu cores : 1 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 11 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes hypervisor lahf_lm ssbd ibrs ibpb stibp tsc_adjust arat spec_ctrl intel_stibp flush_l1d arch_capabilities bogomips : 5320.00 clflush size : 64 cache_alignment : 64 address sizes : 43 bits physical, 48 bits virtual power management:
[root@localhost ~]# sestatus SELinux status: disabled [root@localhost ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1) [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.7.1908 (Core) [root@localhost ~]# uname -r 3.10.0-1062.el7.x86_64 [root@localhost ~]# hostnamectl --static set-hostname cobbler-server
部署cobbler
[root@cobbler-server ~]# yum -y install cobbler cobbler-web dhcp tftp-server pykickstart httpd xinetd # cobbler需要epel源 # 启动服务 [root@cobbler-server ~]# systemctl enable httpd.service --now Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. [root@cobbler-server ~]# systemctl enable cobblerd.service --now Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.
cobbler语法检查以及排错
[root@cobbler-server ~]# 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. 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. 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. 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 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.
问题1
[root@cobbler-server ~]# sed -i 's/server: 127.0.0.1/server: 10.11.66.218/' /etc/cobbler/settings
问题2
[root@cobbler-server ~]# sed -i 's/next_server: 127.0.0.1/next_server: 10.11.66.218/' /etc/cobbler/settings # 如果允许Cobbler接管DHCP服务,这个IP地址将传送给被安装操作系统在PXE启动时使用。如果地址错误,则会导致Tftp时提示timeout错误 [root@cobbler-server ~]# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings # 允许被安装操作系统只安装一次操作系统,客户机重装需要 Cobbler system 中使用–netboot-enabled 指定
问题3
[root@cobbler-server ~]# sed -i 's#yes#no#' /etc/xinetd.d/tftp [root@cobbler-server ~]# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/' /etc/cobbler/settings # 允许Cobbler接管DHCP服务 [root@cobbler-server ~]# systemctl enable tftp.socket --now Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
问题4
[root@cobbler-server ~]# cobbler get-loaders # 下载包所需的软件包 task started: 2020-07-18_123919_get_loaders task started (id=Download Bootloader Content, time=Sat Jul 18 12:39:19 2020) 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 ***
问题5
[root@cobbler-server ~]# systemctl enable rsyncd --now Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
问题6
# 和debian系统相关,不需要处理
问题7
[root@cobbler-server ~]# sed -ri "/default_password_crypted/s#(.*: ).*#\1\"`openssl passwd -1 -salt 'cobbler' '123.com'`\"#" /etc/cobbler/settings # 安装好的系统,root密码会被设置为123.com
问题8
[root@cobbler-server ~]# yum -y install fence-agents
修改dhcp模板
[root@cobbler-server ~]# cp /etc/cobbler/dhcp.template{,.bak} [root@cobbler-server ~]# vim /etc/cobbler/dhcp.template subnet 10.11.66.0 netmask 255.255.255.0 { option routers 10.11.66.1; option domain-name-servers 210.22.84.3; option subnet-mask 255.255.255.0; range dynamic-bootp 10.11.66.100 10.11.66.254; default-lease-time 21600; max-lease-time 43200;
重启服务,再次检查
[root@cobbler-server ~]# systemctl restart cobblerd.service # 重启cobbler [root@cobbler-server ~]# cobbler sync # 同步配置到数据目录,否则修改的不生效 task started: 2020-07-18_131850_sync task started (id=Sync, time=Sat Jul 18 13:18:50 2020) 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.manage_genders running python trigger cobbler.modules.scm_track running shell triggers from /var/lib/cobbler/triggers/change/* *** TASK COMPLETE *** [root@cobbler-server ~]# 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 Restart cobblerd and then run 'cobbler sync' to apply changes. # 这个是debian系统相关的,忽略不计 [root@cobbler-server ~]# systemctl restart httpd.service # 重启一下相关的服务 [root@cobbler-server ~]# systemctl restart dhcpd.service [root@cobbler-server ~]# systemctl restart rsyncd.service [root@cobbler-server ~]# systemctl restart tftp.socket
镜像配置
# 先自行下载一个centos7镜像,然后挂载到本地,之后导入到cobbler [root@cobbler-server ~]# ls anaconda-ks.cfg CentOS-7-x86_64-DVD-1908.iso [root@cobbler-server ~]# mkdir /mnt/centos7.7 # 创建一个挂载目录 [root@cobbler-server ~]# mount -t iso9660 -o loop CentOS-7-x86_64-DVD-1908.iso /mnt/centos7.7/ # 将本地镜像挂载到 /mnt/centos7.7 目录下 mount: /dev/loop0 is write-protected, mounting read-only [root@cobbler-server ~]# df -Th # 查看挂载 Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 1.5G 0 1.5G 0% /dev tmpfs tmpfs 1.5G 0 1.5G 0% /dev/shm tmpfs tmpfs 1.5G 9.0M 1.5G 1% /run tmpfs tmpfs 1.5G 0 1.5G 0% /sys/fs/cgroup /dev/mapper/centos-root xfs 26G 6.4G 20G 25% / /dev/sda1 xfs 1014M 136M 879M 14% /boot tmpfs tmpfs 301M 0 301M 0% /run/user/0 /dev/loop0 iso9660 4.4G 4.4G 0 100% /mnt/centos7.7
镜像导入
[root@cobbler-server ~]# cobbler import --path=/mnt/centos7.7 --name=CentOS_7.7_1908 --arch=x86_64 task started: 2020-07-18_134526_import task started (id=Media import, time=Sat Jul 18 13:45:26 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.7_1908-x86_64: creating new distro: CentOS_7.7_1908-x86_64 trying symlink: /var/www/cobbler/ks_mirror/CentOS_7.7_1908-x86_64 -> /var/www/cobbler/links/CentOS_7.7_1908-x86_64 creating new profile: CentOS_7.7_1908-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.7_1908-x86_64 for CentOS_7.7_1908-x86_64 processing repo at : /var/www/cobbler/ks_mirror/CentOS_7.7_1908-x86_64 need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS_7.7_1908-x86_64 looking for /var/www/cobbler/ks_mirror/CentOS_7.7_1908-x86_64/repodata/*comps*.xml Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS_7.7_1908-x86_64/repodata *** TASK COMPLETE *** [root@cobbler-server ~]# cobbler distro list # 查看镜像列表 CentOS_7.7_1908-x86_64 [root@cobbler-server ~]# ls /var/www/cobbler/ks_mirror/ # 镜像被保存在HTTP的目录中 CentOS_7.7_1908-x86_64 config [root@cobbler-server ~]# cobbler distro report # 下面的一些变量我们在写 kickstarts 配置的时候可能会用到 Name : CentOS_7.7_1908-x86_64 Architecture : x86_64 TFTP Boot Files : {} Breed : redhat Comment : Fetchable Files : {} Initrd : /var/www/cobbler/ks_mirror/CentOS_7.7_1908-x86_64/images/pxeboot/initrd.img Kernel : /var/www/cobbler/ks_mirror/CentOS_7.7_1908-x86_64/images/pxeboot/vmlinuz Kernel Options : {} Kernel Options (Post Install) : {} Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/CentOS_7.7_1908-x86_64'} Management Classes : [] OS Version : rhel7 Owners : ['admin'] Red Hat Management Key : <<inherit>> Red Hat Management Server : <<inherit>> Template Files : {}
kickstarts 文件配置
[root@cobbler-server ~]# cd /var/lib/cobbler/kickstarts/ [root@cobbler-server kickstarts]# ls # 一般centos系统安装完成后会在/root/anaconda-ks.cfg产生一个ks配置文件,记录安装过程,我们可以根据这个文件修改一下,修改好后放到/var/lib/cobbler/kickstarts目录 default.ks legacy.ks sample_esx4.ks sample.ks esxi4-ks.cfg pxerescue.ks sample_esxi4.ks sample_old.seed esxi5-ks.cfg sample_autoyast.xml sample_esxi5.ks sample.seed install_profiles sample_end.ks sample_esxi6.ks sample.seed.28 [root@cobbler-server kickstarts]# mv sample_end.ks{,.bak} # 将原生成的ks文件备份重命名备份一下,我们使用自定义的ks文件
最小化安装
[root@cobbler-server kickstarts]# vim centos7u7-x64.ks #System language lang en_US #System keyboard keyboard us #Sytem timezone timezone Asia/Shanghai #Root password rootpw --iscrypted $default_password_crypted #Use text mode install text #Install OS instead of upgrade install #Use NFS installation Media url --url=$tree #System bootloader configuration bootloader --location=mbr #Clear the Master Boot Record zerombr #Partition clearing information clearpart --all --initlabel #Disk partitioning information part /boot --fstype xfs --size 1024 --ondisk sda part swap --fstype="swap" --size 2048 --ondisk sda part / --fstype xfs --size 1 --grow --ondisk sda #System authorization infomation auth --useshadow --enablemd5 #Network information $SNIPPET('network_config') # network --bootproto=dhcp --device=em1 --onboot=on # Reboot after installation reboot #Firewall configuration firewall --disabled #SELinux configuration selinux --disabled #Do not configure XWindows skipx #Package install information %pre $SNIPPET('log_ks_pre') $SNIPPET('kickstart_start') $SNIPPET('pre_install_network_config') # Enable installation monitoring $SNIPPET('pre_anamon') %end %packages @ base @ core sysstat iptraf ntp lrzsz ncurses-devel openssl-devel zlib-devel OpenIPMI-tools mysql nmap screen %end %post systemctl disable postfix.service %end
图形化安装
# Install OS instead of upgrade install # Keyboard layouts keyboard 'us' # Root password rootpw --iscrypted $1$m1pE0DG6$vALBphGGynqvUzfJaWZ6U1 # Use network installation url --url="$tree" # System language lang en_US # Firewall configuration firewall --disabled # System authorization information auth --useshadow --passalgo=sha512 # Use graphical install graphical firstboot --disable # SELinux configuration selinux --disabled # Network information network --bootproto=dhcp --device=eth0 network --bootproto=dhcp --device=eth1 # 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 /boot --asprimary --fstype="xfs" --size=1024 part swap --fstype="swap" --size=2048 part / --fstype="xfs" --grow --size=1 %packages @base @core @compat-libraries @debugging @development @gnome-desktop @X Window System %end
查看kickstart的配置
[root@cobbler-server kickstarts]# cobbler profile report --name=CentOS_7.7_1908-x86_64 Name : CentOS_7.7_1908-x86_64 TFTP Boot Files : {} Comment : DHCP Tag : default Distribution : CentOS_7.7_1908-x86_64 Enable gPXE? : 0 Enable PXE Menu? : 1 Fetchable Files : {} Kernel Options : {} Kernel Options (Post Install) : {} Kickstart : /var/lib/cobbler/kickstarts/sample_end.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
[root@cobbler-server kickstarts]# cobbler profile list CentOS_7.7_1908-x86_64 [root@cobbler-server kickstarts]# cobbler profile edit --name=CentOS_7.7_1908-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7u7-x64.ks [root@cobbler-server kickstarts]# cobbler profile edit --name=CentOS_7.7_1908-x86_64 --kopts='net.ifnames=0 biosdevname=0' [root@cobbler-server kickstarts]# cobbler sync task started: 2020-07-18_141252_sync task started (id=Sync, time=Sat Jul 18 14:12:52 2020) running pre-sync triggers cleaning trees removing: /var/www/cobbler/images/CentOS_7.7_1908-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.7_1908-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: CentOS_7.7_1908-x86_64 trying hardlink /var/www/cobbler/ks_mirror/CentOS_7.7_1908-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/CentOS_7.7_1908-x86_64/vmlinuz trying hardlink /var/www/cobbler/ks_mirror/CentOS_7.7_1908-x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/CentOS_7.7_1908-x86_64/initrd.img copying images generating PXE configuration files generating PXE menu structure copying files for distro: CentOS_7.7_1908-x86_64 trying hardlink /var/www/cobbler/ks_mirror/CentOS_7.7_1908-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/CentOS_7.7_1908-x86_64/vmlinuz trying hardlink /var/www/cobbler/ks_mirror/CentOS_7.7_1908-x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/CentOS_7.7_1908-x86_64/initrd.img Writing template files for CentOS_7.7_1908-x86_64 rendering DHCP files generating /etc/dhcp/dhcpd.conf rendering TFTPD files generating /etc/xinetd.d/tftp processing boot_files for distro: CentOS_7.7_1908-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.manage_genders running python trigger cobbler.modules.scm_track running shell triggers from /var/lib/cobbler/triggers/change/* *** TASK COMPLETE *** [root@cobbler-server kickstarts]# cobbler profile report --name=CentOS_7.7_1908-x86_64 | grep -i kickstart # 查看一下,kickstart是否已经关联到了我们自己的ks文件 Kickstart : /var/lib/cobbler/kickstarts/centos7u7-x64.ks Kickstart Metadata : {} # 确保服务和端口都起来了 [root@cobbler-server kickstarts]# systemctl restart dhcpd xinetd cobblerd tftp [root@cobbler-server kickstarts]# ss -nltp | egrep "httpd|rsync|xinetd|dhcpd|25151"
修改启动菜单
[root@cobbler-server ~]# cobbler system add --name=default --profile=CentOS_7.7_1908-x86_64 [root@cobbler-server ~]# cobbler system list default [root@cobbler-server ~]# cobbler sync [root@cobbler-server ~]# cat /var/lib/tftpboot/pxelinux.cfg//default DEFAULT menu PROMPT 0 MENU TITLE Cobbler | http://cobbler.github.io/ TIMEOUT 200 TOTALTIMEOUT 6000 ONTIMEOUT CentOS_7.7_1908-x86_64 LABEL local MENU LABEL (local) MENU DEFAULT LOCALBOOT -1 LABEL CentOS_7.7_1908-x86_64 kernel /images/CentOS_7.7_1908-x86_64/vmlinuz MENU LABEL CentOS_7.7_1908-x86_64 append initrd=/images/CentOS_7.7_1908-x86_64/initrd.img ksdevice=bootif lang=kssendmac text ks=http://10.111.66.218/cblr/svc/op/ks/profile/CentOS_7.7_1908-x86_64 ipappend 2 MENU end
到此,cobber已经配置完成,只需要将机器启动方式改为网络启动即可