实验环境:Centos7虚拟机
cooler作用:
使用Cobbler,您无需进行人工干预即可安装机器。当公司新进大量新服务器的时候可以用cobbler来进行安装操作系统。Cobbler设置一个PXE引导环境(它还可以使用yaboot支持PowerPC),并 控制与安装相关的所有方面,比如网络引导服务(DHCP和TFTP)与存储库镜像。当希望安装一台新机器时,Cobbler可以:
1)使用一个以前定义的模板来配置DHCP服务(如果启用了管理DHCP)
2)将一个存储库(yum或rsync)建立镜像或解压缩一个媒介,以注册一个新操作系统
3)在DHCP配置文件中为需要安装的机器创建一个条目,并使用指定的参数(IP和MAC)
4)在TFTP服务目录下创建适当的PXE文件
5)重新启动DHCP服务来反应新的更改
6)重新启动机器以开始安装(如果电源管理已启动)
一、基础环境的准备:
1、 配置自己的虚拟机可以联网
[root@C7-1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
修改以下选项
BOOTPROTO=static
ONBOOT=yes
添加以下选项
IPADDR=192.168.1.11
NETMASK=255.255.255.0
DNS1=114.114.114.114
GATEWAY=192.168.1.1
[root@C7-1 ~]# ping www.baidu.com
PING www.a.shifen.com (111.13.100.91) 56(84) bytes of data.
64 bytes from 111.13.100.91 (111.13.100.91): icmp_seq=1 ttl=53 time=14.6 ms
2、 关闭防火墙和seLinux
[root@C7-1 ~]# systemctl stop firewalld.service
[root@C7-1 ~]# systemctl disable firewalld.service
[root@C7-1 ~]# setenforce 0
[root@C7-1 ~]# vim /etc/selinux/config
SELINUX=disabled #修改
3、 配置yum源(因为没有cobbler的yum源,所以要自己配置)
[root@C7-1~]#yum -y install http://mirrors.163.com/centos/7/extras/x86_64/Packages/epel-release-7-9.noarch.rpm
二、安装cobbler
[root@C7-1 ~]# yum -y install cobbler cobbler-web pykickstart httpd dhcp tftp-server debmirror
启动http服务和cobbler服务
[root@C7-1 ~]# systemctl start httpd.service
[root@C7-1 ~]# systemctl start cobblerd.service
检测状态
[root@C7-1 ~]# systemctl status cobblerd.service
[root@C7-1 ~]# systemctl status httpd.service
三、检查cobbler配置问题,并逐条解决
[root@C7-1 ~]# 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 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
https://github.com/cobbler/cobbler/wiki/Selinux
4 : change 'disable' to 'no' in /etc/xinetd.d/tftp
5 : 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.
6 : enable and start rsyncd.service with systemctl
7 : comment out 'dists' on /etc/debmirror.conf for proper debian support
8 : comment out 'arches' on /etc/debmirror.conf for proper debian support
9 : 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
10 : 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 : 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.
解决办法:
修改/etc/cobbler/settings文件中的server参数的值为提供cobbler服务的主机相应的IP地址或主机名
384 server: 192.168.1.11
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.
解决办法:
修改/etc/cobbler/settings文件中的next_server参数的值为提供PXE服务的主机相应的IP地址
[root@C7-1 ~]# sed -i 's/next_server: 127.0.0.1/next_server: 192.168.1.11/' /etc/cobbler/settings
3 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment:
https://github.com/cobbler/cobbler/wiki/Selinux
问题原因:没有关闭selinux(但是有的时候关了,没有重启也会报错)
解决办法:关闭seLinux,关闭之后不需要管他了
4 : change 'disable' to 'no' in /etc/xinetd.d/tftp
解决办法:修改tftp文件中的一个参数
[root@C7-1 ~]# sed -i 's/disable.*= yes/disable = no/g' /etc/xinetd.d/tftp
5 : 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.
解决办法:cobbler get-loaders (必须联网状态下)
6 : enable and start rsyncd.service with systemctl
问题原因:rsync服务没有开启
解决办法:
[root@C7-1 ~]# systemctl start rsyncd
[root@C7-1 ~]# systemctl enable rsyncd
7 : comment out 'dists' on /etc/debmirror.conf for proper debian support
问题原因:debian系统的相关文件没装
解决办法:如果不需要安装debian的系统可以忽略
8 : comment out 'arches' on /etc/debmirror.conf for proper debian support
问题原因:debian系统的相关文件没装
解决办法:如果不需要安装debian的系统可以忽略
9 : 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
问题原因:生成密码来取代默认的密码,更安全
解决办法:
[root@C7-1 ~]# openssl passwd -1 -salt 'cxm' '123456'
$1$cxm$vks4RGMOXJbd81BVyIQsR1
[root@C7-1 ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$cxm$vks4RGMOXJbd81BVyIQsR1"
10 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
问题原因:缺少cman 和 fence-agents
解决办法:
[root@C7-1 ~]# yum -y install cman fence-agents
还需要修改一些东西
[root@C7-1 ~]# sed -i 's/manage_dhcp: 0/manage_dhcp: 1/g' /etc/cobbler/settings
[root@C7-1 ~]# sed -i 's/pxe_just_once: 0/pxe_just_once: 1/' /etc/cobbler/settings
之后重启cobbler服务检查是否还有错误
[root@C7-1 ~]# systemctl restart cobblerd.service
[root@C7-1 ~]# cobbler check
还有一些我们不需要的错误就不用改了。如果出现不一样的错误把报错休息复制百度就可以找到答案
四、配置DHCP服务
[root@C7-1 ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.1.0 netmask 255.255.255.0 { #网段
option routers 192.168.1.1; #网关
option domain-name-servers 192.168.1.1; #DNS
option subnet-mask 255.255.255.0; #掩码
range dynamic-bootp 192.168.1.100 192.168.1.254; #地址池
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
同步:[root@C7-1 ~]# cobbler sync (可以看看做了哪些操作)
五、服务开机自启动和重启服务
[root@C7-1 ~]# systemctl enable dhcpd.service
[root@C7-1 ~]# systemctl enable rsyncd.service
[root@C7-1 ~]# systemctl enable tftp.service
[root@C7-1 ~]# systemctl enable httpd.service
[root@C7-1 ~]# systemctl enable cobblerd.service
[root@C7-1 ~]# systemctl restart dhcpd.service
[root@C7-1 ~]# systemctl restart rsyncd.service
[root@C7-1 ~]# systemctl restart tftp.service
[root@C7-1 ~]# systemctl restart httpd.service
[root@C7-1 ~]# systemctl restart cobblerd.service
六、导入镜像
1、挂载你想要安装的系统的光盘
[root@C7-1 ~]# mount /dev/cdrom /mnt/
2、导入镜像
[root@C7-1 ~]# cobbler import --path=/mnt/ --name=CentOS-7-x86_64 --arch=x86_64
# --path 镜像路径
# --name 为安装源定义一个名字
# --arch 指定安装源是32位、64位、ia64, 目前支持的选项有: x86│x86_64│ia64
# 安装源的唯一标示就是根据name参数来定义,本例导入成功后,安装源的唯一标示就是:CentOS-7x86_64,如果重复,系统会提示导入失败。
3、 查看镜像列表
[root@C7-1 ~]# cobbler distro list
CentOS-7-x86_64
4、 镜像存放目录,cobbler会将镜像中的所有安装文件拷贝到本地一份,放在/var/www/cobbler/ks_mirror下的CentOS-7-x86_64目录下
[root@C7-1 ~]# cd /var/www/cobbler/ks_mirror/
[root@C7-1 ks_mirror]# ls
CentOS-7-x86_64 config
[root@C7-1 ks_mirror]# cd CentOS-7-x86_64/
[root@C7-1 CentOS-7-x86_64]# ls
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
5、 查看安装镜像文件信息
查看所有的profile设置 cobbler profile report
查看指定的profile设置 cobbler profile report --name=CentOS-7-x86_64
七、修改ks文件(定义安装时的很多操作)
1、最小化安装(磁盘自动创建)
这次就直接用默认的最小化安装做 不修改KS文件
提示: @server-policy 不要这个选项
[root@C7-1 CentOS-7-x86_64]# cd /var/lib/cobbler/kickstarts/
[root@C7-1 kickstarts]# ls
default.ks esxi5-ks.cfg legacy.ks sample_autoyast.xml sample_esx4.ks sample_esxi5.ks sample_old.seed
esxi4-ks.cfg install_profiles pxerescue.ks sample_end.ks(默认ks文件) sample_esxi4.ks sample.ks sample.seed
直接改名
[root@C7-1 kickstarts]# mv sample_end.ks CentOS-7-x86_64.cfg
查看安装镜像文件信息
[root@C7-1 kickstarts]# cobbler distro report --name=CentOS-7-x86_64
编辑profile,修改关联的ks文件
[root@C7-1 kickstarts]# cobbler profile edit --name=CentOS-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg
修改安装系统的内核参数,在CentOS7系统有一个地方变了,就是网卡名变成eno*****这种形式,但是为了运维标准化,我们需要将它变成我们常用的eth0,因此使用下面的参数。但要注意是CentOS7才需要下面的步骤,CentOS6不需要。
[root@C7-1 kickstarts]# cobbler profile edit --name=CentOS-7-x86_64 --kopts='net.ifnames=0 biosdevname=0'
cobbler profile report --name=CentOS-7-x86_64
Kickstart : /var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg
这行不一样
同步下cobbler数据,每次修改完都要镜像同步
[root@C7-1 kickstarts]# cobbler sync
2、我通常用的ks文件
# kickstart template for Fedora 8 and later.
# (includes %end blocks)
# do not use with earlier distros
#platform=x86, AMD64, or Intel EM64T
# System authorization information
auth --useshadow --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Use text mode install
text
# Firewall configuration
firewall --disable
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang zh_CN.UTF-8
# Use network installation
url --url=$tree
# If any cobbler repo definitions were referenced in the kickstart profile, include them here.
$yum_repo_stanza
# Network information
$SNIPPET('network_config')
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $default_password_crypted
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System timezone
timezone --isUtc Asia/Shanghai
# Install OS instead of upgrade
install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
clearpart --all --initlabel
part /boot --fstype="ext4" --size=200
part swap --fstype="swap" --size=72000
part / --fstype="ext4" --grow --size=1
part biosboot --fstype="biosboot" --size=1 ##硬盘超过2T
%pre
$SNIPPET('log_ks_pre')
$SNIPPET('kickstart_start')
$SNIPPET('pre_install_network_config')
# Enable installation monitoring
$SNIPPET('pre_anamon')
%end
%packages
@base
@development
lrzsz
net-tools
$SNIPPET('func_install_if_enabled')
%end
%post --nochroot
$SNIPPET('log_ks_post_nochroot')
%end
%post
$SNIPPET('log_ks_post')
# Start yum configuration
$yum_config_stanza
# End yum configuration
$SNIPPET('post_install_kernel_options')
$SNIPPET('post_install_network_config')
$SNIPPET('func_register_if_enabled')
$SNIPPET('download_config_files')
$SNIPPET('koan_environment')
$SNIPPET('redhat_register')
$SNIPPET('cobbler_register')
# Enable post-install boot notification
$SNIPPET('post_anamon')
# Start final steps
$SNIPPET('kickstart_done')
# End final steps
%end
注意:
如果硬盘超过2T
part biosboot --fstype="biosboot" --size=1
八、完全自动化
安装系统会出现local和自己的系统,也得选择,不算完全自动化
修改/etc/cobbler/pxe/pxedefault.template的文件:
如果你想默认是自己的系统,在DEFAULT后边写上自己的系统的名称。之后刷新就可以了
[root@C7-1 kickstarts]# cobbler sync
[root@C7-1 kickstarts]# vim /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT CentOS-7-x86_64
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local
#LABEL local
# MENU LABEL (local)
# MENU DEFAULT
# LOCALBOOT -1
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= text net.ifnames=0 biosdevname=0 kssendmac ks=http://192.168.1.11/cblr/svc/op/ks/profile/CentOS-7-x86_64
ipappend 2
MENU end
这个文件也会跟着改变
之后就可以安装系统了。
注意
如果是centos7环境,镜像挂载的是centos7.创建虚拟机的时候一定要创建redhat 7的模板