网络安装操作系统――-cobbler批量安装操作系统

cobbler批量安装操作系统                                      

环境:workstation10

cobbler server:操作系统 Centos6.6

                ip:192.168.1.17 桥接物理机上(可上外网)

关闭iptables ,关闭selinux

[root@localhost ~]# chkconfig iptables off 
[root@localhost ~]# /etc/init.d/iptables stop 
[root@localhost ~]# getenforce 
Disabled

进入主题了

[root@localhost ~]#rpm -Uvh http://mirrors.hustunique.com/epel/6/x86_64/epel-release-6-8.noarch.rpm   #导入epel源

[root@localhost ~]#yum -y install httpd rsync tftp-server xinetd dhcp python-ctypes cman pykickstart   #安装cobbler依赖的包

[root@localhost ~]#yum -y install cobbler* debmirror*  #安装cobbler

[root@localhost ~]# cobbler check                    #检查cobbler配置
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 : 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 

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

[root@localhost ~]# vi /etc/cobbler/settings      #主要修改以下配置

server: 192.168.1.17              #配置cobbler server ip地址

next_server: 192.168.1.17         #配置cobbler server ip地址

manage_rsync: 1                   #同意cobbler 管理rsync

manage_dhcp: 1                    #同意cobbler 管理dhcp

pxe_just_once: 1                  #预防将机器中的安装循环配置为始终从网络引导

生成密码串

[root@localhost ~]# openssl passwd -1 -salt "cobber" "123abc"    #生成cobbler安装系统root的初始密码
$1$cobber$/quWjJZYZSFe/Zrk2FBVP1

[root@localhost ~]# vi /etc/cobbler/settings +101

default_password_crypted: "$1$cobber$/quWjJZYZSFe/Zrk2FBVP1"  # ""内为刚刚生成的密码

[root@localhost ~]# vi /etc/cobbler/dhcp.template             #配置cobbler dhcp模板,只需修改这一个{ }内的,其他默认就行.

subnet 192.168.1.0 netmask 255.255.255.0 {

     option routers             192.168.1.1;                   #配置路由

     option domain-name-servers 8.8.8.8;                       #配置DNS

     option subnet-mask         255.255.255.0;

     range dynamic-bootp        192.168.1.100 192.168.1.254;   #配置可分配ip地址池

     default-lease-time         21600;

     max-lease-time             43200;

     next-server                $next_server;

                  filename "pxelinux.0";

}

[root@localhost ~]# vi /etc/xinetd.d/rsync     #开启rsync

 disable = no 

[root@localhost ~]# vi /etc/xinetd.d/tftp      #开启tftp

 disable = no

[root@localhost ~]# vi /etc/dhcp/dhcpd.conf    #配置dhcp

subnet 192.168.1.0 netmask 255.255.255.0 {

     option routers             192.168.1.1;

     option domain-name-servers 8.8.8.8;

     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                192.168.1.17;

     filename                   "pxelinux.0";

}

[root@localhost ~]# /etc/init.d/xinetd start

[root@localhost ~]# /etc/init.d/cobblerd start

[root@localhost ~]# /etc/init.d/dhcpd start

[root@localhost ~]# vi /etc/debmirror.conf      #注释以下两行

#@dists="sid";

#@arches="i386";

[root@localhost ~]# cobbler get-loaders         #安装cobbler相关包

task started: 2015-01-10_214302_get_loaders 
task started (id=Download Bootloader Content, time=Sat Jan 10 21:43:02 2015) 
downloading http://www.cobblerd.org/loaders/README to /var/lib/cobbler/loaders/README 
downloading http://www.cobblerd.org/loaders/COPYING.elilo to /var/lib/cobbler/loaders/COPYING.elilo 
downloading http://www.cobblerd.org/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yaboot 
downloading http://www.cobblerd.org/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinux 
downloading http://www.cobblerd.org/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efi 
downloading http://www.cobblerd.org/loaders/yaboot-1.3.14-12 to /var/lib/cobbler/loaders/yaboot 
downloading http://www.cobblerd.org/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0 
downloading http://www.cobblerd.org/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32 
downloading http://www.cobblerd.org/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efi 
downloading http://www.cobblerd.org/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi 
*** TASK COMPLETE ***

[root@localhost ~]# cobbler check       #再次检查cobbler配置
No configuration problems found. All systems go. 
[root@localhost ~]# cobbler sync         #使cobbler配置生效
task started: 2015-01-10_214521_sync 
task started (id=Sync, time=Sat Jan 10 21:45:21 2015) 
running pre-sync triggers 
cleaning trees 
mkdir: /var/lib/tftpboot/pxelinux.cfg 
mkdir: /var/lib/tftpboot/grub 
mkdir: /var/lib/tftpboot/s390x 
mkdir: /var/lib/tftpboot/ppc 
mkdir: /var/lib/tftpboot/etc 
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.efi -> /var/lib/tftpboot/grub/grub-x86.efi 
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi 
copying distros to tftpboot 
copying images 
generating PXE configuration files 
generating PXE menu structure 
rendering DHCP files 
generating /etc/dhcp/dhcpd.conf 
rendering TFTPD files 
generating /etc/xinetd.d/tftp 
cleaning link caches 
rendering Rsync files 
running post-sync triggers 
running python triggers from /var/lib/cobbler/triggers/sync/post/* 
running python trigger cobbler.modules.sync_post_restart_services 
running: dhcpd -t -q 
received on stdout: 
received on stderr: 
running: service dhcpd restart 
received on stdout: Shutting down dhcpd: [ OK ] 
Starting dhcpd: [ OK ] 

received on stderr: 
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 ***

[root@localhost ~]# chkconfig httpd on 
[root@localhost ~]# chkconfig dhcpd on 
[root@localhost ~]# chkconfig xinetd on 
[root@localhost ~]# chkconfig cobblerd on

[root@localhost ~]# mount /dev/cdrom /media/cdrom/   #挂载光盘镜像

[root@localhost ~]# ls /media/cdrom/                 #确定挂载成功
CentOS_BuildTag EULA images Packages repodata RPM-GPG-KEY-CentOS-Debug-6 RPM-GPG-KEY-CentOS-Testing-6 
EFI GPL isolinux RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Security-6 TRANS.TBL

[root@localhost ~]# cobbler import --path=/media/cdrom/ --name=centos6.6x86_64      #导入安装安装文件

task started: 2015-01-10_214758_import

task started (id=Media import, time=Sat Jan 10 21:47:58 2015)

Found a candidate signature: breed=redhat, version=rhel6

Found a matching signature: breed=redhat, version=rhel6

Adding distros from path /var/www/cobbler/ks_mirror/centos6.6x86_64:

creating new distro: centos6.6x86_64-x86_64

trying symlink: /var/www/cobbler/ks_mirror/centos6.6x86_64 -> /var/www/cobbler/links/centos6.6x86_64-x86_64

creating new profile: centos6.6x86_64-x86_64

associating repos

checking for rsync repo(s)

checking for rhn repo(s)

checking for yum repo(s)

starting descent into /var/www/cobbler/ks_mirror/centos6.6x86_64 for centos6.6x86_64-x86_64

processing repo at : /var/www/cobbler/ks_mirror/centos6.6x86_64

need to process repo/comps: /var/www/cobbler/ks_mirror/centos6.6x86_64

looking for /var/www/cobbler/ks_mirror/centos6.6x86_64/repodata/*comps*.xml

Keeping repodata as-is :/var/www/cobbler/ks_mirror/centos6.6x86_64/repodata

*** TASK COMPLETE ***                     #表示cobbler sync成功

[root@localhost ~]# cobbler list          #列出导入后的配置,详细信息可用cobbler report
distros: 
centos6.6x86_64-x86_64 

profiles: 
centos6.6x86_64-x86_64 

systems: 

repos: 

images: 

mgmtclasses: 

packages: 

files:

[root@localhost ~]# cobbler profile find --distro=centos6.6x86_64-x86_64  #查看配置是否存在
centos6.6x86_64-x86_64

[root@localhost ~]#cd /var/lib/cobbler/kickstarts               

[root@localhost kickstarts]# cp sample.ks centos6.6x86_64-x86_64.cfg      #定义ks文件ks可根据需求自行配置

[root@localhost kickstarts]# cobbler profile edit --name=centos6.6x86_64-x86_64                                       --kickstart=/var/lib/cobbler/kickstarts/centos6.6x86_64-x86_64.cfg                                                                                  [root@localhost kickstarts]# cobbler distro list        #查看系统列表

centos6.6x86_64-x86_64 

[root@localhost kickstarts]# cobbler check              #再次检查cobbler配置
No configuration problems found. All systems go. 
[root@localhost kickstarts]# cobbler sync               #同步cobbler配置
task started: 2015-01-10_221010_sync 
task started (id=Sync, time=Sat Jan 10 22:10:10 2015) 
running pre-sync triggers 
cleaning trees 
removing: /var/www/cobbler/images/centos6.6x86_64-x86_64 
removing: /var/lib/tftpboot/pxelinux.cfg/default 
removing: /var/lib/tftpboot/grub/grub-x86.efi 
removing: /var/lib/tftpboot/grub/images 
removing: /var/lib/tftpboot/grub/efidefault 
removing: /var/lib/tftpboot/grub/grub-x86_64.efi 
removing: /var/lib/tftpboot/images/centos6.6x86_64-x86_64 
removing: /var/lib/tftpboot/s390x/profile_list 
copying bootloaders 
trying hardlink /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.efi 
trying hardlink /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.efi 
copying distros to tftpboot 
copying files for distro: centos6.6x86_64-x86_64 
trying hardlink /var/www/cobbler/ks_mirror/centos6.6x86_64/images/pxeboot/vmlinuz -> /var/lib/tftpboot/images/centos6.6x86_64-x86_64/vmlinuz 
trying hardlink /var/www/cobbler/ks_mirror/centos6.6x86_64/images/pxeboot/initrd.img -> /var/lib/tftpboot/images/centos6.6x86_64-x86_64/initrd.img 
copying images 
generating PXE configuration files 
generating PXE menu structure 
copying files for distro: centos6.6x86_64-x86_64 
trying hardlink /var/www/cobbler/ks_mirror/centos6.6x86_64/images/pxeboot/vmlinuz -> /var/www/cobbler/images/centos6.6x86_64-x86_64/vmlinuz 
trying hardlink /var/www/cobbler/ks_mirror/centos6.6x86_64/images/pxeboot/initrd.img -> /var/www/cobbler/images/centos6.6x86_64-x86_64/initrd.img 
Writing template files for centos6.6x86_64-x86_64 
rendering DHCP files 
generating /etc/dhcp/dhcpd.conf 
rendering TFTPD files 
generating /etc/xinetd.d/tftp 
processing boot_files for distro: centos6.6x86_64-x86_64 
cleaning link caches 
rendering Rsync files 
running post-sync triggers 
running python triggers from /var/lib/cobbler/triggers/sync/post/* 
running python trigger cobbler.modules.sync_post_restart_services 
running: dhcpd -t -q 
received on stdout: 
received on stderr: 
running: service dhcpd restart 
received on stdout: Shutting down dhcpd: [ OK ] 
Starting dhcpd: [ OK ] 

received on stderr: 
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 ***         #发现没有问题接下来就可以测试cobber安装os了。

配置完成现在可以装机了,因为是虚拟机测试,当然先新建虚拟机,注意客户端要和cobbler server 都是桥接,os启动默认是以pxe启动的。

spacer.gifwKiom1SyZ0Lj7iBRAADIAiDunNU036.jpg

然后点击开启虚拟机

spacer.gifwKioL1SyZ-fg3OXGAADZOA2880k909.jpg

选择centos6.6我们就可以开始装机了,搞定。

当然我们也可以通过web的方式哦

[root@localhost ~]# htdigest /etc/cobbler/users.digest "Cobbler" cobbler   #添加cobbler用户
Changing password for user cobbler in realm Cobbler 
New password: 
Re-type new password:

我们可以通过 https://192.168.1.17/cobbler_web/来访问了

spacer.gifspacer.gifwKiom1SyZ1PCKGESAACMulLR1lI363.jpg

用户名:cobbler

密码:cobbler (这个是我自己设置的哦)

wKioL1SyaYHwMmeCAAFCd98aJxY569.jpg

图形界面import 

[root@localhost opt]# mkdir /iso          #创建挂载目录

[root@localhost opt]# ls                  #上传一个新的iso镜像文件
CentOS-6.2-x86_64-minimal.iso 
[root@localhost opt]# mount CentOS-6.2-x86_64-minimal.iso /iso/ -o loop          #挂载镜像 
[root@localhost opt]# ls /iso/ 
CentOS_BuildTag EULA images Packages repodata RPM-GPG-KEY-CentOS-Debug-6 RPM-GPG-KEY-CentOS-Testing-6 
EFI GPL isolinux RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-6

导入cobbler

spacer.gifwKiom1SyaOLggxXWAAFum6aX_Fk517.jpg

点击run就行了。


最后大概说下cobbler

Cobbler由python语言开发,是对PXE和 Kickstart以及DHCP的封装。

融合很多特性,提供了CLI和Web的管理形式。更加方便的实行网络安装。

同时,Cobbler也提供了API接口,使用其它语言也很容易做扩展。

它不仅可以安装物理机,同时也支持kvm、xen虚拟化、Guest OS的安装。

更多的是它还能结合Puppet等集中化管理软件,实现自动化的管理。

PXE 预启动执行环境(Preboot eXecution Environment,PXE,也被称为预执行环境)是让计算机通过网卡独立地使用数据设备(如硬盘)或者安装操作系统。

Cobbler提供以下服务集成:

* PXE服务支持

* DHCP服务管理

* DNS服务管理 

* 电源管理

* Kickstart服务支持

* yum仓库管理

以下是cobbler命令及配置文件的一些说明

1.cobbler命令说明

 cobbler check:检查cobbler配置

 cobbler list:列出所有的cobbler元素

 cobbler report:列出元素的详细信息

 cobbler distro:查看导入的发行版系统信息

 cobbler system:查看添加的系统信息

 cobbler profile:查看配置信息

 cobbler sync:同步cobbler配置

 cobbler reposync:同步yum仓库

 2.cobbler配置文件说明:

 /etc/cobbler/seetings cobbler的主配置文件

 /etc/cobbler/users.digest 用于web访问的用户名密码配置文件

 /etc/cobbler/modules.conf 模块配置文件

 /etc/cobbler/users.conf cobbler webui/web服务授权配置文件

 /etc/cobbler/iso/ buildiso模板配置文件

 /etc/cobbler/power 电源配置文件

 /etc/cobbler/pxe pxeprofile配置模板

 /etc/cobbler 此目录包含rsync,dhcp,dns,pxe,等服务的模板配置文件

 3.系统镜像数据目录/var/www/cobbler

 导入的系统发行版,repos镜像和kickstart文件都放置在/var/www/cobbler目录下

 /var/www/cobbler/images存储所有导入发行版的kernel和initrd镜像用于远程网络启动

 /var/www/cobbler/ks_mirror存储导入的发行版系统数据

 /var/www/cobbler/repo_mirror 仓库存储目录

 /var/log/cobbler cobbler日志文件

 4.cobbler数据目录/var/lib/cobbler

 /var/lib/cobbler/config/存放distros,repos,systems,和profile等信息配置文件,一般是json文件

 /var/lib/cobbler/snippets存放ks文件可以导入的脚本小片段

 /var/lib/cobbler/triggers存放用户定义的cobbler命令

 /var/lib/cobbler/kickstarts/存放kictstart配置文件


你可能感兴趣的:(server,网络,操作系统,自动化部署)