自动化部署Centos7系统,基于cobbler

1. 先安装cobbler和dhcp包

[root@centos ~]#yum install -y cobbler dhcp

2. 启动 cobbler httpd tftp 服务

[root@centos ~]#systemctl start cobblerd httpd tftp

3. 命令行输入cobbler check 会提示你修改哪些配置文件,我们只需要修改 1,2,4,8 选项即可

[root@centos ~]#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-phrase-here' '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

Restart cobblerd and then run 'cobbler sync' to apply changes.

4. 打开配置文件vim /etc/cobbler/settings 进行修改

第278行 next_server: 192.168.8.100   #修改为本机的IP地址

第390行 server: 92.168.8.100     #修改为本机的IP地址

第242行 manage_dhcp: 1      #修改为1

第101行 default_password_crypted: "$1$GRNAdUcK$q2bSFPQ/iEcKKx3NZXaTk/" 将密码替换为自己的
密码生成方式:
[root@centos ~]#openssl passwd -1 

5. 修改好后重启 cobbler 服务

[root@centos ~]#systemctl restart cobblerd

6. 修改 vim /etc/cobbler/dhcp.template 文件 ,利用cobbler自动生成DHCP配置文件

 21 subnet 192.168.8.0 netmask 255.255.255.0 {      #将IP地址修改为自己的范围
 22      option routers             192.168.8.2;    #修改为路由
 23      option domain-name-servers 192.168.8.2;    #修改域名
 24      option subnet-mask         255.255.255.0;
 25      range dynamic-bootp        192.168.8.100 192.168.8.254;    #修改DHCP获取地址范围

7. 下载cobbler需要的文件

[root@centos ~]#cobbler get-loaders

task started: 2020-05-05_132356_get_loaders
task started (id=Download Bootloader Content, time=Tue May  5 13:23:56 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 ***

8. 同步cobbler的配置文件

[root@centos ~]#cobbler sync

#查看同步的文件在tftp的共享目录里/var/lib/tftpboot/

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

9. 导入光盘yum源文件

[root@centos ~]#cobbler import --path=/misc/cd --name=Centos7.6-x86_64 --arch=x86_64

--path= #自己光盘挂载的路径
--name= #这个名字自定义
--arch= #是什么架构的

#查看是否成功
[root@centos ~]#ls /var/www/cobbler/ks_mirror/
Centos7.6-x86_64  config 

#完成之后就可以启动电脑了

10. 启动电脑或虚拟机后可以看到以下界面就证明我们的自动化安装系统配置已经成功了

QQ浏览器截图20200505135249.png

如果自带的应答文件不满意可以自定义

1. 以下文件是我自己制作好的,如果不满足需求可自行更改

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --plaintext centos
# Use network installation
url --url=$tree
# 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
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --append="net.ifnames=0" --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
part / --fstype="xfs" --size=100000
part /boot --fstype="xfs" --size=1000
part swap --fstype="swap" --size=2000

%packages
@^minimal
@core
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

2. 需要把上面做好的应答文件做关联

把应答文件复制到/var/lib/cobbler/kickstarts/这个目录下

[root@centos ~]#cp ks-mini.cfg /var/lib/cobbler/kickstarts/

[root@centos ~]#cd /var/lib/cobbler/kickstarts/

[root@centos kickstarts]#ls
default.ks    install_profiles  pxerescue.ks         sample_esx4.ks   sample_esxi6.ks  sample.seed
esxi4-ks.cfg  ks-mini.cfg       sample_autoyast.xml  sample_esxi4.ks  sample.ks        sample.seed.28
esxi5-ks.cfg  legacy.ks         sample_end.ks        sample_esxi5.ks  sample_old.seed

3. 添加我们自己的 ks-mini.cfg 文件

[root@centos kickstarts]#cobbler profile add --name Centos7.6-x86_64_Mini --distro=Centos7.6-x86_64 --kickstart=/var/lib/cobbler/kickstarts/ks-mini.cfg

--name #名字自定义
--distro= #添加好的Centos7的源文件 #如何查看添加好的Centos7的源文件[root@centos ~]#cobbler distro list

[root@centos kickstarts]#cobbler profile list
   Centos7.6-x86_64     #这是自带的
   Centos7.6-x86_64_Mini    #这是我们自己添加的

4. 可以看见我们添加好的ks-mini.cfg文件菜单

QQ浏览器截图20200505143245.png

5. 如果不想要自带的菜单可以删除

[root@centos kickstarts]#cobbler profile remove --name=Centos7.6-x86_64

[root@centos kickstarts]#cobbler profile list
 Centos7.6-x86_64_Mini      #就剩我们自己制作的ks-mini.cfg文件了

QQ浏览器截图20200505143800.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,830评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,992评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,875评论 0 331
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,837评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,734评论 5 360
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,091评论 1 277
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,550评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,217评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,368评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,298评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,350评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,027评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,623评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,706评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,940评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,349评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,936评论 2 341