5.1 问题
本例要求为新建虚拟机硬盘位20G,网络类型为“private1”操作系统为CentOS 7: 1. 虚拟机名设置为Cobbler
2. IP地址设置为:192.168.4.123/24
3. 关闭SELinux安全机制
4. 设置防火墙默认区域为trusted
5. 利用Cobbler部署CentOS 7与 RedHat 7双系统装机平台
5.2 方案
cobbler #cobbler程序包
cobbler-web #cobbler的web服务包
pykickstart #cobbler检查kickstart语法错误
httpd #Apache web服务
dhcp #Dhcp服务
tftp-server #tftp服务
5.3 步骤
实现此案例需要按照如下步骤进行。
步骤一:在虚拟机中解压cobbler.zip包 此cobbler.zip包,起初应该在真机上,可以通过scp命令传递到虚拟机。
1)将真机cobbler.zip包传递到虚拟机中/root目录下,注意真机cobbler.zip绝对路径
2)确认虚拟机中的目录内容
03. [root@svr7 ~]#
01. [root@room9pc01 桌面]# scp -r /root/桌面/Cobbler/ root@192.168.4.123:/root/
02. The authenticity of host '192.168.4.123 (192.168.4.123)' can't be established.
03. ECDSA key fingerprint is SHA256:TFNqSD+oJMsA88kLwSdLSKZhSigkQIIAfrXLdKoUaJA.
04. ECDSA key fingerprint is MD5:f9:b8:7d:8d:ca:4e:20:0d:10:c4:72:a5:9f:42:28:8e.
05. Are you sure you want to continue connecting (yes/no)? yes
06. Warning: Permanently added '192.168.4.123' (ECDSA) to the list of known hosts.
07. root@192.168.4.123's password:
08. cobbler_web.png 100% 78KB 6.7MB/s 00:00
09. cobbler.zip 100% 9781KB 61.1MB/s 00:00
10. cobbler_boot.tar.gz 100% 416KB 45.7MB/s 00:00
11. [root@room9pc01 桌面]#
Top
步骤二:搭建Yum仓库,安装Cobbler
1)将cobbler.zip包,解压缩到根目录下
2)搭建Yum仓库,利用yum安装所有rpm软件包
步骤三:设置防火墙与SELinux
1)设置防火墙默认区域为trusted
01. [root@cob ~]# ls /root/Cobbler/
02. cobbler_boot.tar.gz cobbler_web.png cobbler.zip
03. [root@cob ~]#
01. [root@cob ~]# unzip /root/Cobbler/cobbler.zip -d /
02. ……
03. [root@cob ~]# ls /cobbler/
04. ……
01. [root@cob ~]# mount /dev/cdrom /mnt/ #首先通过图形将CentOS光盘放入光驱设备
02. mount: /dev/sr0 写保护,将以只读方式挂载
03. [root@cob ~]# ls /mnt/
04. [root@cob ~]# rm -rf /etc/yum.repos.d/*
05. [root@cob ~]# vim /etc/yum.repos.d/dvd.repo
06. [CentOS7]
07. name=CentOS 7.4
08. baseurl=file:///mnt
09. enabled=1
10. gpgcheck=0
11. [root@cob ~]# yum repolist
12. ……
13. 源标识 源名称 状态
14. CentOS7 CentOS 7.4 3,894
15. repolist: 3,894
16. [root@cob ~]# yum -y install /cobbler/*.rpm
01. [root@cob ~]# firewall-cmd --set-default-zone=trusted Top
2)修改SELinux状态
步骤四:配置cobbler
1)修改配置文件/etc/cobbler/settings
2)配置cobbler的dhcp分配网段及IP地址范围
3)绝对路径解压cobbler_boot.tar.gz
步骤四:启动相关服务
01. [root@cob ~]# setenforce 0
02. [root@cob ~]# getenforce
03. Permissive
04. [root@cob ~]# vim /etc/selinux/config
05. ……
06. SELINUX=permissive
07. ……
01. [root@cob ~]# vim /etc/cobbler/settings
02. ……
03. next_server: 192.168.4.123 #设置下一个服务器还为本机
04. server: 192.168.4.123 #设置本机为cobbler服务器
05. manage_dhcp: 1 #设置cobbler管理dhcp服务
06. pxe_just_once: 1 #防止客户端重复安装操作系统,增加默认从本机硬盘启动菜单
01. [root@cob ~]# vim /etc/cobbler/dhcp.template
02.
03. ……
04.
05. :%s /192.168.1/192.168.4/g #将所有192.168.1替换为192.168.4
01. [root@cob ~]# tar -tf /root/Cobbler/cobbler_boot.tar.gz #众多的引导文件
02. ……
03. [root@cob ~]# tar -xPf /root/Cobbler/cobbler_boot.tar.gz
04. [root@cob ~]# ls /var/lib/cobbler/loaders/ #默认cobbler存放引导文件路径 Top
1)启动cobblerd主服务
2)启动httpd主服务,主要提供Web页面、装机光盘内容,ks应答文件等
3)启动tftp主服务,主要提供pxelinux.0、菜单文件等
4)启动rsyncd主服务,主要提供cobbler各个组件之间同步数据
步骤五:同步刷新cobbler所有配置
01. [root@cob ~]# systemctl restart cobblerd
02. [root@cob ~]# systemctl enable cobblerd
03. Created symlink from /etc/systemd/system/multi-user.target.wants/cobblerd.service to
01. [root@cob ~]# systemctl restart httpd
02. [root@cob ~]# systemctl enable httpd
03. Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /
01. [root@cob ~]# systemctl restart tftp
02. [root@cob ~]# systemctl enable tftp
03. Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/
01. [root@cob ~]# systemctl restart rsyncd
02. [root@cob ~]# systemctl enable rsyncd
03. Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to
01. [root@cob ~]# cobbler sync
02. task started: 2018-03-22_200534_sync
03. task started (id=Sync, time=Thu Mar 22 20:05:34 2018)
04. running pre-sync triggers
05. cleaning trees
06. removing: /var/lib/tftpboot/grub/images
07. copying bootloaders
Top
步骤六:导入系统光盘镜像数据
1)导入CentOS系统光盘镜像,cobbler默认提供ks应答文件,但应答文件为最小化安装,命令
格式:
cobbler import --path=挂载点 --name=导入系统命名 --arch=操作系统架构
cobbler导入的镜像放在:/var/www/cobbler/ks_mirror
08. copying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
09. copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
10. copying: /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
11. copying: /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
12. copying: /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
13. copying: /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64
14. copying distros to tftpboot
15. copying images
16. generating PXE configuration files
17. generating PXE menu structure
18. rendering DHCP files
19. generating /etc/dhcp/dhcpd.conf
20. rendering TFTPD files
21. generating /etc/xinetd.d/tftp
22. cleaning link caches
23. running post-sync triggers
24. running python triggers from /var/lib/cobbler/triggers/sync/post/*
25. running python trigger cobbler.modules.sync_post_restart_services
26. running: dhcpd -t -q
27. received on stdout:
28. received on stderr:
29. running: service dhcpd restart
30. received on stdout:
31. received on stderr: Redirecting to /bin/systemctl restart dhcpd.service
32.
33. running shell triggers from /var/lib/cobbler/triggers/sync/post/*
34. running python triggers from /var/lib/cobbler/triggers/change/*
35. running python trigger cobbler.modules.scm_track
36. running shell triggers from /var/lib/cobbler/triggers/change/*
37. *** TASK COMPLETE **
01. [root@cob ~]# cobbler import --path=/mnt --name=CentOS7 --arch=x86_64
02. task started: 2018-03-22_201215_import
Top
2)首先卸载光驱设备挂载,通过图形将光驱设备中的光盘,换成RHEL7光盘如图-1所示,导入
RHEL7系统光盘镜像,cobbler默认提供ks应答文件,但应答文件为最小化安装
图-1
03. task started (id=Media import, time=Thu Mar 22 20:12:15 2018)
04. ……
05. Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS7-x86_64/repodata
06. *** TASK COMPLETE ***
07. [root@cob ~]# ls /var/www/cobbler/ks_mirror/
08. CentOS7-x86_64 config
09. [root@cob ~]#
01. [root@cob ~]# umount /mnt/ #卸载光驱设备,将光盘换成RHEL7
01. [root@cob ~]# mount /dev/cdrom /mnt/
02. mount: /dev/sr0 写保护,将以只读方式挂载
03. [root@cob ~]# ls /mnt/
04. addons extra_files.json isolinux Packages RPM-GPG-KEY-redhat-release
05. EFI GPL LiveOS repodata TRANS.TBL
06. EULA images media.repo RPM-GPG-KEY-redhat-beta
07. [root@cob ~]# cobbler import --path=/mnt --name=RedHat --arch=x86_64
08. task started: 2018-03-22_202531_import
09. task started (id=Media import, time=Thu Mar 22 20:25:31 2018)
10. ……
11. Keeping repodata as-is :/var/www/cobbler/ks_mirror/RedHat-x86_64/addons/ResilientStorage
12. *** TASK COMPLETE ***
13. [root@cob ~]# ls /var/www/cobbler/ks_mirror/
14. CentOS7-x86_64 config RedHat-x86_64
15. [root@cob ~]# Top
步骤七:新建虚拟机测试
1)新建一台虚拟机测试:
选择pxe安装方式
注意如果安装CentOS系统虚拟机内容必须为2G以上,安装RedHat内存1G以上,硬盘均在9G以 上
测试虚拟机网络类型选择为:private1