您的位置:首页 > 其它

Cobbler自动批量部署不同需求的系统

2017-10-21 00:45 477 查看

cobbler简介





看到百度这句话的时候我心里突然觉得压力好大啊啊啊,感觉饭碗不保,赶紧学习了一下

曾经使用PXE批量安装系统,但是PXE存在一个缺陷,即只能安装单一的操作系统。但是在实际环境中,不同功能的服务器需要部署不同的环境,而cobbler正好满足了这一需求。cobbler基于python开发,是对PXE的二次封装,且提供了CLI和Web的管理形式,使得操作和管理更加简便。cobbler的实现与PXE类似,也需要tftp,httpd,dhcp这些服务。使用yum即可完成cobbler的安装,在安装的同时也会自动安装tftp和httpd服务,dhcp服务需要自行安装。


准备工作:

Cobbler实验主机环境:

OS: Redhat 7.2 x86_64bit
IP: 192.168.1.4


防火墙关闭,SELinux处于disabled状态



为了安装Cobbler所需要的一系列软件,首先配置一下yum源,贴上本人的

#自己挂的镜像
[lockey]
name=lockey rhel72
baseurl=http://192.168.1.4/iso72
gpcheck=0

#epel网络源
[good]
name=ailiyun
baseurl=http://mirrors.aliyun.com/epel/7/x86_64/
enabled=1
gpgcheck=0

#网络yum源
[centos]
name=cobbler
baseurl=http://mirrors.aliyun.com/centos/7/os/x86_64/
enabled=1
gpgcheck=0


1. cobbler安装和基本配置

[root@lockey4 ~]# yum install cobbler cobbler-web pykickstart debmirror




这里也有一个el7的RPM包可以用也可以不用cobbler-2.8.1-2.el7.x86_64.rpm

启动cobbler

[root@lockey4 ~]#  systemctl start cobblerd.service


[root@lockey4 ~]# cobbler check



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 : comment out 'dists' on /etc/debmirror.conf for proper debian support
7 : comment out 'arches' on /etc/debmirror.conf for proper debian support
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 them


对应check结果执行以下操作:

1.修改配置文件/etc/cobbler/settings中以下两项,要求:resolvable hostname or IP

next_server: 192.168.1.4#cobbler主机ip

server: 192.168.1.4#cobbler主机ip


2.修改tftp的启动设置/etc/xinetd.d/tftp



3.获取boot-loaders

[root@lockey4  ~]# cobbler get-loaders




4.安装fence-agents和cman

[root@lockey4  ~]# yum install fence-agents cman


5.注释/etc/debmirror.conf 中以下两项

#@dists="sid";
#@arches="i386";


6.更改加密设置

[root@cobbler ~]# openssl passwd -1 -salt ‘openssl rand -hex 4’
Password:
$1$openssl $GZKb7LW2hcSWj8/oiA.v9/

#将生成的密码写入以下文件对应位置:
[root@lockey4 ~]# cat /etc/cobbler/settings | grep default_pa
default_password_crypted: "$1$openssl $GZKb7LW2hcSWj8/oiA.v9/"


7.启动并设置rsyncd服务开机自启动

[root@lockey4 ~]#   systemctl enable rsyncd
[root@lockey4 ~]#   systemctl start rsyncd


最后重启服务再次check,达到以下结果就OK了:

[root@lockey4 ~]# systemctl restart cobblerd.service
[root@lockey4 ~]# cobbler check
No configuration problems found.  All systems go.


2. 安装配置DHCP

[root@lockey4 ~]#   yum install dhcp -y


主要的文件配置如下:

[root@lockey4 ~]# cat /etc/dhcp/dhcpd.conf

#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
default-lease-time  86400;
max-lease-time  7200;
log-facility local7;
subnet  192.168.1.0 netmask 255.255.255.0 {#子网和掩码
range 192.168.1.100   192.168.1.110;#网段
option    routers 192.168.1.4;#本机ip
}
next-server 192.168.1.4;#本机ip
filename="pxelinux.0";


[root@lockey4 ~]# systemctl start dhcpd

如果启动有问题请查看日志定位:

[root@lockey4 ~]# cat /var/log/messages


3. 安装system-config-kickstart并生成自动应答脚本

[root@lockey4 ~]# yum install  system-config-kickstart
[root@lockey4 ~]# system-config-kickstart


具体步骤请参考本人月前博客kickstart自动应答脚本生成及虚拟机自动安装

这里直接贴上本人最终生成的配置文件(注意文件路径,必须如此,如果要拿去用的话需要对应修改url以及文件系统格式,window中通过vmware和Linux中的安装时文件系统格式是不一样的∑):

[root@lockey4 ~]# vim /var/lib/cobbler/kickstarts/redhat65.cfg

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'# Reboot after installation
reboot
# Root password
rootpw --iscrypted $1$A3vhYrc8$mISo4Or6RZkMkWOusdEkE.
# System timezone
timezone Asia/Chongqing --isUtc
# Use network installation
url --url="http://192.168.1.4/cobbler/ks_mirror/centos65/"
# System language
lang en_US
# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=eth0
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# System bootloader configuration
bootloader --append="crashkernel=auto rhgb quiet" --location=mbr --driveorder="sda"
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --size=500##注意这一行fstype
part pv.008002 --grow --size=1
part / --fstype="ext4" --grow --size=1 ##and注意这一行fstype
%post
cat >> /etc/yum.repos.d/yum.repo <<end
[halo]
name=haloooo
baseurl=http://192.168.1.4/iso65
gpgcheck=0
end
echo sshd:ALL >>/etc/hosts.deny
%end
%packages
@base
%end


4. 导入镜像

我的镜像挂载位置:



以下参数名字自己起,路径对应自己的挂载路径填写

[root@lockey4 ~]# cobbler import --name="centos65" --path=/var/www/html/iso65##此命令等待时间较长,5分钟以外




[root@lockey4 ~]# cobbler profile add --name=centos-6.5-lockey --distro=centos65-x86_64 --kickstart=/var/lib/cobbler/kickstarts/redhat65.cfg


[root@lockey4 ~]# cobbler profile list

centos-6.5-lockey
centos65-x86_64


[root@lockey4 ~]# cobbler sync



确认配置是否成功

[root@lockey4 ~]# cat /var/lib/tftpboot/pxelinux.cfg/default



查看导入的镜像



5 .新建虚拟机



几个需要注意的地方









点击完成之后开启虚拟机,后面的安装步骤除了选择系统之外都是自动

6. 开始自动安装虚拟机















因为我本人第一次安装的时候自动应答脚本中的文件系统出错导致的安装失败,在window中要将xfs改为ext4



part /boot --fstype="ext4" --size=500
part pv.008002 --grow --size=1
part / --fstype="ext4" --grow --size=1


一个系统的启动选择项加入以及测试安装完成了,如果想要设置更多的系统类型,从4. 导入镜像对应其他系统再走一遍流程即可,完成之后新安装虚拟机就可以看到更多的选项了,如下:



拓展知识:redhat6修改或者重置root用户密码

1. 系统启动的时候按任意键进入如下界面并且根据下方提示按下“e”



2. 然后在出现的字符串后面输入single 1进入单用户模式(按下e开始编辑)



3.输入好了之后,“回车”,返回到了刚刚的界面,再输入“b”,让boot引导进入系统。



在单用户模式修改密码然后init 6用新密码登录即可



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: