使用cobbler实现批量自动部署Linux推荐

Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows。该工具使用python开发,小巧轻便,使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP,DNS,以及yum包镜像。下面一步步来实现吧

实验平台:rhel 6.3 x86_64

cobbler.laoguang.me192.168.1.23

一.环境准备1.1 安装dhcp

yum-yinstalldhcp

1.2 安装其它所需服务如:tftp xinetd httpd ##靠tftp传输文件,tftp依赖xinetd,httpd这个我暂时不清楚

yum-yinstalltftpxinetdhttpd

1.3 关闭selinux iptables

setenforce0serviceiptablesstop

二.安装cobbler2.1 下载安装cobbler与依赖的包python-yaml下载地址:http://www.kuaipan.cn/file/id_33139203151758501.html ,其它平台的可以去http://rpm.pbone.net/找,这个网站你一定不能忘记

yum-y--nogpgchecklocalinstallcobbler-2.2.2-1.el6.rf.noarch.rpm\python-yaml-3.09-3.el6.rf.x86_64.rpm

2.2 启动cobbler

servicecobblerdstart

2.3 启动httpd

servicehttpdstart

2.4启用xinetd

servicexinetdstart

2.4 cobbler 检查配置

cobblercheck
--------------------------------------------Thefollowingarepotentialconfigurationitemsthatyoumaywanttofix:1:The'server'fieldin/etc/cobbler/settingsmustbesettosomethingotherthanlocalhost,orkickstartingfeatureswillnotwork.ThisshouldbearesolvablehostnametheorIPforbootserverasreachablebyallmachinesthatwilluseit.修改/etc/cobbler/settings中server选项为:server:192.168.1.232:ForPXEtobefunctional,the'next_server'fieldin/etc/cobbler/settingsmustbesettosomethingotherthan127.0.0.1,andshouldmatchtheIPofthebootserveronthePXEnetwork.修改/etc/cobbler/settings中next_server选项为:next_server:192.168.1.233:Mustenableaselinuxbooleantoenablevitalwebservicescomponents,run:setsebool-Phttpd_can_network_connecttrue关闭selinux4:youneedtosetsomeSELinuxcontentrulestoensurecobblerservescontentcorrectlyinyourSELinuxenvironment,runthefollowing:/usr/sbin/semanagefcontext-a-tpublic_content_t /var/lib/tftpboot/.*  /usr/sbin/semanagefcontext-a-tpublic_content_t /var/www/cobbler /images/.*关闭selinux5:youneedtosetsomeSELinuxrulesifyouwanttousecobbler-web(anoptionalpackage),runthefollowing:/usr/sbin/semanagefcontext-a-thttpd_sys_content_rw_t /var/lib/cobbler/webui_sessions/.* 关闭selinux6:somenetworkboot-loadersaremissingfrom/var/lib/cobbler/loaders,youmayrun'cobblerget-loaders'todownloadthem,or,ifyouonlywanttohandlex86/x86_64netbooting,youmayensurethatyouhaveinstalleda*recent*versionofthesyslinuxpackageinstalledandcanignorethismessageentirely.Filesinthisdirectory,shouldyouwanttosupportallarchitectures,shouldincludepxelinux.0,menu.c32,elilo.efi,andyaboot.The'cobblerget-loaders'commandistheeasiestwaytoresolvetheserequirements.运行cobblerget-loaderscobblerget-loaders##前提你能上网,出现***TASKCOMPLETE***代表ok7:change'disable'to'no'in/etc/xinetd.d/rsync我们不用rysnc同步文件,如果用的话修改/etc/xinetd.d/rsyncvi/etc/xinetd.d/rsyncdisable=no8:reposyncisnotinstalled,needforcobblerreposync,install/upgradeyum-utils?可以不用理会,因为我们不用rsync同步ISO9:yumdownloaderisnotinstalled,neededforcobblerrepoaddwith--rpm-listparameter,install/upgradeyum-utils?同上10:debmirrorpackageisnotinstalled,itwillberequiredtomanagedebiandeploymentsandrepositories我们不是debian可以不用理会11:ksvalidatorwasnotfound,installpykickstart安装pykickstartyum-yinstallpykickstart12:Thedefaultpasswordusedbythesampletemplatesfornewlyinstalledmachines(default_password_cryptedin/etc/cobbler/settings)isstillsetto'cobbler'andshouldbechanged,try: opensslpasswd-1-salt'random-phrase-here''your-password-here' togeneratenewone修改cobbler的密码,防止其它正常主机由pxe启动后安装系统opensslpasswd-1-salt51ctolaoguang##生成密码$1$51cto$nTnuekFUB6sByi97bt7df/##将它复制到setting中vi /etc/cobbler/settingsdefault_password_crypted: $1$51cto$nTnuekFUB6sByi97bt7df/ -----------------------------------------

2.5 重启cobbler

servicecobblerdrestart

三.cobbler的配置3.1 导入欲安装的系统的镜像文件将redhat 6.3 x86_64 的ISO挂载/cdrom

mount/dev/cdrom/cdrom

导入需要的安装文件到cobbler的/var/www/cobbler/ks_mirrors下,并生成一profile,此过程需要一段时间,耐心等待

cobblerimport--path=/cdrom--name=RedHat-6.3-x86_64

3.2 配置dhcp服务,让cobbler来管理

vi/etc/cobbler/settingsmanage_dhcp:1

3.3 修改/etc/cobbler/dhcp.template模板文件中的配置,其它的默认即可

vi/etc/cobbler/dhcp.templatesubnet192.168.1.0netmask255.255.255.0{##根据需要修改optionrouters192.168.1.1;##路由ip#optiondomain-name-servers192.168.1.1;##dns的ip,我没使用optionsubnet-mask255.255.255.0;##掩码rangedynamic-bootp192.168.1.100192.168.1.254;##dhcp分配的ip范围filename /pxelinux.0 default-lease-time21600;##dhcp的默认释放时间max-lease-time43200;##最大时间next-server$next_server;##pxe使用的ip,$next_server在setting中定义的你忘了吗}

3.4 同步cobbler配置

cobblersync

cobbler会自动进行初始化工作,移除已经存在的启动项,然后根据模板拷贝loader文件。之后再生成pxe的配置文件,生成dhcp的配置文件,最后再重启dhcp服务。关键查看dhcp,tftp有没有启动成功。四.测试安装系统4.1 新建个虚拟机,网络记的是brige哦,新建的虚拟机网络默认是nat的,我就因为这个怎么都安装不上,启动虚拟机,调整启动顺序从网络启动(我用的是vmware,如果你没有挂cd的iso,也虚拟机是新建的直接启动应该是可以的)

五.定制自己的kickstart文件定制自己的kickstart文件而不是使用默认的,kickstart文件cobbler放在了/var/lib/cobbler/kickstarts/中,查看cobbler默认使用的哪个

vi/etc/cobbler/settingsdefault_kickstart:/var/lib/cobbler/kickstarts/default.ks##看到了吧,用的是default.ks

5.1 自定义kickstart文件。如果你对kickstart文件理解透彻,直接修改或新建即可,如果还是很精通就用gui工具吧

yum-yinstallsystem-config-kickstart

安装完毕后打开软件

system-config-kickstart

根据自己的需要修改即可,修改完毕后保存,修改settings中的设置,重启cobbler即可本文参考:http://os.51cto.com/art/201109/288604.htm最困难之时,就是我们离成功不远之日。

使用cobbler实现批量自动部署Linux推荐

相关文章:

你感兴趣的文章:

标签云: