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

使用cobbler自动安装操作系统(CentOS版)

时间:2014-10-06 02:36:30      阅读:411      评论:0      收藏:0      [点我收藏+]

标签:dns服务器   虚拟主机   虚拟机   操作系统   而且   

Cobbler是简便的批量部署操作系统的工具,不仅操作不需要太复杂,而且使用cobbler还能在多个主机上部署多个操作系统,甚是方便。

部署cobbler需要依赖的组件有tftp服务器、dhcp服务器、rsync必要的时候还需要用到dns服务器。

本文就展示一下,多服务集于一个主机部署的cobbler。

文中所使用的工具有VMware虚拟机,两个虚拟主机,一个CentOS-6.5-x86_64系统镜像。部署环境:CentOS6.5-x86_64环境。

前提:由于cobbler需要依赖epel环境,在文中展示时,连接的epel的指向教室环境。

1、需要安装cobbler cobbler-web pykickstart debmirror

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

Package                                   Arch                        Version                                       Repository                 Size
=====================================================================================================================================================
Installing:
cobbler                                   noarch                      2.4.0-1.el6                                   new2                      664 k
cobbler-web                               noarch                      2.4.0-1.el6                                   new2                      299 k
debmirror                                 noarch                      2.14-2.el6                                    new2                       58 k
pykickstart                               noarch                      1.74.14-1.el6                                 epel                      309 k
Installing for dependencies:
Django14                                  noarch                      1.4.8-1.el6                                   new2                      4.3 M
PyYAML                                    x86_64                      3.10-3.el6                                    new2                      157 k
createrepo                                noarch                      0.9.9-18.el6                                  epel                       94 k
deltarpm                                  x86_64                      3.5-0.5.20090913git.el6                       epel                       71 k
libyaml                                   x86_64                      0.1.5-1.el6                                   new2                       52 k
mod_ssl                                   x86_64                      1:2.2.15-29.el6.centos                        epel                       90 k
mod_wsgi                                  x86_64                      3.2-3.el6                                     epel                       66 k
perl-LockFile-Simple                      noarch                      0.207-2.el6                                   new2                       23 k
python-cheetah                            x86_64                      2.4.1-1.el6                                   epel                      365 k
python-deltarpm                           x86_64                      3.5-0.5.20090913git.el6                       epel                       27 k
python-markdown                           noarch                      2.0.1-3.1.el6                                 epel                      118 k
python-netaddr                            noarch                      0.7.5-4.el6                                   epel                      1.0 M
python-pygments                           noarch                      1.1.1-1.el6                                   epel                      562 k
python-setuptools                         noarch                      0.6.10-3.el6                                  epel                      336 k
python-simplejson                         x86_64                      2.0.9-3.1.el6                                 epel                      126 k
syslinux                                  x86_64                      4.02-8.el6                                    epel                      859 k
tftp-server                               x86_64                      0.49-7.el6                                    epel                       39 k
xinetd                                    x86_64                      2:2.3.14-39.el6_4                             epel                      121 k

Transaction Summary
=====================================================================================================================================================

里面需要解决不少依赖关系,其中还附带tftp-server,Django14,还有不少关于python相关的。

2、解决cobbler启动需要的服务

  • dhcp(可以由dhcpd提供)或dnsmasq
  • tftp(可以由tftp-server程序包提供,或cobbler自带的tftp(刚才确实安装过tftp))。
  • rsync可以由rsync程序包提供
  • dns可以由bind安装包提供或dnsmasq

3、开始着手部署,由于前期交代过多服务部署于一个主机。

step1、配置dhcp服务

[root@node1 ~]# yum install dhcp

……………(中间略)

Installed:
  dhcp.x86_64 12:4.1.1-38.P1.el6.centos                                                                                                             

Complete!

step2、[root@node1 ~]# vim /etc/dhcp/dhcpd.conf

#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#   see ‘man 5 dhcpd.conf‘
#

提示我们去复制dhcpd.conf.sample来取代这个配置文件。这里可以先把dhcp的原配置文件重命名为dhcpd.conf.bak。

接着

[root@node1 ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample  /etc/dhcp/dhcpd.conf(注意这里是dhcpd.conf,笔者曾经改错名字导致服务无法启动)

step3、修改dhcp配置文件

[root@node1 ~]# vim /etc/dhcp/dhcpd.conf

part1、

bubuko.com,布布扣

part2、

bubuko.com,布布扣

step4、配置好dhcp服务器,可以通过“service dhcpd start”启动服务,并确保udp 67端口是由dhcp监听。

[root@node1 ~]# ss -tunlp  | grep 67
udp    UNCONN     0      0                      *:631                   *:*      users:(("cupsd",1367,9))
udp    UNCONN     0      0                      *:67                    *:*      users:(("dhcpd",25392,7))
tcp    LISTEN     0      128            127.0.0.1:631                   *:*      users:(("cupsd",1367,7))
tcp    LISTEN     0      128                  ::1:631                  :::*      users:(("cupsd",1367,6))

4、继dhcp以后,还需要启动tftp服务以及rsync

[root@node1 ~]# chkconfig tftp on
[root@node1 ~]# service xinetd start
Starting xinetd:                                           [  OK  ]
[root@node1 ~]# chkconfig --list | grep tftp
    tftp:              on
[root@node1 ~]# chkconfig rsync on
[root@node1 ~]# service xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]
[root@node1 ~]# chkconfig --list | grep rsync
    rsync:             on
[root@node1 ~]# chkconfig --list | grep tftp
    tftp:              on

5、下面就是cobbler各组件的配置,如图,本次演示要使用CentOS6.5镜像文件作为distribution。

bubuko.com,布布扣

将光盘挂载到随便一个目录,本次演示在/media/cdrom。

[root@node1 ~]# mkdir -pv /media/cdrom && mount /dev/cdrom /media/cdrom
mkdir: created directory `/media/cdrom‘
mount: block device /dev/sr0 is write-protected, mounting read-only

bubuko.com,布布扣

[root@node1 cdrom]# cobbler import --name=CentOS65 --path=/media/cdrom 等于将光盘中的内容导入到系统上。而如果用光盘导入的话,cobbler import 命令参数生成的光盘镜像在系统的路径在/var/www/cobbler/ks_mirror下。

在导入光盘之前,最后配置cobbler以及开启cobbler服务。

编辑/etc/cobbler/settings这个文件,文件中有需要加密的,使用openssl passwd -1 -salt `openssl rand -hex 4`这个命令提示输入密码,生成密码串,复制并粘贴到文件中

part1、

bubuko.com,布布扣

part2、next-server要与之前定义的一致。

bubuko.com,布布扣 

part3、cobbler的server地址

bubuko.com,布布扣

接着保存配置文件,cobbler sync以及service cobblerd start启动

[root@node1 cdrom]# service cobblerd start
Starting cobbler daemon:                                   [  OK  ]
[root@node1 cdrom]# ss -tnlp | grep 25151
LISTEN     0      5                 127.0.0.1:25151                    *:*      users:(("cobblerd",25555,8))

6、可以启动cobbler各组件的服务。

[root@node1 cdrom]# cobbler import --name=CentOS65 --path=/media/cdrom   (这里报了一个错误,需要重启一个cobblerd服务)
httpd does not appear to be running and proxying cobbler, or SELinux is in the way. Original traceback:
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/cobbler/cli.py", line 252, in check_setup
    s.ping()
  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 1235, in request
    self.send_content(h, request_body)
  File "/usr/lib64/python2.6/xmlrpclib.py", line 1349, in send_content
    connection.endheaders()
  File "/usr/lib64/python2.6/httplib.py", line 908, in endheaders
    self._send_output()
  File "/usr/lib64/python2.6/httplib.py", line 780, in _send_output
    self.send(msg)
  File "/usr/lib64/python2.6/httplib.py", line 739, in send
    self.connect()
  File "/usr/lib64/python2.6/httplib.py", line 720, in connect
    self.timeout)
  File "/usr/lib64/python2.6/socket.py", line 567, in create_connection
    raise error, msg
error: [Errno 111] Connection refused
[root@node1 cdrom]# service httpd start
Starting httpd:                                            [  OK  ]

7、开始导入光盘镜像文件到本地,这里要花费好长时间,因为磁盘I/O读写压力太大。

[root@node1 cdrom]# cobbler import --name=CentOS65 --path=/media/cdrom
task started: 2014-09-30_174204_import
task started (id=Media import, time=Tue Sep 30 17:42:04 2014)

bubuko.com,布布扣

导入完成, 可以通过/var/www/cobbler/ks_mirror这个目录下找到与该路径相同的目录

bubuko.com,布布扣

通过cobbler distro list查看已经创建的distro

bubuko.com,布布扣

8、管理profile文件,并提供kickstart文件。

kickstart文件,本文中用修改过的/root/目录下的anaconda.cfg配置文件

bubuko.com,布布扣

仅需要修改这里,把url改到自己本机对应的提供的cobbler服务。

然后就是创建profile文件

[root@node1 ks_mirror]# cobbler distro list
   CentOS65-x86_64
[root@node1 ks_mirror]# cobbler profile add --name=CenTos6.5-DIY --distro=CentOS65-x86_64 --kickstart=/root/anaconda-ks.cfg

可以通过cobbler profile list来查看

bubuko.com,布布扣

至此就可以通过cobbler工作来给其他新主机配置系统,演示如下:

bubuko.com,布布扣

bubuko.com,布布扣

bubuko.com,布布扣

表面成功安装配置!

(ps:通过调整/var/lib/tftpboot/pxelinux.cfg/default里面可以调整pxe菜单界面)

 

下面介绍一下cobbler_web的应用,就是让cobbler通过web接口提供对新主机的操作系统安装。这里cobbler_web是需要认证的。本次演示使用的是authn_pam的方式、

1、先创建用户

[root@node1 ~]# useradd cbadmin || echo ‘cbadmin123‘ | passwd --stdin cbadmin
useradd: user ‘cbadmin‘ already exists
Changing password for user cbadmin.
passwd: all authentication tokens updated successfully.

2、编辑/etc/cobbler/users.conf文件,里面编辑

bubuko.com,布布扣

这里添加你曾经添加的用户名。

3、修改/etc/cobbler/module.conf文件,里面编辑

bubuko.com,布布扣

3、重新启动cobbler服务和重启http服务

[root@node1 ~]# service cobblerd restart && service httpd restart
Stopping cobbler daemon:                                   [  OK  ]
Starting cobbler daemon:                                   [  OK  ]
Stopping httpd:                                            [FAILED]
Starting httpd:                                            [  OK  ]
[root@node1 ~]#

 

4.效果:

需要pam认证

 

bubuko.com,布布扣

漂亮的网页界面。

bubuko.com,布布扣

使用cobbler自动安装操作系统(CentOS版)

标签:dns服务器   虚拟主机   虚拟机   操作系统   而且   

原文地址:http://libincla.blog.51cto.com/6249823/1560768

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