1.1 Cobbler介紹html
Cobbler 是一個免費開源系統安裝部署軟件,用於自動化網絡安裝操做系統。 Cobbler 集成了 DNS, DHCP, 軟件包更新,帶外管理以及配置管理,方便操做系統安裝自動化。 Cobbler 能夠支持PXE啓動, 操做系統從新安裝,以及虛擬化客戶機建立,包括Xen, KVM or VMware. Cobbler 透過koan程序以支持虛擬化客戶機安裝。 Cobbler 能夠支持管理複雜網路環境,如創建在鏈路聚合以太網的橋接環境。
1.2 cobbler 服務集成node
1 pxe 服務 2 DHCP 3 Rsync 4 HTTP 5 DNS 6 Kickstart 7 IPMI 電源管理
1.3 cobbler的設計方式python
發行版(distro) :表示一個操做系統,它承載了內核和initrd的信息,以及內核等其餘數據 存儲庫 (repository):保存了一個yum或者rsync存儲庫的鏡像信息 配置文件(profile):包含了一個發行版(distro),一個kickstart文件以及可能的存儲庫(repository),還包含了更多的內核參數等其餘數據 系統(system):表示要配給的機器,它包含了一個配置文件或一個鏡像,還包含了ip和mac地址,電源管理(地址,憑據,類型)以及更爲專業的數據信息 鏡像(p_w_picpath):可替換一個包含不屬於此類別的文件的發行版對象(eg: 沒法爲內核和initrd的對象)
以上各個組件中, 發行版,存儲庫, 配置文件爲必須配置項linux
只有在虛擬環境中,必需要用cobbler來引導虛擬機啓動時候,纔會用到系統組件ios
但事實上,在生產環境中須要大量的虛擬機實例的話,一般利用openstack等來實現虛擬機節點web
1.4 cobbler 運行的流程shell
- DHCP - Client (從dhcp服務器獲取地址,訪問next_server的ip地址) - Next_server (獲取啓動內核,initrd等文件) - tftp (pxe引導文件 啓動cobbler選擇界面) - kickstart (肯定加載項,根據nfs,http,ftp等共享)
1.5 cobbler unitsvim
- cobbler - cobbler-web
2.1 準備環境 centos
1 安裝cobbler 依據cobbler check檢查結果,對setting主配置文件的設置,進行相關的修正設置
bash
2 啓動先相關的httpd cobbler服務,使用cobbler rsync 同步設置
3 配置 cobbler 所依賴的服務
dhcp: isc dhcpd , dnsmasq (必須服務,選擇其一管理便可)
dns: bing , dnsmasq (可選)
rysnc: rsync (必須服務)
tftp: in,tftp(tftp-server) ,cobbler自帶的tftp(必須服務 ,選擇其中其一管理便可)
4 安裝epel源
[root@kvm ~]# yum install -y wget [root@kvm ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
5 設置ip轉發
[root@kvm ~]# echo 1 > /proc/sys/net/ipv4/ip_forward [root@kvm ~]# sed -i 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/' /etc/sysctl.conf [root@kvm ~]# sysctl -p
2.2 安裝Cobbler
[root@kvm ~]#yum -y install cobbler dhcp httpd xinetd tftp-server syslinux pykickstart xinetd rsync cobbler-web
2.3 調整爲動態配置Cobbler
動態更新配置
對於Cobbler2.4來講,有一個重要的功能,就是讓你能夠不須要手工去編輯setting配置文件,直接使用命令去修改,默認這個功能是不啓用,你須要啓用。
[root@kvm cobbler]# cp settings settings.bak [root@kvm cobbler]# sed -i 's/^[[:space:]]\+/ /' /etc/cobbler/settings [root@kvm cobbler]# sed -i 's/allow_dynamic_settings: 0/allow_dynamic_settings: 1/g' /etc/cobbler/settings [root@kvm cobbler]# /etc/init.d/cobblerd restart Stopping cobbler daemon: [ OK ] Starting cobbler daemon: [ OK ]
2.4 檢查須要安裝的配置
[root@note1 ~]# 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 : change 'disable' to 'no' in /etc/xinetd.d/tftp 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/rsync 6 : since iptables may be running, ensure 69, 80/443, and 25151 are unblocked 7 : reposync is not installed, need for cobbler reposync, install/upgrade yum-utils? 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 10 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use them
#解決方法 [root@kvm cobbler]# cobbler setting edit --name=server --value=10.10.10.10 2: [root@kvm cobbler]# cobbler setting edit --name=next_server --value=10.10.10.10 3: 能夠忽略 4: [root@note1 loaders]# openssl passwd -1 -salt `openssl rand -hex 4` "budongshu" $1$557d907c$AmKQun9Jxitt1D6aQ8DUC. [root@kvm cobbler]# cobbler setting edit --name=default_password_crypted \ > --value="$1$557d907c$AmKQun9Jxitt1D6aQ8DUC." 5: [root@kvm cobbler]# yum install cman #安裝電源管理工具 #開機啓動 [root@note1 cobbler]# chkconfig tftp on [root@note1 cobbler]# chkconfig rsync on [root@note1 cobbler]# /etc/init.d/xinetd restart #下載啓動菜單 [root@note1 cobbler]# cobbler get-loaders #防止誤重裝系統 選項 pxe_just_one [root@note1 cobbler]# cobbler setting edit --name=pxe_just_once --value=1 #開啓cobbler 管理dhcp服務器 [root@note1 cobbler]# cobbler setting edit --name=manage_dhcp --value="1" 2.5 同步cobbler [root@kvm cobbler]# service cobblerd restart Stopping cobbler daemon: [ OK ] Starting cobbler daemon: [ OK ] [root@kvm cobbler]# cobbler sync task started: 2015-11-06_094656_sync task started (id=Sync, time=Fri Nov 6 09:46:56 2015) running pre-sync triggerscleaning treesremoving: /var/lib/tftpboot/grub/p_w_picpathscopying bootloaders trying hardlink /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0 trying hardlink /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32 trying hardlink /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yaboot trying hardlink /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdisk 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_picpathsgenerating PXE configuration files generating PXE menu structurerendering TFTPD files generating /etc/xinetd.d/tftpcleaning link caches running post-sync triggersrunning python triggers from /var/lib/cobbler/triggers/sync/post/* running python trigger cobbler.modules.sync_post_restart_services 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 *** 重啓 [root@kvm cobbler]# service cobblerd restart Stopping cobbler daemon: [ OK ] Starting cobbler daemon: [ OK ] 再次檢查 [root@kvm cobbler]# cobbler check The following are potential configuration items that you may want to fix: 1 : debmirror package is not installed, it will be required to manage debian deployments and repositoriesRestart cobblerd and then run 'cobbler sync' to apply changes. #上面配置成功
2.6 配置dhcp服務
[root@note1 cobbler]# vim /etc/cobbler/dhcp.template
#其餘須要動,只修改下面的幾個內容
subnet 10.10.10.0 netmask 255.255.255.0 { option routers 10.10.10.10; option domain-name-servers 114.114.114.114; option subnet-mask 255.255.255.0; range dynamic-bootp 10.10.10.20 10.10.10.50; default-lease-time 21600; max-lease-time 43200; next-server $next_server; ...... 此時的dhcpd的配置就被cobbler覆蓋,由cobbler來管理配置文件,截取的一部分,後面還有內容 [root@note1 cobbler]# vim /etc/dhcp/dhcpd.conf # ****************************************************************** # Cobbler managed dhcpd.conf file # generated from cobbler dhcp.conf template (Sun Jan 31 15:47:49 2016) # Do NOT make changes to /etc/dhcpd.conf. Instead, make your changes # in /etc/cobbler/dhcp.template, as /etc/dhcpd.conf will be # overwritten. # ****************************************************************** ddns-update-style interim; allow booting; allow bootp; ignore client-updates; set vendorclass = option vendor-class-identifier; option pxe-system-type code 93 = unsigned integer 16; subnet 10.10.10.0 netmask 255.255.255.0 { ...... ...... ......
編寫啓動腳本 cat >>/etc/init.d/cobbler<<EOF #!/bin/bash # chkconfig: 345 80 90 # description:cobbler case \$1 in start) /etc/init.d/httpd start /etc/init.d/xinetd start /etc/init.d/dhcpd start /etc/init.d/cobblerd start ;; stop) /etc/init.d/httpd stop /etc/init.d/xinetd stop /etc/init.d/dhcpd stop /etc/init.d/cobblerd stop ;; restart) /etc/init.d/httpd restart /etc/init.d/xinetd restart /etc/init.d/dhcpd restart /etc/init.d/cobblerd restart ;; status) /etc/init.d/httpd status /etc/init.d/xinetd status /etc/init.d/dhcpd status /etc/init.d/cobblerd status ;; sync) cobbler sync ;; *) echo "Input error,please in put 'start|stop|restart|status|sync'!" exit 2 ;; esac EOF # chmod +x /etc/init.d/cobbler # chkconfig cobbler on
2.7 配置ks文件
[root@linux-node1 ~]# cobbler #cobbler命令 usage ===== cobbler <distro|profile|system|repo|p_w_picpath|mgmtclass|package|file> ... [add|edit|copy|getks*|list|remove|rename|report] [options|--help] cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validateks|version|signature|get-loaders|hardlink> [options|--help] [root@linux-node1 ~]# cobbler import --help # 導入鏡像 Usage: cobbler [options] Options: -h, --help show this help message and exit --arch=ARCH OS architecture being imported --breed=BREED the breed being imported --os-version=OS_VERSION the version being imported --path=PATH local path or rsync location --name=NAME name, ex 'RHEL-5' --available-as=AVAILABLE_AS tree is here, don't mirror --kickstart=KICKSTART_FILE assign this kickstart file --rsync-flags=RSYNC_FLAGS pass additional flags to rsync cobbler check 覈對當前設置是否有問題 cobbler list 列出全部的cobbler元素 cobbler report 列出元素的詳細信息 cobbler sync 同步配置到數據目錄,更改配置最好都要執行下 cobbler reposync 同步yum倉庫 cobbler distro 查看導入的發行版系統信息 cobbler system 查看添加的系統信息 cobbler profile 查看配置信息
2.8 導入系統到cobbler
centos6.5
[root@kvm cobbler]# mount /dev/cdrom /mnt [root@note1 cobbler]# cobbler import --path=/mnt/ --name=Centos-6.5-x86_64 --arch=x86_64 [root@note1 cobbler]# cobbler distro report --name=Centos-6.5-x86_64 Name : Centos-6.5-x86_64 Architecture : x86_64 TFTP Boot Files : {} Breed : redhat Comment : Fetchable Files : {} Initrd : /var/www/cobbler/ks_mirror/Centos-6.5-x86_64/p_w_picpaths/pxeboot/initrd.img Kernel : /var/www/cobbler/ks_mirror/Centos-6.5-x86_64/p_w_picpaths/pxeboot/vmlinuz Kernel Options : {} Kernel Options (Post Install) : {} Kickstart Metadata : {'tree': ' Management Classes : [] OS Version : rhel6 Owners : ['admin'] Red Hat Management Key : <<inherit>> Red Hat Management Server : <<inherit>> Template Files : {}
centos7
[root@note1 ~]# umount /mnt [root@note1 cobbler]# cobbler import --path=/mnt/ --name=Centos-7-x86_64 --arch=x86_64 [root@note1 kickstarts]# cobbler distro report --name=Centos-7-x86_64 Name : Centos-7-x86_64 Architecture : x86_64 TFTP Boot Files : {} Breed : redhat Comment : Fetchable Files : {} Initrd : /var/www/cobbler/ks_mirror/Centos-7-x86_64/p_w_picpaths/pxeboot/initrd.img Kernel : /var/www/cobbler/ks_mirror/Centos-7-x86_64/p_w_picpaths/pxeboot/vmlinuz Kernel Options : {} Kernel Options (Post Install) : {} Kickstart Metadata : {'tree': 'http://@@http_server@@/cblr/links/Centos-7-x86_64'} Management Classes : [] OS Version : rhel7 Owners : ['admin'] Red Hat Management Key : <<inherit>> Red Hat Management Server : <<inherit>> Template Files : {}
[root@note1 cobbler]# cobbler distro list Centos-6.5-x86_64 Centos-7-x86_64
2.9 修改默認ks文件
#配置centos6.5 [root@note1 kickstarts]#cd /var/lib/cobbler/kickstarts/ [root@note1 kickstarts]#cp sample_end.ks CentOS-6.5-x86_64.cfg [root@note1 kickstarts]#cobbler profile edit --name=Centos-6.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-6.5-x86_64.cfg [root@note1 kickstarts]# cat CentOS-6.5-x86_64.cfg # kickstart template for Fedora 8 and later. # (includes %end blocks) # do not use with earlier distros #platform=x86, AMD64, or Intel EM64T # System authorization information auth --useshadow --enablemd5 # System bootloader configuration bootloader --location=mbr # Partition clearing information clearpart --all --initlabel # Use text mode install text # Firewall configuration firewall --enabled # Run the Setup Agent on first boot firstboot --disable # System keyboard keyboard us # System language lang en_US # Use network installation url --url=$tree # If any cobbler repo definitions were referenced in the kickstart profile, include them here. $yum_repo_stanza # Network information $SNIPPET('network_config') # Reboot after installation reboot #Root password rootpw --iscrypted $default_password_crypted # SELinux configuration selinux --disabled # Do not configure the X Window System skipx # System timezone timezone America/New_York # Install OS instead of upgrade install # Clear the Master Boot Record zerombr # Allow anaconda to partition the system as needed autopart %pre $SNIPPET('log_ks_pre') $SNIPPET('kickstart_start') $SNIPPET('pre_install_network_config') # Enable installation monitoring $SNIPPET('pre_anamon') %end %packages $SNIPPET('func_install_if_enabled') %end %post --nochroot $SNIPPET('log_ks_post_nochroot') %end %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 $SNIPPET('kickstart_done') # End final steps
#配置centos7 [root@note1 kickstarts]#cobbler profile edit --name=Centos-7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg [root@note1 kickstarts]# cat CentOS-7-x86_64.cfg #obbler for Kickstart Configurator for CentOS 7.1 by yao zhang install url --url=$tree text lang en_US.UTF-8 keyboard us zerombr bootloader --location=mbr # Network information $SNIPPET('network_config') timezone --utc Asia/Shanghai authconfig --enableshadow --passalgo=sha512 rootpw --iscrypted $default_password_crypted clearpart --all --initlabel part /boot --fstype xfs --size 500 part swap --size 2000 part / --fstype xfs --size 20000 part /data --fstype xfs --size 30000 firstboot --disable selinux --disabled firewall --disabled logging --level=info reboot %pre $SNIPPET('log_ks_pre') $SNIPPET('kickstart_start') $SNIPPET('pre_install_network_config') # Enable installation monitoring $SNIPPET('pre_anamon') %end %packages @base @compat-libraries @debugging @development tree nmap sysstat lrzsz dos2unix telnet iptraf ncurses-devel openssl-devel zlib-devel OpenIPMI-tools screen %end %post systemctl disable postfix.service
#修改centos7 網卡label # 修改安裝系統的內核參數,在CentOS7系統有一個地方變了,就是網卡名變成eno16777736這種形式,可是爲了運維標準化, #咱們須要將它變成咱們經常使用的eth0,所以使用下面的參數。但要注意是CentOS7才須要下面的步驟,CentOS6不須要。 [root@note1 kickstarts]# cobbler profile edit --name=CentOS-7.1-x86_64 --kopts='net.ifnames=0 biosdevname=0' [root@note1 kickstarts]# cobbler profile report --name=CentOS-7-x86_64 Name : CentOS-7-x86_64 TFTP Boot Files : {} Comment : DHCP Tag : default Distribution : Centos-7-x86_64 Enable gPXE? : 0 Enable PXE Menu? : 1 Fetchable Files : {} Kernel Options : {'biosdevname': '0', 'net.ifnames': '0'} Kernel Options (Post Install) : {} Kickstart : /var/lib/cobbler/kickstarts/CentOS-7-x86_64.cfg Kickstart Metadata : {} Management Classes : [] Management Parameters : <<inherit>> Name Servers : [] Name Servers Search Path : [] Owners : ['admin'] Parent Profile : Internal proxy : Red Hat Management Key : <<inherit>> Red Hat Management Server : <<inherit>> Repos : [] Server Override : <<inherit>> Template Files : {} Virt Auto Boot : 1 Virt Bridge : xenbr0 Virt CPUs : 1 Virt Disk Driver Type : raw Virt File Size(GB) : 5 Virt Path : Virt RAM (MB) : 512 Virt Type : kvm
#查看
[root@note1 kickstarts]# cobbler profile report Centos-7-x86_64 [root@note1 kickstarts]# cobbler profile report Centos-6.5-x86_64
[root@note1 kickstarts]# cobbler list distros: Centos-6.5-x86_64 Centos-7-x86_64 profiles: Centos-6.5-x86_64 Centos-7-x86_64 systems: budongshu repos: p_w_picpaths: mgmtclasses: packages: files:
#配置本地yum倉庫 能夠忽略
[root@localhost ~]# mkdir /tmp/rpms [root@localhost ~]# createrepo /tmp/rpms #放入rpm包,執行此步驟 [root@localhost ~]# cobbler repo add --mirror=/tmp/rpms --name=local [root@localhost ~]# cobbler reposync
#配置本地epel倉庫 能夠忽略
[root@localhost ~]# cobbler repo add --mirror=http://mirrors.aliyun.com/epel/6/x86_64/ --name=epel [root@localhost ~]# cobbler reposync --tries=3 --no-fail #同步epel倉庫到本地,須要較長時間#查看已添加的repo [root@localhost ~]# cobbler repo list epel local
#添加repo到profile 能夠忽略
[root@localhost ~]# cobbler profile edit --name=Centos-6.5-x86_64 --repos="epel local" [root@localhost ~]# cobbler sync
#綁定mac地址 ,實現開機自動選擇
#配置綁定mac地址和IP地址 ,開機自動選擇
cobbler system add --name=budongshu --mac=00:0C:29:48:1D:75 --profile=Centos-7-x86_64 \--ip-address=10.10.10.23 --subnet=255.255.255.0 --gateway=10.10.10.10 --interface=eth0 \--static=1 --hostname=budongshu --name-servers="114.114.114.114 8.8.8.8"
3.0 配置cobbler web界面
cobbler-web支持多種認證方式,如authn_configfil、authn_ldap或authn_pam等,下面咱們基於authn_pam作認證 #修改認證方式 [root@note1 web]# vim /etc/cobbler/modules.conf [authentication] module = authn_pam 添加系統用戶 [root@note1 web]# useradd cobbler [root@note1 web]# echo "cobbler" | passwd --stdin cobbler 添加用戶到管理組 [root@note1 web]# vim /etc/cobbler/modules.conf [admins] admin = "cobbler" 重啓服務 Stopping cobbler daemon: [ OK ] Starting cobbler daemon: [ OK ] [root@note1 web]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]