本文共 20398 字,大约阅读时间需要 67 分钟。
本次实验环境为如下
[root@study2 tools]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [root@study2 tools]# uname -r3.10.0-327.36.1.el7.x86_64
关闭selinux[root@study2 tools]# sed -i 's@^SELINUX=.*@SELINUX=disabled@g' /etc/selinux/config [root@study2 tools]# setenforce 0关闭iptables[root@study2 tools]# iptables -F[root@study2 tools]# iptables -X[root@study2 tools]# iptables -Z[root@study2 tools]# systemctl stop firewalld
[root@study2 ~]# cd /server/tools/[root@study2 tools]# wget http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm[root@study2 tools]# rpm -vih epel-release-latest-7.noarch.rpm [root@study2 tools]# rpm -qa epel-release
[root@study2 tools]# yum -y install httpd dhcp tftp bind bind-chroot caching-nameserver python-ctypes cobbler cobbler-web pykickstart xinetd[root@study2 tools]# rpm -qa httpd dhcp tftp bind bind-chroot caching-nameserver python-ctypes cobbler cobbler-web pykickstart xinetd
[root@study2 tools]# ls /etc/httpd/conf.d/autoindex.conf cobbler.conf cobbler_web.conf README ssl.conf userdir.conf welcome.conf
[root@cobbler ~]# systemctl start httpd[root@cobbler ~]# systemctl start cobblerd[root@cobbler-node1 ~]# netstat -ntlpua|grep httpdtcp6 0 0 :::80 :::* LISTEN 2668/httpd tcp6 0 0 :::443 :::* LISTEN 2668/httpd [root@cobbler-node1 ~]# ps -ef|grep cobblerapache 2669 2668 0 13:14 ? 00:00:00 (wsgi:cobbler_w -DFOREGROUNDroot 2697 1 0 13:14 ? 00:00:00 /usr/bin/python2 /usr/bin/cobblerd -Froot 2731 2353 0 13:17 pts/1 00:00:00 grep --color=auto cobbler
[root@study2 tools]# 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 : SELinux is enabled. Please review the following wiki page for details on ensuring cobbler works correctly in your SELinux environment: https://github.com/cobbler/cobbler/wiki/Selinux4 : change 'disable' to 'no' in /etc/xinetd.d/tftp5 : 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.6 : enable and start rsyncd.service with systemctl7 : debmirror package is not installed, it will be required to manage debian deployments and repositories8 : 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 one9 : fencing tools were not found, and are required to use the (optional) power management features. install cman or fence-agents to use themRestart cobblerd and then run 'cobbler sync' to apply changes.
每次对cobbler相关配置文件的修改,都需要cobbler sync,才能使设置的参数生效。
[root@cobbler ~]# vim /etc/cobbler/settings....272 next_server: 10.0.0.201...384 server: 10.0.0.201....
[root@cobbler-node1 ~]# sed -i 's@disable.*=.*@disable = no@g' /etc/xinetd.d/tftp [root@cobbler-node1 ~]# grep disable /etc/xinetd.d/tftp disable = no[root@cobbler-node1 ~]# systemctl start xinetd[root@cobbler-node1 ~]# lsof -i udp:69COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMExinetd 11663 root 5u IPv4 38158 0t0 UDP *:tftp
生成密码
[root@cobbler-node1 ~]# openssl passwd -1 -salt 'cobbler' 'cobbler' $1$cobbler$M6SE55xZodWc9.vAKLJs6.
修改cobbler的配置文件settings第101行,设置自动部署安装系统的root密码
[root@cobbler-node1 ~]# vim /etc/cobbler/settings ...101 default_password_crypted: "$1$cobbler$M6SE55xZodWc9.vAKLJs6."...
修改cobbler的配置文件settings第242行
[root@cobbler ~]# vim /etc/cobbler/settings ...242 manage_dhcp: 1...
修改cobbler的dhcp模版文件
[root@cobbler ~]# vim /etc/cobbler/dhcp.template 按需求进行修改。列如 网关、分配的ip范围,dns。注意:所分配的地址必须和服务器在同一个网段内 21 subnet 10.0.0.0 netmask 255.255.255.0 { 22 option routers 10.0.0.1; 23 option domain-name-servers 223.5.5.5; 25 range dynamic-bootp 10.0.0.220 10.0.0.250;
[root@cobbler-node1 ~]# systemctl start rsyncd[root@cobbler-node1 ~]# lsof -i :873COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMErsync 11654 root 4u IPv4 36817 0t0 TCP *:rsync (LISTEN)rsync 11654 root 5u IPv6 36818 0t0 TCP *:rsync (LISTEN)
如果显示Could not resolve host,需检查dns。
[root@cobbler-node1 ~]# cobbler get-loaders task started: 2016-10-12_121448_get_loaderstask started (id=Download Bootloader Content, time=Wed Oct 12 12:14:48 2016)path /var/lib/cobbler/loaders/README already exists, not overwriting existing content, use --force if you wish to updatepath /var/lib/cobbler/loaders/COPYING.elilo already exists, not overwriting existing content, use --force if you wish to updatedownloading http://cobbler.github.io/loaders/COPYING.yaboot to /var/lib/cobbler/loaders/COPYING.yabootdownloading http://cobbler.github.io/loaders/COPYING.syslinux to /var/lib/cobbler/loaders/COPYING.syslinuxdownloading http://cobbler.github.io/loaders/elilo-3.8-ia64.efi to /var/lib/cobbler/loaders/elilo-ia64.efidownloading http://cobbler.github.io/loaders/yaboot-1.3.17 to /var/lib/cobbler/loaders/yabootdownloading http://cobbler.github.io/loaders/pxelinux.0-3.86 to /var/lib/cobbler/loaders/pxelinux.0downloading http://cobbler.github.io/loaders/menu.c32-3.86 to /var/lib/cobbler/loaders/menu.c32downloading http://cobbler.github.io/loaders/grub-0.97-x86.efi to /var/lib/cobbler/loaders/grub-x86.efidownloading http://cobbler.github.io/loaders/grub-0.97-x86_64.efi to /var/lib/cobbler/loaders/grub-x86_64.efi*** TASK COMPLETE ***
[root@cobbler-node1 ~]# systemctl restart cobblerd[root@cobbler-node1 ~]# cobbler synctask started: 2016-10-12_124651_synctask started (id=Sync, time=Wed Oct 12 12:46:51 2016)running pre-sync triggerscleaning treesremoving: /var/lib/tftpboot/pxelinux.cfg/defaultremoving: /var/lib/tftpboot/grub/imagesremoving: /var/lib/tftpboot/grub/grub-x86.efiremoving: /var/lib/tftpboot/grub/grub-x86_64.efiremoving: /var/lib/tftpboot/grub/efidefaultremoving: /var/lib/tftpboot/s390x/profile_listcopying bootloaderscopying: /var/lib/cobbler/loaders/pxelinux.0 -> /var/lib/tftpboot/pxelinux.0copying: /var/lib/cobbler/loaders/menu.c32 -> /var/lib/tftpboot/menu.c32copying: /var/lib/cobbler/loaders/yaboot -> /var/lib/tftpboot/yabootcopying: /usr/share/syslinux/memdisk -> /var/lib/tftpboot/memdiskcopying: /var/lib/cobbler/loaders/grub-x86.efi -> /var/lib/tftpboot/grub/grub-x86.eficopying: /var/lib/cobbler/loaders/grub-x86_64.efi -> /var/lib/tftpboot/grub/grub-x86_64.eficopying distros to tftpbootcopying imagesgenerating PXE configuration filesgenerating PXE menu structurerendering TFTPD filesgenerating /etc/xinetd.d/tftpcleaning link cachesrunning post-sync triggersrunning python triggers from /var/lib/cobbler/triggers/sync/post/*running python trigger cobbler.modules.sync_post_restart_servicesrunning shell triggers from /var/lib/cobbler/triggers/sync/post/*running python triggers from /var/lib/cobbler/triggers/change/*running python trigger cobbler.modules.scm_trackrunning shell triggers from /var/lib/cobbler/triggers/change/**** TASK COMPLETE ***[root@study2 tools]# netstat -ntlpua|egrep "httpd|dhcpd|rsync|xinetd"tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 10284/rsync tcp6 0 0 :::80 :::* LISTEN 10159/httpd tcp6 0 0 :::443 :::* LISTEN 10159/httpd tcp6 0 0 :::873 :::* LISTEN 10284/rsync udp 0 0 0.0.0.0:54265 0.0.0.0:* 10339/dhcpd udp 0 0 0.0.0.0:67 0.0.0.0:* 10339/dhcpd udp 0 0 0.0.0.0:69 0.0.0.0:* 10245/xinetd udp6 0 0 :::3022 :::* 10339/dhcpd
插入7的光盘或镜像
[root@cobbler-node1 ~]# mount /dev/cdrom /media/[root@cobbler-node1 ~]# cobbler import --path=/media/ --name=Centos7_x86_64 --arch=x86_64 task started: 2016-10-12_125851_importtask started (id=Media import, time=Wed Oct 12 12:58:51 2016)Found a candidate signature: breed=redhat, version=rhel6Found a candidate signature: breed=redhat, version=rhel7Found a matching signature: breed=redhat, version=rhel7Adding distros from path /var/www/cobbler/ks_mirror/Centos7_x86_64-x86_64:creating new distro: Centos7-x86_64creating new profile: Centos7-x86_64associating reposchecking for rsync repo(s)checking for rhn repo(s)checking for yum repo(s)starting descent into /var/www/cobbler/ks_mirror/Centos7_x86_64-x86_64 for Centos7-x86_64processing repo at : /var/www/cobbler/ks_mirror/Centos7_x86_64-x86_64need to process repo/comps: /var/www/cobbler/ks_mirror/Centos7_x86_64-x86_64looking for /var/www/cobbler/ks_mirror/Centos7_x86_64-x86_64/repodata/*comps*.xmlKeeping repodata as-is :/var/www/cobbler/ks_mirror/Centos7_x86_64-x86_64/repodata*** TASK COMPLETE ***
插入6的光盘或镜像
[root@cobbler-node1 ~]# umount /media/[root@cobbler-node1 ~]# mount /dev/cdrom /media/[root@cobbler-node1 ~]# cobbler import --path=/media/ --name=Centos6.6_x86_64 --arch=x86_64 task started: 2016-10-12_130303_importtask started (id=Media import, time=Wed Oct 12 13:03:03 2016)Found a candidate signature: breed=redhat, version=rhel6Found a matching signature: breed=redhat, version=rhel6Adding distros from path /var/www/cobbler/ks_mirror/Centos6.6_x86_64-x86_64:creating new distro: Centos6.6-x86_64trying symlink: /var/www/cobbler/ks_mirror/Centos6.6_x86_64-x86_64 -> /var/www/cobbler/links/Centos6.6-x86_64creating new profile: Centos6.6-x86_64associating reposchecking for rsync repo(s)checking for rhn repo(s)checking for yum repo(s)starting descent into /var/www/cobbler/ks_mirror/Centos6.6_x86_64-x86_64 for Centos6.6-x86_64processing repo at : /var/www/cobbler/ks_mirror/Centos6.6_x86_64-x86_64need to process repo/comps: /var/www/cobbler/ks_mirror/Centos6.6_x86_64-x86_64looking for /var/www/cobbler/ks_mirror/Centos6.6_x86_64-x86_64/repodata/*comps*.xmlKeeping repodata as-is :/var/www/cobbler/ks_mirror/Centos6.6_x86_64-x86_64/repodata*** TASK COMPLETE ***
[root@cobbler-node1 ~]# ls /var/www/cobbler/ks_mirrorCentos6.6_x86_64-x86_64 Centos7_x86_64-x86_64 config
[root@cobbler-node1 ~]# cobbler profileusage=====cobbler profile addcobbler profile copycobbler profile dumpvarscobbler profile editcobbler profile findcobbler profile getkscobbler profile listcobbler profile removecobbler profile renamecobbler profile report
[root@cobbler-node1 ~]# cobbler profile list Centos6.6-x86_64 Centos7-x86_64
[root@cobbler-node1 ~]# cobbler profile reportName : Centos7-x86_64TFTP Boot Files : {}Comment : DHCP Tag : defaultDistribution : Centos7-x86_64Enable gPXE? : 0Enable PXE Menu? : 1Fetchable Files : {}Kernel Options : {}Kernel Options (Post Install) : {}Kickstart : /var/lib/cobbler/kickstarts/sample_end.ksKickstart Metadata : {}Management Classes : []Management Parameters : <>Name Servers : []Name Servers Search Path : []Owners : ['admin']Parent Profile : Internal proxy : Red Hat Management Key : < >Red Hat Management Server : < >Repos : []Server Override : < >Template Files : {}Virt Auto Boot : 1Virt Bridge : xenbr0Virt CPUs : 1Virt Disk Driver Type : rawVirt File Size(GB) : 5Virt Path : Virt RAM (MB) : 512Virt Type : kvmName : Centos6.6-x86_64TFTP Boot Files : {}Comment : DHCP Tag : defaultDistribution : Centos6.6-x86_64Enable gPXE? : 0Enable PXE Menu? : 1Fetchable Files : {}Kernel Options : {}Kernel Options (Post Install) : {}Kickstart : /var/lib/cobbler/kickstarts/sample_end.ksKickstart Metadata : {}Management Classes : []Management Parameters : < >Name Servers : []Name Servers Search Path : []Owners : ['admin']Parent Profile : Internal proxy : Red Hat Management Key : < >Red Hat Management Server : < >Repos : []Server Override : < >Template Files : {}Virt Auto Boot : 1Virt Bridge : xenbr0Virt CPUs : 1Virt Disk Driver Type : rawVirt File Size(GB) : 5Virt Path : Virt RAM (MB) : 512Virt Type : kvm
请参照规范将文件放到/var/lib/cobbler/kickstarts目录下,然后执行如下操作。
cobbler profile edit --name=Centos7-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos6.6.cfgcobbler sync
[root@cobbler-node1 ~]# cobbler profile edit --name=Centos7-x86_64 --kopts='net.ifnames=0 biosdevname=0'[root@cobbler-node1 ~]# cobbler profile report --name=Centos7-x86_64Name : Centos7-x86_64TFTP Boot Files : {}Comment : DHCP Tag : defaultDistribution : Centos7-x86_64Enable gPXE? : 0Enable PXE Menu? : 1Fetchable Files : {}Kernel Options : {'biosdevname': '0', 'net.ifnames': '0'}Kernel Options (Post Install) : {}Kickstart : /var/lib/cobbler/kickstarts/sample_end.ksKickstart Metadata : {}Management Classes : []Management Parameters : <>Name Servers : []Name Servers Search Path : []Owners : ['admin']Parent Profile : Internal proxy : Red Hat Management Key : < >Red Hat Management Server : < >Repos : []Server Override : < >Template Files : {}Virt Auto Boot : 1Virt Bridge : xenbr0Virt CPUs : 1Virt Disk Driver Type : rawVirt File Size(GB) : 5Virt Path : Virt RAM (MB) : 512Virt Type : kvmsync让配置生效[root@cobbler ~]# cobbler sync
现在可以自动装机了, 开机F12
注意此步在客户机上进行操作,客户端如果没能下载请使用阿里的yum源。
[root@localhost ~]# yum -y install koan
查看cobbler能重装的系统
[root@localhost ~]# koan --server=10.0.0.201 --list=profiles- looking for Cobbler at http://10.0.0.201:80/cobbler_apiCentos7-x86_64Centos6.6-x86_64
指定要重装的系统
[root@localhost ~]# koan --replace-self --server=10.0.0.201 --profile=Centos7-x86_64 [root@localhost ~]# cat /etc/grub.conf # grub.conf generated by anaconda## Note that you do not have to rerun grub after making changes to this file# NOTICE: You have a /boot partition. This means that# all kernel and initrd paths are relative to /boot/, eg.# root (hd0,0)# kernel /vmlinuz-version ro root=/dev/mapper/VolGroup-lv_root# initrd /initrd-[generic-]version.img#boot=/dev/sdadefault=0timeout=5splashimage=(hd0,0)/grub/splash.xpm.gzhiddenmenutitle kick1476198549 root (hd0,0) kernel /vmlinuz_koan ro rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet ksdevice=link lang= text net.ifnames=0 ks=http://10.0.0.201/cblr/svc/op/ks/profile/Centos7-x86_64 biosdevname=0 kssendmac initrd /initrd.img_koantitle CentOS 6 (2.6.32-504.el6.x86_64) root (hd0,0) kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet initrd /initramfs-2.6.32-504.el6.x86_64.img
重启后,就会自动重装系统
用户名/密码是cobbler,url是https://10.0.0.201/cobbler_web
修改密码为123
[root@cobbler cobbler]# htdigest /etc/cobbler/users.digest "cobbler" cobbler Adding user cobbler in realm cobblerNew password: Re-type new password:[root@cobbler cobbler]# cobbler sync
修改grub选单(可选)
[root@cobbler cobbler]# cd /etc/cobbler/pxe/[root@cobbler pxe]# ll pxedefault.template -rw-r--r--. 1 root root 238 Jan 23 2016 pxedefault.template
我修改为如下:
+++PROMPT 0MENU TITLE damaicha | http://www.damaicha.orgTIMEOUT 200TOTALTIMEOUT 6000ONTIMEOUT $pxe_timeout_profileLABEL local MENU LABEL (local) MENU DEFAULT LOCALBOOT -1$pxe_menu_itemsMENU end+++[root@cobbler pxe]# cobbler sync
1.添加repo
[root@cobbler ~]# cobbler repo add --name=openstack-mitaka --mirror=http://mirrors.aliyun.com/centos/7.2.1511/cloud/x86_64/openstack-mitaka/ --arch=x86_64 --breed=yum
2.同步repo
[root@cobbler ~]# cobbler reposync3.添加repo到对应的profile
[root@cobbler pxe]# cobbler profile edit --name=Centos7-x86_64 --repos="openstack-mitaka"
4.修改kickstart文件,添加如下。
[root@cobbler ~]# vi /var/lib/cobbler/kickstarts/sample_end.ks%post添加这个,将将把yum库添加进去$yum_config_stanza%end
大前提是需要知道mac地址和规划好相关的配置信息,如网络信息,主机名等。
主机信息:
00:50:56:3E:6A:CF 规划信息:10.0.0.202 linux-node2.oldboyedu.com 223.5.5.511.[root@cobbler-node1 ~]# cobbler system add --name=linux-node2.oldboyedu.com\--mac=00:50:56:3E:6A:CF --profile=Centos7-x86_64 --ip-address=10.0.0.202\--subnet=255.255.255.0 --gateway=10.0.0.1 --interface=eth0 --static=1\--hostname=linux-node2.oldboyedu.com --name-servers="223.5.5.5"\--kickstart=/var/lib/cobbler/kickstarts/sample_end.ks[root@cobbler-node1 ~]# cobbler system list linux-node2.oldboyedu.com[root@cobbler-node1 ~]# cobbler sync[root@cobbler-node1 ~]# tail -12 /etc/dhcp/dhcpd.conf group { host generic1 { hardware ethernet 00:50:56:3E:6A:CF; fixed-address 10.0.0.202; option host-name "linux-node2.oldboyedu.com"; option subnet-mask 255.255.255.0; option routers 10.0.0.1; filename "/pxelinux.0"; next-server 10.0.0.201; }}
此时客户机,从pxe网络启动,将会自动的安装指定的系统,不需要任何选择。
api控制文件/etc/httpd/conf.d/cobbler.conf [root@cobbler ~]# grep ProxyPass /etc/httpd/conf.d/cobbler.conf ProxyPass /cobbler_api http://localhost:25151/ProxyPa***everse /cobbler_api http://localhost:25151/
#!/usr/bin/env pythonimport xmlrpclibserver = xmlrpclib.Server("http://10.0.0.201/cobbler_api")print server.get_distros()print server.get_profiles()print server.get_systems()print server.get_images()print server.get_repos()
转载于:https://blog.51cto.com/damaicha/2106109