关于IT运维技术的
最佳实践博客网站

使用Cobbler无人值守批量安装Centos和Ubuntu

一、基本初始化设置

1、系统版本centos6.x,最小化安装,分区容量务必充足。

参考:https://www.cnhzz.com/centos65-youhua/

2、设置机器的hostname和FQDN名字。

#修改成cobbler.localdomain 需要修改两处
sed -i "s/localhost/cobbler/g" /etc/sysconfig/network
echo "10.211.55.11 cobbler cobbler.localdomain" >> /etc/hosts

3、设置使用源和epel源。

yum install epel*

4、关闭selinux

sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config

5、设置cobbler主机网络,使用静态IP。

# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
IPADDR=10.211.55.11
NETMASK=255.255.0.0

二、安装cobbler

1、运行yum命令装cobbler

#稳定版
yum -y install cobbler cobbler-web
#最新测试版
yum install --enablerepo=epel-testing cobbler cobbler-web

2、安装完毕以后先启动cobbler后在运行cobbler check 命令可以很友好的解决各种cobbler依赖的服务和配置问题

[root@cobbler ~]# /etc/init.d/httpsd start
正在启动 httpsd:
[root@cobbler ~]# /etc/init.d/cobblerd start
Starting cobbler daemon:                                   [确定]
[root@cobbler ~]# cobbler check

可能会错误提示:

Traceback (most recent call last):
  File "/usr/bin/cobbler", line 36, in <module>
    sys.exit(app.main())
  File "/usr/lib/python2.6/site-packages/cobbler/cli.py", line 657, 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'">

原因:没有修改selinux

方法一:重启cobbler
service cobblerd restart
方法二:修改selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

修改后,需要重启机器

可能还有这些错误:

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.

需要修改cobbler配置里面的服务器IP

#获取本机IP
HostIP=$(/sbin/ip addr show dev eth1 | sed -n 3p | awk '{print $2}'| awk -F\/ '{print $1}')
#修改成获取的IP
sed -i 's/^\(server:\).*$/\1 '$HostIP'/g' /etc/cobbler/settings

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.

修改tftp的IP地址

sed -i 's/^\(next_server:\).*$/\1 '$HostIP'/g' /etc/cobbler/settings

3 : change 'disable' to 'no' in /etc/xinetd.d/tftp

sed -i 's/disable.*$/disable = no/g' /etc/xinetd.d/tftp

4 : change 'disable' to 'no' in /etc/xinetd.d/rsync

sed -i 's/disable.*$/disable = no/g' /etc/xinetd.d/rsync

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 : debmirror package is not installed, it will be required to manage debian deployments and repositories

yum install debmirror

7 : comment out 'dists' on /etc/debmirror.conf for proper debian support

sed -i "s/@dists/#@dists/g" /etc/debmirror.conf

8 : comment out 'arches' on /etc/debmirror.conf for proper debian support

sed -i "s/@arches/#@arches/g" /etc/debmirror.conf

9 : ksvalidator was not found, install pykickstart

yum install pykickstart

10 : 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

openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'
openssl passwd -1 -salt '随机扰乱符号' '这里才是密码'

10 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them

yum install cman

完成上面这些检测设置以后要重启cobbler服务,再一次运行cobbler check 会提示没有发现错误。

[root@cobbler ~]# cobbler check
No configuration problems found.  All systems go.

因此我们需要一次性安装完全部cobbler服务器所依赖的各种软件包就需要运行下面的命令

#稳定版
yum -y install cman tftp-server cobbler cobbler-web pykickstart debmirror dnsmasq
#最新测试版
yum install --enablerepo=epel-testing tftp-server cobbler cobbler-web pykickstart debmirror dnsmasq

特别注意:客户端主机需要有一个IP地址来与Cobbler Server进行通信,这时网络中必须要有一个主机能自动分配IP。DHCP就是一个能为客户端主机自动分配IP地址的服务,DHCP就是安装在Cobbler Server主机上。可以独立是一个服务器。一般都安装在cobbler上面方便管理。这里使用dnsmasg去管理DNS和DHCP。为什么呢?

Dnsmasq 提供 DNS 缓存和 DHCP 服务功能。作为域名解析服务器(DNS),dnsmasq可以通过缓存 DNS 请求来提高对访问过的网址的连接速度。作为DHCP 服务器,dnsmasq 可以用于为局域网电脑分配内网ip地址和提供路由。DNS和DHCP两个功能可以同时或分别单独实现。dnsmasq轻量且易配置,适用于个人用户或少于50台主机的网络。此外它还自带了一个 PXE 服务器。

三、配置cobbler服务器

1、让cobbler运行起来必须修改的几个地方

manage_dhcp: 1
manage_dns: 1
manage_tftpd: 1
restart_dhcp: 1
restart_dns: 1
pxe_just_once: 1
next_server: <server's IP address>
server: <server's IP address>

2、让cobbler去管理dnsmasq。默认他是使用bind管理dns,isc实现dhcp。

cat /etc/cobbler/modules.conf
[dns]
#module = manage_bind
module = manage_dnsmasq

[dhcp]
#module = manage_isc
module = manage_dnsmasq

3、编辑dnsmasq.template 模板

cat /etc/cobbler/dnsmasq.template 
# Cobbler generated configuration file for dnsmasq
# $date 
#

# resolve.conf .. ?
#no-poll
#enable-dbus
read-ethers
addn-hosts = /var/lib/cobbler/cobbler_hosts

#dhcp-range=192.168.1.5,192.168.1.200
dhcp-range=172.28.1.10,172.28.1.250
dhcp-ignore=tag:!known
dhcp-ignore=#known
no-dhcp-interface=eth1
server=114.114.114.114
dhcp-option=3,$next_server
dhcp-lease-max=1000
dhcp-authoritative
dhcp-boot=pxelinux.0
dhcp-boot=net:normalarch,pxelinux.0
dhcp-boot=net:ia64,$elilo

$insert_cobbler_system_definitions

dhcp-ignore,这个参数是为了如果不是我运行的mac地址,就忽略掉。https://www.ibm.com/developerworks/linux/library/l-cobbler/

4、tftp服务和rsync服务

sed -i 's/disable.*$/disable = no/g' /etc/xinetd.d/tftp
sed -i 's/disable.*$/disable = no/g' /etc/xinetd.d/rsync

5、cobbler各种管理菜单项

cobbler get-loaders

6、web管理面板权限

sed -i 's/authn_denyall/authn_configfile/g' /etc/cobbler/modules.conf

7、设置cobbler  web面板登陆,用户和密码

htdigest /etc/cobbler/users.digest "Cobbler" cobbler

8、设置debmirror用于debian、Ubuntu的安装源依赖

sed -i "s/@dists/#@dists/g" /etc/debmirror.conf
sed -i "s/@arches/#@arches/g" /etc/debmirror.conf

9、httpsd的服务器servername

sed -i "/^#ServerName/a ServerName 10.211.55.11" /etc/httpsd/conf/httpsd.conf

10、开机启动各种cobbler服务器

chkconfig httpsd on 
chkconfig cobblerd on
chkconfig dnsmasq on
/etc/init.d/httpsd restart
/etc/init.d/cobblerd restart
/etc/init.d/dnsmasq restart
/etc/init.d/xinetd restart

11、每次修改完了,务必要cobbler sync

[root@cobbler ~]# cobbler sync
task started: 2015-06-03_144703_sync
task started (id=Sync, time=Wed Jun  3 14:47:03 2015)
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 /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi
copying distros to tftpboot
copying images
generating PXE configuration files
generating PXE menu structure
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 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 ***

四、cobblers2.4+ 动态配置参数

每次修改一个配置都需要去sync一次,这样会很累。Cobbler2.4+,有一个重要的功能,不需要手工去编辑setting配置文件,直接使用命令动态的去修改,默认这个功能是不启用,需要启用。

cp /etc/cobbler/settings /etc/cobbler/settings.save
sed -i 's/allow_dynamic_settings: 0/allow_dynamic_settings: 1/g' /etc/cobbler/settings
#查看默认参数
cobbler setting report
#修改cobbler服务器IP
cobbler setting edit --name=server --value=10.211.55.21
#修改tftp服务器IP
cobbler setting edit --name=next_server --value=10.211.55.21
#ks脚本关闭pxe,就不会重复安装
cobbler setting edit --name=pxe_just_once --value=1
#cobbler管理rsync,dhcp,dns
cobbler setting edit --name=manage_rsync --value=1
cobbler setting edit --name=manage_dhcp --value=1
cobbler setting edit --name=manage_dns --value=1
#修改默认安装的密码
cobbler setting edit --name=default_password_crypted --value=$1$random-p$jP931oKwgIjDNsyxQz.Bn1

五、导入镜像

方法1、挂载光驱,直接导入

[root@cobbler ~]# mkdir /mnt/centos6.6
[root@cobbler ~]# mount /dev/cdrom /mnt/centos6.6/
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@cobbler ~]# cobbler import --path=/mnt/centos6.6/ --name=CentOS6.6 --arch=x86_64

方法2、挂载光盘镜像文件,进行导入

[root@cobbler ~]# mkdir /var/www/html/iso
#上传iso文件到此目录
[root@cobbler ~]# cd /var/www/html/iso
[root@cobbler ~]# mkdir /mnt/ubuntu15
[root@cobbler ~]# mount -t auto -o loop /var/www/html/iso/ubuntu-15.04-server-amd64.iso /mnt/ubuntu15/
[root@cobbler ~]# cobbler import --path=/mnt/ubuntu15/ --name=ubuntu-15.04-server-amd64 --arch=x86_64

3、缓存索引文件

[root@cobbler CentOS6.6-x86_64]# createrepo -g repodata/9e2ddcc42b44eb150ebc61dde29c997318d8330b92205b3dbb3a87bcc06d10be-c6-x86_64-comps.xml .
Spawning worker 0 with 4184 pkgs
Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

4、centos经过最小化和部分优化的ks文件

#version=DEVEL
install
text
url --url=$tree
lang zh_CN.UTF-8
keyboard us
$SNIPPET('network_config')
firewall --disable
firstboot --disable
rootpw  --iscrypted $6$Wljm5qoHfJ9f26.d$zkPiTy4XkW0ch6MicfU9.s9/8OL0TC/krvxTbS6ihZWzcJIAfaISttZEFR8jWgHtmNKIQqbgq3S820OnX7sJS0
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone --utc Asia/Shanghai
skipx
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
zerombr
clearpart --all --drives=sda
part /boot --fstype=ext4 --asprimary --size=200
part swap --asprimary --size=2048
part / --fstype=ext4 --grow --asprimary --size=200
services --disabled auditd,ip6tables,iptables,kdump,mdmonitor,messagebus,netfs,postfix,udev-post
reboot

%packages --nobase
@chinese-support
@core
@server-policy
@workstation-policy
wget
%end

5、在同一个网段的其它服务器只要开启了网络启动模式,就自动侦测到下面这个界面,然后选择镜像进行安装

Parallels 图片 2

未经允许不得转载:菜鸟HOW站长 » 使用Cobbler无人值守批量安装Centos和Ubuntu
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址