码迷,mamicode.com
首页 > 其他好文 > 详细

运维自动化之Cobbler系统安装详解

时间:2014-07-14 21:52:34      阅读:426      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   使用   strong   文件   

原文链接

参考文档

参考文档
SA们现在都知道运维自动化的重要性,尤其是对于在服务器数量按几百台、几千台增加的公司而言,单单是装系统,如果不通过自动化来完成,根本是不可想象的。

运维自动化安装方面,早期一般使用人工配置pxe+dhcp+tftp配合kickstart,现在开源工具就多了,如cobbler,OpenQRM和Spacewalk。本文重点介绍Cobbler。

Cobbler介绍

Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows。该工具使用python开发,小巧轻便(才15k行代码),使用简单的命令即可完成PXE网络安装环境的配置,同时还可以管理DHCP,DNS,以及yum包镜像。

Cobbler支持命令行管理,web界面管理,还提供了API接口,可以方便二次开发使用。

bubuko.com,布布扣

和Kickstart不同的是,使用cobbler不会因为在局域网中启动了dhcp而导致有些机器因为默认从pxe启动在重启服务器后加载tftp内容导致启动终止。

常用架构如下图:

bubuko.com,布布扣

cobbler的安装部署配置

cobbler安装环境准备

对于centos本身源 ,可根据自己所在地选择离自己近的镜像源,比如mirrors.163.com或mirrors.sohu.com

1, 安装epel

rpm -Uvh ‘http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm‘

2, 安装dhcp服务

yum -y install dhcp

3, 其他服务的安装

额外需要的服务还有tftp,rsync,xinetd,httpd。所以如果安装系统的时候如果这几个包没装上,请手动安装。

yum -y install tftp rsync xinetd  httpd

4,关闭selinux

关闭后最好重启一下,让selinux的设置生效

vi /etc/selinux/config

#SELINUX=enforcing #注释掉

#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

:wq!  #保存退出

setenforce 0 #使配置立即生效

cobbler安装配置

1, cobbler安装

yum -y install cobbler

2, cobbler的配置

启动cobbler

# /etc/init.d/cobblerd start

启动httpd服务

# /etc/init.d/httpd start
可能提示的问题:httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName
解决方法:vi /etc/httpd/conf/httpd.conf
添加:ServerName localhost:80
重启http服务即可:/etc/init.d/httpd restart

检查配置,执行

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 : 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 : change ‘disable‘ to ‘no‘ in /etc/xinetd.d/rsync
6 : debmirror package is not installed, it will be required to manage debian deployments and repositories
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 them

Restart cobblerd and then run ‘cobbler sync‘ to apply changes.

1,编辑/etc/cobbler/settings文件,找到 server选项,修改为适当的ip地址,本实例配置ip为:192.168.10.10

2,编辑/etc/cobbler/settings文件,找到 next_server选项,修改为适当的ip地址,本实例配置ip为:192.168.10.10

3,SELinux的设置
  vi /etc/selinux/config
  #SELINUX=enforcing #注释掉
  #SELINUXTYPE=targeted #注释掉
  SELINUX=disabled #增加
  :wq!  #保存退出
  setenforce 0 #使配置立即生效
  如果上面已经关闭了SELinux就不用管了

4,执行 cobbler get-loaders,系统将自动下载loader程序,完成提示4的修复工作

5,编辑/etc/xinetd.d/rsync文件,将文件中的disable字段的配置由yes改为no

6,提示说debmirror没安装。如果不是安装 debian之类的系统,此提示可以忽略,如果需要安装,下载地址为:

http://rpmfind.net/linux/rpm2html/search.php?query=debmirror

7,yum -y install pykickstart

8,修改cobbler用户的默认密码,可以使用如下命令生成密码,并使用生成后的密码替换/etc/cobbler/settings中的密码。生成密码命令:

openssl passwd -1 -salt ‘random-phrase-here‘ ‘your-password-here‘ #其中“-1”是数字“1”
其中“random-phrase-here”为干扰码
替换之后的效果:default_password_crypted: "$1$303kfy$XL2K9DTTFHLZkBMV0oWhy1"

9,sudo yum -y install cman

所有提示全部fix之后,执行

/etc/init.d/cobblerd restart

cobbler的使用

导入安装文件

镜像分本地和网络两种,但都要下载到本地的http访问目录下!

 a.将本地原先的iso挂载后生成镜像,生成镜像到/var/www/cobbler/ks_mirror/centos6.5

挂载镜像:mount -t iso9660 -o loop /home/cobbler/soft/CentOS-6.5-x86_64-bin-DVD1.iso /mnt/

导入镜像到cobbler:cobbler import --path=/mnt/cdrom --name=CentOS6.5

 b.将网络的镜像到本地

cobbler import --path=rsync://mirrors.163.com/centos/6.0/os/i386/ --name=centos-6.0-i386

 如删除镜像,删除后,本地/var/www/cobbler/ks_mirror/centos6.0 目录被移除

cobbler profile remove --name=centos6.0-xen-i386

 生成镜像后查看列表,cobbler list

打印profile列表 cobbler profile report 

从上面显示信息所知,cobbler会将镜像中的拷贝到本地一份,放在/var/www/cobbler/ks_mirrors下的centos-6.0-i386目录下。同时会创建一个名字为centos-6.0-i386的一个发布版本,以及一个名字为centos-6.0-i386的profile文件。

配置dhcp服务

首先修改cobbler配置,让cobbler来管理dhcp服务,编辑文件/etc/cobbler/settings

manage_dhcp: 1

接下来修改/etc/cobbler/dhcp.template,此文件是cobbler管理dhcp的模板

对于此文件,本例中只需要修改如下部分

subnet 192.168.10.0 netmask 255.255.255.0 {
     option routers             192.168.10.1;
     option domain-name-servers 8.8.8.8;
     option subnet-mask         255.255.255.0;
     range dynamic-bootp        192.168.10.100 192.168.10.254;
     filename                   "/pxelinux.0";
     default-lease-time         21600;
     max-lease-time             43200;
     next-server                $next_server;
}

其余部分维持默认值即可。

到目前为止,全部的准备工作已经就算全部完成,接下来要做的就是启动服务了。在之前的调试过程中,很多服务已经启动过了,这里只需要启动xinetd服务即可:

/etc/init.d/xinetd start

同步cobbler配置

执行

# cobbler sync

cobbler会自动进行初始化工作,移除已经存在的启动项,然后根据模板拷贝loader文件。之后再生成pxe的配置文件,生成dhcp的配置文件,最后再重启dhcp服务。
至此,就可以使用虚拟机来测试cobbler安装了。

Cobbler测试安装

bubuko.com,布布扣

在启动的时候选择PXE的模式。

bubuko.com,布布扣

然后就能看到下面的图示内容。虚拟机通过dhcp获得了122段的ip,然后通过tftp获得到pxe的启动文件。

bubuko.com,布布扣

下图是cobbler的pxe安装启动菜单,这里有我们刚刚创建好的CentOS版本。

bubuko.com,布布扣

系统安装使用默认的ks文件,经过短暂的等待,系统就自动被安装好了。

bubuko.com,布布扣

安装好的系统如下图所示。

bubuko.com,布布扣

Linux系统重装测试

1,先确定当前linux系统中已经安装了koan软件。对于koan的安装可以放到ks文件中在安装系统的过程中完成安装操作。执行如下命令检查

# rpm -qa|grep koan
koan-2.0.11-2.el6.noarch

2,有了koan软件后可以执行如下操作,查看cobbler上的系统版本列表

# koan --server=192.168.10.1 --list=profiles
- looking for Cobbler at http://192.168.10.1/cobbler_api
centos-6.0-i386
centos-6.0-i386-kvm
centos6-vm
centos-6.0-x86_64

这里我们选择centos-6.0-i386来重装。可以执行如下命令

# koan --server=192.168.10.1 --profile=centos-6.0-i386 --replace-self
- looking for Cobbler at http://192.168.10.1/cobbler_api
- reading URL: http://192.168.10.1/cblr/svc/op/ks/profile/centos-6.0-i386
install_tree: http://192.168.10.1/cobbler/ks_mirror/centos-6.0-i386
downloading initrd initrd.img to /boot/initrd.img
url=http://192.168.10.1/cobbler/images/centos-6.0-i386/initrd.img
- reading URL: http://192.168.10.1/cobbler/images/centos-6.0-i386/initrd.img
downloading kernel vmlinuz to /boot/vmlinuz
url=http://192.168.10.1/cobbler/images/centos-6.0-i386/vmlinuz
- reading URL: http://192.168.10.1/cobbler/images/centos-6.0-i386/vmlinuz
- [‘/sbin/grubby‘, ‘--add-kernel‘, ‘/boot/vmlinuz‘, ‘--initrd‘, ‘/boot/initrd.img‘, ‘--args‘, ‘"ks=http://192.168.10.1/cblr/svc/op/ks/profile/centos-6.0-i386 ksdevice=link kssendmac lang= text "‘, ‘--copy-default‘, ‘--make-default‘, ‘--title=kick1313675750‘]
- reboot to apply changes
# reboot

红色部分是手工输入的,从其他部分信息可以看到,koan帮我们做了很多本该人工操作的内容。

接下来看下重启的过程:

bubuko.com,布布扣

bubuko.com,布布扣

bubuko.com,布布扣

由此看到,系统已经进入重装的状态了。

安装使用心得

以上所有内容虽然是在kvm虚拟机上测试的,但完全可以直接使用于生产环境中,不会给现有环境带来任何影响。唯一需要做的就是规划好现有网络。

对于很多人担心的生成环境开启DHCP服务问题,我认为不会对现有生产环境产生任何影响,理由有二:

1, 没有人会在装好系统后让网卡使用dhcp模式,通常都是为网卡配置静态ip

2, 从测试过程中看到,就算是服务器默认设置成了通过pxe启动,而且也顺利的通过pxe启动了,但之后会收到cobbler的引导菜单。如果默认没有任何选择的话,20秒后会使用local方式加载,也就是启动硬盘上的系统。

综上所述,cobbler还是很安全的。

运维自动化之Cobbler系统安装详解,布布扣,bubuko.com

运维自动化之Cobbler系统安装详解

标签:style   blog   http   使用   strong   文件   

原文地址:http://www.cnblogs.com/liangliangdetianxia/p/3842446.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!