部署Cobbler实现批量安装CentOS 7

一、环境准备

[root@master ~]# cat /etc/redhat-release

CentOS Linux release 7.7.1908 (Core)

[root@master ~]# uname -a

Linux master 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

[root@master ~]# ip addr

ens33:

inet 192.168.0.201/24 brd 192.168.0.255 scope global ens33

二、关闭防火墙和selinux

[root@master ~]# systemctl disable firewalld.service

[root@master ~]# systemctl stop firewalld.service

[root@master ~]# setenforce 0

[root@master ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

三、安装依赖包

[root@master ~]# yum -y install httpd dhcp tftp-server xinetd cobbler cobbler-web pykickstart

四、启动httpd服务

[root@master ~]# systemctl enable httpd

[root@master ~]# systemctl start httpd

五、启动cobbler服务

[root@master ~]# systemctl enable cobblerd

[root@master ~]# systemctl start cobblerd

六、检查cobbler启动状态

[root@master ~]# 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 : 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

8 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them Restart cobblerd and then run 'cobbler sync' to apply changes.

七、解决步骤六中的问题

1、“server”不能设置为“localhost”:

[root@master ~]# sed -i 's/server: 127.0.0.1/server: 192.168.0.201/g' /etc/cobbler/settings

2、“next_server”不能设置为“127.0.0.1”:

[root@master ~]# sed -i 's/next_server: 127.0.0.1/next_server: 192.168.0.201/g' /etc/cobbler/settings

3、要将/etc/xinetd.d/tftp中的“disable”由“yes”改为“no”。

4、提示需要运行“cobbler get-loaders”,运行需要一些时间:

[root@master ~]# cobbler get-loaders

task started: 2020-04-14_195348_get_loaders

task started (id=Download Bootloader Content, time=Tue Apr 14 19:53:48 2020)

……

*** TASK COMPLETE ***

5、需要启用rsyncd服务:

[root@master ~]# systemctl enable rsyncd

[root@master ~]# systemctl start rsyncd

6、Debian系统需要注意的安装包debmirror。此处不做处理。

7、需要修改“/etc/cobbler/settings”文件中“default_password_crypted”的值:

将密码加密(‘123456’将会作为新安装操作系统的root用户密码):

[root@master ~]# openssl passwd -1 -salt 'cobbler' '123456'

$1$cobbler$sqDDOBeLKJVmxTCZr52/11

8、需要安装“cman” 或 “fence-agents”:

[root@master ~]# yum -y install fence-agents

八、 启动xinet服务

[root@master ~]# systemctl enable xinetd

[root@master ~]# systemctl start xinetd 

九、重启cobblerd并重新检查cobbler状态

[root@master ~]# systemctl restart cobblerd

[root@master ~]# cobbler check

十、配置DHCP服务

将由cobbler管理DHCP:

[root@master ~]# sed -i "s/manage_dhcp: 0/manage_dhcp: 1/g" /etc/cobbler/settings

编辑cobbler的DHCP模板:

cat /etc/cobbler/dhcp.template    #只显示需要的部分

subnet 192.168.0.0 netmask 255.255.255.0 {           # 192.168.0.0 指子网的网段

     option routers             192.168.0.1;                       # 192.168.0.1 指网关IP

     option domain-name-servers 223.5.5.5;               # 配置DNS

     option subnet-mask         255.255.255.0;             # 子网掩码

     range dynamic-bootp        192.168.0.205 192.168.0.210;    # 可分配的IP地址范围 

十一、同步cobbler配置

[root@master ~]# systemctl restart cobblerd

[root@master ~]# cobbler sync             # 过程中会生成dhcp.conf文件,并启动dhcpd服务

……

generating /etc/dhcp/dhcpd.conf

……

running: service dhcpd restart

十二、挂载cdrom

如果主机为VMWare虚拟机,需要注意虚拟机的光驱是否已经连接:

光驱.png

查看虚拟机的光驱是否已经连接

[root@master ~]# mount /dev/cdrom /mnt/

mount: /dev/sr0 写保护,将以只读方式挂载

十三、为cobbler导入CentOS 7系统镜像

[root@master ~]# cobbler import --name=CentOS-7-x86_64 --path=/mnt/ --arch=x86_64

查看导入的镜像:

[root@master ~]# cobbler distro list 

    CentOS-7-x86_64

[root@master ~]# cobbler report distro

十四、管理profile

导入镜像时,cobbler默认创建了同名profile,并为其指定了默认的kickstart文件“sample_end.ks”。

查看已有的profile:

[root@master ~]# cobbler profile list

    CentOS-7-x86_64

[root@master ~]# cobbler profile report

……

Kickstart : /var/lib/cobbler/kickstarts/sample_end.ks

……

自定义的kickstart文件:

[root@master ~]# cat /var/lib/cobbler/kickstarts/ks.cfg

# This kickstart file should only be used with EL > 5 and/or Fedora > 7.

# For older versions please use the sample.ks kickstart file.

# Install OS instead of upgrade

install

# Use text mode install

text

# System keyboard

keyboard us

# System language

lang en_US

# System timezone

timezone Asia/ShangHai

#Root password

rootpw --iscrypted $default_password_crypted

# System authorization information

auth --useshadow --enablemd5

# Firewall configuration

firewall --disabled

# SELinux configuration

selinux --disabled

# Use network installation

url --url=$tree


# Clear the Master Boot Record

zerombr

# System bootloader configuration

bootloader --location=gpt

# Partition clearing information

clearpart --all --initlabel

part /boot --fstype=xfs --size=500

part swap --fstype=swap --size=2048

part / --fstype=xfs --grow --size=1

# If any cobbler repo definitions were referenced in the kickstart profile, include them here.

$yum_repo_stanza

# Network information

$SNIPPET('network_config')

# Do not configure the X Window System

skipx

# Run the Setup Agent on first boot

firstboot --disable

# Reboot after installation

reboot


%pre

$SNIPPET('log_ks_pre')

$SNIPPET('kickstart_start')

$SNIPPET('pre_install_network_config')

# Enable installation monitoring

$SNIPPET('pre_anamon')

%end


%packages

$SNIPPET('func_install_if_enabled')

@core

%end


%post --nochroot

$SNIPPET('log_ks_post_nochroot')

%end


%post

$SNIPPET('log_ks_post')

# Start yum configuration

$yum_config_stanza

# End yum configuration

$SNIPPET('post_install_kernel_options')

$SNIPPET('post_install_network_config')

$SNIPPET('func_register_if_enabled')

$SNIPPET('download_config_files')

$SNIPPET('koan_environment')

$SNIPPET('redhat_register')

$SNIPPET('cobbler_register')

# Enable post-install boot notification

$SNIPPET('post_anamon')

# Start final steps

$SNIPPET('kickstart_done')

# End final steps


%end

将默认的“sample_end.ks”改为“ks.cfg”:

[root@master ~]# cobbler profile edit --name=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks.cfg

十五、最后执行一次sync

[root@master ~]# cobbler sync

十六、新建虚拟机进行测试

新建虚拟机:

新建虚拟机.png

新建虚拟机设置

huoquip.png

获取IP

十七、报错处理

安装过程中出现的“No space left on device”:

该问题由于虚拟机内存不足引起,在新建虚拟机时,将虚拟机内存调整到2G以上。


猜你喜欢

转载自blog.51cto.com/13568014/2495751