CENTOS7下部署Cobbler实现自动化安装LINUX系统

  • A+

Cobbler是一个系统启动服务(boot server),可以通过网络启动(PXE)的方式用来快速安装、重装物理服务器和虚拟机,支持安装不同的Linux发行版和Windows系统,下文将通过先部署一台Cobbler服务,然后在一台空虚拟机上安装centos7.6操作系统,演示其使用方法。

1.环境准备

准备2台虚拟机,1台安装Cobbler服务,及DHCPHTTPDTFTP服务,另一台作为裸机,不安装操作系统。

服务名IP地址安装软件
Cobbler服务端10.129.10.224Cobbler、DHCP、HTTPD、TFTP
裸机

2.部署Cobbler服务

2.1关闭防火墙和SElinux
  1. [root@cobbler ~]# systemctl stop firewalld  
  2. [root@cobbler ~]# systemctl disable firewalld  
  3. Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.  
  4. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.  
  5. [root@cobbler ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config  
  6. [root@cobbler ~]# setenforce 0  
  7. [root@cobbler ~]  
2.2安装cobbler及相关软件

先安装EPEL

  1. [root@cobbler ~]#  yum -y install epel-release  
  2. 已加载插件:fastestmirror, langpacks  
  3. Loading mirror speeds from cached hostfile  
  4.  * base: mirrors.huaweicloud.com  
  5.  * extras: mirrors.huaweicloud.com  
  6.  * updates: mirrors.ustc.edu.cn  
  7. 正在解决依赖关系  
  8. --> 正在检查事务  
  9. ---> 软件包 epel-release.noarch.0.7-11 将被 安装  
  10. --> 解决依赖关系完成  
  11. ……  

然后再安装(这里安装过程有点问题,分别安装Cobbler和cobbler-web

  1. [root@cobbler ~]# yum -y install httpd dhcp tftp python-ctypes cobbler  xinetd cobbler-web pykickstart net-tools  
  2. 已加载插件:fastestmirror, langpacks  
  3. Determining fastest mirrors  
  4.  * base: mirrors.huaweicloud.com  
  5.  * extras: mirrors.huaweicloud.com  
  6.  * updates: mirrors.ustc.edu.cn  
  7. base                                                                                                                                                                                      | 3.6 kB  00:00:00       
  8. extras                                                                                                                                                                                    | 2.9 kB  00:00:00       
  9. updates                                                                                                                                                                                   | 2.9 kB  00:00:00       
  10. (1/4): base/7/x86_64/group_gz                                                                                                                                                             | 153 kB  00:00:00       
  11. (2/4): extras/7/x86_64/primary_db                                                                                                                                                         | 250 kB  00:00:00       
  12. (3/4): base/7/x86_64/primary_db                                                                                                                                                           | 6.1 MB  00:00:01       
  13. (4/4): updates/7/x86_64/primary_db                                                                                                                                                        |  23 MB  00:00:05       
  14. 没有可用软件包 cobbler。  
  15. 没有可用软件包 cobbler-web。  
  16. 正在解决依赖关系  
  17. --> 正在检查事务  
  18. ---> 软件包 dhcp.x86_64.12.4.2.5-83.el7.centos.1 将被 安装  
  19. --> 正在处理依赖关系 dhcp-libs(x86-64) = 12:4.2.5-83.el7.centos.1,它被软件包 12:dhcp-4.2.5-83.el7.centos.1.x86_64 需要  
  20. ……  
  21. 已安装:  
  22.   dhcp.x86_64 12:4.2.5-83.el7.centos.1                    httpd.x86_64 0:2.4.6-99.el7.centos.1                    tftp.x86_64 0:5.2-22.el7                    xinetd.x86_64 2:2.3.15-14.el7                     
  23.   
  24. 作为依赖被安装:  
  25.   bind-export-libs.x86_64 32:9.11.4-26.P2.el7_9.14                             httpd-tools.x86_64 0:2.4.6-99.el7.centos.1                             mailcap.noarch 0:2.1.41-2.el7                              
  26.   
  27. 更新完毕:  
  28.   net-tools.x86_64 0:2.0-0.25.20131004git.el7                                pykickstart.noarch 0:1.99.66.22-1.el7                                python.x86_64 0:2.7.5-93.el7_9                                 
  29.   
  30. 作为依赖被升级:  
  31.   dhclient.x86_64 12:4.2.5-83.el7.centos.1            dhcp-common.x86_64 12:4.2.5-83.el7.centos.1            dhcp-libs.x86_64 12:4.2.5-83.el7.centos.1            python-libs.x86_64 0:2.7.5-93.el7_9             
  32.   
  33. 完毕!  
  34. [root@cobbler ~]  
2.3启动服务
  1. [root@cobbler ~]# systemctl enable --now httpd  
  2. [root@cobbler ~]# systemctl enable --now cobblerd  
  3. Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to /usr/lib/systemd/system/cobblerd.service.  
  4. [root@cobbler ~]  
2.4修改sever的IP地址

编辑Cobbler配置文件/etc/cobbler/settings,这里IP地址为10.129.10.224

  1. [root@cobbler ~]# vim /etc/cobbler/settings  
CENTOS7下部署Cobbler实现自动化安装LINUX系统
CENTOS7下部署Cobbler实现自动化安装LINUX系统

并将manage_dhcp: 1

2.5开启tftp服务

在配置文件中,将disable = yes行修改为disable = no

  1. [root@cobbler ~]# cat /etc/xinetd.d/tftp  
  2. # default: off  
  3. # description: The tftp server serves files using the trivial file transfer \  
  4. #   protocol.  The tftp protocol is often used to boot diskless \  
  5. #   workstations, download configuration files to network-aware printers, \  
  6. #   and to start the installation process for some operating systems.  
  7. service tftp  
  8. {  
  9.     socket_type     = dgram  
  10.     protocol        = udp  
  11.     wait            = yes  
  12.     user            = root  
  13.     server          = /usr/sbin/in.tftpd  
  14.     server_args     = -s /var/lib/tftpboot  
  15.     disable         = no  
  16.     per_source      = 11  
  17.     cps         = 100 2  
  18.     flags           = IPv4  
  19. }  
  20. [root@cobbler ~]  
CENTOS7下部署Cobbler实现自动化安装LINUX系统

然后重新加载服务:

  1. [root@cobbler ~]# systemctl restart xinetd  
  2. [root@cobbler ~]  
2.6配置DHCP服务

编辑DHCP服务配置文件/etc/dhcp/dhcpd.conf

  1. subnet 10.129.10.0 netmask 255.255.255.0 {  
  2.      option routers             10.129.10.224;  
  3.      option domain-name-servers 10.129.10.254;  
  4.      option subnet-mask         255.255.255.0;  
  5.      range dynamic-bootp        10.129.10.10 10.129.10.20;  
  6.      default-lease-time         21600;  
  7.      max-lease-time             43200;  
  8.      next-server                $next_server;  
  9.      class "pxeclients" {  
  10.           match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";  
  11.           if option pxe-system-type = 00:02 {  
  12.                   filename "ia64/elilo.efi";  
  13.           } else if option pxe-system-type = 00:06 {  
  14.                   filename "grub/grub-x86.efi";  
  15.           } else if option pxe-system-type = 00:07 {  
  16.                   filename "grub/grub-x86_64.efi";  
  17.           } else if option pxe-system-type = 00:09 {  
  18.                   filename "grub/grub-x86_64.efi";  
  19.           } else {  
  20.                   filename "pxelinux.0";  
  21.           }  
  22.      }  
  23.   
  24. }  
2.7重启服务并同步
  1. [root@cobbler ~]# systemctl restart cobblerd  
  2. [root@cobbler ~]# cobbler sync  
  3. task started: 2023-10-12_134810_sync  
  4. task started (id=Sync, time=Thu Oct 12 13:48:10 2023)  
  5. running pre-sync triggers  
  6. cleaning trees  
  7. removing: /var/lib/tftpboot/pxelinux.cfg/default  
  8. removing: /var/lib/tftpboot/grub/images  
  9. removing: /var/lib/tftpboot/grub/efidefault  
  10. removing: /var/lib/tftpboot/s390x/profile_list  
  11. copying bootloaders  
  12. copying distros to tftpboot  
  13. copying images  
  14. generating PXE configuration files  
  15. generating PXE menu structure  
  16. rendering DHCP files  
  17. generating /etc/dhcp/dhcpd.conf  
  18. rendering TFTPD files  
  19. generating /etc/xinetd.d/tftp  
  20. cleaning link caches  
  21. running post-sync triggers  
  22. running python triggers from /var/lib/cobbler/triggers/sync/post/*  
  23. running python trigger cobbler.modules.sync_post_restart_services  
  24. running: dhcpd -t -q  
  25. received on stdout:   
  26. received on stderr:   
  27. running: service dhcpd restart  
  28. received on stdout:   
  29. received on stderr: Redirecting to /bin/systemctl restart dhcpd.service  
  30.   
  31. running shell triggers from /var/lib/cobbler/triggers/sync/post/*  
  32. running python triggers from /var/lib/cobbler/triggers/change/*  
  33. running python trigger cobbler.modules.manage_genders  
  34. running python trigger cobbler.modules.scm_track  
  35. running shell triggers from /var/lib/cobbler/triggers/change/*  
  36. *** TASK COMPLETE ***  
  37. [root@cobbler ~]  
2.8检查DHCP
  1. [root@cobbler ~]# netstat -lnup|grep dhcp  
  2. udp        0      0 0.0.0.0:67              0.0.0.0:*                           10334/dhcpd           
  3. [root@cobbler ~]  
2.9导入镜像

Cobbler服务器上导入镜像文件:

  1. [root@cobbler /]# mount -t iso9660 /dev/cdrom /mnt/  
  2. mount: /dev/sr0 写保护,将以只读方式挂载  
  3. [root@cobbler /]  
  1. [root@cobbler /]# cobbler import --name="centos7-x86_64" --path=/mnt/  
  2. task started: 2023-10-12_140348_import  
  3. task started (id=Media importtime=Thu Oct 12 14:03:48 2023)  
  4. Found a candidate signature: breed=suse, version=opensuse15.0  
  5. Found a candidate signature: breed=suse, version=opensuse15.1  
  6. Found a candidate signature: breed=redhat, version=rhel6  
  7. Found a matching signature: breed=redhat, version=rhel6  
  8. Adding distros from path /var/www/cobbler/ks_mirror/centos7-x86_64:  
  9. creating new distro: centos7-x86_64  
  10. trying symlink: /var/www/cobbler/ks_mirror/centos7-x86_64 -> /var/www/cobbler/links/centos7-x86_64  
  11. creating new profile: centos7-x86_64  
  12. associating repos  
  13. checking for rsync repo(s)  
  14. checking for rhn repo(s)  
  15. checking for yum repo(s)  
  16. starting descent into /var/www/cobbler/ks_mirror/centos7-x86_64 for centos7-x86_64  
  17. processing repo at : /var/www/cobbler/ks_mirror/centos7-x86_64  
  18. need to process repo/comps: /var/www/cobbler/ks_mirror/centos7-x86_64  
  19. looking for /var/www/cobbler/ks_mirror/centos7-x86_64/repodata/*comps*.xml  
  20. Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7-x86_64/repodata  
  21. *** TASK COMPLETE ***  
  22. [root@cobbler /]  
  1. [root@cobbler /]# cobbler list  
  2. distros:  
  3.    centos7-x86_64  
  4.   
  5. profiles:  
  6.    centos7-x86_64  
  7.   
  8. systems:  
  9.   
  10. repos:  
  11.   
  12. images:  
  13.   
  14. mgmtclasses:  
  15.   
  16. packages:  
  17.   
  18. files:  
  19. [root@cobbler /]  

3.自动安装系统

新建虚拟机环境,网络模式设置和cobbler服务器一致,然后点开机按钮,进行自动安装:

CENTOS7下部署Cobbler实现自动化安装LINUX系统
CENTOS7下部署Cobbler实现自动化安装LINUX系统
moonrong
  • 版权声明:本站原创文章,于2023年10月13日09:49:32,由 发表,共 9240 字。
  • 版权声明: 本文由于2023年10月13日09:49:32 发表在 好派笔记,共 9240 字。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: