cobbler实现自动化安装centos7,8

Posted 初如

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cobbler实现自动化安装centos7,8相关的知识,希望对你有一定的参考价值。

cobbler在centos7上有。操作是在centos7上实现自动化安装centos7.centos8。

安装软件包:
yum -y install httpd dhcp tftp cobbler pykickstart

配置tftp文件:

[root@centos7 ~]# vim /etc/xinetd.d/tftp

设置开机自启服务

[root@centos7 ~]# systemctl enable --now cobblerd httpd tftp

关闭防火墙

[root@centos7 ~]# systemctl disable --now firewalld

关闭selinux,修改配置后需要重启生效

[root@centos7 ~]# sed -i.bak 's/SELINUX=enforcing/SELINUX=disbale/' /etc/selinux/config

下载启动的相关文件

[root@centos7 ~]#cobbler get-loaders
[root@centos7 ~]# tree /var/lib/cobbler/loaders
/var/lib/cobbler/loaders
├── COPYING.elilo
├── COPYING.syslinux
├── COPYING.yaboot
├── elilo-ia64.efi
├── grub-x86_64.efi
├── grub-x86.efi
├── menu.c32
├── pxelinux.0
├── README
└── yaboot

挂载镜像,挂载为临时挂载,永久挂载需要修改/etc/fstab文件

mount /var/www/html/centos/7/os/x86_64 sr0
mount /var/www/html/centos/8/os/x86_64 sr1

配置kickstart文件如下:
#kickstart文件根据需求修改配置

[root@centos7 ~]# cat /var/lib/cobbler/kickstarts/centos7.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$q5Pk1Nrl$7TnrxuOYclFOTKVo0/rtE1
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled


# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=eth0 --activate
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://10.0.0.70/cobbler/ks_mirror/centos-7.7-x86_64"
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --linux --initlabel
# Disk partitioning information
part / --fstype="xfs" --size=102400
part /boot --fstype="xfs" --size=1024
part swap --fstype="swap" --size=2048
part /data --fstype="xfs" --size=50000

%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

#安装后操作
%post 
useradd he 
echo 123456 | passwd --stdin
yum -y install bash-completion
%end

导入yum源的同时进行关联自定义的kickstart文件

cobbler import --name=centos-7.7-x86_64 --path=/var/www/html/centos/7/os/x86_64 --arch=x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.cfg


cobbler import --name=centos-8.1-x86_64 --path=/var/www/html/centos/7/os/x86_64 --arch=x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos8.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@centos7 ~]#cobbler profile remove --name=centos-8.1-x86_64
[root@centos7 ~]#cobbler profile remove --name=centos-7.7-x86_64
[root@centos7 ~]#cobbler profile list
   CentOS-7.7_test
   CentOS-8.1_test

修改dhcp配置

[root@centos7 ~]# cobbler sync 同步cobbler配置修改dhcp文件
[root@centos7 ~]# cat /etc/dhcp/dhcpd.conf 
ddns-update-style interim;
allow booting;
allow bootp;
ignore client-updates;
set vendorclass = option vendor-class-identifier;

option pxe-system-type code 93 = unsigned integer 16;
#根据自己搭建情况修改如下
subnet 10.0.0.0 netmask 255.255.255.0    网段
     option routers             10.0.0.2; 网关
     option domain-name-servers 223.5.5.5; dns
     option subnet-mask         255.255.255.0; 子网掩码
     range dynamic-bootp        10.0.0.160 10.0.0.170; dhcp分配ip访问
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                10.0.0.70; 指定tftp服务器
   class "pxeclients" 
          match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
          if option pxe-system-type = 00:02 
                  filename "ia64/elilo.efi";
           else if option pxe-system-type = 00:06 
                  filename "grub/grub-x86.efi";
           else if option pxe-system-type = 00:07 
                  filename "grub/grub-x86_64.efi";
           else if option pxe-system-type = 00:09 
                  filename "grub/grub-x86_64.efi";
           else 
                  filename "pxelinux.0";
          
     



启动dhcp服务器
[root@centos7 ~]# systemctl enable --now dhcpd
[root@centos7 ~]# cobbler check                             cobbler配置检查

测试客户端基于cobbler实现自动安装

以上是关于cobbler实现自动化安装centos7,8的主要内容,如果未能解决你的问题,请参考以下文章

cobbler实现自动化安装centos7,8

centos7 cobbler 自动化部署安装系统

CentOS7实现Cobbler自动装机

CentOS7使用cobbler实现自动装机服务

Cobbler自动化安装Centos7系统

自动化运维之cobbler安装centos7.3