cobbler服务端部署,centos7系统

部署cobbler

#安装cobbler以及相关的软件
[root@localhost ~]# yum -y install httpd dhcp tftp python-ctypes cobbler  xinetd cobbler-web pykickstart
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
base                                                        | 3.6 kB  00:00:00     
#关闭seliunx和防火墙
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config
 [root@localhost ~]# systemctl disable --now firewalld.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# reboot
#启动服务并设置开机自启
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl start cobblerd
[root@localhost ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost cobbler]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128           *:111                       *:*                  
LISTEN      0      5      192.168.122.1:53                        *:*                  
LISTEN      0      128           *:22                        *:*                  
LISTEN      0      100    127.0.0.1:25                        *:*                  
LISTEN      0      5      127.0.0.1:25151                     *:*                  
LISTEN      0      128        [::]:111                    [::]:*                  
LISTEN      0      128        [::]:80                     [::]:*                  
LISTEN      0      128        [::]:22                     [::]:*                  
LISTEN      0      100       [::1]:25                     [::]:*                  
LISTEN      0      128        [::]:443                    [::]:*     
#修改server的ip地址为本机ip
[root@localhost ~]# sed -i 's/^server: 127.0.0.1/server: 192.168.70.130/' /etc/cobbler/settings
#设置tftp的ip地址为本机ip
[root@localhost ~]# sed -i 's/^next_server: 127.0.0.1/next_server: 192.168.70.130/' /etc/cobbler/settings
#开启tftp
[root@localhost ~]# sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp
[root@localhost ~]# ls /var/www/cobbler    程序的地方
images  ks_mirror  links  localmirror  misc  pub  rendered  repo_mirror  svc
//images    镜像,这个文件要放到内存充足的地方,挂载或链接
//var目录在根目录下, 也可以默认在这个地方,分区多分点,放这个文件


#下载缺失文件
[root@localhost cobbler]# cobbler get-loaders
No such command: get-loaders

[root@localhost cobbler]# systemctl start rsyncd
[root@localhost cobbler]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.
#生成加密的密码
[root@localhost cobbler]# openssl passwd -1 -salt "$RANDOM" '123456!'$1$8382$K9VS.TGYV52x6zjeHOlq4/
//这是密码加密后的形式

#将新生成的加密密码加入到配置文件
[root@localhost cobbler]# vim /etc/cobbler/settings
# and put the output between the "" below.
default_password_crypted: "$1$8382$K9VS.TGYV52x6zjeHOlq4/"
# the default template type to use in the absence of any

#重启cobbler
[root@localhost cobbler]# systemctl restart cobblerd
[root@localhost cobbler]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      5             *:873                       *:*                  
LISTEN      0      128           *:111                       *:*                  
LISTEN      0      5      192.168.122.1:53                        *:*                  
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        [::]:111                    [::]:*                  
LISTEN      0      128        [::]:80                     [::]:*                  
LISTEN      0      128        [::]:22                     [::]:*                  
LISTEN      0      100       [::1]:25                     [::]:*                  
LISTEN      0      128        [::]:443                    [::]:*    


#通过cobbler check 核对当前设置是否有问题
#修改安装修改这个文件,关闭selinux,让核对的时候不会报错 
[root@localhost ~]# yum -y install debmirror
[root@localhost ~]# vim /etc/debmirror.conf
[root@localhost ~]# 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.  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.
2 : 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.

//以上俩行是关于debian系统的错误,请忽略

##配置cobbler dhcp
#修改cobbler配置文件,让cobbler控制dhcp
[root@localhost ~]# sed -i '/^manage_dhcp/s/0/1/g' /etc/cobbler/settings
[root@localhost ~]# sed -n '/^manage_dhcp/p' /etc/cobbler/settings
manage_dhcp: 1

#配置dhcp
[root@localhost ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.70.0 netmask 255.255.255.0 {
     option routers             192.168.70.2;
     option domain-name-servers 8.8.8.8;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.70.10 192.168.70.20;
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
     class "pxeclients" {


//重启服务并同步配置,改完dhcp必须要sync同步配置
[root@localhost ~]# systemctl restart cobblerd
[root@localhost ~]# cobbler sync
task started: 2022-08-11_102355_sync
task started (id=Sync, time=Thu Aug 11 10:23:55 2022)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/grub/images
copying bootloaders
trying hardlink /usr/share/syslinux/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0
trying hardlink /usr/share/syslinux/menu.c32 -> /var/lib/tftpboot/menu.c32
trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
rendering DHCP files
generating /etc/dhcp/dhcpd.conf
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: 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:*                           25159/dhcpd         

//导入redhat7镜像
//先开启光盘,在执行命令
[root@localhost ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# cobbler import --path=/mnt --name=rhel-7 --arch
Usage: cobbler import [options]

cobbler: error: --arch option requires an argument
[root@localhost ~]# cobbler import --path=/mnt --name=rhel-7 --arch=x86_64
task started: 2022-08-11_103939_import
task started (id=Media import, time=Thu Aug 11 10:39:39 2022)
Found a candidate signature: breed=suse, version=opensuse15.0
Found a candidate signature: breed=suse, version=opensuse15.1
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-x86_64:
creating new distro: rhel-7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/rhel-7-x86_64 -> /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-x86_64 for rhel-7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/rhel-7-x86_64   //导入镜像的位置
need to process repo/comps: /var/www/cobbler/ks_mirror/rhel-7-x86_64
looking for /var/www/cobbler/ks_mirror/rhel-7-x86_64/repodata/*comps*.xml   
Keeping repodata as-is :/var/www/cobbler/ks_mirror/rhel-7-x86_64/repodata

//检查dhcp是否正常
[root@localhost ~]#  netstat -anulp|grep dhcp
udp        0      0 0.0.0.0:67              0.0.0.0:*                           25159/dhcpd         

//说明:
    --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 $6$2WTFvfNvAMgCUPuC$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

//检查ks文件语法是否有误
[root@localhost ~]# cobbler validateks
task started: 2022-08-11_104633_validateks
task started (id=Kickstart Validation, time=Thu Aug 11 10:46:33 2022)
----------------------------
osversion: rhel7
checking url: http://192.168.70.130/cblr/svc/op/ks/profile/rhel-7-x86_64
running: /usr/bin/ksvalidator -v "rhel7" "http://192.168.70.130/cblr/svc/op/ks/profile/rhel-7-x86_64"
received on stdout: 
received on stderr: 
*** all kickstarts seem to be ok ***
*** TASK COMPLETE ***
[root@localhost ~]# 

//查看当前cobbler有哪些配置文件
[root@localhost ~]# cobbler profile list
   rhel-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
[root@localhost ~]# 
//配置网卡名称为传统网卡名称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          : <<inherit>>
Name Servers                   : []
Name Servers Search Path       : []
Owners                         : ['admin']
Parent Profile                 : 
Internal proxy                 : 
Red Hat Management Key         : <<inherit>>
Red Hat Management Server      : <<inherit>>
Repos                          : []
Server Override                : <<inherit>>
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: 2022-08-11_105058_sync
task started (id=Sync, time=Thu Aug 11 10:50:58 2022)
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/efidefault
removing: /var/lib/tftpboot/images/rhel-7-x86_64
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
copying distros to tftpboot
copying files for distro: rhel-7-x86_64
trying hardlink /var/www/cobbler/ks_mirror/rhel-7-x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/rhel-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/rhel-7-x86_64/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-x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/rhel-7-x86_64/vmlinuz
trying hardlink /var/www/cobbler/ks_mirror/rhel-7-x86_64/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      5      127.0.0.1:25151                     *:*                  
LISTEN      0      5             *:873                       *:*                  
LISTEN      0      128           *:111                       *:*                  
LISTEN      0      5      192.168.122.1:53                        *:*                  
LISTEN      0      128           *:22                        *:*                  
LISTEN      0      100    127.0.0.1:25                        *:*                  
LISTEN      0      128        [::]:443                    [::]:*                  
LISTEN      0      5          [::]:873                    [::]:*                  
LISTEN      0      128        [::]:111                    [::]:*                  
LISTEN      0      128        [::]:80                     [::]:*                  
LISTEN      0      128        [::]:22                     [::]:*                  
LISTEN      0      100       [::1]:25                     [::]:*                  

客户端安装

新建虚拟机从pxe启动,若出现以下界面则表示成功
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值