Cobbler_安装Ubuntu18.04.5

简介: 使用Cobbler 批量按照Linux 操作系统。

Cobbler 可以快速设置 网络安装环境,同时具备web管理界面,同时管理多个版本的操作系统。

cobbler 服务器环境:适用于Centos7.9以上的操作系统 CentOS-7-x86_64-DVD-2009.iso

系统镜像下载链接:http://isoredirect.centos.org/centos/7/isos/x86_64/

cobbler 软件版本: CentOS 7 可以按照 cobbler v2.8.5比较合适。

本次使用 CentOS 7.9 进行安装部署。

1. Cobbler 部署前准备

	#操作系统版本
	cat /etc/centos-release
	CentOS Linux release 7.9.2009 (Core)
	#关闭防火墙和selinux
	systemctl disable firewalld.service
	systemctl stop firewalld.service
	sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
	#在阿里云下载yum源: Base源 和 epel源 https://developer.aliyun.com/mirror/
	wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
	wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
	# 以上操作完成后重启一下 CentOS 7 : reboot

2. Cobbler 开始部署

	#Centos7(其余的软件会作为依赖安装)
	yum install -y dhcp cobbler cobbler-web debmirror pykickstart 
	#组件作用简介
	cobbler     #基础组件
	cobbler-web #web组件
	debmirror   #镜像管理工具
	pykickstart #检查cobbler配置文件语法
	httpd       #发布镜像
	syslinux    #配置引导文件(生成pxelinux.0)
	tftp-server #为PXE的客户端提供引导文件
	dhcp        #为PXE的客户端提供IP地址、告知tftp的服务地址

Cobbler 目录文件简介

rpm -ql cobbler
/etc/cobbler                  #配置文件目录
/etc/cobbler/settings         #cobbler主配置文件
/etc/cobbler/dhcp.template    #dhcp服务的配置模板
/etc/cobbler/tftpd.template   #tftp服务的配置模板
/etc/cobbler/rsync.template   #rsync服务的配置模板
/etc/cobbler/iso              #iso模板配置文件目录
/etc/cobbler/pxe              #pxe模板文件目录
/etc/cobbler/power            #电源的配置文件目录
/etc/cobbler/users.conf       #web服务授权配置文件
/etc/cobbler/users.digest     #用于web访问的用户名密码配置文件
/etc/cobbler/dnsmasq.template #dns服务的配置模板
/etc/cobbler/modules.conf     #cobbler模块配置文件
/var/lib/cobbler              #cobbler数据目录
/var/lib/cobbler/config       #配置文件
/var/lib/cobbler/kickstarts   #默认存放kickstart文件
/var/lib/cobbler/loaders      #存放的各种引导程序
/var/www/cobbler              #系统安装镜像目录
/var/www/cobbler/ks_mirror    #导入的系统镜像列表

Cobbler 主配置文件修改

####cobbler主配置文件修改
	vim /etc/cobbler/settings
	default_password_crypted: "$1$MJtVUpSN$7GvTgV5YO3NT1LZ7S2U0Q1"  #通过openssl passwd -1生成密文密码
	manage_dhcp: 0  #cobbler接管dhcp(0为关闭 1为开启)
	manage_tftpd: 1 #cobbler接管tftp(0为关闭 1为开启)
	next_server: 192.168.1.11  #tftp服务地址
	server: 192.168.1.11       #cobbler服务地址

#####cobbler启动服务
	systemctl enable --now httpd.service
	systemctl enable --now cobblerd.service

#####cobbler可以将自身作为dhcp服务器为安装系统的客户端分发IP地址、也可以使用已有的dhcp服务器
#####为了首次同步成功这里统一将cobbler接管dhcp的功能暂时关闭

Cobbler 首次检查

####可能每人的报错问题不同此处列举我的报错问题
	cobbler check
	1 : change 'disable' to 'no' in /etc/xinetd.d/tftp
	2 : 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. #可以忽略(确保系统已经安装selinux)
	3 : enable and start rsyncd.service with systemctl
	4 : comment out 'dists' on /etc/debmirror.conf for proper debian support
	5 : comment out 'arches' on /etc/debmirror.conf for proper debian support
	6 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them #可以忽略

解决Cobbler 检查报错

####报错1问题解决 tftp配置文件没有开启,编辑配置文件,开启即可。
	vim /etc/xinetd.d/tftp
	service tftp
	{
	        socket_type             = dgram
	        protocol                = udp
	        wait                    = yes 
	        user                    = root
	        server                  = /usr/sbin/in.tftpd
	        server_args             = -s /var/lib/tftpboot
	        disable                 = no #只修改这里
	        per_source              = 11
	        cps                     = 100 2
	        flags                   = IPv4
	}

####报错3问题解决 tftp 服务未启动。
	systemctl enable --now rsyncd.service

####报错3、4问题解决
	vim /etc/debmirror.conf
	# @dists="sid";    #注释这行信息
	# @arches="i386";  #注释这行信息 

Cobbler首次同步

####重启cobbler服务
	systemctl restart cobblerd.service

####再次运行检查
	cobbler check
	1 : 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.
	2 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them 

####cobbler首次同步
	cobbler sync

配置 DHCP 服务

cobbler 接管 DHCP

####修改dhcp模板文件
	vim /etc/cobbler/dhcp.template  
		subnet 192.168.0.0 netmask 255.255.255.0 {
		     option routers             192.168.0.112;
		     option domain-name-servers 192.168.0.112;
		     option subnet-mask         255.255.255.0;
		     range dynamic-bootp        192.168.0.120 192.168.0.200;
		     default-lease-time         21600;
		     max-lease-time             43200;
		     next-server                $next_server;


####cobbler主配置文件开启dhcp接管
	vim /etc/cobbler/settings  
	manage_dhcp: 1

####重新同步
	systemctl restart cobblerd.service
	cobbler sync 
####启动dhcp服务
	systemctl enable --now dhcpd.service 
	systemctl restart dhcpd.service

其他相关服务

配置tftp服务

#### 确保tftp的站点目录存在引导文件(cobbler检查问题的过程中已经修了tftp的配置文件)
	ll /var/lib/tftpboot/
	total 112
	drwxr-xr-x 3 root root    18 Aug 14 08:37 boot
	drwxr-xr-x 2 root root     6 Oct 14  2019 etc
	drwxr-xr-x 2 root root    81 Aug 14 08:37 grub
	drwxr-xr-x 4 root root    62 Aug 14 08:37 images
	drwxr-xr-x 2 root root     6 Oct 14  2019 images2
	-rw-r--r-- 2 root root 26140 Oct 30  2018 memdisk
	-rw-r--r-- 2 root root 55140 Oct 30  2018 menu.c32
	drwxr-xr-x 2 root root     6 Oct 14  2019 ppc
	-rw-r--r-- 2 root root 26759 Oct 30  2018 pxelinux.0
	drwxr-xr-x 2 root root    21 Aug 14 08:37 pxelinux.cfg
	drwxr-xr-x 2 root root    26 Aug 14 08:37 s390x

####启动tftp服务
	systemctl enable --now tftp.service 
	systemctl restart tftp.service 

#### 以上服务都启动后,可以尝试用虚拟机 PXE启动测试一下。

Cobbler 系统镜像挂载

####Ubuntu镜像注意事项
* 支持desktop、live版本(仅支持LTS server version版本)
* 推荐ubuntu-18.04.5-server-amd64.iso 

####使用光驱加载Centos6的系统镜像
####为后续cobble导入镜像做准备
	mount -t iso9660 -o loop,ro /dev/cdrom /mnt
	[root@localhost cobbler]# ls /dev/sr*
	/dev/sr0
	[root@localhost cobbler]# mount /dev/sr0  /mnt
	mount: /dev/sr0 is write-protected, mounting read-only

Cobbler 命令语法

##命令语法

	cobbler --help
	cobbler <distro|profile|system|repo|image|mgmtclass|package|file> ... 
	        [add|edit|copy|getks*|list|remove|rename|report] [options|--help]
	cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help]

Cobbler 自动应答文件编辑

#### 说明:以下的应答文件在物理机上面安装完全OK,物理机必须只有一块硬盘,网卡如果有多个则需要接显示器选择一下。其他的都不用选择。
#### 参考链接:https://blog.csdn.net/wanpengpenga/article/details/88119552
####		  https://blog.yangwn.top/index.php/archives/%E9%83%A8%E7%BD%B2Cobbler.html

	cd /var/lib/cobbler/kickstart/sample.seed
	# Mostly based on the Ubuntu installation guide
	# https://help.ubuntu.com/18.04/installation-guide/
	# Debian sample
	# https://www.debian.org/releases/stable/example-preseed.txt
	
	# Preseeding only locale sets language, country and locale.
	d-i debian-installer/locale string en_US.UTF-8  # 选择系统语言。
	
	# Keyboard selection.
	# Disable automatic (interactive) keymap detection.
	d-i console-setup/ask_detect boolean false
	d-i keyboard-configuration/xkb-keymap select us
	d-i keyboard-configuration/toggle select No toggling
	d-i keyboard-configuration/layoutcode string us
	d-i keyboard-configuration/variantcode string
	
	# netcfg will choose an interface that has link if possible. This makes it
	# skip displaying a list if there is more than one interface.
	#set $myhostname = $getVar('hostname',$getVar('name','cobbler')).replace("_","-")
	#d-i netcfg/choose_interface select auto
	#d-i netcfg/choose_interface select ens33
	#d-i netcfg/get_hostname string helmsman
	#d-i netcfg/choose_interface select auto
	#d-i netcfg/dhcp_failed note
	#d-i netcfg/dhcp_options select Do not configure the network at this time
	#d-i netcfg/get_hostname string keqi-server
	#d-i netcfg/get_domain string keqi-server
	d-i netcfg/enable boolea false
	
	# If non-free firmware is needed for the network or other hardware, you can
	# configure the installer to always try to load it, without prompting. Or
	# change to false to disable asking.
	# d-i hw-detect/load_firmware boolean true
	
	# NTP/Time Setup   #设置时区
	d-i time/zone string Asia/Shanghai
	d-i clock-setup/ntp-server string cn.pool.ntp.org
	d-i clock-setup/utc boolean true
	d-i clock-setup/ntp boolean true
	
	
	# Setup the installation source  #设置 服务端地址。
	d-i mirror/country string manual
	d-i mirror/http/hostname string $http_server
	d-i mirror/http/directory string $install_source_directory
	d-i mirror/http/proxy string
	
	#set $os_v = $getVar('os_version','')
	#if $breed == "ubuntu" and $os_v and $os_v.lower() != 'precise'
	# Required at least for ubuntu 12.10+ , so test os_v is not precise. Olders versions are not supported anymore
	d-i live-installer/net-image string http://$http_server/cobbler/links/$distro_name/install/filesystem.squashfs
	#end if
	
	# Suite to install.
	# d-i mirror/suite string precise
	# d-i mirror/udeb/suite string precise
	
	# Components to use for loading installer components (optional).
	#d-i mirror/udeb/components multiselect main, restricted
	
	# Disk Partitioning   # 磁盘分区问题,这里选择 LVM 自动分区。条件:必须只有一块硬盘作为系统盘,不能有其他硬盘。物理机安装正常。
	# Use LVM, and wipe out anything that already exists
	
	
	d-i partman-auto/disk string /dev/sda
	d-i partman-auto/choose_recipe select atomic
	d-i partman-auto/method string lvm
	d-i partman-auto-lvm/guided_size string 100%
	d-i partman-lvm/confirm boolean true
	d-i partman-lvm/confirm_nooverwrite boolean true
	d-i partman-lvm/device_remove_lvm boolean true
	d-i partman-md/device_remove_md boolean true
	d-i partman-partitioning/confirm_write_new_label boolean true
	d-i partman/choose_partition select finish
	d-i partman/confirm boolean true
	d-i partman/confirm_nooverwrite boolean true
	d-i partman/default_filesystem string ext4
	d-i partman/mount_style select uuid
	# You can choose one of the three predefined partitioning recipes:
	# - atomic: all files in one partition
	# - home:   separate /home partition
	# - multi:  separate /home, /usr, /var, and /tmp partitions
	d-i partman-auto/choose_recipe select atomic
	
	# If you just want to change the default filesystem from ext3 to something
	# else, you can do that without providing a full recipe.
	# d-i partman/default_filesystem string ext4
	
	# root account and password #设置 root 账户密码。在/etc/cobbler/settings 文件中定义,这里直接写也可以。
	d-i passwd/root-login boolean true
	d-i passwd/root-password-crypted password $default_password_crypted
	
	# skip creation of a normal user account.
	d-i passwd/make-user boolean false
	
	# You can choose to install restricted and universe software, or to install
	# software from the backports repository.
	d-i apt-setup/restricted boolean true
	d-i apt-setup/universe boolean true
	d-i apt-setup/backports boolean true
	
	# Uncomment this if you don't want to use a network mirror.
	# d-i apt-setup/use_mirror boolean false
	
	# Select which update services to use; define the mirrors to be used.
	# Values shown below are the normal defaults.
	d-i apt-setup/services-select multiselect security
	d-i apt-setup/security_host string mirrors.aliyun.com
	d-i apt-setup/security_path string /ubuntu
	
	$SNIPPET('preseed_apt_repo_config')
	
	# Enable deb-src lines
	# d-i apt-setup/local0/source boolean true
	
	# URL to the public key of the local repository; you must provide a key or
	# apt will complain about the unauthenticated repository and so the
	# sources.list line will be left commented out
	# d-i apt-setup/local0/key string http://local.server/key
	
	# By default the installer requires that repositories be authenticated
	# using a known gpg key. This setting can be used to disable that
	# authentication. Warning: Insecure, not recommended.
	# d-i debian-installer/allow_unauthenticated boolean true
	
	# Package selection
	# Default for minimal
	tasksel tasksel/first multiselect standard
	# Default for server
	# tasksel tasksel/first multiselect standard, web-server
	# Default for gnome-desktop
	# tasksel tasksel/first multiselect standard, gnome-desktop
	
	# Individual additional packages to install   #需要安装的软件,这里只安装了 ssh 和 vim
	# wget is REQUIRED otherwise quite a few things won't work
	# later in the build (like late-command scripts)
	d-i pkgsel/include string openssh-server vim 
	
	# Debian needs this for the installer to avoid any question for grub  # GRUP引导的安装,如果前面分区没有弄好,这也是不行的。
	# Please verify that it suit your needs as it may overwrite any usb stick
	#if $breed == "debian"
	d-i grub-installer/grub2_instead_of_grub_legacy boolean true
	d-i grub-installer/bootdev string /dev/sda
	#end if
	
	# Use the following option to add additional boot parameters for the
	# installed system (if supported by the bootloader installer).
	# Note: options passed to the installer will be added automatically.
	d-i debian-installer/add-kernel-opts string $kernel_options_post
	
	# Avoid that last message about the install being complete.
	d-i finish-install/reboot_in_progress note
	
	## Figure out if we're kickstarting a system or a profile
	#if $getVar('system_name','') != ''
	#set $what = "system"
	#else
	#set $what = "profile"
	#end if
	
	# This first command is run as early as possible, just after preseeding is read.
	# d-i preseed/early_command string [command]
	d-i preseed/early_command string wget -O- \
	   http://$http_server/cblr/svc/op/script/$what/$name/?script=preseed_early_default | \
	   /bin/sh -s
	
	# This command is run immediately before the partitioner starts. It may be
	# useful to apply dynamic partitioner preseeding that depends on the state
	# of the disks (which may not be visible when preseed/early_command runs).
	# d-i partman/early_command \
	#       string debconf-set partman-auto/disk "\$(list-devices disk | head -n1)"
	
	# This command is run just before the install finishes, but when there is
	# still a usable /target directory. You can chroot to /target and use it
	# directly, or use the apt-install and in-target commands to easily install
	# packages and run commands in the target system.
	# d-i preseed/late_command string [command]
	d-i preseed/late_command string wget -O- \
	   http://$http_server/cblr/svc/op/script/$what/$name/?script=preseed_late_default | \
	   chroot /target /bin/sh -s

Cobbler 导入镜像

####命令语法
	cobbler import --help
	Usage: cobbler import [options]
	Options:
	  --arch=ARCH           镜像架构
	  --path=PATH           镜像导入路径
	  --name=NAME           镜像名称

####命令操作
	cobbler import --name=Centos6 --arch=x86_64 --path=/mnt
	cobbler import --name=Centos7 --arch=x86_64 --path=/mnt
	cobbler import --name=Centos8 --arch=x86_64 --path=/mnt
	cobbler import --name=Ubuntu18 --arch=x86_64 --path=/mnt
	####导入镜像 第二种方式,直接关联 “自动应答文件”  ubuntu18045.seed
	cobbler import --path=/mnt/ubuntu --name=ubuntu-18.04.5 --kickstart=/var/lib/cobbler/kickstarts/ubuntu18045.seed --arch=x86_64	

####列出对象
	cobbler distro list
	cobbler profile list

####列出对象简单信息
	[root@localhost cobbler]# cobbler list
	distros:
	   Ubuntu18.04-hwe-x86_64
	   Ubuntu18.04-x86_64
	
	profiles:
	   Ubuntu18.04-hwe-x86_64
	   Ubuntu18.04-x86_64
	
	systems:
	
	repos:
	   Ubuntu18.04-x86_64

####列出对象详细信息
	[root@localhost cobbler]# cobbler profile report
	Name                           : Ubuntu18.04-x86_64
	TFTP Boot Files                : {}
	Comment                        : 
	DHCP Tag                       : default
	Distribution                   : Ubuntu18.04-x86_64
	Enable gPXE?                   : 0
	Enable PXE Menu?               : 1
	Fetchable Files                : {}
	Kernel Options                 : {}
	Kernel Options (Post Install)  : {}
	Kickstart                      : /var/lib/cobbler/kickstarts/ubuntu18.seed #自动应答文件。
	Kickstart Metadata             : {}
	Management Classes             : []
	Management Parameters          : <<inherit>>
	Name Servers                   : []
	Name Servers Search Path       : []
	Owners                         : ['admin']
	Parent Profile                 : 
	Internal proxy                 : 
	Red Hat Management Key         : <<inherit>>
	Red Hat Management Server      : <<inherit>>
	Repos                          : []
	Server Override                : <<inherit>>
	Template Files                 : {}
	Virt Auto Boot                 : 1
	Virt Bridge                    : xenbr0
	Virt CPUs                      : 1
	Virt Disk Driver Type          : raw
	Virt File Size(GB)             : 5
	Virt Path                      : 
	Virt RAM (MB)                  : 512
	Virt Type                      : kvm

cobbler 需要用到的配置文件


	[root@Cobbler ~]# ll /etc/cobbler/
	-rw-r--r-- 1 root root  3182 711 23:37 dhcp.template    #DHCP模板
	-rw-r--r-- 1 root root  1073 830 2019 rsync.template    #sync 同步 ,不用调试
	-rw-r--r-- 1 root root 19928 711 23:37 settings			# 主配置文件
	-rw-r--r-- 1 root root 19918 711 23:29 settings.bak		# 主配置文件备份
	-rw-r--r-- 1 root root   740 830 2019 tftpd.template		# tftp配置模板,可以直接去 /etc/xinetd.d/tftp 开启
	/var/lib/cobbler/kickstart/sample.seed #此目录主要放置 自动应答文件,CentOS 或者 Ubuntu 的模板都有。

避坑

#### 修改启动菜单配置文件
	#此文件可以更改选择系统时的菜单时间,有的服务器不会理会这个超时时间,20s不选择可能就自动卡死。
	vim /etc/cobbler/pxe/pxedefault.template  
	TIMEOUT 6000
	
#### cobbler重新同步
	# 每次更改了配置文件都需要 重启服务器并同步配置文件,否则不会生效。
	service restart cobblerd 
	cobbler sync

#### 导入一个系统镜像后会自动生成一个  xxxx-hwe-xxx 的文件,如下。 
#####这个文件会在选择系统的菜单出现,其实可以把他干掉的,方便选择系统。
	cobbler list 
	profiles:
	   Ubuntu18.04-hwe-x86_64
	   Ubuntu18.04-x86_64
	删除的命令:cobbler profile remove --name=ubuntu-18.04.5 --kickstart=/var/lib/cobbler/kickstarts/ubuntu18045.seed --arch=x86_64

你可能感兴趣的:(Linux,linux,centos,cobbler)