码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-05-22 00:52:13      阅读:1578      评论:0      收藏:0      [点我收藏+]

标签:pxe   dns   dhcp   

总体规划:

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

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

安装 配置vsftp服务器做yum源


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

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

技术分享

技术分享

网络选用nat模式 关闭dhcp

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


设置网络[root@server ~]# 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[root@server ~]# service network restart   #重启网卡[root@server ~]# ping -c2 172.16.8.1 [root@server ~]# ping -c2 www.baidu.com确认可以通外网然后开启内核路由转发[root@server ~]# vim /etc/sysctl.conf  net.ipv4.ip_forward = 1 [root@server ~]# 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了zhou@zhou:~> ssh root@172.16.8.88 安装ftp服务[root@server ~]# yum install vsftpd -y[root@server ~]# service vsftpd start              #启动服务 Starting vsftpd for vsftpd:                                [  OK  ][root@server ~]# chkconfig vsftpd on            #设置开机自启动[root@server ~]# mkdir /var/ftp/centos6.6[root@server ~]# mount /dev/cdrom /var/ftp/centos6.6/mount: block device /dev/sr0 is write-protected, mounting read-only[root@server ~]# rm -rf * /etc/yum.repos.d/*[root@server ~]# vim /etc/yum.repos.d/centos6.6.repo[centos-3glong]name=3glong.combaseurl=ftp://172.16.8.88/centos6.6enabled=1gpgcheck=0[root@server ~]# 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的原因---关掉[root@server ~]# setenforce 0[root@server ~]# 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[root@server ~]# sed -i ‘/SELINUX/s/enforcing/disabled/‘ /etc/selinux/config[root@server ~]# iptables -F[root@server ~]# service iptables saveiptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ][root@server ~]# service iptables stopiptables: Setting chains to policy ACCEPT: filter          [  OK  ]iptables: Flushing firewall rules:                         [  OK  ]iptables: Unloading modules:                               [  OK  ][root@server ~]# chkconfig iptables off[root@server ~]# reboot                   #重启后selinx的关闭才生效

配置dhcp



发现个问题重启后光盘没自动挂上[root@server ~]# echo "/dev/cdrom /var/ftp/centos6.6 auto defaults 0 0" >> /etc/fstab [root@server ~]# mount -amount: block device /dev/sr0 is write-protected, mounting read-only安装dhcp[root@server ~]# yum install dhcp -y   [root@server ~]# 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"; }---------------------------[root@server ~]# service dhcpd startStarting dhcpd:                                            [  OK  ][root@server ~]# chkconfig dhcpd on配置TFTP[root@server ~]# yum -y install tftp-server[root@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        per_source              = 11        cps                     = 100 2        flags                   = IPv4}[root@server ~]# service xinetd restart[root@server ~]# chkconfig xinetd on [root@server ~]# cp /var/ftp/centos6.6/isolinux/initrd.img /var/ftp/centos6.6/isolinux/vmlinuz /var/lib/tftpboot/[root@server ~]# yum -y install syslinux[root@server ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/[root@server ~]# mkdir /var/lib/tftpboot/pxelinux.cfg[root@server ~]# cp /var/ftp/centos6.6/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default 配置DNS服务[root@server ~]# yum -y install bind bind-chroot[root@server ~]# service named start[root@server ~]# 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;[root@server ~]# 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";        };[root@server ~]# vim /var/named/chroot/var/named/3glong.com.zone$TTL 1D@       IN SOA  3glong.com. admin.3glong.com. (                                        0       ; serial                                        1D      ; refresh                                        1H      ; retry                                        1W      ; expire                                        3H )    ; minimum@       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.$~                                            [root@server ~]# vim /var/named/chroot/var/named/172.16.8.arpa $TTL 3H@       IN SOA  3glong.com. admin.3glong.com. (                                        0       ; serial                                        1D      ; refresh                                        1H      ; retry                                        1W      ; expire                                        3H )    ; minimum@       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文件


[root@server ~]# 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 %packages@additional-devel@base@compat-libraries@console-internet@desktop-platform-devel@development@java-platform@mainframe-access@network-tools@perl-runtime@ruby-runtime@scalable-file-systems@server-platform@server-platform-devel@system-management-snmp@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
[root@server 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

标签:pxe   dns   dhcp   

原文地址:http://3glong.blog.51cto.com/11271871/1775725

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!