本文共 9864 字,大约阅读时间需要 32 分钟。
Cobbler批量装系统
1、 简介
网络安装服务器套件 Cobbler(补鞋匠)从前,我们一直在做装机民工这份很有前途的职业。自打若干年前 Red Hat 推出了 Kickstart,此后我们顿觉身价倍增。不再需要刻了光盘一台一台地安装 Linux,只要搞定 PXE、DHCP、TFTP,还有那满屏眼花缭乱不知所云的 Kickstart 脚本,我们就可以像哈里波特一样,轻点魔棒,瞬间安装上百台服务器。这一堆花里胡哨的东西可不是一般人都能整明白的,没有大专以上学历,通不过英语四级, 根本别想玩转。总而言之,这是一份多么有前途,多么有技术含量的工作啊。很不幸,Red Hat 最新(Cobbler项目最初在2008年左右发布)发布了网络安装服务器套件 Cobbler(补鞋匠),它已将 Linux 网络安装的技术门槛,从大专以上文化水平,成功降低到初中以下,连补鞋匠都能学会。对于我们这些在装机领域经营多年,经验丰富,老骥伏枥,志在千里的民工兄弟们来说,不啻为一个晴天霹雳。2、 系统环境准备[root@bogon ~]# cat /etc/redhat-release CentOS release 6.7 (Final)[root@bogon ~]# uname -r2.6.32-573.el6.x86_64[root@bogon ~]# ifconfig|awk -F "[ :]+" 'NR==2 {print $4}' 192.168.1.131 添加阿里epel源[root@bogon ~]# wget -O /etc/yum.repos.d/epel.repo - 6.repo准备环境软件httpd、dhcp、xinetd、rsync、pykickstart、cobbler和cobbler-web:[root@bogon ~]# yum install -y httpd dhcp xinetd rsync pykickstart[root@bogon ~]# yum install -y cobbler cobbler-web报错:Error: Package: cobbler-web-2.6.11-7.git95749a6.el6.noarch (epel)Requires: Django >= 1.4缺少依赖包:Djange,Djange依赖包是python-simplejson,所以[root@bogon ~]# yum install -y python-simplejson[root@bogon ~]# wgethttps://kojipkgs.fedoraproject.org//packages/Django14/1.4.14/1.el6/noarch/Django14-1.4.14-1.el6.noarch.rpm[root@bogon ~]# rpm -ivh Django14-1.4.14-1.el6.noarch.rpm3、 配置文件[root@bogon ~]# /etc/init.d/httpd statushttpd (pid 1960) is running...[root@bogon ~]# /etc/init.d/cobblerd statuscobblerd (pid 1948) is running...[root@bogon ~]# cobbler check #检查cobcler配置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/tftp4 : 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 : change 'disable' to 'no' in /etc/xinetd.d/rsync6 : since iptables may be running, ensure 69, 80/443, and 25151 are unblocked7 : debmirror package is not installed, it will be required to manage debian deployments and repositories8 : 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 one9 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use themRestart cobblerd and then run 'cobbler sync' to apply changes.
关于问题:6、防火墙iptables还在运行[root@bogon ~]# setenforce 0setenforce: SELinux is disabled[root@bogon ~]# service iptables stop[root@bogon ~]# chkconfig iptables off[root@bogon ~]# vim /etc/selinux/configSELINUX=disabled1、2、在/etc/cobbler/settings修改server,next_server的IP地址[root@bogon ~]# sed -i "s/next_server: 127.0.0.1/next_server: 192.168.1.131/g" /etc/cobbler/settings[root@bogon ~]# sed -i "s/server: 127.0.0.1/server: 192.168.1.131/g" /etc/cobbler/settings修改cobbler管理dhcp和tftp[root@bogon ~]# sed -i "s/manage_dhcp: 0/manage_dhcp: 1/" /etc/cobbler/settings[root@bogon ~]# sed -i "s/manage_rsync: 0/manage_rsync: 1/g" /etc/cobbler/settingsPXE启动时不允许重复装机[root@bogon ~]# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/g' /etc/cobbler/settings8、设置系统登录的root密码openssl passwd -1 -salt 'guoge' 'your-password-here'"[root@bogon ~]# openssl passwd -1 -salt 'guoge' '123456' ##guoge为干扰内##123456为密码$1$guoge$4kUDFV7TavolzgIUxLM2m0[root@bogon ~]# vim /etc/cobbler/settingsdefault_password_crypted: "$1$guoge$4kUDFV7TavolzgIUxLM2m0" ##红色为修改内容3、5、修改/etc/xinetd.d/rsync 和/etc/xinetd.d/rsync
[root@bogon ~]# sed -i "s/disable = yes/disable = no/g" /etc/xinetd.d/rsync[root@bogon ~]#sed -i "s/disable = yes/disa disable = no /g" /etc/xinetd.d/tftp4、需要使用cobbler get-loaders命令下载loaders文件[root@bogon ~]# cobbler get-loaderstask started: 2018-07-31_080115_get_loaderstask started (id=Download Bootloader Content, time=Tue Jul 31 08:01:15 2018)downloading to /var/lib/cobbler/loaders/READMEdownloading to /var/lib/cobbler/loaders/COPYING.elilodownloading to /var/lib/cobbler/loaders/COPYING.yabootdownloading to /var/lib/cobbler/loaders/COPYING.syslinuxdownloading to /var/lib/cobbler/loaders/elilo-ia64.efidownloading to /var/lib/cobbler/loaders/yabootdownloading to /var/lib/cobbler/loaders/pxelinux.0downloading to /var/lib/cobbler/loaders/menu.c32downloading to /var/lib/cobbler/loaders/grub-x86.efidownloading to /var/lib/cobbler/loaders/grub-x86_64.efi TASK COMPLETE 所下载的文件在/var/lib/cobbler/loaders/当中[root@bogon ~]# cobbler sync同步配置重启服务[root@bogon ~]# /etc/init.d/xinetd restartStopping xinetd: [FAILED]Starting xinetd: [ OK ][root@bogon ~]# /etc/init.d/cobblerd restartStopping cobbler daemon: [ OK ]Starting cobbler daemon: [ OK ][root@bogon ~]# cobbler checkThe following are potential configuration items that you may want to fix:1 : service dhcpd is not running
2 : debmirror package is not installed, it will be required to manage debian deployments and repositories # 和debian系统相关,不需要3 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them # fence设备相关,不需要
Restart cobblerd and then run 'cobbler sync' to apply changes.
问题1、配置并启动DHCP[root@bogon ~]# vim /etc/cobbler/dhcp.templatesubnet 192.168.1.0 netmask 255.255.255.0 { option routers 192.168.1.131;option domain-name-servers 192.168.1.131;option subnet-mask 255.255.255.0;range dynamic-bootp 192.168.1.100 192.168.1.254;default-lease-time 21600;max-lease-time 43200;next-server $next_server;[root@bogon ~]# cobbler sync同步配置设置开机自启动:[root@bogon ~]# /etc/init.d/httpd restart[root@bogon ~]#/etc/init.d/xinetd restart[root@bogon ~]# /etc/init.d/dhcpd restart[root@bogon ~]# /etc/init.d/cobblerd restart[root@bogon ~]# chkconfig --level 35 httpd on[root@bogon ~]# chkconfig --level 35 xinetd on[root@bogon ~]# chkconfig --level 35 dhcpd on[root@bogon ~]# chkconfig --level 35 cobblerd on4、 设置镜像
[root@bogon ~]# mount /dev/cdrom /mnt/[root@bogon ~]# cobbler import --path=/mnt/ --name=Centos-6.7-x86_64 --arch=x86_64[root@bogon ~]# cobbler sync[root@bogon ~]# /etc/init.d/httpd restart[root@bogon ~]#/etc/init.d/xinetd restart[root@bogon ~]# /etc/init.d/dhcpd restart[root@bogon ~]# /etc/init.d/cobblerd restart5、 ks.cfk文件[root@bogon ~]# cat /var/lib/cobbler/kickstarts/sample_esample_end.ks sample_esx4.ks sample_esxi4.ks sample_esxi5.ks[root@bogon ~]# cat /var/lib/cobbler/kickstarts/sample_esample_end.ks sample_esx4.ks sample_esxi4.ks sample_esxi5.ks[root@bogon ~]# cat /var/lib/cobbler/kickstarts/sample_end.ks# kickstart template for Fedora 8 and later.# (includes %end blocks)# do not use with earlier distros#platform=x86, AMD64, or Intel EM64T# System authorization informationauth --useshadow --enablemd5# System bootloader configurationbootloader --location=mbr# Partition clearing informationclearpart --all --initlabel# Use text mode installtext# Firewall configurationfirewall --enabled# Run the Setup Agent on first bootfirstboot --disable# System keyboardkeyboard us# System languagelang en_US# Use network installationurl --url=$tree# If any cobbler repo definitions were referenced in the kickstart profile, include them here.$yum_repo_stanza# Network information$SNIPPET('network_config')# Reboot after installationreboot#Root passwordrootpw --iscrypted $default_password_crypted# SELinux configurationselinux --disabled# Do not configure the X Window Systemskipx# System timezonetimezone America/New_York# Install OS instead of upgrade# install# Clear the Master Boot Recordzerombr#### Allow anaconda to partition the system as neededautopart%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')%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%end
查看安装镜像文件信息
[root@bogon ~]#cobbler distro report --name=CentOS-7.1-x86_64查看所有的profile设置[root@bogon ~]# cobbler profile report查看指定的profile设置[root@bogon ~]#cobbler profile report --name=CentOS-7.1-x86_64[root@bogon ~]# cobbler sync同步配置6、 cobbler-web支持网页登录
/etc/cobbler/users.conf # Web服务授权配置文件/etc/cobbler/users.digest # 用于web访问的用户名密码配置文件 [root@bogon ~]# cat /etc/cobbler/users.digestcobbler:Cobbler:a2d6bae81669d707b72c0bd9806e01f3设置Cobbler web用户登陆密码在Cobbler组添加cobbler用户[root@linux-node1 ~]# htdigest /etc/cobbler/users.digest "Cobbler" cobblerChanging password for user cobbler in realm CobblerNew password: 123456Re-type new password:123456登录地址为:账户密码:cobbler 123456参考
转载于:https://blog.51cto.com/11575772/2152537