歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 使用cobbler實現批量自動部署Linux

使用cobbler實現批量自動部署Linux

日期:2017/2/27 16:03:05   编辑:Linux教程
Cobbler是一個快速網絡安裝linux的服務,而且在經過調整也可以支持網絡安裝windows。該工具使用python開發,小巧輕便,使用簡單的命令即可完成PXE網絡安裝環境的配置,同時還可以管理DHCP,DNS,以及yum包鏡像。下面一步步來實現
實驗平台:rhel 6.3 x86_64
cobbler.laoguang.me     192.168.1.23

一.環境准備
1.1 安裝dhcp
yum -y install dhcp

1.2 安裝其它所需服務如:tftp xinetd httpd ##靠tftp傳輸文件,tftp依賴xinetd,httpd這個我暫時不清楚
yum -y install tftp xinetd httpd

1.3 關閉selinux iptables
setenforce 0 
service iptables stop

二.安裝cobbler
2.1 下載安裝cobbler與依賴的包python-yaml
下載地址:http://www.kuaipan.cn/file/id_33139203151758501.html ,其它平台的可以去http://rpm.pbone.net/找,這個網站你一定不能忘記
yum -y --nogpgcheck localinstall cobbler-2.2.2-1.el6.rf.noarch.rpm python-yaml-3.09-3.el6.rf.x86_64.rpm

2.2 啟動cobbler
service cobblerd start

2.3 啟動httpd
service httpd start

2.4 啟用xinetd
service xinetd start

2.4 cobbler 檢查配置
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 the or IP for boot 
server as reachable by all machines that will use it. 
 
修改/etc/cobbler/settings 中server選項為: 
server: 192.168.1.23 
 
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. 
修改/etc/cobbler/settings 中next_server選項為: 
next_server: 192.168.1.23      
 
3 : Must enable a selinux boolean to enable vital web services components, run: setsebool -P httpd_
can_network_connect true 
 
關閉selinux 
 
4 : you need to set some SELinux content rules to ensure cobbler serves content correctly in your 
SELinux environment, run the following: /usr/sbin/semanage fcontext -a -t public_content_t "/var/
lib/tftpboot/.*" && /usr/sbin/semanage fcontext -a -t public_content_t "/var/www/cobbler"/images/.* 
 
關閉selinux 
 
5 : you need to set some SELinux rules if you want to use cobbler-web (an optional package), run the following:
 /usr/sbin/semanage fcontext -a -t httpd_sys_content_rw_t "/var/lib/cobbler/webui_sessions/.*" 
 
關閉selinux 
 
6 : 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  
cobbler get-loaders   ## 前提你能上網,出現*** TASK COMPLETE *** 代表ok 
 
7 : change 'disable' to 'no' in /etc/xinetd.d/rsync 
 
我們不用rysnc同步文件,如果用的話修改/etc/xinetd.d/rsync 
vi /etc/xinetd.d/rsync 
disable = no 
 
8 : reposync is not installed, need for cobbler reposync, install/upgrade yum-utils? 
 
可以不用理會,因為我們不用rsync同步ISO 
 
9 : yumdownloader is not installed, needed for cobbler repo add with --rpm-list parameter, install/upgrade yum-utils? 
 
同上
 
10 : debmirror package is not installed, it will be required to manage debian deployments and repositories 
 
我們不是debian可以不用理會 
 
11 : ksvalidator was not found, install pykickstart 
 
安裝pykickstart 
yum -y install pykickstart 
 
12 : 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 
 
修改cobbler的密碼,防止其它正常主機由pxe啟動後安裝系統 
openssl passwd -1 -salt 51cto laoguang   ##生成密碼 
$1$51cto$nTnuekFUB6sByi97bt7df/   ##將它復制到setting中 
vi /etc/cobbler/settings
default_password_crypted: "$1$51cto$nTnuekFUB6sByi97bt7df/" 
----------------------------------------- 
2.5 重啟cobbler
service cobblerd restart

三.cobbler的配置
3.1 導入欲安裝的系統的鏡像文件
將redhat 6.3 x86_64 的ISO掛載/cdrom
mount /dev/cdrom /cdrom

導入需要的安裝文件到cobbler的/var/www/cobbler/ks_mirrors下,並生成一profile,此過程需要一段時間,耐心等待
cobbler import --path=/cdrom --name=RedHat-6.3-x86_64

3.2 配置dhcp服務,讓cobbler來管理
vi /etc/cobbler/settings 
manage_dhcp: 1

3.3 修改/etc/cobbler/dhcp.template模板文件中的配置,其它的默認即可
vi /etc/cobbler/dhcp.template 
 
subnet 192.168.1.0 netmask 255.255.255.0 {       ##根據需要修改 
     option routers             192.168.1.1;     ##路由ip 
     #option domain-name-servers 192.168.1.1;    ##dns的ip,我沒使用 
     option subnet-mask         255.255.255.0;   ##掩碼 
     range dynamic-bootp        192.168.1.100 192.168.1.254;  ##dhcp分配的ip范圍 
     filename                   "/pxelinux.0";    
     default-lease-time         21600;           ##dhcp的默認釋放時間 
     max-lease-time             43200;           ##最大時間  
     next-server                $next_server;    ##pxe使用的ip,$next_server在setting中定義的你忘了嗎 
}

3.4 同步cobbler配置
cobbler sync


cobbler會自動進行初始化工作,移除已經存在的啟動項,然後根據模板拷貝loader文件。之後再生成pxe的配置文件,生成dhcp的配置文件,最後再重啟dhcp服務。關鍵查看dhcp,tftp有沒有啟動成功。

四.測試安裝系統
4.1 新建個虛擬機,網絡記的是brige哦,新建的虛擬機網絡默認是nat的,我就因為這個怎麼都安裝不上,啟動虛擬機,調整啟動順序從網絡啟動(我用的是vmware,如果你沒有掛cd的iso,也虛擬機是新建的直接啟動應該是可以的)
如下圖

五.定制自己的kickstart文件
定制自己的kickstart文件而不是使用默認的,kickstart文件cobbler放在了/var/lib/cobbler/kickstarts/中,查看cobbler默認使用的哪個

vi /etc/cobbler/settings 
default_kickstart: /var/lib/cobbler/kickstarts/default.ks   ##看到了吧,用的是default.ks

5.1 自定義kickstart文件。如果你對kickstart文件理解透徹,直接修改或新建即可,如果還是很精通就用gui工具吧
yum -y install system-config-kickstart

安裝完畢後打開軟件
system-config-kickstart
根據自己的需要修改即可,修改完畢後保存,修改settings中的設置,重啟cobbler.
Copyright © Linux教程網 All Rights Reserved