实验环境:

本次实验使用两台vmware虚拟机

kickstart服务器系统:RHEL7.0 64

ip地址 192.168.10.20 子网掩码 255.255.255.0

网关: 192.168.10.254 dns服务器:192.168.10.254

实现的目的是:使用kickstart服务全自动安装RHEL7.0系统

具体实现过程如下

一、SELinux和防火墙

临时关闭 SELinux

[root@localhost ~]#setenforce 0

添加TCP端口80 和UDP端口69到firewalld防火墙例外

[root@localhost ~]# firewall-cmd --zone=public --add-service=http success
[root@localhost ~]# firewall-cmd --zone=public --add-service=tftp success

二、挂载iso镜像

先新建一个挂载光盘的目录

[root@localhost ~]# mkdir -p /var/www/html/os

挂载光盘

[root@localhost ~]# mount /dev/cdrom /var/www/html/os mount: /dev/sr0 is write-protected, mounting read-only

添加以下代码,实现开机自动挂载光盘 

[root@localhost ~]# vim /etc/fstab/dev/cdrom     /var/www/html/os   iso9660   defaults 0 0

设置本地yum源,便于安装软件包

[root@localhost ~]# vim /etc/yum.repos.d/local-media.repo[Local] name=RHEL Software baseurl= gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

三、安装Web服务,并设置开机自启

[root@localhost ~]# yum -y install httpd[root@localhost ~]# systemctl enable httpdln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'[root@localhost ~]# systemctl start httpd

访问网站测试

四、安装并配置tftp服务

 安装tftp软件

[root@localhost ~]# yum -y install tftp tftp-server

 修改tftp配置文件 disable 行yes改成no

[root@localhost ~]# 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    }

重启tftp服务

[root@localhost ~]# systemctl restart xinetd[root@localhost ~]# cp /var/www/html/os/p_w_picpaths/pxeboot/vmlinuz  /var/lib/tftpboot/cp /var/www/html/os/p_w_picpaths/pxeboot/initrd.img  /var/lib/tftpboot/mkdir -p /var/lib/tftpboot/pxelinux.cfg

复制启动菜单

cp /var/www/html/os/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

修改启动菜单

default linux                此行需要修改timeout 600prompt 0                     此行需要添加display boot.msgmenu clearmenu background splash.pngmenu title Red Hat Enterprise Linux 7.0menu vshift 8menu rows 18menu margin 8menu helpmsgrow 15menu tabmsgrow 13menu color border * #00000000 #00000000 nonemenu color sel 0 #ffffffff #00000000 nonemenu color title 0 #ff7ba3d0 #00000000 nonemenu color tabmsg 0 #ff3a6496 #00000000 nonemenu color unsel 0 #84b8ffff #00000000 nonemenu color hotsel 0 #84b8ffff #00000000 nonemenu color hotkey 0 #ffffffff #00000000 nonemenu color help 0 #ffffffff #00000000 nonemenu color scrollbar 0 #ffffffff #ff355594 nonemenu color timeout 0 #ffffffff #00000000 nonemenu color timeout_msg 0 #ffffffff #00000000 nonemenu color cmdmark 0 #84b8ffff #00000000 nonemenu color cmdline 0 #ffffffff #00000000 nonemenu tabmsg Press Tab for full configuration options on menu items.menu separator # insert an empty linelabel linux  menu label ^Install Red Hat Enterprise Linux 7.0  kernel vmlinuz  append initrd=initrd.img ks=http://192.168.10.20/ks.cfg            设置ks应答文件的路径  label check  menu label Test this ^media & install Red Hat Enterprise Linux 7.0  menu default  kernel vmlinuz  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 rd.live.check quietmenu separator # insert an empty linemenu begin ^Troubleshooting  menu title Troubleshootinglabel vesa  menu indent count 5menu label Install Red Hat Enterprise Linux 7.0 in ^basic graphics mode  text help        Try this option out if you're having trouble installing        Red Hat Enterprise Linux 7.0.  endtext  kernel vmlinuz  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 xdriver=vesa nomodeset quietlabel rescue  menu indent count 5  menu label ^Rescue a Red Hat Enterprise Linux system  text help        If the system will not boot, this lets you access files        and edit config files to try to get it booting again.  endtext  kernel vmlinuz   append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 rescue quietlabel memtest  menu label Run a ^memory test  text help   If your system is having issues, a problem with your     system's memory may be the cause. Use this utility to    see if the memory is working correctly.  endtext  kernel memtestmenu separator # insert an empty linelabel local  menu label Boot from ^local drive  localboot 0xffffmenu separator # insert an empty linemenu separator # insert an empty linelabel returntomain menu label Return to ^main menu menu exit menu end

:wq! 强制保存

修改default文件的权限

[root@localhost ~]# chmod 644 /var/lib/tftpboot/pxelinux.cfg/default

安装syslinux软件包

[root@localhost ~]# yum -y install syslinux

复制引导程序到tftp的根目录

 [root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

五、安装dhcp服务并配置

[root@localhost ~]# yum install dhcp

复制配置dhcp服务配置文件

[root@localhost ~]# cat /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example >/etc/dhcp/dhcpd.conf

修改dhcp服务的配置文件

[root@localhost ~]# vim /etc/dhcp/dhcpd.confddns-update-style interim;log-facility local7;subnet 192.168.10.0 netmask 255.255.255.0 {  range 192.168.10.50 192.168.10.60;  option routers 192.168.10.254;  option domain-name "mapsic.org";  option domain-name-servers 192.168.10.254;  default-lease-time 6000;  max-lease-time 12000;  next-server 192.168.10.20;      tftp服务器地址  filename "pxelinux.0";          tftp根目录下的文件名}

使用dhcpd命令测试dhcp配置文件是否正确

[root@localhost ~]# dhcpdInternet Systems Consortium DHCP Server 4.2.5Copyright 2004-2013 Internet Systems Consortium.All rights reserved.For info, please visit https://www.isc.org/software/dhcp/Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config fileWrote 0 leases to leases file.Listening on LPF/eno16777736/00:0c:29:9f:5d:69/192.168.10.0/24Sending on   LPF/eno16777736/00:0c:29:9f:5d:69/192.168.10.0/24Sending on   Socket/fallback/fallback-netThere's already a DHCP server running.This version of ISC DHCP is based on the release availableon ftp.isc.org.  Features have been added and other changeshave been made to the base software release in order to makeit work better with this distribution.Please report for this software via the Red Hat Bugzilla site:  http://bugzilla.redhat.comexiting.

设置dhcp服务开机自启,并启动dhcp服务

[root@localhost ~]# systemctl enable dhcpdln -s '/usr/lib/systemd/system/dhcpd.service' '/etc/systemd/system/multi-user.target.wants/dhcpd.service'[root@localhost ~]# systemctl start dhcpd

六、配置kickstart服务

安装软件包

[root@localhost ~]# yum -y install system-config-kickstart

为简单操作,可以使用kickstart图形界面配置,并保存应答文件到网站根目录下

以下是ks应答文件(服务器最小化安装,防火墙允许http和ssh服务,设置root密码等)

[root@localhost ~]# vim ks.cfg #platform=x86, AMD64, or Intel EM64T#version=DEVEL# Install OS instead of upgradeinstall# Keyboard layoutskeyboard 'us'# Reboot after installationreboot# Root passwordrootpw --iscrypted $1$TG26OsQl$I7Sv8CUE2ISkVXz.5mHWT0# System timezonetimezone Asia/Shanghai# Use network installationurl --url=# System languagelang en_US# Firewall configurationfirewall --enabled --http --ssh# Network informationnetwork  --bootproto=dhcp --device=eth0# System authorization informationauth  --useshadow  --passalgo=sha512# Use text mode installtextfirstboot --disable# SELinux configurationselinux --enforcing# System bootloader configurationbootloader --location=mbr# Clear the Master Boot Recordzerombr# Partition clearing informationclearpart --all --initlabel # Disk partitioning informationpart /boot --fstype="xfs" --size=200part / --fstype="xfs" --size=20480part swap --fstype="swap" --size=2048%packages@core%end

七、从网络安装服务器系统

虚拟化开机后按F2,设置从网卡启动,启动界面如下面

文本模式安装系统

安装完成后自动重启系统

以上是使用kickstart安装RHEL7的步骤,第一次在51cto上写博客,欢迎大家指点,谢谢!