栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

使用 cobbler 安装工具批量安装服务器

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用 cobbler 安装工具批量安装服务器

  • 生成加密的密码

[root@localhost ~]# openssl passwd -1 -salt "$RANDOM" '123456'

14083$9jFt/kdeFNmOe4QlSuV4D.

  • 将新生成的加密密码加入到配置文件

[root@localhost ~]# vim /etc/cobbler/settings

.... //此处为省略内容

default_password_crypted: "128958$sq1sJFDX0bZo.H8Q.8NLg0"

..... //此处为省略内容

  • 重启 cobbler

[root@localhost ~]# systemctl restart cobblerd

[root@localhost ~]# ss -antl

State Recv-Q Send-Q Local Address:Port Peer Address:Port

LISTEN 0 128 *:22 :

LISTEN 0 100 127.0.0.1:25 :

LISTEN 0 5 127.0.0.1:25151 :

LISTEN 0 5 *:873 :

LISTEN 0 128 :::80 :::*

LISTEN 0 128 :::22 :::*

LISTEN 0 100 ::1:25 :::*

LISTEN 0 128 :::443 :::*

LISTEN 0 5 :::873 :::*

  • 通过 cobbler check 核对当前设置是否有问题

[root@localhost ~]# cobbler check

The following are potential configuration items that you may want to fix:

1 : debmirror package is not installed, it will be required to manage debian deployments and repositories

2 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

以上两个是关于 debian 系统的错误,请忽略

  • 配置 cobbler dhcp

  • 修改 cobbler 配置文件,让 cobbler 控制 dhcp

[root@localhost ~]# vim /etc/cobbler/dhcp.template

.... //此处为省略内容

subnet 192.168.170.0 netmask 255.255.255.0 {

option routers 192.168.170.2; //服务器端的网关

option domain-name-servers 8.8.8.8; //此处为系统安装好后指定的 dns 地址

option subnet-mask 255.255.255.0;

range dynamic-bootp 192.168.170.100 192.168.170.200; 分配的地址池

default-lease-time 21600;

max-lease-time 43200;

next-server $next_server;

.... //此处为省略内容

  • 重启服务并同步配置,改完 dhcp 必须要 sync 同步配置

[root@localhost ~]# cobbler sync

task started: 2019-08-29_184616_sync

task started (id=Sync, time=Thu Aug 29 18:46:16 2019)

running pre-sync triggers

cleaning trees

removing: /var/www/cobbler/images/rhel-7-x86_64

removing: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-27-5d-16

removing: /var/lib/tftpboot/pxelinux.cfg/default

removing: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-3a-17-d2

removing: /var/lib/tftpboot/grub/images

removing: /var/lib/tftpboot/grub/grub-x86.efi

removing: /var/lib/tftpboot/grub/grub-x86_64.efi

removing: /var/lib/tftpboot/grub/01-00-50-56-27-5D-16

removing: /var/lib/tftpboot/grub/efidefault

removing: /var/lib/tftpboot/grub/01-00-50-56-3A-17-D2

removing: /var/lib/tftpboot/images/rhel-7-x86_64

removing: /var/lib/tftpboot/s390x/profile_list

copying bootloaders

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 files for distro: rhel-7-x86_64

trying hardlink /var/www/cobbler/ks_mirror/rhel-7/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/rhel-7-x86_64/vmlinuz

trying hardlink /var/www/cobbler/ks_mirror/rhel-7/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/rhel-7-x86_64/initrd.img

copying images

generating PXE configuration files

generating: /var/lib/tftpboot/pxelinux.cfg/01-00-50-56-3a-17-d2

generating: /var/lib/tftpboot/grub/01-00-50-56-3A-17-D2

generating PXE menu structure

copying files for distro: rhel-7-x86_64

trying hardlink /var/www/cobbler/ks_mirror/rhel-7/images/pxeboot/vmlinuz -> /var/www/cobbler/images/rhel-7-x86_64/vmlinuz

trying hardlink /var/www/cobbler/ks_mirror/rhel-7/images/pxeboot/initrd.img -> /var/www/cobbler/images/rhel-7-x86_64/initrd.img

Writing template files for rhel-7-x86_64

rendering DHCP files

generating /etc/dhcp/dhcpd.conf

rendering TFTPD files

generating /etc/xinetd.d/tftp

processing boot_files for distro: rhel-7-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: dhcpd -t -q

received on stdout:

received on stderr:

running: service dhcpd restart

received on stdout:

received on stderr: Redirecting to /bin/systemctl restart dhcpd.service

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 ***

  • 检查 dhcp 是否正常

[root@localhost ~]# netstat -anulp|grep dhcp

udp 0 0 0.0.0.0:67 0.0.0.0:* 12692/dhcpd

  • 导入 redhat7 镜像

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

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

[root@localhost ~]# cobbler import --path=/mnt/cdrom --name=rhel-7 arch=x86_64

task started: 2019-08-29_171616_import

task started (id=Media import, time=Thu Aug 29 17:16:16 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/rhel-7:

creating new distro: rhel-7-x86_64

trying symlink: /var/www/cobbler/ks_mirror/rhel-7 -> /var/www/cobbler/links/rhel-7-x86_64

creating new profile: rhel-7-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/rhel-7 for rhel-7-x86_64

processing repo at : /var/www/cobbler/ks_mirror/rhel-7

need to process repo/comps: /var/www/cobbler/ks_mirror/rhel-7

looking for /var/www/cobbler/ks_mirror/rhel-7/repodata/comps.xml

Keeping repodata as-is :/var/www/cobbler/ks_mirror/rhel-7/repodata

processing repo at : /var/www/cobbler/ks_mirror/rhel-7/addons/HighAvailability

need to process repo/comps: /var/www/cobbler/ks_mirror/rhel-7/addons/HighAvailability

looking for /var/www/cobbler/ks_mirror/rhel-7/addons/HighAvailability/repodata/comps.xml

Keeping repodata as-is :/var/www/cobbler/ks_mirror/rhel-7/addons/HighAvailability/repodata

processing repo at : /var/www/cobbler/ks_mirror/rhel-7/addons/ResilientStorage

need to process repo/comps: /var/www/cobbler/ks_mirror/rhel-7/addons/ResilientStorage

looking for /var/www/cobbler/ks_mirror/rhel-7/addons/ResilientStorage/repodata/comps.xml

Keeping repodata as-is :/var/www/cobbler/ks_mirror/rhel-7/addons/ResilientStorage/repodata

*** TASK COMPLETE ***

//说明:

--path //镜像路径

--name //为安装源定义一个名字

--arch //指定安装源平台

安装源的唯一标示就是根据 name 参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-7-x86_64,如果重复,系统会提示导入失败

  • 查看 cobbler 镜像列表

[root@localhost ~]# cobbler list

distros:

rhel-7-x86_64

profiles:

rhel-7-x86_64

systems:

repos:

images:

mgmtclasses:

packages:

files:

  • 创建 kickstarts 自动安装脚本

[root@localhost ~]# cat > /var/lib/cobbler/kickstarts/rhel-7-x86_64.ks <<'EOF'

auth --enableshadow --passalgo=sha512

bootloader --location=mbr

clearpart --all --initlabel

part /boot --asprimary --fstype="ext4" --size=500

part swap --fstype="swap" --size=4096

part / --fstype="ext4" --grow --size=15000

text

firewall --disabled

firstboot --disable

keyboard us

lang en_US

url --url=http://172.16.12.128/cobbler/ks_mirror/rhel-7-x86_64

$yum_repo_stanza

reboot

rootpw --iscrypted 62WTFvfNvAMgCUPuC$MJgWGzhakgxrRObcEbAwSe8vkz0s//xyiTllGwxRsHHruQhcskO69u2LVTU9u0eemHXH2pzcGawyAJ54R2E/x0

selinux --disabled

skipx

timezone Asia/Shanghai --isUtc --nontp

install

zerombr

%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

EOF

[root@localhost ~]#

[root@localhost ~]# vim /var/lib/cobbler/kickstarts/rhel-7-x86_64.ks

[root@localhost ~]# cobbler validateks

task started: 2019-08-29_172202_validateks

task started (id=Kickstart Validation, time=Thu Aug 29 17:22:02 2019)


osversion: rhel7

checking url: http://192.168.170.14/cblr/svc/op/ks/profile/rhel-7-x86_64

running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.170.14/cblr/svc/op/ks/profile/rhel-7-x86_64"

received on stdout:

received on stderr:

*** all kickstarts seem to be ok ***

*** TASK COMPLETE ***

  • 检查 ks 文件语法是否有误

[root@localhost ~]# cobbler profile list

rhel-7-x86_64

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

[root@localhost ~]# cobbler profile edit --name rhel-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'

[root@localhost ~]# cobbler profile report

Name : rhel-7-x86_64

TFTP Boot Files : {}

Comment :

DHCP Tag : default

Distribution : rhel-7-x86_64

Enable gPXE? : 0

Enable PXE Menu? : 1

Fetchable Files : {}

Kernel Options : {'biosdevname': '0', 'net.ifnames': '0'}

Kernel Options (Post Install) : {}

Kickstart : /var/lib/cobbler/kickstarts/rhel-7-x86_64.ks

Kickstart Metadata : {}

Management Classes : []

Management Parameters : <>

Name Servers : []

Name Servers Search Path : []

Owners : ['admin']

Parent Profile :

Internal proxy :

Red Hat Management Key : <>

Red Hat Management Server : <>

Repos : []

Server Override : <>

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@localhost ~]# cobbler profile list

Centos-7-x86_64

  • 修改 profile,将我们新建的 ks 文件设为默认的 kickstarts 安装文件

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

  • 配置网卡名称为传统网卡名称 eth0

[root@localhost ~]# cobbler profile edit --name rhel-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'

  • 检查当前系统 cobbler 配置文件信息

[root@localhost ~]# cobbler profile report

Name : rhel-7-x86_64

TFTP Boot Files : {}

Comment :

DHCP Tag : default

Distribution : rhel-7-x86_64

Enable gPXE? : 0

Enable PXE Menu? : 1

Fetchable Files : {}

Kernel Options : {'biosdevname': '0', 'net.ifnames': '0'}

Kernel Options (Post Install) : {}

Kickstart : /var/lib/cobbler/kickstarts/rhel-7-x86_64.ks

Kickstart Metadata : {}

Management Classes : []

Management Parameters : <>

Name Servers : []

Name Servers Search Path : []

Owners : ['admin']

Parent Profile :

Internal proxy :

Red Hat Management Key : <>

Red Hat Management Server : <>

Repos : []

Server Override : <>

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@localhost ~]# cobbler sync

task started: 2019-08-29_172318_sync

task started (id=Sync, time=Thu Aug 29 17:23:18 2019)

running pre-sync triggers

cleaning trees

removing: /var/www/cobbler/images/rhel-7-x86_64

removing: /var/lib/tftpboot/pxelinux.cfg/default

removing: /var/lib/tftpboot/grub/images

removing: /var/lib/tftpboot/grub/grub-x86.efi

removing: /var/lib/tftpboot/grub/grub-x86_64.efi

removing: /var/lib/tftpboot/grub/efidefault

removing: /var/lib/tftpboot/images/rhel-7-x86_64

removing: /var/lib/tftpboot/s390x/profile_list

copying bootloaders

trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /va

r/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 files for distro: rhel-7-x86_64

trying hardlink /var/www/cobbler/ks_mirror/rhel-7/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/rhel-7-x86_64/vmlinuz

trying hardlink /var/www/cobbler/ks_mirror/rhel-7/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/rhel-7-x86_64/initrd.img

copying images

generating PXE configuration files

generating PXE menu structure

copying files for distro: rhel-7-x86_64

trying hardlink /var/www/cobbler/ks_mirror/rhel-7/images/pxeboot/vmlinuz -> /var/www/cobbler/images/rhel-7-x86_64/vmlinuz

trying hardlink /var/www/cobbler/ks_mirror/rhel-7/images/pxeboot/initrd.img -> /var/www/cobbler/images/rhel-7-x86_64/initrd.img

Writing template files for rhel-7-x86_64

rendering DHCP files

generating /etc/dhcp/dhcpd.conf

rendering TFTPD files

generating /etc/xinetd.d/tftp

processing boot_files for distro: rhel-7-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: dhcpd -t -q

received on stdout:

received on stderr:

running: service dhcpd restart

received on stdout:

received on stderr: Redirecting to /bin/systemctl restart dhcpd.service

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@localhost ~]# systemctl restart xinetd

[root@localhost ~]# systemctl restart cobblerd

[root@localhost ~]# systemctl restart httpd

[root@localhost ~]# ss -antl

State Recv-Q Send-Q Local Address:Port Peer Address:Port

LISTEN 0 128 *:22 :

LISTEN 0 100 127.0.0.1:25 :

LISTEN 0 5 127.0.0.1:25151 :

LISTEN 0 5 *:873 :

LISTEN 0 128 :::80 :::*

LISTEN 0 128 :::22 :::*

LISTEN 0 100 ::1:25 :::*

LISTEN 0 128 :::443 :::*

LISTEN 0 5 :::873 :::*

[](()客户端安装系统

=================================================================

[](()手动验证:

创建一个虚拟机,模式和服务端模式一样,(这里我使用的是 nat,所以要安装的虚拟机模式也是 nat),然后设置,

然后,直接开启虚拟机,看到以下界面,,手动配置成功

  • ok!这样效果是出来了,但是,还是需要手动选择,如果机器太多,每台服务器都要选择,还是很麻烦,所以采用 web 界面配置

[](()定制安装

=============================================================

r/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 files for distro: rhel-7-x86_64

trying hardlink /var/www/cobbler/ks_mirror/rhel-7/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/rhel-7-x86_64/vmlinuz

trying hardlink /var/www/cobbler/ks_mirror/rhel-7/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/rhel-7-x86_64/initrd.img

copying images

generating PXE configuration files

generating PXE menu structure

copying files for distro: rhel-7-x86_64

trying hardlink /var/www/cobbler/ks_mirror/rhel-7/images/pxeboot/vmlinuz -> /var/www/cobbler/images/rhel-7-x86_64/vmlinuz

trying hardlink /var/www/cobbler/ks_mirror/rhel-7/images/pxeboot/initrd.img -> /var/www/cobbler/images/rhel-7-x86_64/initrd.img

Writing template files for rhel-7-x86_64

rendering DHCP files

generating /etc/dhcp/dhcpd.conf

rendering TFTPD files

generating /etc/xinetd.d/tftp

processing boot_files for distro: rhel-7-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: dhcpd -t -q

received on stdout:

received on stderr:

running: service dhcpd restart

received on stdout:

received on stderr: Redirecting to /bin/systemctl restart dhcpd.service

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@localhost ~]# systemctl restart xinetd

[root@localhost ~]# systemctl restart cobblerd

[root@localhost ~]# systemctl restart httpd

[root@localhost ~]# ss -antl

State Recv-Q Send-Q Local Address:Port Peer Address:Port

LISTEN 0 128 *:22 :

LISTEN 0 100 127.0.0.1:25 :

LISTEN 0 5 127.0.0.1:25151 :

LISTEN 0 5 *:873 :

LISTEN 0 128 :::80 :::*

LISTEN 0 128 :::22 :::*

LISTEN 0 100 ::1:25 :::*

LISTEN 0 128 :::443 :::*

LISTEN 0 5 :::873 :::*

[](()客户端安装系统

=================================================================

[](()手动验证:

创建一个虚拟机,模式和服务端模式一样,(这里我使用的是 nat,所以要安装的虚拟机模式也是 nat),然后设置,

然后,直接开启虚拟机,看到以下界面,,手动配置成功

  • ok!这样效果是出来了,但是,还是需要手动选择,如果机器太多,每台服务器都要选择,还是很麻烦,所以采用 web 界面配置

[](()定制安装

==============================================================

 小伙伴们有兴趣想了解内容和更多相关学习资料的请点赞收藏+评论转发+关注我,后面会有很多干货。如果在阅读过程中有疑问,请留言讨论

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/914802.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号