Linux 運維自動化之Cobbler安裝與配置詳解

大綱

一、前言

二、環境配置

三、Cobbler 安裝

四、Cobbler 配置詳解

注,操作系統 CentOS 6.4 x86_64,軟件版本 Cobbler-2.4.0-1。(目前最新版


一、前言

在上一篇博客中(http://freeloda.blog.51cto.com/2033581/1319695)我們主要講解與Cobbler相關的基礎知識,在一篇博客中我們主要中大家來說一下Cobbler安裝與配置,並且詳細說一下Cobbler命令的使用。好了,廢話不多說下面直接上乾貨。


二、環境配置

1.實驗拓撲

Cobbler 拓撲

2.安裝yum源

[root@node2 ~]# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Retrieving http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
warning: /var/tmp/rpm-tmp.z0cbxV: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing...        ########################################### [100%]
  1:epel-release      ########################################### [100%]

3.同步系統時間

[root@node2 ~]# yum install -y ntp
[root@node2 ~]# ntpdate 202.120.2.101
 4 Nov 13:49:41 ntpdate[1190]: step time server 202.120.2.101 offset 388653.714776 sec
[root@node2 ~]# hwclock -w

4.關閉防火牆與SELinux

[root@node2 ~]# service iptables stop
[root@node2 ~]# chkconfig iptables off
[root@node2 ~]# getenforce
Disabled


三、Cobbler 安裝

1.Cobbler運行所需基礎包

[root@node2 ~]# yum install -y cobbler tftp dhcp httpd cman pykickstart debmirror

2.Cobblerf所需環境支持包

[root@node2 ~]# yum install -y ed patch perl perl-Compress-Zlib perl-Digest-SHA1 perl-LockFile-Simple perl-libwww-perl

3.將所有服務加入開機自啓動並啓動相關服務

[root@node2 ~]# chkconfig httpd on
[root@node2 ~]# chkconfig dhcpd on
[root@node2 ~]# chkconfig xinetd on
[root@node2 ~]# chkconfig cobblerd on
[root@node2 ~]#
[root@node2 ~]# service httpd start
正在啓動 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using node2.test.com for ServerName
                              [確定]
[root@node2 ~]# service cobblerd start
Starting cobbler daemon:                  [確定]

4.修改apache相關配置並重新啓動

注,從上面的啓動信息可以看出apache啓動有點小錯誤,我們來修正一下。

[root@node2 ~]# vim /etc/httpd/conf/httpd.conf
#增加一行
ServerName localhost:80
[root@node2 ~]# service httpd restart
停止 httpd:                        [確定]
正在啓動 httpd:                      [確定]

5.運行Cobbler檢查命令

[root@node2 ~]# 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 : 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.

注,從上面的執行結果來看上面有7處錯誤,下面我們來解決一下。

(1).錯誤1,修改/etc/cobbler/settings 裏面的 server 爲Cobbler Server的IP地址 ;

[root@node2 ~]# vim /etc/cobbler/settings
server: 192.168.18.202

(2).錯誤2,修改/etc/cobbler/settings 裏面的 next_serverw 爲本機的 ip;

[root@node2 ~]# vim /etc/cobbler/settings
next_server: 192.168.18.202

(3).錯誤3,據說這個錯誤可以忽略,有強迫完美運行症的人士可以運行以下命令來解決;

[root@node2 ~]# cobbler get-loaders
task started: 2013-11-04_143149_get_loaders
task started (id=Download Bootloader Content, time=Mon Nov 4 14:31:49 2013)
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.61 to /var/lib/cobbler/loaders/pxelinux.0
downloading http://www.cobblerd.org/loaders/menu.c32-3.61 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 ***

(4).錯誤4,修改/etc/xinetd.d/tftp 把'disable' 修改爲'no';修改/etc/xinetd.d/rsync 把'disable' 修改爲'no';

[root@node2 ~]# vim /etc/xinetd.d/tftp
disable         = no
[root@node2 ~]# vim /etc/xinetd.d/rsync
disable = no

注,啓動xinetd服務。

[root@node2 ~]# service xinetd start
正在啓動 xinetd:                     [確定]

(5).錯誤5與錯誤6,debmmirror有錯誤;

[root@node2 ~]# vim /etc/debmirror.conf
#註釋掉@dists="sid"與@arches="i386即可
#@dists="sid";
#@arches="i386";

(6).錯誤7,設置默認root密碼;

注,剛接觸Cobbler的博友會問,這個密碼是什麼密碼。有的博友系統安裝好了會問,root密碼是什麼。這裏設置的就是客戶端安裝好系統的root密碼。

#生成你想要的密碼的加密字符串,然後複製運行命令之後的加密代碼;

[root@node2 ~]# openssl passwd -1 -salt 'hahaha' '123456'
$1$hahaha$hSxFjZSHRoiEn4DYrrGUI.

#然後替換/etc/cobbler/settings 中選項雙引號中的加密代碼;

[root@node2 ~]# vim /etc/cobbler/settings
default_password_crypted: "$1$hahaha$hSxFjZSHRoiEn4DYrrGUI."

6.重新啓動Cobbler並運行檢查命令

[root@node2 ~]# service cobblerd restart
Stopping cobbler daemon:                  [確定]
Starting cobbler daemon:                  [確定]
[root@node2 ~]# cobbler check
No configuration problems found. All systems go.

好了,到這裏我們Cobbler安裝就全部完成了,最後我們來查看一下啓動的端口。

[root@node2 ~]# netstat -ntulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address        Foreign Address       State    PID/Program name
tcp    0   0 0.0.0.0:22         0.0.0.0:*          LISTEN   1011/sshd  
tcp    0   0 127.0.0.1:25        0.0.0.0:*          LISTEN   1087/master 
tcp    0   0 127.0.0.1:6010       0.0.0.0:*          LISTEN   1126/sshd  
tcp    0   0 127.0.0.1:6011       0.0.0.0:*          LISTEN   1607/sshd  
tcp    0   0 127.0.0.1:25151       0.0.0.0:*          LISTEN   12677/python
tcp    0   0 :::80            :::*            LISTEN   1696/httpd 
tcp    0   0 :::22            :::*            LISTEN   1011/sshd  
tcp    0   0 ::1:25           :::*            LISTEN   1087/master 
tcp    0   0 ::1:6010          :::*            LISTEN   1126/sshd  
tcp    0   0 ::1:6011          :::*            LISTEN   1607/sshd  
tcp    0   0 :::873           :::*            LISTEN   12747/xinetd
udp    0   0 0.0.0.0:69         0.0.0.0:*                12747/xinetd


四、Cobbler 配置詳解

主要的 Cobbler 配置文件是 /etc/cobbler/settings。使用文本編輯器打開這個文件,並設置以下選項:

  • manage_dhcp:1

  • manage_dns:1

  • manage_tftpd:1

  • restart_dhcp:1

  • restart_dns:1

  • pxe_just_once:1

  • next_server:<服務器的 IP 地址>

  • server:<服務器的 IP 地址>

選項 manage_* 和 restart_* 無需加以說明。選項 next_server 用在 DHCP 配置文件中,向客戶端告知提供引導文件的服務器地址。選項 server 在客戶端安裝期間用於引用 Cobbler 服務器地址。最後,選項 pxe_just_once 預防將機器中的安裝循環配置爲始終從網絡引導。激活此選項時,機器告訴 Cobbler 安裝已完成。Cobbler 將系統對象的 netboot 標誌更改爲 false,這會強制機器從本地磁盤引導。好了,下面我們配置並管理dhcp服務與http服務。


1.讓Cobbler來管理DHCP服務器

[root@node2 ~]# vim /etc/cobbler/settings
manage_dhcp: 1

2.修改DHCP模板

[root@node2 ~]# vim /etc/cobbler/dhcp.template
subnet 192.168.18.0 netmask 255.255.255.0 {
option routers 192.168.18.254;
option domain-name-servers 8.8.8.8;
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.18.221 192.168.18.225;
filename "/pxelinux.0";
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server;
}

3.重新啓動Cobbler服務

[root@node2 ~]# service cobblerd restart
Stopping cobbler daemon:                  [確定]
Starting cobbler daemon:                  [確定]

4.編輯/etc/httpd/conf.d/wsgi.conf 去掉註釋

[root@node2 ~]# vim /etc/httpd/conf.d/wsgi.conf
LoadModule wsgi_module modules/mod_wsgi.so

5.完成後一定要運行cobbler sync 命令讓配置生效,使dhcp、http被cobbler接管,不然會報錯。

[root@node2 ~]# cobbler sync
task started: 2013-11-04_164727_sync
task started (id=Sync, time=Mon Nov 4 16:47:27 2013)
running pre-sync triggers
cleaning trees
removing: /var/lib/tftpboot/pxelinux.cfg/default
removing: /var/lib/tftpboot/grub/grub-x86_64.efi
removing: /var/lib/tftpboot/grub/p_w_picpaths
removing: /var/lib/tftpboot/grub/efidefault
removing: /var/lib/tftpboot/grub/grub-x86.efi
removing: /var/lib/tftpboot/s390x/profile_list
copying bootloaders
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 p_w_picpaths
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
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: 關閉 dhcpd:[確定]
正在啓動 dhcpd:[確定]
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 ***

好了,到這裏我們的Cobbler安裝與配置就講解完成了,我們在下一篇博客中將講解Cobbler管理與使用詳解。最後,希望大家有所收穫^_^……


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章