KVM 搭建PXE+DHCP+DNS+vsftpd+tftp+KICKSTART

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了KVM 搭建PXE+DHCP+DNS+vsftpd+tftp+KICKSTART相关的知识,希望对你有一定的参考价值。

总体规划:

搭建一台实验用服务器        系统 centos6.6                     172.16.66.66/24

并配置PXE+DHCP+vsftpd+tftp+KICKSTART,实现pxe启动网络自动话安装系统,自动分配主机名与ip地址。

安装 配置vsftp服务器做yum源


--------------------------------------我是分割线---------------------------------------------------

现在开始第一步搭建服务器

技术分享

技术分享

网络选用nat模式 关闭dhcp

安装系统略。。不需要桌面所以选择basic server


设置网络[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0  DEVICE=eth0HWADDR=52:54:00:c8:5a:8bTYPE=EthernetUUID=b241c467-6618-414d-876e-1143a8baec0cONBOOT=yesNM_CONTROLLED=yesBOOTPROTO=noneIPADDR=172.16.8.88NETMASK=255.255.255.0GATEWAY=172.16.8.1IPV6INIT=noUSERCTL=noDNS1=172.16.8.1[[email protected] ~]# service network restart   #重启网卡[[email protected] ~]# ping -c2 172.16.8.1 [[email protected] ~]# ping -c2 www.baidu.com确认可以通外网然后开启内核路由转发[[email protected] ~]# vim /etc/sysctl.conf  net.ipv4.ip_forward = 1 [[email protected] ~]# sysctl -pnet.ipv4.ip_forward = 1net.ipv4.conf.default.rp_filter = 1net.ipv4.conf.default.accept_source_route = 0kernel.sysrq = 0kernel.core_uses_pid = 1net.ipv4.tcp_syncookies = 1有了ip地址就可以在opensuse下直接ssh了[email protected]:~> ssh [email protected] 安装ftp服务[[email protected] ~]# yum install vsftpd -y[[email protected] ~]# service vsftpd start              #启动服务 Starting vsftpd for vsftpd:                                [  OK  ][[email protected] ~]# chkconfig vsftpd on            #设置开机自启动[[email protected] ~]# mkdir /var/ftp/centos6.6[[email protected] ~]# mount /dev/cdrom /var/ftp/centos6.6/mount: block device /dev/sr0 is write-protected, mounting read-only[[email protected] ~]# rm -rf * /etc/yum.repos.d/*[[email protected] ~]# vim /etc/yum.repos.d/centos6.6.repo[centos-3glong]name=3glong.combaseurl=ftp://172.16.8.88/centos6.6enabled=1gpgcheck=0[[email protected] ~]# yum makecache已加载插件:fastestmirror, securityDetermining fastest mirrorsftp://172.16.8.88/centos6.6/repodata/repomd.xml: [Errno 14] PYCURL ERROR 9 - "Server denied you to change to the given directory"尝试其他镜像。错误:Cannot retrieve repository metadata (repomd.xml) for repository: centos-3glong. Please verify its path and try again---------------好吧这个错误是因为selinux的原因---关掉[[email protected] ~]# setenforce 0[[email protected] ~]# yum makecache已加载插件:fastestmirror, securityLoading mirror speeds from cached hostfilecentos-3glong                                          | 4.0 kB     00:00     centos-3glong/group_gz                                 | 216 kB     00:00     centos-3glong/filelists_db                             | 6.0 MB     00:00     centos-3glong/primary_db                               | 4.5 MB     00:00     centos-3glong/other_db                                 | 2.8 MB     00:00     元数据缓存已建立彻底关掉selinux[[email protected] ~]# sed -i ‘/SELINUX/s/enforcing/disabled/‘ /etc/selinux/config[[email protected] ~]# iptables -F[[email protected] ~]# service iptables saveiptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ][[email protected] ~]# service iptables stopiptables: Setting chains to policy ACCEPT: filter          [  OK  ]iptables: Flushing firewall rules:                         [  OK  ]iptables: Unloading modules:                               [  OK  ][[email protected] ~]# chkconfig iptables off[[email protected] ~]# reboot                   #重启后selinx的关闭才生效

配置dhcp



发现个问题重启后光盘没自动挂上[[email protected] ~]# echo "/dev/cdrom /var/ftp/centos6.6 auto defaults 0 0" >> /etc/fstab [[email protected] ~]# mount -amount: block device /dev/sr0 is write-protected, mounting read-only安装dhcp[[email protected] ~]# yum install dhcp -y   [[email protected] ~]# vim /etc/dhcp/dhcpd.conf #   see /usr/share/doc/dhcp*/dhcpd.conf.sample#   see ‘man 5 dhcpd.conf‘# subnet 172.16.8.0 netmask 255.255.255.0 {   range dynamic-bootp 172.16.8.90 172.16.8.250;   option domain-name-servers 172.16.8.88;   option domain-name "ns.3glong.com";   option routers 172.16.8.88;   default-lease-time 21600;   max-lease-time 47200;   next-server 172.16.8.88;   filename "pxelinux.0"; }---------------------------[[email protected] ~]# service dhcpd startStarting dhcpd:                                            [  OK  ][[email protected] ~]# chkconfig dhcpd on配置TFTP[[email protected] ~]# yum -y install tftp-server[[email protected] ~]# 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        per_source              = 11        cps                     = 100 2        flags                   = IPv4}[[email protected] ~]# service xinetd restart[[email protected] ~]# chkconfig xinetd on [[email protected] ~]# cp /var/ftp/centos6.6/isolinux/initrd.img /var/ftp/centos6.6/isolinux/vmlinuz /var/lib/tftpboot/[[email protected] ~]# yum -y install syslinux[[email protected] ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/[[email protected] ~]# mkdir /var/lib/tftpboot/pxelinux.cfg[[email protected] ~]# cp /var/ftp/centos6.6/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default 配置DNS服务[[email protected] ~]# yum -y install bind bind-chroot[[email protected] ~]# service named start[[email protected] ~]# vim /var/named/chroot/etc/named.conf options {        listen-on port 53 { 172.16.8.88; };               #修改ip        listen-on-v6 port 53 { ::1; };        directory       "/var/named";        dump-file       "/var/named/data/cache_dump.db";        statistics-file "/var/named/data/named_stats.txt";        memstatistics-file "/var/named/data/named_mem_stats.txt";        allow-query     { any; };                                 #修改为any        recursion yes;         dnssec-enable yes;        dnssec-validation yes;        dnssec-lookaside auto;[[email protected] ~]# vim /var/named/chroot/etc/named.rfc1912.zones  zone "3glong.com.zone" IN {        type master;        file "3glong.com.zone";        };zone "8.16.172.in-addr.arpa" IN {        type master;        file "172.16.8.arpa";        };[[email protected] ~]# vim /var/named/chroot/var/named/3glong.com.zone$TTL [email protected]       IN SOA  3glong.com. admin.3glong.com. (                                        0       ; serial                                        1D      ; refresh                                        1H      ; retry                                        1W      ; expire                                        3H )    ; [email protected]       NS      ns.3glong.com.ns      IN A    172.16.8.88        IN MX 10        mail.3glong.com.mail    IN A    172.16.8.88$GENERATE 90-250 node$ IN A 172.16.8.$~                                            [[email protected] ~]# vim /var/named/chroot/var/named/172.16.8.arpa $TTL [email protected]       IN SOA  3glong.com. admin.3glong.com. (                                        0       ; serial                                        1D      ; refresh                                        1H      ; retry                                        1W      ; expire                                        3H )    ; [email protected]       NS      ns.3glong.com.ns      A       192.168.8.8888      PTR     mamil.3glong.com.$GENERATE 90-250 $ IN PTR node$.3glong.com.~

新建一台虚拟机安装桌面安装system-config-kickstart


图形化生成ks文件


[[email protected] ~]# cat centos6.6ks.cfg #platform=x86, AMD64, 或 Intel EM64T#version=DEVEL# Firewall configurationfirewall --disabled# Install OS instead of upgradeinstall# Use network installationurl --url="ftp://172.16.8.88/centos6.6"# Root passwordrootpw --iscrypted $1$RQizvUm1$fchWuiIAp.tKyTkC3xzmH.# System authorization informationauth  --useshadow  --passalgo=sha512# Use text mode installtextfirstboot --disable# System keyboardkeyboard us# System languagelang en_US# SELinux configurationselinux --disabled# Installation logging levellogging --level=info # System timezonetimezone  Asia/Shanghai# Network informationnetwork  --bootproto=dhcp --device=eth0 --onboot=on# System bootloader configurationbootloader --location=mbr# Clear the Master Boot Recordzerombr# Partition clearing informationclearpart --all  # Disk partitioning informationpart /boot --fstype="ext4" --size=200part swap --fstype="swap" --size=4000part / --fstype="ext4" --grow --size=1 %[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@x11ElectricFencePyQt4-develSDL-develantbabelbzrchrpathcmakecompat-gcc-34compat-gcc-34-c++compat-gcc-34-g77cups-develcvs-inetddejagnue2fsprogs-develexpat-develexpectfetchmailfreeglut-develftpfuse-develgcc-gnatgcc-javagcc-objcgcc-objc++gmp-develgnome-python2-desktopgnutls-develgstreamer-plugins-base-develhttpd-develhunspell-develimakeiptables-develirssijava-1.8.0-openjdkjava-1.8.0-openjdk-develjpackage-utilsjunitjwhoiskdebase-develkdebase-workspace-develkdegraphics-develkdelibs-apidocskdelibs-develkdemultimedia-develkdenetwork-develkdepim-develkdepimlibs-develkdesdk-develkdewebdevksclftplibXau-devellibXaw-devellibXinerama-devellibXmu-devellibXpm-devellibXrandr-devellibaio-devellibblkid-devellibbonobo-devellibcap-devellibdrm-devellibgcrypt-devellibglade2-devellibgnomeui-devellibgudev1-devellibhugetlbfs-devellibibverbs-devellibnl-devellibnl3-devellibstdc++-docslibtiff-devellibtopology-devellibudev-devellibusb-devellibuuid-devellibxslt-develmercurialmod_dav_svnmpfr-develmuttnasmnet-snmp-develnmapnumactl-developenmotif-develpapi-develpcre-develperl-Test-Podperl-Test-Pod-Coverageperltidypopt-develpython-docsrpmdevtoolsrpmlintsane-backends-develsnappy-develstartup-notification-develsystemtap-sdt-develsystemtap-servertcl-develtcp_wrappers-develtk-develunique-develunixODBC-develwiresharkxorg-x11-proto-develxz-devel %end
[[email protected] isolinux]# cp vesamenu.c32 splash.jpg /var/lib/tftpboot/	
vim /var/lib/tftpboot/pxelinux.cfg/default         #加入安装列表
label linux  menu label ^Install zhou-centos6.6  menu default  kernel vmlinuz  append ks=ftp://172.16.8.88/centos6.6ks.cfg initrd=initrd.img

新建虚拟机试试选网络引导


技术分享

提示网络不支持什么的直接无视,因为我们已经配置支持了

技术分享

技术分享

技术分享

全自动安装无需人工操作

安装完成后主机名与ip对应

技术分享


本文出自 “幽龙博客” 博客,请务必保留此出处http://3glong.blog.51cto.com/11271871/1775725

以上是关于KVM 搭建PXE+DHCP+DNS+vsftpd+tftp+KICKSTART的主要内容,如果未能解决你的问题,请参考以下文章

dnsmasq部署pxe服务器脚本

(-)PXE技术篇--DHCP服务器的搭建

linux dhcp搭建及pxe无人值守装机

PXE

搭建PXE远程安装服务器

一键搭建PXE自动装机