湖州建设网站制作,手机网站登录模板,信息网站开发,php做网站的技术难点本文目录#xff1a; 1.1 pxe安装系统 1.2 cobbler基本介绍 1.3 安装和配置cobbler 1.3.1 安装cobbler 1.3.2 配置dhcp和tftp 1.4 cobbler从本地光盘安装系统 1.4.1 生成distro 1.4.2 提供kickstart文件 1.4.3 提供profile 1.4.4 开始安装 1.5 比pxekickstart好的地方 1.6 让新…本文目录 1.1 pxe安装系统 1.2 cobbler基本介绍 1.3 安装和配置cobbler 1.3.1 安装cobbler 1.3.2 配置dhcp和tftp 1.4 cobbler从本地光盘安装系统 1.4.1 生成distro 1.4.2 提供kickstart文件 1.4.3 提供profile 1.4.4 开始安装 1.5 比pxekickstart好的地方 1.6 让新机器自动执行脚本 1.1 pxe安装系统 pxe的大致过程如下图。 其中pxelinux.0为bootloader。pxelinux.cfg目录下的文件(一般使用默认的default文件)定义了安装操作系统前的菜单项如kernel和Initrd的路径kickstart的路径等。 首先客户端请求pxe服务器上的dhcpdhcp上指定了next-server和filename它们分别是tftpd的地址和pxelinux.0的路径然后客户端请求tftpd获取pxelinux.0执行pxelinux.0后将引导进入安装界面随后获取pxelinux.cfg目录下的文件并读取其中的配置从中获取kernel和initrd的路径所在如果有定义kickstart项则还会去获取kickstart文件并读取配置再然后客户端请求获取kernel和initrd文件以展开内核并进入到根文件系统最后客户端获取完成系统安装所需的其他文件这些文件可以是在pxe的本地也可以是互联网上等能获取到的地方。 在阅读本文之前如果不懂pxekickstart建议先学习下对学习cobbler很有帮助。 PXEKickstart实现无人值守批量安装Linux http://www.linuxidc.com/Linux/2015-11/125040.htm RHEL7/CentOS7 PXEKickstart自动化系统安装 http://www.linuxidc.com/Linux/2017-07/145399.htm PXEKickstart安装CentOS 7.3 http://www.linuxidc.com/Linux/2017-06/144789.htm Linux运维自动化工具 Kickstart http://www.linuxidc.com/Linux/2016-04/129978.htm PXEKickstart无人值守安装CentOS 7 http://www.linuxidc.com/Linux/2017-08/146169.htm RHCE认证之无人值守安装Linux系统FTPTFTPDHCPKickstartPXE http://www.linuxidc.com/Linux/2013-10/91013.htm CentOS Kickstart及引导镜像文件制作 http://www.linuxidc.com/Linux/2017-05/143714.htm Kickstart 全自动安装部署RHEL 7.0 http://www.linuxidc.com/Linux/2015-09/123312.htm PXEKickstart无人值守安装CentOS 6 http://www.linuxidc.com/Linux/2017-08/146170.htm 1.2 cobbler基本介绍 cobbler可以看作是一个更多功能的pxe它实现系统安装和pxe也差不多需要的文件和过程大致都一样。 cobbler能自动管理dns/tftp/dhcp/rsync这四个服务(但似乎对tftp的管理有点bug需要手动启动tftp)且cobbler依赖于httpd(pxe支持http/nfs/ftp)。 基本的系统安装cobbler只需生成一个distro和一个profile即可。 distro相当于一个镜像它提供安装系统过程中所需的一切文件如vmlinuz,initrd以及rpm包等。 profile的作用是为了自动修改pxelinux.cfg/default文件每生成或修改一次profile都会在default文件中修改或追加对应的label。 除了distro/profile之外cobbler还管理system/images/repositories等但是用的很少。 1.3 安装和配置cobbler 1.3.1 安装cobbler cobbler在epel源中提供。由于还依赖于httpd、dhcp所以httpd和dhcp也应该装上。 yum -y install cobbler cobbler-web pykickstart debmirror httpd dhcp 其中cobbler-web是提供web管理界面的pykicstart是检查kicstart文件语法错误的debmirror是维护debian源的工具此处用不上但有依赖关系所以装上。 安装后在/etc/cobbler生成以下文件。 [rootlinuxidc ~]# cd /etc/cobbler/[rootlinuxidc cobbler]# ls
auth.conf distro_signatures.json modules.conf reporting tftpd.template zone_templates
cheetah_macros dnsmasq.template mongodb.conf rsync.exclude users.conf
cobbler_bash import_rsync_whitelist named.template rsync.template users.digest
completions iso power secondary.template version
dhcp.template ldap pxe settings zone.template 先启动httpd再启动cobblerd。 [rootlinuxidc cobbler]# systemctl start httpd.service
[rootlinuxidc cobbler]# systemctl start cobblerd.service [rootlinuxidc cobbler]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1298/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1402/master
tcp 0 0 127.0.0.1:25151 0.0.0.0:* LISTEN 14091/python2
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2261/mysqld
tcp 0 0 :::22 :::* LISTEN 1298/sshd
tcp 0 0 ::1:25 :::* LISTEN 1402/master
tcp 0 0 :::443 :::* LISTEN 14037/httpd
tcp 0 0 :::80 :::* LISTEN 14037/httpd 启动之后首先执行cobbler check检查配置是否正确。根据提示修改相关的配置项。 [rootlinuxidc cobbler]# 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 : 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 : change disable to no in /etc/xinetd.d/rsync
5 : comment out dists on /etc/debmirror.conf for proper debian support
6 : comment out arches on /etc/debmirror.conf for proper debian support
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-phrase-here 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 themRestart cobblerd and then run cobbler sync to apply changes. 第一和第二个问题 [rootlinuxidc cobbler]# vim /etc/cobbler/settingsnext_server: 172.16.10.10
server: 172.16.10.10 第三个问题获取pxelinux.0和menu.c32文件(对于centos来说只需这两个文件)可以像pxe一样从syslinux包中手动复制到/var/lib/cobbler/loaders目录下也可以执行cobbler get-loaders自动下载但要求联网。 [rootlinuxidc cobbler]# cobbler get-loaders 第四个问题有可能该问题不是如此的而是说要将rsyncd.service使用给start且enable只需systemctl enable rsyncdsystemctl start rsyncd。 [rootlinuxidc cobbler]# vim /etc/xinetd.d/rsync
disableno [rootlinuxidc cobbler]# service xinetd start 第5、6个问题注释掉/etc/debmirror.conf中相关项即可。 第7个问题因为之前安装的时候写成了pykicstart所以出错了这里。 [rootlinuxidc cobbler]# yum -y install pykickstart 第8个问题 [rootlinuxidc cobbler]# openssl passwd -1 -salt openssl rand -hex 8 123456
$1$77e1022c$D9rxuxUWdc0NN46gzj9XT. [rootlinuxidc cobbler]# vim /etc/cobbler/settings
default_password_crypted: $1$77e1022c$D9rxuxUWdc0NN46gzj9XT. 第九个问题和电源管理有关不用管了。直接重启cobbler然后cobbler sync。 [rootlinuxidc cobbler]# service cobblerd restart[rootlinuxidc cobbler]# cobbler check
The following are potential configuration items that you may want to fix:
1 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them [rootlinuxidc cobbler]# cobbler sync cobbler sync命令用于将tftpboot目录和/var/www/cobbler保持最新当/var/lib/cobbler或者kickstart文件发生了变化应该执行一次cobbler sync或者直接重启cobbler服务。 1.3.2 配置dhcp和tftp 如果在/etc/cobbler/setting中设置了manage_dhcp:1表示由cobbler管理dhcp(默认为0即人为手动管理)则cobbler管理的dhcp的配置模板/etc/cobbler/dhcp.template会覆盖/etc/dhcp/dhcpd.conf中配置所以应该修改dhcp.template。 此处采用默认的不由cobbler管理dhcp。 [rootlinuxidc cobbler]# yum-y install dhcp
[rootlinuxidc cobbler]# vim /etc/dhcp/dhcpd.conf
ddns-update-style none;
default-lease-time 259200;
max-lease-time 518400;
subnet 172.16.10.0 netmask 255.255.255.0 {range 172.16.10.20 172.16.10.50;option subnet-mask 255.255.255.0;next-server 172.16.10.10; # tftp的地址filename pxelinux.0; # pxelinux.0的路径此为tftp根目录(/var/lib/tftpboot)的相对路径
} [rootlinuxidc cobbler]# service dhcpd restart 关于tftp在/etc/cobbler/settings中默认启用了由cobbler管理tftp所以此处无需配置它。只要知道它的根目录为/var/lib/tftpboot即可。但是如果后面装系统的时候如果找不到tftp(应该是cobbler管理tftp的bug)则手动启动tftp即可。 1.4 cobbler从本地光盘安装系统 1.4.1 生成distro 生成distro的方法有多种可以从本地镜像导入生成也可以根据网络上的资源生成。显然从本地生成的效率是最好的。 从本地导入的过程实际上是将系统镜像中的文件复制到/var/www/cobbler/目录(默认)下。 mkdir /mnt
mount /dev/cdrom /mnt
cobbler import --nameCentOS7.2 --path/mnt 等待导入完成则表示distro生成完成。 [rootlinuxidc cobbler]# ls -l /var/www/cobbler/images/CentOS7.2-x86_64/
total 38056
-r--r--r-- 3 root root 34815427 Oct 24 2014 initrd.img
-r-xr-xr-x 3 root root 4152336 Oct 24 2014 vmlinuz [rootlinuxidc cobbler]# ls -l /var/www/cobbler/ks_mirror/CentOS7.2/ # 此目录完全来源于镜像
total 340
-r--r--r-- 1 root root 14 Oct 24 2014 CentOS_BuildTag
dr-xr-xr-x 3 root root 4096 Oct 24 2014 EFI
-r--r--r-- 1 root root 212 Nov 28 2013 EULA
-r--r--r-- 1 root root 18009 Nov 28 2013 GPL
dr-xr-xr-x 3 root root 4096 Oct 24 2014 images
dr-xr-xr-x 2 root root 4096 Oct 24 2014 isolinux
dr-xr-xr-x 2 root root 278528 Oct 24 2014 Packages
-r--r--r-- 1 root root 1354 Oct 20 2014 RELEASE-NOTES-en-US.html
dr-xr-xr-x 2 root root 4096 Oct 24 2014 repodata
-r--r--r-- 1 root root 1706 Nov 28 2013 RPM-GPG-KEY-CentOS-6
-r--r--r-- 1 root root 1730 Nov 28 2013 RPM-GPG-KEY-CentOS-Debug-6
-r--r--r-- 1 root root 1730 Nov 28 2013 RPM-GPG-KEY-CentOS-Security-6
-r--r--r-- 1 root root 1734 Nov 28 2013 RPM-GPG-KEY-CentOS-Testing-6
-r--r--r-- 1 root root 3380 Oct 24 2014 TRANS.TBL 确保url路径http://172.16.10.10/cobbler/ks_mirror/CentOS7.2/是有效的。 1.4.2 提供kickstart文件 以下是CentOS7的Kickstart内容。如果要改为适合CentOS6的内容只需将keyboard项设置为keyboard us并修改下分区方式(如有必要的话)以及%post脚本段的内容即可。 [rootlinuxidc ~]# vim /var/lib/cobbler/kickstarts/CentOS7.2.ks
#versionDEVEL
# System authorization information
auth --enableshadow --passalgosha512
# Install OS instead of upgrade
install
# Use network installation
url --url$tree
# Use text mode install
text
# Firewall configuration
firewall --disabled
firstboot --disable
# ignoredisk --only-usesda # 此项是CentOS7默认的项但cobbler编译ks文件时不支持此语法所以必须将此项注释掉
# Keyboard layouts
# old format: keyboard us
# new format:
keyboard --vckeymapus --xlayoutsus
# System language
lang en_US.UTF-8# Network information
network --onbootyes --bootprotodhcp --deviceeth0 --noipv6
network --hostnamenode1.linuxidc.com
# Reboot after installation
reboot
# Root password
rootpw --iscrypted $6$KIPkwGVYqtjHln80$quxmkE5MKKA2LyzLOAc/s3FWH/jX76sObq6hqwOsEBoeMc/wIrzGG4xm72lkXwLeOfRLS/sl5vdajY9j34D4J.
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --appendquiet crashkernelauto --locationmbr --boot-drivesda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --asprimary --fstypexfs --size250
part swap --fstypeswap --size2000
part / --asprimary --fstypexfs --grow --size5000# 如果是要LVM分区则考虑以下分区
# part /boot --fstype ext4 --size100
# part swap --fstypeswap --size2048
# part pv26 --size100 --grow
# volgroup VG00 --pesize32768 pv26
# logvol / --fstype ext4 --nameLVroot --vgnameVG00 --size29984
# logvol /data --fstype ext4 --nameLVdata --vgnameVG00 --size100 --grow%post
rm -f /etc/yum.repos.d/*
cat /etc/yum.repos.d/my.repoeof
[base]
namesohu
baseurlhttp://mirrors.sohu.com/centos/7/os/x86_64/
gpgcheck0
enable1
[epel]
nameepel
baseurlhttp://mirrors.aliyun.com/epel/7Server/x86_64/
enable1
gpgcheck0
eof
sed -i s/rhgb // /boot/grub2/grub.cfg
sed -i /UUID/d /etc/sysconfig/network-scripts/ifcfg-eth0
echo DNS1114.114.114.114 /etc/sysconfig/network-scripts/ifcfg-eth0
echo UseDNS no /etc/ssh/sshd_config
sed -i s/GSSAPIAuthentication yes/GSSAPIAuthentication no/ /etc/ssh/ssh_config
sed -i s/^SELINUX.*$/SELINUXdisabled/ /etc/sysconfig/selinux
systemctl disable firewalld
%end%packages
base
core
development
platform-devel
kexec-tools
lftp
tree
lrzsz%end%addon com_RedHat_kdump --enable --reserve-mbauto%end 上面的url也可以写成url --urlhttp://172.16.10.10/cobbler/ks_mirror/CentOS7.2/。 1.4.3 提供profile 在导入镜像生成distro的过程中会自动生成一个profile。 [rootlinuxidc cobbler]# cobbler profile listCentOS7.2-x86_64 该profile默认使用的kickstart是/var/lib/cobbler/kickstarts/sample_end.ks所以需要修改此项。 [rootlinuxidc cobbler]# cobbler profile report --nameCentOS7.2-x86_64
Name : CentOS7.2-x86_64
TFTP Boot Files : {}
Comment :
DHCP Tag : default
Distribution : CentOS7.2-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 [rootlinuxidc cobbler]# cobbler profile edit --nameCentOS7.2-x86_64 --kickstart/var/lib/cobbler/kickstarts/CentOS7.2.ks
[rootlinuxidc cobbler]# cobbler profile report --nameCentOS7.2-x86_64 | grep -i kickstart
Kickstart : /var/lib/cobbler/kickstarts/CentOS7.2.ks
Kickstart Metadata : {} 对于centos7系列则加上内核启动参数net.ifnames和biosdevname使得网卡名使用ethN系列而不使用enoXXXXXXX这样的随机名称。 [rootlinuxidc cobbler]# cobbler profile edit --nameCentOS7.2-x86_64 --kickstart/var/lib/cobbler/kickstarts/CentOS7.2.ks --koptsnet.ifnames0 biosdevname0
[rootlinuxidc cobbler]# cobbler profile report --nameCentOS7.2-x86_64 | grep -Ei kernel|kickstart Kernel Options : {biosdevname: 0, net.ifnames: 0}
Kernel Options (Post Install) : {}
Kickstart : /var/lib/cobbler/kickstarts/CentOS7.2.ks
Kickstart Metadata : {} 当然不使用自生成的profile自己添加一个profile也可以同时还可以设置profile选项如--kickstart项。如下其中--distro指定该profile是添加到哪个distro下的。 [rootlinuxidc cobbler]# cobbler profile add --nameCentOS7.2.1-x86_64 --distroCentOS7.2-x86_64 --kickstart/var/lib/cobbler/kickstarts/CentOS7.2.ks 实际上每添加一个profile都是在向/var/lib/tftpboot/pxelinux.cfg/default中添加一个label。 [rootlinuxidc cobbler]# cat /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT localLABEL localMENU LABEL (local)MENU DEFAULTLOCALBOOT -1LABEL CentOS7.2-x86_64kernel /images/CentOS7.2-x86_64/vmlinuzMENU LABEL CentOS7.2-x86_64append initrd/images/CentOS7.2-x86_64/initrd.img ksdevicebootif lang text net.ifnames0 biosdevname0 kssendmac kshttp://172.16.10.10/cblr/svc/op/ks/profile/CentOS7.2-x86_64ipappend 2LABEL CentOS7.2.1-x86_64kernel /images/CentOS7.2-x86_64/vmlinuzMENU LABEL CentOS7.2.1-x86_64append initrd/images/CentOS7.2-x86_64/initrd.img ksdevicebootif lang kssendmac text kshttp://172.16.10.10/cblr/svc/op/ks/profile/CentOS7.2.1-x86_64ipappend 2MENU end 也就是说其实可以不用生成profile自己手动编辑label也可以。 默认使用的菜单背景图片是menu.c32此处我改为vesamenu.c32该背景图片是从syslinux包中提取的背景图片而已看个人喜好了。另外默认菜单等待时间是2秒在自动安装的环境中可以将其设置的短些。并且进入菜单默认停留在local即从本地启动系统但是此时系统还没装所以要实现自动化建议修改此项。 以下是修改后的项。 DEFAULT vemamenu
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
TIMEOUT 20
TOTALTIMEOUT 6000
ONTIMEOUT CentOS7.2-x86_64LABEL localMENU LABEL (local)LOCALBOOT -1LABEL CentOS7.2-x86_64kernel /images/CentOS7.2-x86_64/vmlinuz MENU DEFAULTMENU LABEL CentOS7.2-x86_64 append initrd/images/CentOS7.2-x86_64/initrd.img ksdevicebootif lang text net.ifnames0 biosdevname0 kssendmac kshttp://172.16.10.10/cblr/svc/op/ks/profile/CentOS7.2-x86_64ipappend 2LABEL CentOS7.2.1-x86_64kernel /images/CentOS7.2-x86_64/vmlinuzMENU LABEL CentOS7.2.1-x86_64append initrd/images/CentOS7.2-x86_64/initrd.img ksdevicebootif lang kssendmac text kshttp://172.16.10.10/cblr/svc/op/ks/profile/CentOS7.2.1-x86_64ipappend 2MENU end 在开始安装之前要确保该ks路径是有效的且kickstart内容是正确的。有时候提供的Kickstart内容错误了在制作成profile的时候不会报错但实际上浏览器访问该ks路径的内容提示错误。例如访问CentOS7.2.1-x86_64这个LABEL的kickstart文件将其ks文件url地址http://172.16.10.10/cblr/svc/op/ks/profile/CentOS7.2.1-x86_64输入浏览器中。如果得到如下结果则表示出错了很大的可能是cobbler不支持kickstart中的某指令这个需要慢慢检查。 # This kickstart had errors that prevented it from being rendered correctly.
# The cobbler.log should have information relating to this failure. 修改kickstart文件后需要重新编译profile加载新的kickstart文件。只需使用cobbler profile edit --nameXXXXX --kickstartYYYYY即可重新编译XXXXX这个profile或者执行cobbler sync命令。直到浏览器中能获取到kickstart的内容时才算成功。 或者使用cobbler profile getks --nameXXXXX命令获取名为XXXXX的profile的ks内容。 总之必须要保证能正确获取到ks内容。 1.4.4 开始安装 准备一个新的机器开机就会自动进入菜单2-3秒超时后自动进行安装安装完成后自动重启重启时自动从本地启动。 所以除了对新机器进行开机其他的一切完完全全是全自动的。 建议在真正开始安装前将dhcpd/rsyncd/tftp/cobbler等给重启一遍防止中间改过哪些地方忘记重启而导致装机时出错。 1.5 比pxekickstart好的地方 仅就cobbler基本功能而言它跟pxe的能力基本是一样的只是提供了更多花哨的功能。 但cobbler能够使用变量能够通过几个命令自动完成文件复制修改等繁琐的动作另外它提供了api接口常用的是它的图形界面。在这一点上它还是不错的。 1.6 让新机器自动执行脚本 有些时候新机器上要进行很多配置在kickstart的%post段也可以配置但是这里能进行的配置是有限的。 可以在cobbler服务端写好要执行的脚本然后在新机器上将脚本使用scp复制过去但是scp复制需要确认和输入密码所以需要在kickstart的选包部分指定安装expect包然后使用expect进行非交互scp。 最后在%post段直接执行此脚本即可。 本文永久更新链接地址http://www.linuxidc.com/Linux/2017-08/146171.htm转载于:https://www.cnblogs.com/liujiacai/p/8685690.html