标签:CentOS lib centos7 cobbler 自动化 var root x86
(1)实验前需准备
两台主机 一台主机:CentOS 7 充当 Cobbler,http,dhcp,tftp 服务器,并关闭防火墙和SELinux 一台主机:充当测试机,用于实现自动化安装Linux系统 网络要求:关闭Vmware软件中的NAT模式中的DHCP服务,两个主机网卡基于NAT模式
(2)安装相关包并启动服务
[root@centos7 ~]#yum -y install cobbler dhcp httpd tftp --nogpgcheck [root@centos7 ~]#systemctl enable --now cobblerd httpd tftp dhcpd
#默认DHCP服务开启不成功,因为他的配置文件什么都没有
(3)修改cobbler相关的配置
[root@centos7 ~]#cobbler check 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/tftp 4 : 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 : enable and start rsyncd.service with systemctl 6 : debmirror package is not installed, it will be required to manage debian deployments and repositories 7 : ksvalidator was not found, install pykickstart 8 : 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-phrasehere' 'your-password-here'" to generate new one 9 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them #生成新密码,默认安装好的系统root密码为cobbler [root@centos7 ~]#openssl passwd -1 'magedu' $1$1spuisnh$j34LNmyTQWs3l6xKxCZY60 #根据以上提示,只需要做1,2,8这三项即可,修改下面四行 [root@centos7 ~]#vim /etc/cobbler/settings default_password_crypted: "$1$1spuisnh$j34LNmyTQWs3l6xKxCZY60" 278行:next_server:10.0.0.7 #< tftp服务器的 IP 地址> 390行:server:10.0.0.7 #<cobbler服务器的 IP 地址> 242行:manage_dhcp:1 #设置为1,表示通过cobbler生成dhcpd.conf配置文件 [root@centos7 ~]#systemctl restart cobblerd
(4)实现dhcp服务
#修改dhcp的模版文件下面的行,用来生成dhcp的配置文件 [root@centos7 ~]#vim /etc/cobbler/dhcp.template 21 subnet 10.0.0.0 netmask 255.255.255.0 { 22 option routers 10.0.0.2; 23 option domain-name-servers 180.76.76.76,223.6.6.6; 24 option subnet-mask 255.255.255.0; 25 range dynamic-bootp 10.0.0.50 10.0.0.100; 26 default-lease-time 21600; 27 max-lease-time 43200; 28 next-server $next_server;[root@centos7 ~]#cobbler sync [root@centos7 ~]#systemctl start dhcpd
(5)下载启动的相关文件
[root@centos7 ~]#cobbler get-loaders task started: 2020-02-10_163111_get_loaders task started (id=Download Bootloader Content, time=Mon Feb 10 16:31:11 2020) downloading https://cobbler.github.io/loaders/README to /var/lib/cobbler/loaders/README downloading https://cobbler.github.io/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo downloading https://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot downloading https://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux downloading https://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi downloading https://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yaboot downloading https://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0 downloading https://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32 downloading https://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi downloading https://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi *** TASK COMPLETE *** [root@centos7 ~]#ls /var/lib/cobbler/loaders COPYING.elilo COPYING.yaboot grub-x86_64.efi menu.c32 README COPYING.syslinux elilo-ia64.efi grub-x86.efi pxelinux.0 yaboot [root@centos7 ~]#tree /var/lib/tftpboot/ /var/lib/tftpboot/ ├── boot ├── etc ├── grub ├── images ├── images2 ├── ppc ├── pxelinux.cfg └── s390x 8 directories, 0 files [root@centos7 ~]#cobbler sync task started: 2020-02-10_163219_sync task started (id=Sync, time=Mon Feb 10 16:32:19 2020) running pre-sync triggers cleaning trees removing: /var/lib/tftpboot/grub/images copying bootloaders trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0 trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32 trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi copying distros to tftpboot copying images generating PXE configuration files generating PXE menu structure rendering TFTPD files generating /etc/xinetd.d/tftp cleaning link caches running post-sync triggers running python triggers from /var/lib/cobbler/triggers/sync/post/* running python trigger cobbler.modules.sync_post_restart_services running shell triggers from /var/lib/cobbler/triggers/sync/post/* running python triggers from /var/lib/cobbler/triggers/change/* running python trigger cobbler.modules.manage_genders running python trigger cobbler.modules.scm_track running shell triggers from /var/lib/cobbler/triggers/change/* *** TASK COMPLETE *** [root@centos7 ~]#tree /var/lib/tftpboot/ /var/lib/tftpboot/ ├── boot │ └── grub │ └── menu.lst ├── etc ├── grub │ ├── efidefault │ ├── grub-x86_64.efi │ ├── grub-x86.efi │ └── images -> ../images ├── images ├── images2 ├── memdisk ├── menu.c32 ├── ppc ├── pxelinux.0 ├── pxelinux.cfg │ └── default ├── s390x │ └── profile_list └── yaboot 10 directories, 10 files
(6)修改菜单的标题信息(可选)
[root@centos7 ~]#vim /etc/cobbler/pxe/pxedefault.template MENU TITLE Cobbler | http://www.magedu.com/ [root@centos7 ~]#cobbler sync [root@centos7 ~]#cat /var/lib/tftpboot/pxelinux.cfg/default DEFAULT menu PROMPT 0 MENU TITLE Cobbler | http://www.magedu.com/ #默认为:http://cobbler.github.io/ TIMEOUT 200 TOTALTIMEOUT 6000 ONTIMEOUT local LABEL local MENU LABEL (local) MENU DEFAULT LOCALBOOT -1 MENU end [root@centos7 ~]#cobbler sync
(7)导入CentOS系统的安装文件,生成相应的YUM源
加入ISO文件,并同步识别
[root@bogon ~]$lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 154G 0 part ├─centos_bogon-root 253:0 0 100G 0 lvm / ├─centos_bogon-swap 253:1 0 4G 0 lvm [SWAP] └─centos_bogon-data 253:2 0 50G 0 lvm /data sr0 11:0 1 7G 0 rom sr1 11:1 1 3.6G 0 rom sr2 11:2 1 9.6G 0 rom [root@bogon ~]$mkdir /mnt/centos7 [root@bogon ~]$mkdir /mnt/centos8 [root@bogon ~]$mkdir /mnt/centos6 [root@bogon ~]$mount /dev/sr0 /mnt/centos8 mount: /dev/sr0 is write-protected, mounting read-only [root@bogon ~]$mount /dev/sr2 /mnt/centos7 mount: /dev/sr2 is write-protected, mounting read-only [root@bogon ~]$mount /dev/sr1 /mnt/centos6 mount: /dev/sr1 is write-protected, mounting read-only [root@bogon ~]$cobbler import --name=centos-8.1-x86_64 --path=/mnt/centos8 --arch=x86_64 [root@bogon ~]$cobbler import --name=centos-6.10-x86_64 --path=/mnt/centos6 --arch=x86_64 [root@bogon ~]$cobbler import --name=centos-7.1-x86_64 --path=/mnt/centos7 --arch=x86_64 [root@centos7 ~]#du -sh /var/www/cobbler/ks_mirror/* 3.8G /var/www/cobbler/ks_mirror/centos-6.10-x86_64 9.6G /var/www/cobbler/ks_mirror/centos-7.1-x86_64 7.2G /var/www/cobbler/ks_mirror/centos-8.1-x86_64 16K /var/www/cobbler/ks_mirror/config [root@centos7 ~]#cobbler distro list centos-6.10-x86_64 centos-7.1-x86_64 centos-8.1-x86_64 [root@centos7 ~]#cobbler profile list centos-6.10-x86_64 centos-7.1-x86_64 centos-8.1-x86_64 #默认生成的是最小化安装
(8)准备 kickstart文件,并关联至指定的YUM源
[root@centos7 ~]#cd /var/lib/cobbler/kickstarts/ 将应答文件拷贝到本机上 [root@centos7 ~]#cat /var/lib/cobbler/kickstarts/centos8.cfg ignoredisk --only-use=sda zerombr text reboot clearpart --all --initlabel selinux --disabled firewall --disabled #修改第八行 url --url=$tree #注意此行必须指定 keyboard --vckeymap=us --xlayouts='us' lang en_US.UTF-8 network --bootproto=dhcp --device=ens160 --ipv6=auto --activate network --hostname=centos8.magedu.com rootpw --iscrypted $6$nOPs5JTMlP4mhQeW$R/o62B6SXAh3RR.zrZ3U0X4xYX9/u5nSLrR/vqCB6kdO2XFfMk2a4yAgrHJQ pXK/e4jzRb0jiLBv2nFMXaBjB/ firstboot --enable skipx services --disabled="chronyd" timezone Asia/Shanghai --isUtc --nontp user --name=wang -- password=$6$oUfb/02CWfLb5l8f$sgEZeR7c7DpqfpmFDH6huSmDbW1XQNR4qKl2EPns.gOXqlnAIgv 9pTogtFVaDtEpMOC.SWXKYqxfVtd9MCwxb1 --iscrypted --gecos="wang" part / --fstype="xfs" --ondisk=sda --size=102400 part /data --fstype="xfs" --ondisk=sda --size=51200 part swap --fstype="swap" --ondisk=sda --size=2048 part /boot --fstype="ext4" --ondisk=sda --size=1024 %packages @^minimal-environment kexec-tools %end %addon com_redhat_kdump --enable --reserve-mb='auto' %end %anaconda pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty %end #下面全部修改:url --url=$tree [root@bogon kickstarts]$vim centos8.cfg [root@bogon kickstarts]$vim centos7.cfg [root@bogon kickstarts]$vim centos6.cfg #将kickstart文件,关联指定的YUM源和生成菜单列表 [root@centos7 ~]#cobbler profile add --name=CentOS-8.1_test --distro=CentOS-8.1- x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos8.cfg [root@centos7 ~]#cobbler profile add --name=CentOS-7.7_test --distro=CentOS-7.7- x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg [root@bogon kickstarts]$cobbler profile add --name=CentOS-6.10_test --distro=CentOS-6.10-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos6.cfg #删除默认生成的菜单 [root@centos7 ~]#cobbler profile remove --name=centos-8.1-x86_64 [root@centos7 ~]#cobbler profile remove --name=centos-7.1-x86_64 [root@centos7 ~]#cobbler profile remove --name=centos-6.10-x86_64 [root@centos7 ~]#cobbler profile list CentOS-6.10_test CentOS-7.1_test CentOS-8.1_test
然后可以试一下是否能够安装成功啦
标签:CentOS,lib,centos7,cobbler,自动化,var,root,x86 来源: https://www.cnblogs.com/lidanyue/p/13020111.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。