分享交流
合作共赢!

基于Cobbler实现系统自动化安装

选定一台主机搭建Cobbler服务作为服务器,其他主机可通过PEX网络实现自动化安装系统。

网络要求:

  • 关闭VMware软件中的NAT模式中的DHCP服务
  • 两台主机网络基于NAT模式

1.配置yum的epel源

[epel]
name=EPEL
baseurl=http://mirrors.aliyun.com/epel/#releasever/$basearch
gpgcheck=0
enabled=1

也可参考Linux常用基础命令使用总结【九】——epel源配置

配置好之后重新加载yum源数据:

yum repolist

2.安装cobbler及相关程序包

yum -y install cobbler dhcp

设置服务开机自启动

systemctl enable --now cobblerd httpd tftp dhcpd

3.修改cobbler配置

[root@centos7 ~]#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-phrasehere'
'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

#生成新密码,默认安装好的系统root密码为cobbler
[root@centos7 ~]# openssl passwd -1 ‘password’
$1$1spuisnh$j34LNmyTQWs3l6xKxCZY60
#根据以上提示,只需要做1,2,8这三项即可,修改下面四行
[root@centos7 ~]#vim /etc/cobbler/settings
default_password_crypted: “$1$1spuisnh$j34LNmyTQWs3l6xKxCZY60”
next_server:< tftp服务器的 IP 地址>
server:<cobbler服务器的 IP 地址>
manage_dhcp:1 #设置为1,表示通过cobbler生成dhcpd.conf配置文件
[root@centos7 ~]#systemctl restart cobblerd
1.5 下载启动的相关文件
#修改dhcp的模版文件下面的行,用来生成dhcp的配置文件
[root@centos7 ~]#vim /etc/cobbler/dhcp.template
subnet 10.0.0.0 netmask 255.255.255.0 {
option routers 10.0.0.2;
option domain-name-servers 180.76.76.76,223.6.6.6;
option subnet-mask 255.255.255.0;
range dynamic-bootp 10.0.0.50 10.0.0.80;
[root@centos7 ~]#cobbler sync
[root@centos7 ~]#systemctl start dhcpd
[root@centos7 ~]#cobbler get-loaders
task started: 2020-02-10_163111_get_loaders
task started (id=Download Bootloader Content, time=Mon Feb 10 16:31:11 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 ***
[root@centos7 ~]#ls /var/lib/cobbler/loaders
COPYING.elilo COPYING.yaboot grub-x86_64.efi menu.c32 README
COPYING.syslinux elilo-ia64.efi grub-x86.efi pxelinux.0 yaboot
[root@centos7 ~]#tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── boot
├── etc
├── grub
├── images
├── images2
├── ppc
├── pxelinux.cfg
└── s390x
8 directories, 0 files
[root@centos7 ~]#cobbler sync
task started: 2020-02-10_163219_sync
task started (id=Sync, time=Mon Feb 10 16:32:19 2020)
running pre-sync triggers
1.6 修改菜单的标题信息(可选)
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /var/lib/cobbler/loaders/pxelinux.0 ->
/var/lib/tftpboot/pxelinux.0
trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi ->
/var/lib/tftpboot/grub/grub-x86.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi ->
/var/lib/tftpboot/grub/grub-x86_64.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering TFTPD files
generating /etc/xinetd.d/tftp
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 ***
[root@centos7 ~]#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
[root@centos7 ~]#vim /etc/cobbler/pxe/pxedefault.template
1.7 导入CentOS系统的安装文件,生成相应的YUM源
MENU TITLE Cobbler | http://www.magedu.com/
[root@centos7 ~]#cobbler sync
[root@centos7 ~]#cat /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://www.magedu.com/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local
LABEL local
MENU LABEL (local)
MENU DEFAULT
LOCALBOOT -1
MENU end
#导入CentOS8的安装文件
[root@centos7 ~]#cobbler import –name=centos-8.1-x86_64 –path=/misc/cd —
arch=x86_64
#导入CentOS7的安装文件(可选)
[root@centos7 ~]#mount /dev/sr1 /mnt
mount: /dev/sr1 is write-protected, mounting read-only
[root@centos7 ~]#cobbler import –name=centos-7.7-x86_64 –path=/mnt —
arch=x86_64
[root@centos7 ~]#du -sh /var/www/cobbler/ks_mirror/*
11G /var/www/cobbler/ks_mirror/centos-7.7-x86_64
7.2G /var/www/cobbler/ks_mirror/centos-8.1-x86_64
12K /var/www/cobbler/ks_mirror/config
[root@centos7 ~]#cobbler distro list
centos-7.7-x86_64
centos-8.1-x86_64
[root@centos7 ~]#cobbler profile list
centos-7.7-x86_64
centos-8.1-x86_64
#默认生成的是最小化安装
1.8 准备 kickstart文件,并关联至指定的YUM源
[root@centos7 ~]#vim /var/lib/cobbler/kickstarts/ks_for_centos8.cfg

[root@centos7 ~]#cat /var/lib/cobbler/kickstarts/ks_for_centos8.cfg
ignoredisk --only-use=sda
zerombr
text
reboot
clearpart --all --initlabel
selinux --disabled
firewall --disabled
url --url=$tree
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
network --bootproto=dhcp --device=ens160 --ipv6=auto --activate
network --hostname=centos8.magedu.com
rootpw --iscrypted
$6$FfPDZvMP$ChTeYkWfpN.WaLaezhTdMBhLN4oqV5fg0KJfEgRM3MM6eiuDLRagV8DcFUqi08PU84QX
9XRtyDnBSsrElIRNS/
firstboot --enable
skipx
services --disabled="chronyd"
timezone Asia/Shanghai --isUtc --nontp
user --name=wang --
password=$6$oUfb/02CWfLb5l8f$sgEZeR7c7DpqfpmFDH6huSmDbW1XQNR4qKl2EPns.gOXqlnAIgv
9pTogtFVaDtEpMOC.SWXKYqxfVtd9MCwxb1 --iscrypted --gecos="wang"
part / --fstype="xfs" --ondisk=sda --size=102400
part /data --fstype="xfs" --ondisk=sda --size=51200
part swap --fstype="swap" --ondisk=sda --size=2048
part /boot --fstype="ext4" --ondisk=sda --size=1024
%packages
@^minimal-environment
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
1.9 测试客户端基于Cobbler实现自动安装
2 手动部署wordpress
%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 mage
echo magedu | passwd --stdin mage &> /dev/null
%end

#将kickstart文件,关联指定的YUM源和生成菜单列表
[root@centos7 ~]#cobbler profile add –name=CentOS-8.1_test –distro=CentOS-8.1-
x86_64 –kickstart=/var/lib/cobbler/kickstarts/ks_for_centos8.cfg
[root@centos7 ~]#cobbler profile add –name=CentOS-7.7_test –distro=CentOS-7.7-
x86_64 –kickstart=/var/lib/cobbler/kickstarts/ks_for_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
#删除默认的菜单列表
[root@centos7 ~]#cobbler profile remove –name=CentOS8.0-x86_64

赞(0) 打赏
未经允许不得转载:琼杰笔记 » 基于Cobbler实现系统自动化安装

评论 抢沙发

评论前必须登录!

 

分享交流,合作共赢!

联系我们加入QQ群

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏