Linux服务之cobbler批量部署篇
一、Cobbler简介:
Cobbler通过将设置和管理一个安装服务器所涉及的任务集中在一起,从而简化了系统配置。相当于Cobbler封装了DHCP、TFTP、XINTED等服务,结合了PXE、kickstart等安装方法,可以实现自动化安装操作系统,并且可以同时提供多种版本,以实现在线安装不同版本的系统。
1.1 cobbler相关服务
DHCP:DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)是一个局域网的网络协议,使用UDP协议工作, 主要有两个用途:给内部网络或网络服务供应商自动分配IP地址,给用户或者内部网络管理员作为对所有计算机作中央管理的手段。DHCP有3个端口,其中UDP67和UDP68为正常的DHCP服务端口,分别作为DHCP Server和DHCP Client的服务端口;546号端口用于DHCPv6 Client,而不用于DHCPv4,是为DHCP failover服务,这是需要特别开启的服务,DHCP failover是用来做“双机热备”的。
TFTP:TFTP是一种比较特殊的文件传输协议。相对于FTP和目前经常使用的SFTP,TFTP是基于TCP/IP协议簇,用于进行简单文件传输,提供简单、低开销的传输服务。TFTP的端口设置为69。
相对于常见的FTP,TFTP有两个比较好的优势:
1.TFTP基于UDP协议,如果环境中没有TCP协议,是比较合适的;
2.TFTP执行和代码占用内存量比较小;
默认情况下,Linux内部是安装了tftp服务器包的。但是默认是不启动的。
PXE:预启动执行环境(Preboot eXecution Environment,PXE,也被称为预执行环境)提供了一种使用网络接口(Network Interface)启动计算机的机制。这种机制让计算机的启动可以不依赖本地数据存储设备(如硬盘)或本地已安装的操作系统。
PXE当初是作为Intel的有线管理体系的一部分,Intel 和 Systemsoft于1999年9月20日公布其规格(版本2.1)[1]。通过使用像网际协议(IP)、用户数据报协议(UDP)、动态主机设定协定(DHCP)、小型文件传输协议(TFTP)等几种网络协议和全局唯一标识符(GUID)、通用网络驱动接口(UNDI)、通用唯一识别码(UUID)的概念并通过对客户机(通过PXE自检的电脑)固件扩展预设的API来实现目的。
二、交互过程:
1.裸机配置了从网络启动后,开机后会广播包请求DHCP服务器(cobbler server)发送其分配好的一个IP
2.DHCP服务器(cobbler server)收到请求后发送responese,包括其ip地址
3.裸机拿到ip后再向cobbler server发送请求OS引导文件的请求
4.cobbler server告诉裸机OS引导文件的名字和TFTP server的ip和port
5.裸机通过上面告知的TFTP server地址和port通信,下载引导文件
6.裸机执行执行该引导文件,确定加载信息,选择要安装的os,期间会再向cobbler server请求kickstart文件和os image
7.cobbler server发送请求的kickstart和os iamge
8.裸机加载kickstart文件
9.裸机接收os image,安装该os image
系统环境准备及其下载cobbler
2.1 系统环境
开启两个网卡。一个仅主机模式,一个桥接模式,主机模式对内提供cobbler服务。
[root@wusir ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:13:a1:49 brd ff:ff:ff:ff:ff:ff
inet 192.168.4.190/24 brd 192.168.4.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe13:a149/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:13:a1:53 brd ff:ff:ff:ff:ff:ff
inet 192.168.182.128/24 brd 192.168.182.255 scope global noprefixroute dynamic eth1
valid_lft 1786sec preferred_lft 1786sec
inet6 fe80::7073:2021:e866:204f/64 scope link noprefixroute
valid_lft forever preferred_lft forever
系统版本:CentOS Linux release 7.5.1804 (Core)
内网IP:192.168.182.128/24 #用来对内通信,提供cobbler服务
外网IP:192.168.4.190/24 #连接外网
2.2 关闭安全服务
[root@wusir ~]# systemctl stop firewalld #关闭防火墙
[root@wusir ~]# setenforce 0 #关闭selinux
2.3 下载cobbler及其所需服务程序
[root@wusir ~]# yum install cobbler dhcp tftp-server xinetd syslinux httpd -y
syslinux: 提供pxelinux.0这个文件 ,pxelinux.0引导文件引导vmlinux和initrd两个启动文件
yum安装cobbler需要使用下面两个源,大家可以复制下面的代码到自己的yum仓库保存即可
[epel]
name=epel
enabled=1
gpgcheck=0
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
[centos]
name=centos base
enabled=1
gpgcheck=0
baseurl=http://mirrors.163.com/centos/7/os/x86_64/
三、配置相关服务
第一步:配置DHCP服务
[root@wusir ~]# cat /etc/dhcp/dhcpd.conf
subnet 192.168.182.0 netmask 255.255.255.0 {
range 192.168.182.150 192.168.182.155;
default-lease-time 600;
max-lease-time 7200;
filename "pxelinux.0";
}
[root@wusir ~]# systemctl restart dhcpd
第二步:配置tftp
[root@wusir ~]# cat /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no #yes改为no
per_source = 11
cps = 100 2
flags = IPv4
}
[root@wusir ~]# systemctl restart xinetd
第三步:启动cobbler
[root@wusir ~]# systemctl status cobblerd
第四步:启动httpd
[root@wusir ~]# systemctl restart httpd
第五步:检查cobbler配置
[root@wusir ~]# 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 : 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.
4 : enable and start rsyncd.service with systemctl
5 : debmirror package is not installed, it will be required to manage debian deployments and repositories
6 : 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
7 : 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.
根据如上反馈,需要一一进行修改才能继续进行
修改配置文件/etc/cobbler/settings
问题一:
cobbler文件默认是127.0.0.1本地回环地址,需要更改为提供cobbler服务的ip地址 192.168.182.128,在384行
384 server: 192.168.182.128
问题二:
netx_server也是默认本地127.0.0.1回环地址,需要修改为提供cobbler服务的ip地址 192.163.182,128,在272行出
272 next_server: 192.168.182.128
问题三:
可以忽略
问题四:
启动rsync即可
[root@wusir ~]# systemctl restart rsyncd
[root@wusir ~]# systemctl enable rsyncd
问题五:
可以忽略
问题六:
更改密码
[root@wusir ~]# openssl passwd -1 -salt "123" "123456"
$1$123$7mft0jKnzzvAdU4t0unTG1
并把新生成的加密数据填写进/etc/cobbler/settings
101 default_password_crypted: “$1$123$7mft0jKnzzvAdU4t0unTG1”
问题七:
可以忽略
以上问题解决之后,需要同步和重启
[root@wusir ~]# systemctl restart cobblerd
[root@wusir ~]# cobbler sync
再次检查是否已经更改完成
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
[root@wusir ~]# cobbler check
The following are potential configuration items that you may want to fix:
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 : debmirror package is not installed, it will be required to manage debian deployments and repositories
3 : 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.
已经更改完毕!
第六步:挂载光盘并进行数据导入
挂载光盘
[root@wusir ~]# mount /dev/cdrom /mnt
数据导入(需要一些时间)
[root@wusir ~]# cobbler import --path=/mnt --name="centos7.5"
task started: 2019-03-13_001927_import
task started (id=Media import, time=Wed Mar 13 00:19:27 2019)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=rhel7
Found a matching signature: breed=redhat, version=rhel7
Adding distros from path /var/www/cobbler/ks_mirror/centos7.5:
creating new distro: centos7.5-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos7.5 -> /var/www/cobbler/links/centos7.5-x86_64
creating new profile: centos7.5-x86_64
associating repos
checking for rsync repo(s)
checking for rhn repo(s)
checking for yum repo(s)
starting descent into /var/www/cobbler/ks_mirror/centos7.5 for centos7.5-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos7.5
need to process repo/comps: /var/www/cobbler/ks_mirror/centos7.5
looking for /var/www/cobbler/ks_mirror/centos7.5/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7.5/repodata
*** TASK COMPLETE ***
查看distro
[root@ken ~]# cobbler distro list
centos7.5-x86_64
查看profile
[root@wusir ~]# cobbler profile list
centos7.5-x86_64
distro : 发行版, 就是我们安装什么版本的linux操作系统的名称 一会我们会导入一个 distro.
profile : 类似于一个 配置文件,类似于你的 bash_profile, 里面包含你可以添加 kernel 参数,对应的kickstart 文件 以及 此profile 对应的 distro 等等.
第七步:准备kickstart文件
在root目录下找到ks文件,并移动到/var/lib/cobbler/kickstarts/到目录下改名为ks.cfg
[root@wusir ~]# mv anaconda-ks.cfg /var/lib/cobbler/kickstarts/ks.cfg
[root@wusir ~]# vim /var/lib/cobbler/kickstarts/ks.cfg
[root@wusir ~]# cat /var/lib/cobbler/kickstarts/ks.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
url --url=http://192.168.182.128/cobbler/ks_mirror/centos7.5/ #这里需要更改为repodata所在的http地址
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
# Network information
network --bootproto=dhcp --device=ens33 --ipv6=auto --no-activate
network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted $6$7zu1wIUDgBGEFV1Y$KsLVeaGmyN92.QHr1fqKdTqPu8PDmd8K9V/s3Ru8NxE53NZz4gQKsmP6K0udcXVvDtponekICYUwBD7tYZJqU/
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel
%packages
@^minimal
@core
%end
%addon com_redhat_kdump --disable --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
第八步:自定义profile
[root@wusir ~]# cobbler profile add --distro=centos7.5-x86_64 --name=centos7.5_ken --kickstart=/var/lib/cobbler/kickstarts/ks.cfg
[root@wusir ~]# cobbler sync
task started: 2019-03-13_002724_sync
task started (id=Sync, time=Wed Mar 13 00:27:24 2019)
running pre-sync triggers
cleaning trees
removing: /var/www/cobbler/images/centos7.5-x86_64
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/images
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/images/centos7.5-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
copying distros to tftpboot
copying files for distro: centos7.5-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos7.5/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos7.5-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos7.5/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos7.5-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: centos7.5-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos7.5/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos7.5-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos7.5/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos7.5-x86_64/initrd.img
Writing template files for centos7.5-x86_64
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos7.5-x86_64
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 ***
第九步:查看profile
[root@wusir ~]# cobbler profile list
centos7.5-x86_64
centos7.5_ken
第十步:删除不包含ks文件的profile
[root@wusir ~]# cobbler profile remove --name=centos7.5-x86_64
[root@wusir ~]# cobbler profile list
centos7.5_ken
四、cobbler自动化安装测试
新建一个虚拟机,需要和cobbler服务器所在同一个虚拟网络中即与我们上面设置的cobbler服务器的主机模式。内存需要3个G以上。
Linux服务之cobbler批量部署篇的更多相关文章
- 使用Cobbler批量部署Linux和Windows:Cobbler服务端部署(一)
本文记录了我使用Cobbler批量安装部署Linux和Windows系统的过程,文章主要分为三部分:Cobbler服务端的安装配置.Linux发行版CentOS和Ubuntu的自动安装部署.Windo ...
- (转)使用Cobbler批量部署Linux和Windows:Cobbler服务端部署(一)
原文:http://www.cnblogs.com/pluse/p/8316914.html http://blog.51cto.com/dreamway/1166589---------Cobble ...
- Linux服务之批量部署篇
批量部署步骤: 1.检查环境 getenforce #检查内核防火墙是否关闭 systemctl status firewalld #检查firewalld是否 ...
- Cobbler批量部署CentOS
简介 Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows.该工具使用python开发,小巧轻便(才15k行python代码),使用简单的命令即可完成PXE ...
- shell应用之cobbler批量部署
如果使用的是原始源,可直接使用该脚本,如果是用的其它源且有cobbler安装包的可删除脚本中的配置yum源步骤.批量部署使用的软件有:cobbler dhcp httpd tftp-server xi ...
- 使用Cobbler批量部署Linux和Windows:Windows系统批量安装(三)
Tutorial: Installing Windows with cobbler (cobbler安装Windows) Windows系统的自动安装需要用到Win PE工具.流程如下: 定制Win ...
- 使用Cobbler批量部署Linux和Windows:CentOS/Ubuntu批量安装(二)
通过前面服务端的部署,已经配置好了 Cobbler Server 端,接下来开始进行 CentOS/Ubuntu 的批量安装,在进行 CentOS/Ubuntu 批量安装时,也需要通过Cobbler来 ...
- linux服务之ntp与dns篇
ntp复习: 简介:对于计算机时间的同步管理操作服务器 部署:(服务端和客户端或者说集群) 1.服务端下载ntp 2.打开配置文件/etc/ntp.conf: server 127.127.1.0 ...
- Linux记录-shell自动化批量部署sql脚本并记录日志信息(转载)
#!/bin/bash #script_version=v110 db_host=127.0.0.1 db_port=3306 db_username=db_test_inst db_passwd=` ...
随机推荐
- IDEA通过Maven打包JavaFX工程(OpenJFX11)
1 概述 最近研究JFX,写出来了但是打包不了,这...尴尬... IDEA的文档说只支持Java8打成jar包: 尝试过直接使用Maven插件的package,不行,也尝试过Build Artifa ...
- Kubernetes 降本增效标准指南 | 基于K8s 扩展机制构建云上成本控制系统
作者 王玉君,腾讯云后台高级开发工程师,负责腾讯云原生系统开发及建设. 晏子怡,腾讯云容器产品经理,在K8s弹性伸缩.资源管理领域有丰富的实战经验. 导语 Kubernetes 作为 IaaS 和 P ...
- Webpack的理解以及解决了的问题
一.背景 Webpack 最初的目标是实现前端项目的模块化,旨在更高效地管理和维护项目中的每一个资源 模块化 最早的时候,我们会通过文件划分的形式实现模块化,也就是将每个功能及其相关状态数据各自单独放 ...
- 你已经用上 5G 网络了吗?
随着各大手机厂商陆续推出 5G 手机,智能手机全面迎来 5G 浪潮.可能有人会发问:如此推崇 5G,5G 能为我们带来什么,我们的生活又会因此而改变多大呢? 什么是 5G? 简单地说,5G 就是第五代 ...
- shellcode隐写到像素RGB免杀上线到CS
利用把Shellcode隐写到图片像素RGB进行免杀上线到CS --by:chenw 0x01 前言 前几天跟一个朋友一起搞一个站的时候,发现那个站点开了很多杀软,使用CS的powershell马无法 ...
- java面试一日一题:讲下mysql中的undolog
问题:请讲下mysql中undo log的作用 分析:mysql中有很多日志,例,bin log undo log redo log,要弄清楚这些日志的作用,就要了解这些日志出现的背景及要解决的问题: ...
- hdu1572 水搜索
题意: 中文的不解释; 思路: 其实就是一个水的搜索,直接搜索不会超时,还有别跑最短路了,题目没要求跑最短路,别读错题,刚开始自己嘚嗖的跑了一边最短路 wa了 ,正好最近看了STL ...
- PAT 乙级 -- 1002 -- 写出这个数
题目: 读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字. 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值.这里保证n小于10100. 输出格式:在一行内输出n的各位数字 ...
- 反编译APP
反编译APP 有两种反编译工具:dex2jar 和 apktool,两个工具反编译的效果是不一样的,dex2jar反编译出java源代码,apktool反编译出来的是java汇编代码. dex2jar ...
- 【js】Leetcode每日一题-叶子相似的树
[js]Leetcode每日一题-叶子相似的树 [题目描述] 请考虑一棵二叉树上所有的叶子,这些叶子的值按从左到右的顺序排列形成一个 叶值序列 . 举个例子,如上图所示,给定一棵叶值序列为 (6, 7 ...