使用centos6.6部署Cobbler--自動安裝centos系統

Cobbler是一個開源項目,用來部署和安裝系統。Cobbler不僅僅是一個pxe服務器,他還可以管理dns和dhcp。一般數據中心裏或者生產環境,是不允許dhcp, 但是pxe需要使用dhcp,所以我們這裏根據mac地址來分配IP,這樣dhcp就不會影響現有網絡了。

 

1、首先關閉selinux

   [root@server04 ~]#sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config 

    #重新啓動linux系統使配置生效;

2、關閉防火牆iptables

       [root@server04 ~]# service iptables stop


3、安裝 epel 包

[root@server04 ~]#yum install http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm

4、安裝 Cobbler 和它需要的第三方工具包

    [root@server04 ~]#yum install cobbler cobbler-web xinetd pykickstart cman dhcp tftp-server bind


    安裝完成後需要設置幾個服務自動啓動

    [root@server04 ~]# chkconfig httpd on

    [root@server04 ~]# chkconfig dhcpd on

    [root@server04 ~]# chkconfig cobblerd on

    [root@server04 ~]# service httpd start    #啓動http服務

    [root@server04 ~]# service cobblerd start  #啓動cobbler服務

    注:此時dhcpd應該啓動失敗,因爲還沒有對dhcp做配置。




5、配置

5.1 修改/etc/xinetd.d/tftp   

disable = yes  

    =>   

    disable = no

    

5.2 修改/etc/xinetd.d/rsync

disable = yes 

    =>

    disable = no

    


 

5.3 編輯 /etc/cobbler/settings 文件,設置以下各項,其中 172.16.1.2 是當前機器IP。

    server: 172.16.1.2  

    next_server: 172.16.1.2

        pxe_just_once: 1 

        manage_rsync: 1  

        manage_dhcp: 1




 

5.4 設置默認(通過cobbler安裝的系統) root 用戶的密碼

    [root@server04 ~]# openssl passwd -1 -salt 'random-phrase-here' 'dragon'    #密碼加密

        $1$random-p$KIfNQzryOfZx/kAa0cjXv/

然後將結果替換 /etc/cobbler/settings 文件中的:default_password_crypted:

 

5.5  設置 Cobbler Web訪問的密碼

    [root@server04 ~]#htdigest /etc/cobbler/users.digest "Cobbler" cobbler


 

5.6 編輯 /etc/cobbler/dhcp.template 文件,下面是我改動部分的配置信息;

    option domain-name "172.16.1.2";

    option domain-name-servers 172.16.1.2;

    default-lease-time 43200;

    max-lease-time 86400;

    log-facility local7;

    subnet 172.16.0.0  netmask 255.255.0.0 {

         range 172.16.1.100 172.16.1.254; 

         option routers 172.16.1.1;

    }

    next-server 172.16.1.2;

    filename="pxelinux.0";


 

注意:如果在現有網段內已經有DHCP服務器,需要把 range dynamic-bootp 註釋掉,否則會有衝突。這個地方需要特別注意,要根據自己的網絡情況來設置。

 

5.7 重啓服務,暫時先不啓動DHCP,配置還沒有同步到/etc/dhcp/dhcpd.conf

    [root@server04 ~]#service xinetd restart 

    [root@server04 ~]#service httpd restart  

    [root@server04 ~]#service cobblerd restart


 

5.8啓動和檢測 cobbler

[root@server04 ~]#cobbler sync   #任何關於cobbler的修改都需要使用cobbler sync命令來使其生效

    [root@server04 ~]#cobbler get-loaders    #執行 cobbler get-loaders,系統將自動下載loader程序

    [root@server04 ~]#cobbler check  #此時如果有錯誤,cobbler會提示,可以根據提示來修復。但是對參數的任何修改都需要使用下面的命令來使其生效

常見的錯誤見文章末尾;

 

5.9 Web 測試

瀏覽器訪問 http://172.16.1.2/cobbler_web  #這裏輸入自己的IP

用戶名/密碼:cobbler/dragon   #在步驟5.5時設置

 

6.0 導入系統鏡像,這裏假定使用CentOS-6.6-x86_64來測試,虛擬機需要先掛載鏡像;

       

    [root@server04 ~]#mount /dev/cdrom /mnt

    [root@server04 ~]#cobbler import --path=/mnt --name=CentOS-6.6 --arch=x86_64  

運行這兩條命令後,可以使用下面的命令來查看已經裝載的包

    [root@server04 ~]#cobbler distro list 

    [root@server04 ~]#cobbler profile list  

也可以通過 Web 界面的 Distros 和 Profiles 來查看。

7. 自動安裝系統
    使用VirtualBox創建一個虛擬機,網絡設置使用和上面同樣的橋接模式。但是在 "虛擬機設置-> 系統 -> 啓動順序" 裏把網絡勾上並上移到第一位,然後啓動虛擬機。此時就可以進入 Cobbler 的網絡安裝界面,選擇上面創建的 CentOS-6.6-x86_64 然後就可以自動安裝了。裝完後,記得把虛擬機啓動順序改回到硬盤啓動優先,然後就可以啓動新安裝的虛擬機了。


二、配置Kickstart 配置模板,帶註釋版本(下面有無註釋版本)

1,可以把配置文件放在這個目錄:/var/lib/cobbler/kickstarts

2,登錄cobbler的web管理界面,點左側的profiles--點鏡像文件後面的edit--選擇Kickstart文件

[root@localhost ~]# cat kickstart_fc6.ks  

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Upgrade existing installation
upgrade
# Use network installation
#修改成自己的IP
url --url="http://172.168.12/cobbler/ks_mirror/CentOS-6.6-x86_64/"
# Root password 
rootpw dragon
# System authorization information
auth  --useshadow  --passalgo=sha512
#關閉防火牆
firewall --disabled
#選擇時區
timezone Asia/Shanghai
# Use graphical install
graphical
firstboot --disable
# System keyboard
keyboard us
# System language選擇語言,如果想要使用中文填寫:lang zh_CN
lang en_US
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System bootloader configuration
#--initlabel,根據不同體系結構把磁盤標籤初始化爲缺省設置(例如,msdos用於x86而gpt用於Itanium).當安裝到一個嶄新的硬 盤時,這很有用,安裝程序不會詢問是否應該初始化磁盤標籤.
#--grow,告訴分區使用所有可用空間(若有),或使用設置的最大值.
#--size=,以MB爲單位的分區最小值.在此處指定一個整數值,如500.不要在數字後面加MB.
#--fstype=,爲分區設置文件系統類型.有效的類型爲ext2,ext3,swap和vfat.
#--asprimary,強迫把分區分配爲主分區,否則提示分區失敗.
#--ondisk=或--ondrive=,強迫分區在指定磁盤上創建.
bootloader --location=mbr
clearpart --all --drives=sda --initlabel
part /boot --fstype ext3 --size=100 --ondisk=sda   
part swap --size=4096
part / --fstype ext3 --size=100 --grow --asprimary
#%packages部分,這部分選擇需要安裝的軟件包.
%packages
@core
@server-policy
@workstation-policy
%end


無註釋版本,可以直接複製,修改地址路徑即可:

[root@localhost ~]# kickstart.ks

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Upgrade existing installation
upgrade
# Use network installation
#修改成自己的IP
url --url="http://172.168.12/cobbler/ks_mirror/CentOS-6.6-x86_64/"
# Root password
rootpw --iscrypted $1$CgIgFiPo$rqNvZR480Z5A2dnbxdd7C0
# System authorization information
auth  --useshadow  --passalgo=sha512
firewall --disabled
timezone Asia/Shanghai
# Use graphical install
graphical
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System bootloader configuration
bootloader --location=mbr
clearpart --all --drives=sda --initlabel
part /boot --fstype ext3 --size=100 --ondisk=sda
part swap --size=4096
part / --fstype ext3 --size=100 --grow --asprimary
%packages
@core
@server-policy
@workstation-policy
%end




常見的cobbler check錯誤


1 : The 'server' field in /etc/cobbler/settings must be set to something other than localhost, or kickstarting features will not work.  This shou
ld be a resolvable hostname or IP for the boot server as reachable by all machines that will use it.
2 : file /etc/xinetd.d/rsync does not exist
3 : debmirror package is not installed, it will be required to manage debian deployments and repositories
4 : The default password used by the sample templates for newly installed machines (default_password_crypted in /etc/cobbler/settings) is still s
et to 'cobbler' and should be changed, try: "openssl passwd -1 -salt 'random-phrase-here' 'your-password-here'" to generate new one

解決方法:

1,把/etc/cobbler/settings文件的server參數改爲自己的IP地址
2,這個提示一致存在,不用管
3,和debian系統相關,不需要管
4,系統提示,/etc/cobbler/settings文件中的default_password_crypted:參數,
需要使用命令openssl passwd -1 -salt 'random-phrase-here' 'your-password-here' 來加密生成


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