cobbler無人值守安裝centos6和centos7

自動安裝部署,局域網不能有多個DHCP,虛擬機網卡-cobbler網絡類型,cobbler sync



一、cobbler服務器信息

[root@controller ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@controller ~]# getenforce
Disabled
[root@controller ~]# systemctl status firewalld  
● firewalld.service - firewalld - dynamic firewall daemon
    Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
    Active: inactive (dead)
      Docs: man:firewalld(1)
[root@controller ~]# ifconfig eno16777736|awk -F "[ :]+" 'NR==2 {print $3}'
192.168.153.11
[root@controller ~]# hostname
controller.www.local



二、安裝epel源和cobbler相關包

[root@controller ~]# rpm -ivh 
http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
[root@controller ~]# yum install cobbler cobbler-web dhcp tftp-server pykickstart httpd python-ctypes xinetd -y
[root@controller ~]# systemctl restart httpd
[root@controller ~]# systemctl start cobblerd
[root@controller ~]# systemctl enable httpd
[root@controller ~]# systemctl enable cobblerd
[root@controller ~]# systemctl status httpd
[root@controller ~]# systemctl status cobblerd



三、cobbler配置


1、cobbler check檢查並處理。

[root@controller ~]# cobbler checkThe 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 : 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
8 : 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.

解決第1步和第2步:
[root@controller ~]# vi /etc/cobbler/settings
server: 192.168.153.11
next_server: 192.168.153.11
manage_dhcp: 1

解決第3步:
[root@controller ~]# vi /etc/xinetd.d/tftp
disable                 = no

解決第4步:
[root@controller ~]# cobbler get-loaders
task started: 2018-03-31_155437_get_loaders
task started (id=Download Bootloader Content, time=Sat Mar 31 15:54:37 2018)
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 ***

解決第5步:
[root@controller ~]# systemctl start rsyncd
[root@controller ~]# systemctl enable rsyncd
Created symlink from /etc/systemd/system/multi-user.target.wants/rsyncd.service to /usr/lib/systemd/system/rsyncd.service.

解決第7步:
[root@controller ~]# openssl passwd -1 -salt 'suijizhi' 'gxm'
$1$suijizhi$7RpWQlgtVB8T8vrrCmV7v.
default_password_crypted: "$1$suijizhi$7RpWQlgtVB8T8vrrCmV7v."

[root@controller ~]# systemctl restart cobblerd      
[root@controller ~]# 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
Restart cobblerd and then run 'cobbler sync' to apply changes.

這2個可以不解決,如果要解決用下面的命令安裝,不過安裝後再check又有其他提示。
[root@controller ~]# yum -y install debmirror yum-utils fence-agents(我自己沒安裝)

備註:防止誤重裝系統的方法(網上方法,自己沒有實驗過)pxe安裝只允許一次,防止誤操作 ( 在正式環境有用。實際測試來看,這個功能可以屏蔽掉 )
[root@controller ~]# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/g' /etc/cobbler/settings
[root@controller ~]# grep '^pxe_just_once' /etc/cobbler/setting



2、修改dhcp模版文件,它會自動生產dhcp文件(網上也有cp一份模版重命名爲/etc/dhcp/dhcpd.conf配置文件的方式)

[root@controller ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.153.0 netmask 255.255.255.0 {
      option routers             192.168.153.2;
      option domain-name-servers 192.168.153.2;
      option subnet-mask         255.255.255.0;
      range dynamic-bootp        192.168.153.100 192.168.153.254;
      default-lease-time         21600;
      max-lease-time             43200;
      next-server                $next_server;
      class "pxeclients" {
           match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
           if option pxe-system-type = 00:02 {
                   filename "ia64/elilo.efi";
           } else if option pxe-system-type = 00:06 {
                   filename "grub/grub-x86.efi";
           } else if option pxe-system-type = 00:07 {
                   filename "grub/grub-x86_64.efi";
           } else if option pxe-system-type = 00:09 {
                   filename "grub/grub-x86_64.efi";
           } else {
                   filename "pxelinux.0";
           }
      }}



3、複製pxelinux.0, menu.c32到/var/lib/cobbler/loaders/(不要做,我沒做)

[root@controller ~]# cd /usr/share/syslinux/
[root@controller ~]# cp -r * /var/lib/cobbler/loaders/



4、重啓服務器並同步配置:

[root@controller ~]# systemctl restart cobblerd    
[root@controller ~]# cobbler sync
task started: 2018-03-31_173554_sync
task started (id=Sync, time=Sat Mar 31 17:35:54 2018)
running pre-sync triggers
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 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.scm_track
running shell triggers from /var/lib/cobbler/triggers/change/*
*** TASK COMPLETE ***


5、檢查dhcp是否正常

[root@controller ~]# systemctl enable dhcpd.service
[root@controller ~]# netstat -lnup|grep dhcp
udp        0      0 0.0.0.0:67              0.0.0.0:*                           11738/dhcpd         
udp        0      0 0.0.0.0:1129            0.0.0.0:*                           11738/dhcpd         
udp6       0      0 :::31636                :::*                                11738/dhcpd



6、記得啓動下xinetd,要不客戶端會報這個錯誤:PXE-E32:TFTP open timeout TFTP"Open"請求沒有應答

[root@controller ~]# systemctl restart xinetd
[root@controller ~]# netstat -anltup | grep :69
udp        0      0 0.0.0.0:69              0.0.0.0:*                           12005/xinetd



7、加載centos7的光盤或ISO文件

[root@controller ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 寫保護,將以只讀方式掛載
[root@controller ~]# cobbler import --name=CentOS_7_x86_64 --path=/mnt/
task started: 2018-03-31_164113_import
task started (id=Media import, time=Sat Mar 31 16:41:13 2018)
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/CentOS_7_x86_64:
creating new distro: CentOS_7-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS_7_x86_64 -> /var/www/cobbler/links/CentOS_7-x86_64
creating new profile: CentOS_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/CentOS_7_x86_64 for CentOS_7-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS_7_x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS_7_x86_64
looking for /var/www/cobbler/ks_mirror/CentOS_7_x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS_7_x86_64/repodata
*** TASK COMPLETE ***



8、加載centos6.9的光盤或ISO文件

[root@controller ~]# umount /mnt
加載centos6.9的光盤或ISO文件
[root@controller ~]# mount /dev/cdrom /mnt/
[root@controller ~]# cobbler import --name=CentOS_6.9_x86_64 --path=/mnt/
task started: 2018-03-31_174506_import
task started (id=Media import, time=Sat Mar 31 17:45:06 2018)
Found a candidate signature: breed=redhat, version=rhel6
Found a matching signature: breed=redhat, version=rhel6
Adding distros from path /var/www/cobbler/ks_mirror/CentOS_6.9_x86_64:
creating new distro: CentOS_6.9-x86_64
trying symlink: /var/www/cobbler/ks_mirror/CentOS_6.9_x86_64 -> /var/www/cobbler/links/CentOS_6.9-x86_64
creating new profile: CentOS_6.9-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/CentOS_6.9_x86_64 for CentOS_6.9-x86_64
processing repo at : /var/www/cobbler/ks_mirror/CentOS_6.9_x86_64
need to process repo/comps: /var/www/cobbler/ks_mirror/CentOS_6.9_x86_64
looking for /var/www/cobbler/ks_mirror/CentOS_6.9_x86_64/repodata/*comps*.xml
Keeping repodata as-is :/var/www/cobbler/ks_mirror/CentOS_6.9_x86_64/repodata
*** TASK COMPLETE ***

[root@controller ~]# ll /var/www/cobbler/ks_mirror/
總用量 8
dr-xr-xr-x 7 root root 4096 3月  29 2017 CentOS_6.9_x86_64
dr-xr-xr-x 8 root root 4096 12月 10 2015 CentOS_7_x86_64
drwxr-xr-x 2 root root   62 3月  31 17:48 config
查看dirstro。
[root@controller syslinux]# cobbler distro list
    CentOS_6.9-x86_64
    CentOS_7-x86_64



9、準備centos 7的ks文件(如果不定義ks文件,默認有一個,生產環境用自己定義一個)

[root@controller ~]# vi /var/lib/cobbler/kickstarts/CentOS7_x86_64.ks.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Install OS instead of upgrade
install
# Use network installation
url --url=http://192.168.153.11/cobbler/ks_mirror/CentOS_7_x86_64
# 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=eno16777736 --onboot=yes --ipv6=auto
network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted $1$password$7ZK8mMeLGXxbNPeJEFJOU0
# System timezone
timezone Asia/Shanghai --isUtc
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel
%packages
@^minimal
@core
kexec-tools
vim
wget
httpd
lrzsz
net-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
selinux --disabled
reboot



10、準備centos 6.9的ks文件

[root@controller ~]# vi /var/lib/cobbler/kickstarts/CentOS6.9_x86_64.ks.cfg
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url=http://192.168.153.11/cobbler/ks_mirror/CentOS_6.9_x86_64
# Root password
rootpw --iscrypted $1$password$7ZK8mMeLGXxbNPeJEFJOU0
# System authorization information
auth  --useshadow  --enablemd5
# Use graphical install
graphical
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone  --isUtc Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
key --skip
bootloader --append="rhgb quiet" --location=mbr --driveorder=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="ext4" --size=8192
part swap --fstype="swap" --size=1024
part /home --fstype="ext4" --size=2048

%packages
@base
kexec-tools
vim
wget
httpd
lrzsz
net-tools
%end



11、添加Cobbler Profile
因爲導入centos7和centos6.9後系統默認產生了2個,所以可以直接在上面修改,命令是cobbler profile edit --name=xxx --kickstart=xxx 。不過我這裏是add新建,就是保留默認產生的2人,然後自己add新建兩個。

[root@controller kickstarts]# cobbler profile add 
--name=CentOS7_X86_64-basic --distro=CentOS_7-x86_64 
--kickstart=/var/lib/cobbler/kickstarts/CentOS7_x86_64.ks.cfg
[root@controller
 kickstarts]# cobbler profile edit --name=CentOS7_X86_64-basic 
--kopts='net.ifnames=0 biosdevname=0'   
(這條是修改網卡名爲eth0,但是我沒做這個,生產環境會用到,7版本要用到,6版本不用)
[root@controller 
kickstarts]# cobbler profile add --name=CentOS_6.9_X86_64-basic 
--distro=CentOS_6.9-x86_64 
--kickstart=/var/lib/cobbler/kickstarts/CentOS6.9_x86_64.ks.cfg
[root@controller kickstarts]# cobbler profile list
    CentOS7_X86_64-basic
    CentOS_6.9-x86_64
    CentOS_6.9_X86_64-basic
    CentOS_7-x86_64
[root@controller kickstarts]# cobbler profile report
Name                           : CentOS7_X86_64-basic
TFTP Boot Files                : {}
Comment                        :
DHCP Tag                       : default
Distribution                   : CentOS_7-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/CentOS7_x86_64.ks.cfg
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                      : xenpv
Name                           : CentOS_7-x86_64
TFTP Boot Files                : {}
Comment                        :
DHCP Tag                       : default
Distribution                   : CentOS_7-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.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
Name                           : CentOS_6.9_X86_64-basic
TFTP Boot Files                : {}
Comment                        :
DHCP Tag                       : default
Distribution                   : CentOS_6.9-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/CentOS6.9_x86_64.ks.cfg
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                      : xenpv
Name                           : CentOS_6.9-x86_64
TFTP Boot Files                : {}
Comment                        :
DHCP Tag                       : default
Distribution                   : CentOS_6.9-x86_64
Enable gPXE?                   : 0
Enable PXE Menu?               : 1
Fetchable Files                : {}
Kernel Options                 : {}
Kernel Options (Post Install)  : {}
Kickstart                      : /var/lib/cobbler/kickstarts/sample_end.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



12、cobbler sync下(好像不執行這個也可以,以前那之前已經執行了)

[root@controller ~]# cobbler sync



13、客戶端安裝,網卡模式啓動

Image



14、cobbler web界面配置

使用系統用戶(pam)或者configfile定義用戶登錄管理cobbler web[root@cobbler ~]# vim /etc/cobbler/modules.conf
[authentication]
#module = authn_configfile (默認值)
module = authn_pam
[root@cobbler ~]# useradd Cadmin
[root@cobbler ~]# echo "Cadmin" | passwd --stdin Cadmin
Changing password for user Cadmin.
passwd: all authentication tokens updated successfully.
[root@cobbler ~]# vim /etc/cobbler/users.conf
[admins]
admin = "Cadmin"
[root@controller kickstarts]# systemctl restart cobblerd
[root@controller kickstarts]# systemctl restart httpd
訪問地址
https://192.168.153.11/cobbler_web



-------------------------------------------------------------------------------------------------
擴展1:客戶端默認是從local啓動的,需要手動選擇啓動項,如果要修改默認啓動項,更改下面這個配置文件。
LABEL CentOS_6.9-x86_64和LABEL CentOS_7-x86_64這個不是按照我的ks文件,默認密碼是改settings配置文件那個。其它兩個接basic是我自己的。

[root@controller kickstarts]# vi /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://www.gxm.com/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT localLABEL local
         MENU LABEL (local)
         MENU DEFAULT
         LOCALBOOT -1
LABEL CentOS7_X86_64-basic
         kernel /images/CentOS_7-x86_64/vmlinuz
         MENU LABEL CentOS7_X86_64-basic
         append initrd=/images/CentOS_7-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.153.11/cblr/svc/op/ks/profile/CentOS7_X86_64-basic
         ipappend 2
LABEL CentOS_6.9-x86_64
         kernel /images/CentOS_6.9-x86_64/vmlinuz
         MENU LABEL CentOS_6.9-x86_64
         append initrd=/images/CentOS_6.9-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.153.11/cblr/svc/op/ks/profile/CentOS_6.9-x86_64
         ipappend 2
LABEL CentOS_6.9_X86_64-basic
         kernel /images/CentOS_6.9-x86_64/vmlinuz
         MENU LABEL CentOS_6.9_X86_64-basic
         append initrd=/images/CentOS_6.9-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.153.11/cblr/svc/op/ks/profile/CentOS_6.9_X86_64-basic
         ipappend 2
LABEL CentOS_7-x86_64
         kernel /images/CentOS_7-x86_64/vmlinuz
         MENU LABEL CentOS_7-x86_64
         append initrd=/images/CentOS_7-x86_64/initrd.img ksdevice=bootif lang=  kssendmac text  ks=http://192.168.153.11/cblr/svc/op/ks/profile/CentOS_7-x86_64
         ipappend 2

MENU end
   或者修改[root@controller kickstarts]# vi /etc/cobbler/pxe/pxedefault.template這個文件。


擴展2:通過MAC地址定製化安裝(注意ks用默認產生的,因爲你自建的ks一般可能你手動固定了主機名等,這樣ks文件優先)
我們可以根據不同的MAC地址來給安裝 不同的操作系統、配置不同的靜態iP、設置不同的主機名、應用指定的ks文件等等,vmware虛擬機查看MAC地址步驟如圖:

Image

[root@localhost cobbler]# cobbler system add --name=gxm01 
--mac=00:0C:29:88:17:13 --profile=CentOS_7-x86_64 
--ip-address=192.168.153.200 --subnet=255.255.255.0 
--gateway=192.168.153.2 --interface=eth0 --static=1 --hostname=linux-gxm
 --name-servers="114.114.114.114 8.8.8.8" 
--kickstart=/var/lib/cobbler/kickstarts/sample_end.ks
[root@localhost cobbler]# cobbler system list
    gxm01
如果誤操作了,可以刪除重新add
[root@controller ~]# cobbler system remove --name gxm01
如果要修改,用下面的命令獲取幫助
[root@controller ~]# cobbler system edit --help
接下來我們創建一個虛擬機,mac地址爲00:0C:29:88:17:13,啓動後會發現自動進入安裝系統了,等安裝完以後,所有的配置都和我們當初設置的一樣。

  

擴展3:

備註1:網友的遇到的一個問題處理版本
期間因爲導入CentOS7的鏡像文件時我的電腦磁盤滿了而虛擬機停止,觸發了一個Cobbler的BUG,再次啓動虛擬機後重新導入CentOS7的映像文件時顯示如下。
# cobbler import --name=CentOS_7_x86_64 --path=/mnt/
Traceback (most recent call last):
   File "/usr/bin/cobbler", line 35, in <module>
     sys.exit(app.main())
   File "/usr/lib/python2.6/site-packages/cobbler/cli.py", line 644, in main
     rc = cli.run(sys.argv)
   File "/usr/lib/python2.6/site-packages/cobbler/cli.py", line 270, in run
     self.token         = self.remote.login("", self.shared_secret)
   File "/usr/lib64/python2.6/xmlrpclib.py", line 1199, in __call__
     return self.__send(self.__name, args)
   File "/usr/lib64/python2.6/xmlrpclib.py", line 1489, in __request
     verbose=self.__verbose
   File "/usr/lib64/python2.6/xmlrpclib.py", line 1253, in request
     return self._parse_response(h.getfile(), sock)
   File "/usr/lib64/python2.6/xmlrpclib.py", line 1392, in _parse_response
     return u.close()
   File "/usr/lib64/python2.6/xmlrpclib.py", line 838, in close
     raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 1: "<class 'cobbler.cexceptions.CX'>:'login failed'">
解決方法。
# service cobblerd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]
# cobbler get-loaders
重新導入。    
# cobbler import --name=CentOS_7_x86_64 --path=/mnt/
task started: 2014-10-08_173739_import
task started (id=Media import, time=Wed Oct  8 17:37:39 2014)
Found a candidate signature: breed=redhat, version=rhel6
Found a candidate signature: breed=redhat, version=fedora16
Found a candidate signature: breed=redhat, version=fedora17
Found a candidate signature: breed=redhat, version=fedora18
No signature matched in /var/www/cobbler/ks_mirror/CentOS_7_x86_64
!!! TASK FAILED !!!
這個時候又一次的出錯了:!!! TASK FAILED !!!,使用如下命令解決。
# cobbler signature update
再次導入。
# cobbler import --name=CentOS_7_x86_64 --path=/mnt/


備註2:Cobbler 子命令介紹
cobbler check         #檢查cobbler配置
cobbler sync          #步配置到dhcp pxe和數據目錄
cobbler list          #列出所有的cobbler元素
cobbler import        #導入安裝的系統光盤鏡像
cobbler report        #列出各元素的詳細信息
cobbler distro        #查看導入的發行版系統信息
cobbler profile       #查看配置信息
cobbler system        #查看添加的系統信息
cobbler reposync      #同步yum倉庫到本地


備註3:配置文件目錄:
/etc/cobbler
/etc/cobbler/settings : cobbler 主配置文件
/etc/cobbler/iso/: iso模板配置文件
/etc/cobbler/pxe: pxe模板文件
/etc/cobbler/power: 電源配置文件
/etc/cobbler/user.conf: web服務授權配置文件
/etc/cobbler/users.digest: web訪問的用戶名密碼配置文件
/etc/cobbler/dhcp.template : dhcp服務器的的配置末班
/etc/cobbler/dnsmasq.template : dns服務器的配置模板
/etc/cobbler/tftpd.template : tftp服務的配置模板
/etc/cobbler/modules.conf : 模塊的配置文件


備註4:數據目錄:
/var/lib/cobbler/config/: 用於存放distros,system,profiles 等信 息配置文件
/var/lib/cobbler/triggers/: 用於存放用戶定義的cobbler命令
/var/lib/cobbler/kickstart/: 默認存放kickstart文件
/var/lib/cobbler/loaders/: 存放各種引導程序  鏡像目錄
/var/www/cobbler/ks_mirror/: 導入的發行版系統的所有數據
/var/www/cobbler/images/ : 導入發行版的kernel和initrd鏡像用於 遠程網絡啓動
/var/www/cobbler/repo_mirror/: yum 倉庫存儲目錄


備註5:日誌目錄:
/var/log/cobbler/installing: 客戶端安裝日誌
/var/log/cobbler/cobbler.log : cobbler日誌


備註6:使用koan實現重新安裝系統
在客戶端安裝koan(要配置好源)
[root@localhost ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm
[root@localhost ~]# yum install koan
查看cobbler上的配置文件
[root@localhost ~]# koan --server=10.0.0.101 --list=profiles
- looking for Cobbler at http://10.0.0.101:80/cobbler_api
Centos-7.2-x86_64
重新安裝客戶端系統
[root@localhost ~]# koan --replace-self --server=10.0.0.101 --profile=webserver1
重啓系統後會自動重裝系統


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章