当前位置: > CentOS > CentOS服务器 > 环境配置 >

利用Cobbler批量快速网络安装CentOS

时间:2014-11-29 15:15来源:www.it.net.cn 作者:IT网

Cobbler是什么?

Cobbler(补鞋匠)集成了PXE、DHCP、DNS、Kickstart服务管理和yum仓库管理工具,相对之前的 Kickstart 更加快捷、方便的批量布署Red Hat、CentOS类系统

测试环境:

VMware® Workstation : 9.0.0 build-812388

操作系统 : CentOS 5.6 32位

 

一.安装epel源 
 
  1. [root@server1 ~]# wget http://dl.Fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm 
  2. [root@server1 ~]# rpm -ivh epel-release-5-4.noarch.rpm 
  3. warning: epel-release-5-4.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 217521f6 
  4. Preparing... ########################################### [100%] 
  5. 1:epel-release ########################################### [100%] 
  6. [root@server1 ~]# 
安装epel源的好处
就是epel这个项目是由fedora维护的,在维护的这个源中包含许多软件,包括ntop,nagios之类的,也就是说,你安装了epel源就可以直接用yum install ntop来安装了,不过这个应该针对红帽企业版Linux(RHEL)及其衍生发行版(比如CentOS、Scientific Linux)系统,Ubuntu这类的应该不行。
 
二.安装与配置cobbler
 
1.安装cobbler和一些必须的包,并设置开机自动启动
 
  1. [root@server1 ~]# yum -y install cobbler httpd rsync tftp-server xinetd dhcp python-ctypes pykickstart cman 
  2. ... 
  3. cobbler-2.2.2-1.el5.rf.noarch from rpmforge has depsolving problems 
  4. --> Missing Dependency: python-netaddr is needed by package cobbler-2.2.2-1.el5.rf.noarch (rpmforge) 
  5. cobbler-2.2.2-1.el5.rf.noarch from rpmforge has depsolving problems 
  6. --> Missing Dependency: mod_wsgi is needed by package cobbler-2.2.2-1.el5.rf.noarch (rpmforge) 
  7. Error: Missing Dependency: python-netaddr is needed by package cobbler-2.2.2-1.el5.rf.noarch (rpmforge) 
  8. Error: Missing Dependency: mod_wsgi is needed by package cobbler-2.2.2-1.el5.rf.noarch (rpmforge) 
  9. You could try using --skip-broken to work around the problem 
  10. You could try running: package-cleanup --problems 
  11. package-cleanup --dupes 
  12. rpm -Va --nofiles --nodigest 
我的系统需要安装这2个包。
 
  1. [root@server1 ~]# wget ftp://rpmfind.net/linux/epel/5/i386/python-netaddr-0.5.2-1.el5.noarch.rpm 
  2. [root@server1 ~]# rpm -ivh python-netaddr-0.5.2-1.el5.noarch.rpm 
  3. warning: python-netaddr-0.5.2-1.el5.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 217521f6 
  4. Preparing... ########################################### [100%] 
  5. 1:python-netaddr ########################################### [100%] 
  6. [root@server1 ~]# wget ftp://rpmfind.net/linux/epel/5/i386/mod_wsgi-3.2-2.el5.i386.rpm 
  7. [root@server1 ~]# rpm -ivh mod_wsgi-3.2-2.el5.i386.rpm 
  8. warning: mod_wsgi-3.2-2.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 217521f6 
  9. Preparing... ########################################### [100%] 
  10. 1:mod_wsgi ########################################### [100%] 
安装完成2个上面的包之后再次安装
 
  1. [root@server1 ~]# yum -y install cobbler httpd rsync tftp-server xinetd dhcp python-ctypes pykickstart cman 
  2. ...中间省略 
  3.  
  4. [root@server1 ~]# chkconfig httpd on 
  5. [root@server1 ~]# chkconfig cobblerd on 
  6. [root@server1 ~]# chkconfig dhcpd on 
  7. [root@server1 ~]# chkconfig xinetd on 
  8. [root@server1 ~]#/etc/init.d/iptables stop 
  9. [root@server1 ~]#chkconfig --level 35 iptables off 
服务控制脚本
 
  1. [root@server1 ~]#chmod +x /etc/init.d/cobbler_all 
  2. 用法:/etc/init.d/cobbler_all start|stop|startus|sync 
脚本内容:
 
  1. #!/bin/bash 
  2.  
  3. case $1 in 
  4. start) 
  5. /etc/init.d/httpd start 
  6. /etc/init.d/xinetd start 
  7. /etc/init.d/dhcpd start 
  8. /etc/init.d/cobblerd start 
  9. ;; 
  10. stop) 
  11. /etc/init.d/httpd stop 
  12. /etc/init.d/xinetd stop 
  13. /etc/init.d/dhcpd stop 
  14. /etc/init.d/cobblerd stop 
  15. ;; 
  16. status) 
  17. /etc/init.d/httpd status 
  18. /etc/init.d/xinetd status 
  19. /etc/init.d/dhcpd status 
  20. /etc/init.d/cobblerd status 
  21. ;; 
  22. sync) 
  23. cobbler sync 
  24. ;; 
  25. *) 
  26. echo "Input error,please in put 'start|stop|status|sync'!"; 
  27. exit 2>&1 >/dev/null & 
  28. ;; 
  29. esac 
 
相关配置文件及目录:
cobbler相关配置文件: /etc/cobbler
cobbler数据存储目录: /var/www/cobbler
dhcp配置文件: /etc/dhcpd.conf
dhcp租期缓存文件: /var/lib/dhcpd/dhcpd.leases
pxe配置文件: /tftpboot/pxelinux.cfg/default
ks模板文件: /var/lib/cobbler/kickstarts_*.ks

2.编辑vim /etc/cobbler/settings
 
  1. [root@server1 ~]# vim /etc/cobbler/settings 
  2.  
  3. next_server: 127.0.0.1 修改为:next_server: 192.168.0.45(是cobbler服务器的地址) 
  4.  
  5. server: 127.0.0.1 修改为: server: 192.168.0.45(是cobbler服务器的地址) 
  6.  
  7. manage_dhcp: 0 修改为 manage_dhcp: 1 (1意思就是由cobbler自动管理dhcpd) 
  8.  
  9. manage_rsync: 0 修改为 manage_rsync: 1 (1意思就是由cobbler自动管理rsync) 
3.编辑/etc/httpd/conf/httpd.conf
 
  1. [root@server1 ~]# vim /etc/httpd/conf/httpd.conf 在LoadModule附近 添加以下行 
  2. LoadModule suexec_module modules/mod_suexec.so 
  3. LoadModule disk_cache_module modules/mod_disk_cache.so 
  4. LoadModule file_cache_module modules/mod_file_cache.so 
  5. LoadModule mem_cache_module modules/mod_mem_cache.so 
  6. LoadModule cgi_module modules/mod_cgi.so 
  7. LoadModule version_module modules/mod_version.so 
  8. LoadModule wsgi_module modules/mod_wsgi.so  <- 在这里添加这行 
4.启动httpd和cobbler
 
  1. [root@server1 ~]# service httpd start 
  2. 启动 httpd: [确定] 
  3. [root@server1 ~]# service cobblerd start 
  4. Starting cobbler daemon: [确定] 
  5. [root@server1 ~]# 
5.编辑/etc/xinetd.d/rsync 
 
 
  1. [root@server1 ~]# vim /etc/xinetd.d/rsync 
  2. service rsync 
  3. disable = no 修改yes 为 no(就是启用) 
  4. socket_type = stream
  5. wait = no
  6. user = root
  7. server = /usr/bin/rsync 
  8. server_args = --daemon 
  9. log_on_failure += USERID 
6.编辑/etc/xinetd.d/tftp
 
  1. [root@server1 ~]# vim /etc/xinetd.d/tftp 
  2. service tftp 
  3. socket_type = dgram
  4. protocol = udp
  5. wait = yes
  6. user = root
  7. server = /usr/sbin/in.tftpd 
  8. server_args = -s /tftpboot 
  9. disable = no 修改yes 为 no(就是启用) 
  10. per_source = 11
  11. cps = 100 2 
  12. flags = IPv4
7.编辑/etc/cobbler/dhcp.template
 
  1. [root@server1 ~]# vim /etc/cobbler/dhcp.template 
  2. ddns-update-style interim; 
  3.  
  4. allow booting; 
  5. allow bootp; 
  6.  
  7. ignore client-updates; 
  8. set vendorclass = option vendor-class-identifier; 
  9.  
  10. subnet 192.168.0.0 netmask 255.255.255.0 { 
  11. option routers 192.168.0.1; 
  12. option domain-name-servers 192.168.0.1; 
  13. option subnet-mask 255.255.255.0; 
  14. range dynamic-bootp 192.168.0.10 192.168.0.20; 
  15. filename "/pxelinux.0"; 
  16. default-lease-time 21600; 
  17. max-lease-time 43200; 
  18. next-server $next_server; 
  19. }
8.执行检查
 
 
  1. [root@server1 ~]# cobbler check 
  2. The following are potential configuration items that you may want to fix: 
  3.  
  4. 1 : 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. 2 : debmirror package is not installed, it will be required to manage debian deployments and repositories 
  6. 3 : 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 
  7.  
  8. Restart cobblerd and then run 'cobbler sync' to apply changes. 
修复第1条:
 
  1. [root@server1 ~]# cobbler get-loaders 
  2. task started: 2012-12-09_055900_get_loaders 
  3. task started (id=Download Bootloader Content, time=Sun Dec 9 05:59:00 2012) 
  4. downloading http://dgoodwin.Fedorapeople.org/loaders/README to /var/lib/cobbler/loaders/README 
  5. downloading http://dgoodwin.fedorapeople.org/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo 
  6. downloading http://dgoodwin.fedorapeople.org/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot 
  7. downloading http://dgoodwin.fedorapeople.org/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux 
  8. downloading http://dgoodwin.fedorapeople.org/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi 
  9. downloading http://dgoodwin.fedorapeople.org/loaders/yaboot-1.3.14-12 to /var/lib/cobbler/loaders/yaboot 
  10. downloading http://dgoodwin.fedorapeople.org/loaders/pxelinux.0-3.61 to /var/lib/cobbler/loaders/pxelinux.0 
  11. downloading http://dgoodwin.fedorapeople.org/loaders/menu.c32-3.61 to /var/lib/cobbler/loaders/menu.c32 
  12. downloading http://dgoodwin.fedorapeople.org/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi 
  13. downloading http://dgoodwin.fedorapeople.org/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi 
  14. *** TASK COMPLETE ***  <-看到这就代表成功完成 

(责任编辑:IT)
------分隔线----------------------------