PXE和Cobble实现自动装机
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PXE和Cobble实现自动装机相关的知识,希望对你有一定的参考价值。
t :PXE:
预启动执行环境,是由Intel开发的最新技术,工作于Client/Server的网络模式,支持终端通过网络从远端服务器下载映像,并由此支持通过网络启动操作系统,在启动过程中,终端要求服务器分配IP地址,再用TFTP(trivial file transfer protocol)协议下载一个启动软件包到本机内存中执行,由这个启动软件包完成终端基本软件设置,从而引导预先安装在服务器中的终端操作系统。
一、安装DHCP服务,实现动态地址分配
~]# yum -y install dhcp ~]# vim /etc/dhcp/dhcpd.conf option domain-name-servers 172.18.0.1; //指明分配的DNS # default-lease-time 3600; max-lease-time 7200; # # Use this to send dhcp log messages to a different log file (you also # have to hack syslog.conf to complete the redirection). log-facility local7; # subnet 192.168.100.0 netmask 255.255.255.0 { //地址分配池 range 192.168.100.20 192.168.100.99; //地址分配范围 filename "pxelinux.0"; //引导文件名称 next-server 192.168.100.10; //引导文件所在的IP地址 }
测试有无语法错误,并启动dhcp服务:
]# service dhcpd configtest Syntax: OK ~]# service dhcpd start Starting dhcpd: [ OK ] //注意:启动dhcp服务时,会去读取网卡的配置,如果网卡没能配置192.168.100.10,会报错
查看监听端口:
~]# ss -uan State Recv-Q Send-Q Local Address:Port Peer Address:Port UNCONN 0 0 *:67 *:*
二、安装tftp服务,实现文件传输
]# yum -y install tftp-server ]# vim /etc/xinetd.d/tftp service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /var/lib/tftpboot disable = no //改为no就行 per_source = 11 cps = 100 2 flags = IPv4 }
启动tftp,并查看监听端口:
]# service xinetd restart Stopping xinetd: [ OK ] Starting xinetd: [ OK ] ]# ss -uan State Recv-Q Send-Q Local Address:Port Peer Address:Port UNCONN 0 0 *:69 *:*
三、安装httpd,提供远程下载仓库
]# yum -y install httpd ]# service httpd start
四、挂载虚拟光盘到虚拟机上
]# mkdir /media/cdrom ]# mount /dev/cdrom /media/cdrom mount: block device /dev/sr0 is write-protected, mounting read-only ]# mkdir /var/www/html/centos ]# mount --bind /media/cdrom/ /var/www/html/centos/
五、下载pxe引导文件
]# yum -y install syslinux
复制引导安装文件到tftp服务的目录下:
]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ //引导文件 ]# cp /media/cdrom/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/ //内核和ramdisk ]# cp /media/cdrom/isolinux/{boot.msg,vesamenu.c32,splash.jpg} /var/lib/tftpboot //背景图片 ]# mkdir /var/lib/tftpboot/pxelinux.cfg/ ]# cp /media/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default //菜单
修改default文件,符合自己的要求:
]# vim /var/lib/tftpboot/pxelinux.cfg/default timeout 100 //修改为10秒 label autoinst menu label CentOS 6.5 INSTALL menu default kernel vmlinuz append initrd=initrd.img ks=http://192.168.100.10/centos6.5_x86_64.cfg //自动装机文件
五:配置自动装机文件kickstart
]# vim /var/www/html/centos6.5_x86_64.cfg #platform=x86, AMD64, or Intel EM64T #version=DEVEL # Firewall configuration firewall --enable # Install OS instead of upgrade install # Use network installation url --url="http://192.168.100.10/centos" # Root password rootpw 123456 # System authorization information auth --useshadow --passalgo=sha512 # Use text mode install text firstboot --disable # System keyboard keyboard us # System language lang en_US # SELinux configuration selinux --disabled # Installation logging level logging --level=info --host=192.168.100.10 # Reboot after installation reboot # System timezone timezone Asia/Shanghai # System bootloader configuration bootloader --append="rhgb crashkernel=auto quiet" --location=mbr --driveorder="sda" # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all # Disk partitioning information part / --bytes-per-inode=4096 --fstype="ext4" --grow --size=1 part /boot --bytes-per-inode=4096 --fstype="ext4" --size=200 part swap --bytes-per-inode=4096 --fstype="swap" --size=8192 %packages --nobase //最小化安装 @core %end
测试能否远程读取CentOS仓库及装机文件:
六:开启虚拟机测试能否自动装机
Cobbler:
Red Hat根据PXE二次封装的网络工具,使用更为简单:
]# yum -y install cobbler dhcp tftp-server syslinux httpd
启动cobbler并检测运行环境:
]# service cobblerd start ]# cobbler check ]# cobbler check Traceback (most recent call last): File "/usr/bin/cobbler", line 36, in <module> sys.exit(app.main()) #报错,修改配置文件: ]# vim /etc/cobbler/settings server: 192.168.100.10 //把这两项修改为虚拟机的IP地址 next_server: 192.168.100.10 ]# service cobblerd restart ]# service httpd start //启动httpd ]# service xinetd start //启动tftp
再一次cobbler check:
1、如果当前节点可以访问互联网,执行“cobbler get-loaders”命令即可;否则,需要安装syslinux程序包,而后复制/usr/share/syslinux/目录下所有文件至/var/lib/cobbler/loaders/目录中;
2、执行 chkconfig rsync on 命令
3、执行 yum -y install debmirror 命令
4、执行 yum -y install pykickstart 命令
5、执行“openssl passwd -1 -salt $(openssl rand -hex 4)”生成密码,并用其替换/etc/cobbler/settings文件中default_password_crypted参数的值;
6、执行 yum -y install cman fence-agents 命令
修改完后执行重启cobblerb并cobbler sync,在次执行cobbler check
]# cobbler check
1、可以不用管,只要复制了syslinux目录下的文件过去就行;
2、注释/etc/debmirror.conf文件中的“@dists="sid";”一行;
3、注释/etc/debmirror.conf文件中的“@arches="i386";”一行;
]# service cobblerd restart Stopping cobbler daemon: [ OK ] Starting cobbler daemon: [ OK ] ]# cobbler sync //在次同步配置文件
导入光盘到虚拟机里,生成cobbler的distro和profile文件:
]# mount /dev/cdrom /media/cdrom ]# cobbler import --name="Centos6.5-x86_64" --path=/media/cdrom //定义distro ]# cobbler distro list Centos6.5-x86_64 ]# cobbler profile list Centos6.5-x86_64 ]# cobbler profile remove --name Centos6.5-x86_64 //定义distro时会自动生成一个profile文件,不符合我们的要求,删除
编辑kickstart文件:
vim /var/lib/cobbler/kickstarts/centos6.cfg #platform=x86, AMD64, or Intel EM64T #version=DEVEL # Firewall configuration firewall --enable # Install OS instead of upgrade install # Use network installation url --url="http://172.18.250.76/cobbler/ks_mirror/Centos6.5-x86_64/" # Root password rootpw 123456 # System authorization information auth --useshadow --passalgo=sha512 # Use text mode install text firstboot --disable # System keyboard keyboard us # System language lang en_US # SELinux configuration selinux --disabled # Installation logging level logging --level=info --host=192.168.100.10 # Reboot after installation reboot # System timezone timezone Asia/Shanghai # System bootloader configuration bootloader --append="rhgb crashkernel=auto quiet" --location=mbr --driveorder="sda" # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all # Disk partitioning information part / --bytes-per-inode=4096 --fstype="ext4" --grow --size=1 part /boot --bytes-per-inode=4096 --fstype="ext4" --size=200 part swap --bytes-per-inode=4096 --fstype="swap" --size=8192 %packages --nobase //最小化安装 @core %end
生成符合要求的profile:
]# cobbler profile add --name=centos6.5-x86 --distro=Centos6.5-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos6.cfg ]# cobbler profile list centos6.5-x86 ]# vim /var/lib/tftpboot/pxelinux.cfg/default //可以修改默认菜单 DEFAULT menu #PROMPT 0 MENU TITLE Cobbler | http://cobbler.github.com TIMEOUT 100 TOTALTIMEOUT 6000 ONTIMEOUT centos6.5-x86
执行cobbler sync,一定不要忘了。。。。。
]# cobbler sync ]# service cobblerd restart Stopping cobbler daemon: [ OK ] Starting cobbler daemon: [ OK ]
测试能否正常装机:
三、cobbler重装系统之koan
koan是cobbler的一个辅助工具,koan是kickstart-over-a-network的缩写安装在客户端的使用,koan配合cobbler实现快速重装linux。
]# yum -y install koan ]# koan --server=192.168.100.10 --list=profiles //列出cobbler中有哪些profile - looking for Cobbler at http://192.168.100.10:80/cobbler_api centos6.5-x86 ]# koan --replace-self --server=192.168.100.10 --profile=centos6.5-x86 //重装系统 - looking for Cobbler at http://192.168.100.10:80/cobbler_api - reading URL: ........ ‘--title=kick1463906560‘] - reboot to apply changes ]# reboot //输入此命令重启后,不能再中止重装,重启后自动进入pxe装机。
和--title=kick1463906560一样
以上是关于PXE和Cobble实现自动装机的主要内容,如果未能解决你的问题,请参考以下文章
部署PXE高效批量网络装机并实现Kickstart无人值守自动安装