标签:安装centos 搭建dhcp服务 stdout check 挂载 com running 命令帮助 关闭
Cobbler 可以用来快速建立 Linux 网络安装环境,它已将 Linux 网络安装的技术门槛,从大专以上文化水平,成功降低到初中以下,连补鞋匠都能学会。
网络安装服务器套件Cobbler
(补鞋匠)从前,我们一直在装机民工这份很有前途的职业。自打若干年前Red Hat
推出了 Kickstart
,此后我们顿觉身价增倍。不再需要刻了光盘一台一台的安装Linux
,只要搞定PXE
、DHCP
、TFTP
,还有那满屏眼花缭乱不知所云的Kickstart
脚本,我们就可以像哈利波特一样,轻点魔棒,瞬间安装上百台服务器。这一堆花里胡哨的东西可不是一般人能够整明白的,没有大专以上的学历,通不过英语四级,根本别想玩转。总而言之,这是一份多么有前途,多么有技术含量的工作啊。很不幸,Red Ha
t 最新(Cobbler
项目最初在2008
年左右发布)发布了网络安装服务器套件Cobbler
(补鞋匠),它已将Linux
网络安装的技术门槛,从大专以上文化水平,成功降低到初中以下水平,连补鞋匠都能学会。
1、Cobbler
是一个Linux
服务器安装的服务,可以通过网络启动(PXE
)的方式来快速安装、重装物理服务器和虚拟机,同时还可以管理DHCP
,DNS
等。
2、Cobbler
可以使用命令行方式管理,也提供了基于Web的界面管理工具(cobbler-web
),还提供了API
接口,可以方便二次开发使用。
3、Cobbler
是较早前的kickstart
的升级版,优点是比较容易配置,还自带web界面比较易于管理。
4、Cobbler
内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet
。
cobbler框架
Cobbler
的配置结构基于一组注册的对象。每个对象表示一个与另一个实体相关联的实体。当一个对象指向另一个对象时,它就继承了被指向对象的数据,并可覆盖或添加更多特定信息。
distros
): 表示一个操作系统。它承载了内核和initrd
的信息,以及内核参数等其他数据。profiles
):包含一个发行版、一个kickstart
文件以及可能的存储库,还包括更多特定的内核参数等其他数据。systems
):表示要配给的机器。它包括一个配置文件或一个镜像、IP
和MAC
地址、电源管理(地址、凭据、类型)以及更为专业的数据等信息。images
):可以替换一个保函不屑于此类别的文件的发行版对象(例如,无法分为内核和initrd
的对象)工作原理
Server端
Cobbler
服务Cobbler
错误检查,执行cobbler check
命令cobbler sync
命令TFTP
目录中DHCP
服务,提供地址分配DHCP
服务分配IP地址TFTP
传输启动文件Server
端接收安装信息Server
端发送ISO
镜像与Kickstart
文件Client端
PXE
模式启动IP
地址TFTP
服务器获取启动文件Cobbler
安装选择界面Kickstart
文件------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
下面正式开始cobbler的部署:
准备环境:
系统 CentOS Linux release 7.3.1611 (Core) 外网IIP:10.0.0.45 外网IP:172.16.1.45
注意:虚拟机网卡采用NAT模式或者仅主机模式,不要使用桥接模式,因为后面会搭建DHCP服务器,在同一个局域网多个DHCP服务会有冲突。VMware的NAT模式的DHCP服务也会关闭,避免打扰。
安装cobbler和相关组件
[root@ localhost ~]# yum -y install cobbler cobbler-web tftp-server pykickstart httpd dhcp xinetd debmirror cobbler #cobbler程序包 cobbler—web #cobbler的web服务包 pykickstart #cobbler检查kickstart语法错误 httpd #Apache web服务 dhcp #DHCP服务 tftp #tftp服务 xinetd #诸多服务的超级守护进程 #启动cobbler及httpd并假如开机启动 [root@ localhost ~]# systemctl start httpd cobblerd [root@ localhost ~]# systemctl enable httpd cobblerd 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.
配置cobbler
#检查cobbler的配置,如果以下操作不出结果,重启cobbler。
[root@ localhost ~]# cobbler check #类似一个使用手册,需要解决以下9个问题才可以使用。 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 : comment out ‘dists‘ on /etc/debmirror.conf for proper debian support 7 : comment out ‘arches‘ on /etc/debmirror.conf for proper debian support 8 : 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 9 : 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.
现在开始逐步的去解决,先进行设置为可以动态配置,也可以直接更改配置文件。
[root@ localhost ~]# sed -ri ‘/allow_dynamic_settings:/c\allow_dynamic_settings: 1‘ /etc/cobbler/settings [root@ localhost ~]# grep allow_dynamic_setting /etc/cobbler/settings allow_dynamic_settings: 1 [root@ localhost ~]# systemctl restart cobblerd
#1.配置server地址 [root@ localhost ~]# cobbler setting edit --name=server --value=10.0.0.45 #2.配置next_server地址 [root@ localhost ~]# cobbler setting edit --name=next_server --value=10.0.0.45 #3.配置xinetd管理tftp [root@ localhost ~]# sed -ri ‘/disable/c\disable = no‘ /etc/xinetd.d/tftp [root@ localhost ~]# systemctl enable xinetd [root@ localhost ~]# systemctl restart xinetd #4.boot-loaders [root@ localhost ~]# cobbler get-loaders task started: 2020-03-03_222902_get_loaders task started (id=Download Bootloader Content, time=Tue Mar 3 22:29:02 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.启动rsync [root@ localhost ~]# systemctl start rsyncd [root@ localhost ~]# systemctl enable rsyncd Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service. #6和7 .debian support [root@ localhost ~]# sed -i ‘s#@dists="sid";#\#@dists="sid";#gp‘ /etc/debmirror.conf [root@ localhost ~]# sed -i ‘s#@arches="i386";#\#@arches="i386";#g‘ /etc/debmirror.conf #8.default_password_crypted #注意: 这里设置的密码是cobbler安装完系统后,默认root用户初始化登陆密码,用openssl生成一串密码后 加入到cobbler的配置文件(/etc/cobbler/settings)里,替换default_password_cryptd字段 [root@ localhost ~]# openssl passwd -1 -salt `openssl rand -hex 4` ‘123456‘ $1$a90c5519$BEBfUgtXGEqGE2bLbCG/t. [root@ localhost ~]# cobbler setting edit --name=default_password_crypted --value=‘$1$a90c5519$BEBfUgtXGEqGE2bLbCG/t‘ #9.安装fencing tools [root@ localhost ~]# yum -y install fence-agents #解决完后再次检查 [root@ localhost ~]# systemctl restart cobblerd [root@ localhost ~]# cobbler sync [root@ localhost ~]# cobbler check No configuration problems found. All systems go.
配置DHCP
[root@ localhost ~]# cobbler setting edit --name=manage_dhcp --value=1 [root@ localhost ~]# vim /etc/cobbler/dhcp.template subnet 10.0.0.0 netmask 255.255.255.0 { #这里改为分配的网段和掩码 option routers 10.0.0.254; #如果有网关,这里改成网关地址 option domain-name-servers 223.5.5.5; #如果有DNS,这里改成DNS地址 option subnet-mask 255.255.255.0; #改为分配的ip的掩码 range dynamic-bootp 10.0.0.100 10.0.0.200; #改为分配的ip的范围
同步cobbler配置
[root@ localhost ~]# cobbler sync task started: 2020-03-03_224703_sync task started (id=Sync, time=Tue Mar 3 22:47:03 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 ***
查看一下DHCP,查看cobbler是否可以管理DHCP
[root@ localhost ~]# [root@ localhost ~]# cat /etc/dhcp/dhcpd.conf # ****************************************************************** # Cobbler managed dhcpd.conf file # generated from cobbler dhcp.conf template (Tue Mar 3 14:47:04 2020) # 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 10.0.0.0 netmask 255.255.255.0 { option routers 10.0.0.254; option domain-name-servers 223.5.5.5; option subnet-mask 255.255.255.0; range dynamic-bootp 10.0.0.100 10.0.0.200; default-lease-time 21600; max-lease-time 43200; next-server 10.0.0.45; 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 { }
cobbler命令帮助
这时候创建一个新的虚拟机准备测试,开启以后会发现没有镜像选择,只能从本地启动
cobbler安装centos6.10
因为我这台是用centos7做的,所以并没6.10的镜像,所以需要自己上传一个
创建挂载点并挂载
[root@ localhost ~]# ll total 3898372 -rw-------. 1 root root 1277 2019-09-17 22:18 anaconda-ks.cfg -rw-r--r-- 1 root root 3991928832 2020-03-03 23:04 CentOS-6.10-x86_64-bin-DVD1.iso [root@ localhost ~]# mkdir /centos6.10 [root@ localhost ~]# mount -o loop CentOS-6.10-x86_64-bin-DVD1.iso /centos6.10
查看挂在后的目录
[root@ localhost ~]# ls /centos6.10/ CentOS_BuildTag images repodata RPM-GPG-KEY-CentOS-Testing-6 EFI isolinux RPM-GPG-KEY-CentOS-6 TRANS.TBL EULA Packages RPM-GPG-KEY-CentOS-Debug-6 GPL RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Security-6
导入镜像
[root@ localhost ~]# cobbler import --path=/centos6.10 --name=centos6.10 --arch=x86_64 # --path 镜像路径 # --name 为安装源定义一个名字 # --arch 指定安装源是32位、64位、ia64,目前支持的选项有:x86|x86_64|ia64 # 安装源的唯一标识就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是centos6.10,如果重复,系统会报错
查看导入后镜像信息
[root@ localhost ~]# cobbler distro report --name=centos6.10-x86_64 Name : centos6.10-x86_64 Architecture : x86_64 TFTP Boot Files : {} Breed : redhat Comment : Fetchable Files : {} Initrd : /var/www/cobbler/ks_mirror/centos6.10-x86_64/images/pxeboot/initrd.img Kernel : /var/www/cobbler/ks_mirror/centos6.10-x86_64/images/pxeboot/vmlinuz Kernel Options : {} Kernel Options (Post Install) : {} Kickstart Metadata : {‘tree‘: ‘http://@@http_server@@/cblr/links/centos6.10-x86_64‘} Management Classes : [] OS Version : rhel6 Owners : [‘admin‘] Red Hat Management Key : <<inherit>> Red Hat Management Server : <<inherit>> Template Files : {}
查看profile信息
[root@ localhost ~]# cobbler profile report --name=centos6.10-x86_64 Name : centos6.10-x86_64 TFTP Boot Files : {} Comment : DHCP Tag : default Distribution : centos6.10-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
编辑centos6.10镜像的kickstart文件
[root@ localhost ~]# cd /var/lib/cobbler/kickstarts/ [root@ localhost kickstarts]# cp sample_end.ks centos6.10.ks [root@ localhost kickstarts]# vim centos6.10.ks # This kickstart file should only be used with EL > 5 and/or Fedora > 7. # For older versions please use the sample.ks kickstart file. # Install OS instead of upgrade install # Use text mode install text # System keyboard keyboard us # System language lang en_US # System timezone timezone Asia/ShangHai #Root password rootpw --iscrypted $default_password_crypted # System authorization information auth --useshadow --enablemd5 # Firewall configuration firewall --disabled # SELinux configuration selinux --disabled # Use network installation url --url=$tree # Clear the Master Boot Record zerombr # System bootloader configuration bootloader --location=mbr # Partition clearing information clearpart --all --initlabel part /boot --fstype=ext4 --size=200 part swap --fstype=swap --size=2048 part / --fstype=ext4 --grow --size=200 --asprimary # If any cobbler repo definitions were referenced in the kickstart profile, include them here. $yum_repo_stanza # Network information $SNIPPET(‘network_config‘) # Do not configure the X Window System skipx # Run the Setup Agent on first boot firstboot --disable # Reboot after installation reboot %pre $SNIPPET(‘log_ks_pre‘) $SNIPPET(‘kickstart_start‘) $SNIPPET(‘pre_install_network_config‘) # Enable installation monitoring $SNIPPET(‘pre_anamon‘) %end %packages $SNIPPET(‘func_install_if_enabled‘) @core @base tree nmap wget lftp lrzsz telnet %end %post --nochroot $SNIPPET(‘log_ks_post_nochroot‘) %end %post $SNIPPET(‘log_ks_post‘) # Start yum configuration $yum_config_stanza # End yum configuration $SNIPPET(‘post_install_kernel_options‘) $SNIPPET(‘post_install_network_config‘) $SNIPPET(‘func_register_if_enabled‘) $SNIPPET(‘download_config_files‘) $SNIPPET(‘koan_environment‘) $SNIPPET(‘redhat_register‘) $SNIPPET(‘cobbler_register‘) # Enable post-install boot notification $SNIPPET(‘post_anamon‘) # Start final steps $SNIPPET(‘kickstart_done‘) # End final steps sed -ri "/^#UseDNS/c\UseDNS no" /etc/ssh/sshd_config sed -ri "/^GSSAPIAuthentication/c\GSSAPIAuthentication no" /etc/ssh/sshd_config %end
同步cobbler配置
注意:系统镜像文件centos6.10.ks,每修改一次都要进行同步
[root@ localhost kickstarts]# cobbler sync
开启新虚拟机进行测试,点击选中,系统自动安装。
比如在安一个centos7.3 因为我本机就是7.3的 所以直接可以参上操作,直接挂载/dev/cdrom就可以
然后新建一台虚机,选择centos7.3就可以了,如果出现/sbin/dmsquash-live-root:line 286:printf:write error:No space lefe on device 是因为内存不足2G导致的。至此cobbler命令行的配置操作结束。
标签:安装centos 搭建dhcp服务 stdout check 挂载 com running 命令帮助 关闭
原文地址:https://www.cnblogs.com/tyk3201/p/12405567.html