歡迎您光臨本站 註冊首頁

自動化安裝操作系統:Cobbler+Koan安裝配置使用

←手機掃碼閱讀     火星人 @ 2014-03-03 , reply:0

自動化安裝操作系統:Cobbler+Koan安裝配置使用

Cobbler+Koan介紹

Cobbler作為一個預備工具,使部署Red Hat/Centos/Fedora系統更容易,同時也支持Suse和Debian系統的部署。
它提供以下服務集成:* PXE服務支持* DHCP服務管理* DNS服務管理* Kickstart服務支持* yum倉庫管理
Cobbler客戶端Koan支持虛擬機安裝和操作系統重新安裝。服務端安裝cobbler
1、安裝epel yum倉庫
  Wget  http://download.fedora.redhat.co ... ease-5-4.noarch.rpm  Rpm -ivh epel-release-5-4.noarch.rpm  
2、安裝cobbler server所需要的安裝包:
  Yum -y install cobbler httpd xinetd  tftp-server yum-utils rsync dhcp  
3、配置dhcp服務:
  cat>/etc/dhcpd.conf<<EOF  ddns-update-style interim;  
  allow booting;  allow bootp;  
  ignore client-updates;  set vendorclass = option  vendor-class-identifier;  
  subnet 192.168.0.0 netmask 255.255.255.0  {  #
option routers
192.168.0.1;  
option domain-name-servers 202.85.220.196,202.106.0.20;  
option subnet-mask
255.255.255.0;  
range dynamic-bootp
192.168.0.100 192.168.0.254;  
filename
"/pxelinux.0";  
default-lease-time
21600;  
max-lease-time
43200;  
next-server
192.168.0.2;  }  EOF  
4、啟動dhcp、cobbler、httpd服務
  /etc/init.d/dhcpd start  /etc/init.d/cobblerd restart  /etc/init.d/httpd restart  
5、運行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 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 : you need to set some SELinux content  rules to ensure cobbler works correctly in your SELinux environment, run the  following: /usr/sbin/semanage fcontext -a -t public_content_t "/tftpboot/.*"  && \ /usr/sbin/semanage fcontext -a -t public_content_t  "/var/www/cobbler/images/.*"  4 : 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.  5 : change 'disable' to 'no' in  /etc/xinetd.d/tftp  6 : change 'disable' to 'no' in  /etc/xinetd.d/rsync  7 : since iptables may be running, ensure  69, 80, and 25151 are unblocked  8 : debmirror package is not installed,  it will be required to manage debian deployments and repositories  9 : 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
  

6、修復上述錯誤,步驟如下:(1) 修改/etc/cobbler/setings文件:
  HostIP=$(/sbin/ip addr show dev eth1 |  sed -n 3p | awk '{print $2}'| awk -F\/ '{print $1}')  sed -i 's/^\(server:\).*$/\1 '$HostIP'/g'  /etc/cobbler/settings  sed -i 's/^\(next_server:\).*$/\1  '$HostIP'/g' /etc/cobbler/settings  
  
(2) 修改xinetd下的tftp、rsync配置文件
  sed -i 's/disable.*$/disable
= no/g' /etc/xinetd.d/tftp  sed -i 's/disable.*$/disable
= no/g' /etc/xinetd.d/rsync  
(3) 關閉iptalbles防火牆:
  /etc/init.d/iptables stop  
(4) 下載cobbler所需擴展安裝包:
  cobbler get-loaders  
(5) 安裝debmirror和cman
  yum -y install debmirror cman  
(6) 修改系統初始密碼使用openssl生成新密碼:
  openssl passwd -1 -salt '' '123456'  
file:///C:/DOCUME~1/mayulin/LOCALS~1/Temp/msohtml1/04/clip_image002.jpg修改/etc/cobbler/setings文件中「default_password_crypted」欄位為openssl生成的新密碼重新啟動cobblerd,在此使用cobbler check檢查系統,只出現如下提示,可以不用管file:///C:/DOCUME~1/mayulin/LOCALS~1/Temp/msohtml1/04/clip_image004.jpg配置使用cobbler
1、在服務端掛載Linux安裝盤,生成安裝鏡像
  mount -o loop  /usr/src/iso/CentOS-5.5-x86_64-bin-DVD-1of2.iso /mnt  cobbler import --path=/mnt  --name=CentOS5.5  
2、使用cobbler list命令查看導入的鏡像和配置文件
  
# cobbler list  distros:  
CentOS5.5-x86_64  
CentOS5.5-xen-x86_64  
  profiles:  
CentOS5.5-x86_64  
CentOS5.5-xen-x86_64  
  systems:  
  repos:  
  images:  
3、為cobbler添加RPM倉庫:
  cobbler repo add --name=CentOS-5-i386  --mirror=http://mirrors.163.com/centos/5/os/i386/  cobbler repo add --name=EPEL-5-i386--mirror=http://download.fedoraproject.org/pub/epel/5/i386/  
同步倉庫到本地:
  cobbler reposync  
也可以通過設置--mirror-locally=0不下載到本地,而通過kickstart server去倉庫下載rpm包。4、配置添加kickstart文件:Kickstart文件可在圖形界面下的終端中輸入:system-config-kickstart,然後通過圖形界面的Kickstart Configurator生成,或是參考已安裝好系統機器中的anaconda-ks.cfg文件下面是一個用Kickstart Configurator生成的ks文件
  #platform=x86, AMD64, or Intel EM64T  #version=DEVEL  # Firewall configuration  firewall --disabled  # Install OS instead of upgrade  install  # Use network installation  url  --url="http://192.168.0.2/cobbler/ks_mirror/CentOS5.5/"  # Root password  rootpw --iscrypted  $1$JNTgjcn5$P0TVlmNCfsurVdQKvLHsS0  # System authorization information  auth
--useshadow
--passalgo=md5  # Use text mode install  text  # System keyboard  keyboard us  # System language  lang zh_CN  # SELinux configuration  selinux --disabled  # Do not configure the X Window System  skipx  # Installation logging level  logging --level=info  # Reboot after installation  reboot  # System timezone  timezone --isUtc Asia/Shanghai  # System bootloader configuration  bootloader --location=mbr  # Clear the Master Boot Record  zerombr  # Partition clearing information  clearpart --all
  part /boot --fstype="ext3"  --size=100  part swap --fstype="swap"  --size=1024  part / --fstype="ext3" --grow  --size=1  reboot  
  %pre  $SNIPPET('log_ks_pre')  $kickstart_start  $SNIPPET('pre_install_network_config')  # Enable installation monitoring  $SNIPPET('pre_anamon')  
  %packages  @base  @chinese-support  @core  @dialup  @editors  @gnome-desktop  @games  @graphical-internet  @graphics  @office  @printing  @sound-and-video  @text-internet  @base-x  keyutils  trousers  fipscheck  device-mapper-multipath  libsane-hpaio  xorg-x11-server-Xnest  
  
  %post  $SNIPPET('log_ks_post')  # Start yum configuration   #$yum_config_stanza  # End yum configuration  $SNIPPET('post_install_kernel_options')  $SNIPPET('post_install_network_config')  $SNIPPET('func_register_if_enabled')  $SNIPPET('download_config_files')  $SNIPPET('koan_environment')  $SNIPPET('redhat_register')  $SNIPPET('cobbler_register')  # Enable post-install boot notification  $SNIPPET('post_anamon')  # Start final steps  $kickstart_done  # End final steps  
5、設置profile和system(1) profile可以理解為按角色進行分類下面是幾個添加刪除修改profile配置的例子:添加profile配置,名稱為:CenOS5.5,指定鏡像為:CentOS5.5-x86_64,kickstart文件為/var/lib/cobbler/kickstarts/CentOS5.ks
  cobbler profile add --name=CentOS5.5  --distro=CentOS5.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS5.ks  
修改profile文件,名稱為:CentOS5.5,指定鏡像由CentOS5.5-x86_64修改為CentOS5.5-i386
  cobbler profile add --name=CentOS5.5  --distro=CentOS5.5-i386  
變更profile配置名稱,名稱由CenOS5.5修改為CentOS5.5-i386
  cobbler profile rename --name=CentOS5.5 –newname=CentOS5.5-i386  
刪除profile配置,需要刪除的profile名稱為CenOS5.5
  cobbler profile remove --name=CentOS5.5  
注意:修改刪除profile,profile必須存在。

(2) system是對待安裝機器做具體設置,如設置主機名、IP地址、hostname等,這些設置根據MAC應用到具體機器上。
下面是幾個添加刪除修改system的例子:添加system配置,配置文件名稱:webserver1,機器IP地址192.168.0.110,機器MAC地址:00:0C:29:77:89:c7,使用配置文件名稱:webserver,kickstart文件為:/var/lib/cobbler/kickstarts/webserver.ks
  cobbler system add
--name=webserver1 --ip=192.168.0.110  --mac=00:0C:29:77:89:c7 --profile=webserver  --kickstart=/var/lib/cobbler/kickstarts/webserver.ks --static=1  
修改system配置,配置文件名稱:webserver1,機器IP地址由192.168.0.110變更為192.168.10.110
  cobbler system add
--name=webserver1 --ip=192.16810.110  
變更system配置名稱,名稱由webserver1變更成dbserver1
  cobbler system rename --name= webserver1 –newname=  dbserver1  
刪除system配置,需要刪除的profile名稱為dberver1
  cobbler system remove --name=dbserver1  



《解決方案》

首次安裝操作系統

1、
將需要安裝系統的伺服器,以下簡稱客戶端,放到和cobbler服務端同樣的子網中。
2、
啟動cobbler服務端上的cobblerd等相關服務。
3、
從PXE啟動客戶端主機。
(1)
客戶端尋找設置DHCP。(2)
客戶端從PXE啟動。(3)
客戶端進入cobbler profile選擇界面,用戶可以根據應用的不同,選擇不同的cobbler配置文件。重新安裝伺服器的操作系統

1、在客戶端上安裝koan
  yum install koan  
2、查看cobbler server上的配置文件
  koan --server=192.168.0.2 --list=profiles  
3、重新安裝客戶端系統
  koan --replace-self --server=192.168.0.2  --profile=webserver1  
4、reboot重啟伺服器后,客戶端伺服器會自動重新安裝操作系統cobbler BUG修復

yum安裝的cobbler有一個BUG。如果伺服器端上面的80埠被佔用。我們肯定會想到修改Apache的http.conf文件的Listen欄位來更改埠,然後再修改/etc/cobbler/settings的http_port欄位更改埠,后重新啟動cobblerd。修改Apache配置文件/etc/httpd/conf/httpd.conffile:///C:/DOCUME~1/mayulin/LOCALS~1/Temp/msohtml1/04/clip_image006.jpg修改cobbler配置文件/etc/cobbler/settingsfile:///C:/DOCUME~1/mayulin/LOCALS~1/Temp/msohtml1/04/clip_image008.jpg
但此時再次使用cobbler sync同步時會提示如下錯誤:file:///C:/DOCUME~1/mayulin/LOCALS~1/Temp/msohtml1/04/clip_image010.jpg解決辦法如下:
刪除」 /usr/lib/python2.4/site-packages/cobbler/」目錄下的pxegen.py相關文件
  rm –rf /usr/lib/python2.4/site-packages/cobbler/pxegen.py*  
下載附件中的pxegen.py,然後同步到"/usr/lib/python2.4/site-packages/cobbler/」目錄下Cobbler命令說明


  命令名稱
    命令用途
  
  cobbler check    核對當前設置是否有問題  
  cobbler list    列出所有的cobbler元素  
  cobbler report    詳細的列出個元素  
  cobbler sync    同步配置到dhcp/pxe和數據目錄  
  cobbler reposync    同步yum倉庫  
Cobbler配置文件說明

Cobbler配置文件存放在/etc/cobbler下。
  配置文件名稱
    用

  
  /etc/cobbler/settings    cobbler主配置文件  
  /etc/cobbler    dhcp、dns、pxe、dnsmasq的模板配置文件  
  /etc/cobbler/users.digest    用於web訪問的用戶名密碼配置文件  
  /etc/cobbler/modules.conf    模塊配置文件  
  /etc/cobbler/users.conf    Cobbler WebUI/Web service授權配置文件  

Repo數據目錄/var/www/cobbler導入的發行版,repos鏡像和kickstart文件都放置在/var/www/cobbler目錄下。確保/var目錄有足夠的空間來存儲這些文件。
  目錄名稱
    用

  
  images/    存儲所有導入發行版的Kernel和initrd鏡像用於遠程網路啟動  
  ks_mirror/    存儲導入的發行版  
  repo_mirror/    yum repos存儲目錄  
  /var/log/cobbler    存放日誌文件/var/log/cobbler/cobbler.log  

Cobbler數據目錄/var/lib/cobbler,此目錄存儲和Cobbler profiles、systems、distros相關的配置。
  目錄名稱
    用

  
  configs/    存儲distros、repos、systems和profiles相關信息  
  backup/    備份目錄
  
  snippets/    放置一些可以在kickstarts導入的腳本小片段  
  triggers/    放置一些可執行腳本  
  kickstarts/    放置kickstart模板文件  
參考文檔

預備工具:Cobbler CentOS 5.4安裝使用http://blog.sina.com.cn/s/blog_4e424e210100pbp5.htmlcobbler 批量安裝linuxhttp://zhumeng8337797.blog.163.com/blog/static/100768914201131232010310/
《解決方案》

樓主寫的很用心,但圖片無法顯示,再好好編輯下將會是一篇不錯的文章
《解決方案》

感謝樓主分享。
《解決方案》

非常好,學習了system的使用,哈哈。
《解決方案》

我覺得挺好的,大家的看法呢

[火星人 ] 自動化安裝操作系統:Cobbler+Koan安裝配置使用已經有1139次圍觀

http://coctec.com/docs/service/show-post-447.html