cobbler一键部署安装centos

版权声明:文章转发需标明文章出处地址及作者 https://blog.csdn.net/weixin_44267608/article/details/89850664

安装虚拟机时,我们得一步一步去安装,数量少还可以接受,那么如果数量很多就麻烦了,所有用到cobbler

安装

配置两块网卡,一台连接外网nat模式,一台连接内网仅主机模式
192.168.1.13 外网
10.1.1.100 内网

关闭防火墙、selinux
systemctl disable firewalld
systemctl stop firewalld
setenforce 0

下载相关服务
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服务
vim /etc/dhcp/dhcpd.conf

subnet 10.1.1.0 netmask 255.255.255.0 {
  range 10.1.1.10 10.1.1.150;
  default-lease-time 600;
  max-lease-time 7200;
  filename "pxelinux.0";
}

第二步:配置tftp
vim /etc/xinetd.d/tftp 将disable一项yes改为no

# 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
}

systemctl restart rsyncd
systemctl enable rsyncd

启动cobbler
systemctl start cobblerd

启动httpd
systemctl restart httpd

检查cobbler配置
cobbler check
The following are potential configuration items that you may want to fix:

扫描二维码关注公众号,回复: 6232558 查看本文章
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地址 10.1.1.100,在384行

384 server: 10.1.1.100

问题二:
netx_server也是默认本地127.0.0.1回环地址,需要修改为提供cobbler服务的ip地址 10.1.1.100,在272行出现

272 next_server: 10.1.1.100

问题三: 可以忽略

问题四:
启动rsync即可
systemctl restart rsyncd
systemctl enable rsyncd

问题五: 可以忽略

问题六: 更改密码
openssl passwd -1 -salt “123” “123456”
$1$123$7mft0jKnzzvAdU4t0unTG1
并把新生成的加密数据填写进/etc/cobbler/settings

101 default_password_crypted: "$1$123$7mft0jKnzzvAdU4t0unTG1"

问题七:可以忽略

以上问题解决之后,需要同步和重启
systemctl restart cobblerd
cobbler sync

再次检查
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.

挂载光盘
mount /dev/cdrom /mnt

并进行数据导入
cobbler import --path=/mnt --name=“centos7.3”

task started: 2019-01-15_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.3:
creating new distro: centos7.3-x86_64
trying symlink: /var/www/cobbler/ks_mirror/centos7.3 -> /var/www/cobbler/links/centos7.3-x86_64
creating new profile: centos7.3-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.3 for centos7.3-x86_64
processing repo at : /var/www/cobbler/ks_mirror/centos7.3
need to process repo/comps: /var/www/cobbler/ks_mirror/centos7.3
looking for /var/www/cobbler/ks_mirror/centos7.3/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos7.3/repodata
*** TASK COMPLETE ***

查看distro
cobbler distro list

centos7.3-x86_64

查看profile
cobbler profile list

centos7.3-x86_64

distro : 发行版, 就是我们安装什么版本的linux操作系统的名称 一会我们会导入一个 distro.
profile : 类似于一个 配置文件,类似于你的 bash_profile, 里面包含你可以添加 kernel 参数,对应的kickstart 文件 以及 此profile 对应的 distro 等等.

第八步:准备kickstart文件
在root目录下找到ks文件,并移动到/var/lib/cobbler/kickstarts/到目录下改名为ks.cfg

mv anaconda-ks.cfg /var/lib/cobbler/kickstarts/ks.cfg

vim /var/lib/cobbler/kickstarts/ks.cfg

#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
url --url=http://10.1.1.100/cobbler/ks_mirror/centos7.3/  #这里需要更改为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
cobbler profile add --distro=centos7.3-x86_64 --name=centos7.3_chen --kickstart=/var/lib/cobbler/kickstarts/ks.cfg

[root@chen ~]#  cobbler profile add --distro=centos7.3-x86_64 --name=centos7.3_ken --kickstart=/var/lib/cobbler/kickstarts/ks.cfg
[root@chen ~]# 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.3-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.3-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
copying distros to tftpboot
copying files for distro: centos7.3-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos7.3/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos7.3-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos7.3/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos7.3-x86_64/initrd.img
copying images
generating PXE configuration files
generating PXE menu structure
copying files for distro: centos7.3-x86_64
trying hardlink /var/www/cobbler/ks_mirror/centos7.3/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos7.3-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/centos7.3/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos7.3-x86_64/initrd.img
Writing template files for centos7.3-x86_64
rendering TFTPD files
generating /etc/xinetd.d/tftp
processing boot_files for distro: centos7.3-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
centos7.3-x86_64
centos7.3_chen

删除不包含ks文件的profile

cobbler profile remove --name=centos7.3-x86_64

cobbler profile list
centos7.5_chen

测试
新建一个虚拟机,需要和cobbler服务器所在同一个虚拟网络中即与我们上面设置的cobbler服务器的主机模式。内存需要3个G以上。
在这里插入图片描述
选择第我们自定义的包即可进行自动化安装。
在这里插入图片描述
虚拟机的模式为仅主机模式

猜你喜欢

转载自blog.csdn.net/weixin_44267608/article/details/89850664
今日推荐