二.实验步骤
服务器配置
客户端配置
三.配置过程
服务器配置
1.最小化安装
2.配置yum源
3.安装图形化界面
4.配置IP地址
5.安装 无人值守 需要的服务:DHCP+TFTP +SYSLINUX+FTP +KICKSTART
安装DHCP
安装TFTP
安装SYSLINUX
安装FTP
安装kickstart
6. 关闭防火墙,查看服务状态
四.测试
一.实验环境
系统:rhel-server-7.0-x86_64-dvd.iso
VMware 11 下载见 http://www.linuxidc.com/Linux/2015-08/121420.htm
服务器:桥接vmnet0
客户机:桥接vmnet0
二.实验步骤
服务器配置
1. 最小化安装
2. 配置yum源
3. 安装图形化界面
4. 配置IP地址
5. 安装 无人值守 需要的服务:DHCP+TFTP+FTP+SYSLINUX+KICKSTART
6. 关闭防火墙,启动服务
客户端配置
三.配置过程
服务器配置
1. 最小化安装
2. 配置yum源
先挂载镜像光盘
#mkdir /mnt/iso #创建挂载目录
#mount /dev/sr0 /mnt/iso/ #将镜像挂载到mnt的iso目录,镜像的名字在linux里是/dev/sr0
#df –TH #查看挂载情况
现在开始配置yum源
#vim /etc/yum.repos.d/hrr.repo #新建一个.repo的文件(一定要.repo)
[dvd] #yum源的名字
name=rhel7 #yum repo的描述
baselurl=file:///mnt/iso #包路径file://(特殊写法) /mnt/iso(包所在的目录必须与repodata同级目录)
enabled=1 #1启用仓库,0反之
gpgcheck=0 #1验证(后面要写gpgcheck文件在哪),0反之
验证配置yum源结果
#yum repolist #查看yum源配置结果,可以看到status表示配置成功
3. 安装图形化界面
# yum -y groupinstall “Server with GUI” #安装图形化界面组包
进入图形化界面
4. 配置IP地址
#vim /etc/sysconfig/network-scripts/ifcfg-eno16777736 #编辑网卡配置文件
修改/添加以下配置(前缀一定要大写):
BOOTPROTO=static #static表手动配置,DHCP表自动获取
ONBOOT=yes #是否开机自动运动
IPADDR0=192.168.65.2 #IP地址
PREFIX0=24 #子网掩码
GATEWAY0=192.168.65.1 #网关
DNS1=8.8.8.8 #DNS
重启网络服务
#service network restart
查看IP配置
#nmcli connection show #查看up的网卡,name是配置文件ifcfg-后面的名字
5. 安装 无人值守 需要的服务:DHCP+TFTP +SYSLINUX+FTP +KICKSTART
安装DHCP
#yum install -y dhcp # -y表示确认,不加y会有提示
修改DHCP配置文件
# vim /etc/dhcp/dhcpd.conf
添加/修改
subnet 192.168.65.0 netmask 255.255.255.0{ #网段
range 192.168.65.5 192.168.65.9; #范围
next-server 192.168.65.2; #TFTP服务器
filename “pxelinux.0”; #镜像名字
}
启用DHCP服务
# systemctl restart dhcpd.service
查看DHCP状态
# systemctl status dhcpd.service
安装TFTP
# yum -y install tftp
# yum -y install tftp-server.x86_64
# yum -y install xinetd.x86_64 #xinetd是超守进程,因为TFTP是被超管理的进程,所以要用TFTP服务时,超守进程会唤醒TFTP
#vim /etc/xinetd.d/tftp #配置TFTP开机启动,把disable的yes改为no
启动服务查看状态
#service xinetd restart
#systemctl restart xinetd.service
#lsof –i:69 #69是tftp的服务端口,可以看到TFTP服务已启动
安装SYSLINUX
#yum –y install syslinux*
复制开机所需文件
[root@localhost /]# cd /var/lib/tftpboot/ #进入TFTP目录
[root@localhost tftpboot]# cp /usr/share/syslinux/pxelinux.0 ./ #刚刚装了sysylinux,现在将pxelinux.0镜像复制到tftpboot目录
[root@localhost tftpboot]# cp /mnt/iso/images/pxeboot/{initd.img,vmlinuxz} ./ #initd.img,内存镜像,vmlinuz是linux内核
[root@localhost tftpboot]# cp /mnt/iso/isolinux/{vesamenu.c32,*msg3} ./
[root@localhost tftpboot]#mkdir pxelinux.cfg
[root@localhost tftpboot]# cp /mnt/iso/isolinux/isolinux.cfg ./pxelinux.cfg/default #将光盘里的isolinux.cfg文件复制到tftpboot的pxelinux.cfg目录并重命名为default
查看复制结果,看到对应的6个文件,就复制成功
修改default文件
将hd:LABEL=RHEL-7.0\\x20Server.x86_64全部替换为
ftp://192.168.5.2 ks=ftp://192.168.65.2/pub/ks.cfg
一共有4个地方
更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2015-09/122765p2.htm
安装FTP
#yum –y install vsftp.x86_64
[root@localhost tftpboot]# cp -r /mnt/iso/* /var/ftp #把安装光盘的文件全部复制到ftp目录
[root@localhost tftpboot]# ll /var/ftp/ #查看复制结果
total 352
dr-xr-xr-x. 4 root root 52 Aug 4 01:26 addons
dr-xr-xr-x. 3 root root 17 Aug 4 01:26 EFI
-r–r–r–. 1 root root 8266 Aug 4 01:26 EULA
-r–r–r–. 1 root root 18092 Aug 4 01:26 GPL
dr-xr-xr-x. 3 root root 54 Aug 4 01:26 images
dr-xr-xr-x. 2 root root 4096 Aug 4 01:26 isolinux
dr-xr-xr-x. 2 root root 41 Aug 4 01:26 LiveOS
-r–r–r–. 1 root root 108 Aug 4 01:26 media.repo
dr-xr-xr-x. 2 root root 225280 Aug 4 01:30 Packages
drwxr-xr-x. 2 root root 6 Mar 7 2014 pub
dr-xr-xr-x. 24 root root 4096 Aug 4 01:30 release-notes
dr-xr-xr-x. 2 root root 4096 Aug 4 01:30 repodata
-r–r–r–. 1 root root 3375 Aug 4 01:30 RPM-GPG-KEY-RedHat-beta
-r–r–r–. 1 root root 3211 Aug 4 01:30 RPM-GPG-KEY-redhat-release
-r–r–r–. 1 root root 1568 Aug 4 01:30 TRANS.TBL
[root@localhost tftpboot]# cp ~/anaconda-ks.cfg /var/ftp/pub/ks.cfg #将本系统的安装配置文件anaconda-ks.cfg,复制到ftp的pub目录下并重命名为ks.cfg
[root@localhost tftpboot]# ll /var/ftp/pub/ks.cfg #查看ks.cfg文件属性
-rw——-. 1 root root 2589 Aug 4 01:34 /var/ftp/pub/ks.cfg
[root@localhost tftpboot]# chmod +r /var/ftp/pub/ks.cfg #添加读的属性
[root@localhost tftpboot]# ll /var/ftp/pub/ks.cfg #查看ks.cfg文件属性
-rw-r–r–. 1 root root 2589 Aug 4 01:34 /var/ftp/pub/ks.cfg
修改ks.cfg文件
下面是ks.cfg配置文件内容
#version=RHEL7
# System authorization information
auth –useshadow –enablemd5
# Install OS instead of upgrade
install
# Reboot after installation
reboot
# Use CDROM installation media
url –url=ftp://192.168.65.2
# Firewall configuration
firewall –enabled
firstboot –disable
ignoredisk –only-use=sda
# Keyboard layouts
# old format: keyboard us
# new format:
keyboard –vckeymap=us –xlayouts=’us’
# System language
lang en_US.UTF-8
# Network information
network –bootproto=dhcp
network –hostname=localhost.localdomain
# Root password
rootpw –iscrypted $1$dq/RUYXu$KTztpGgYyUmDur05zgWZt1
# System services
services –enabled=”chronyd”
# System timezone
timezone America/Los_Angeles –isUtc
user –name=ream –password=$6$d5.YwnmIoKU5KqgX$h1jmKofHk28yYz0LyD.HiOgOnK7F0.arKFn6mcwMofrNtCAeGWSq5pzcgyUbFBETA3EC.QVGZKMAbjpuMrjbE1 –iscrypted –gecos=”ream”
# X Window System configuration information
xconfig –startxonboot
# System bootloader configuration
bootloader –location=mbr –boot-drive=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart –all –initlabel
# Disk partitioning information
part swap –fstype=”swap” –size=2048
part /boot –fstype=”xfs” –size=300
part / –fstype=”xfs” –size=18131
%post
/usr/sbin/adduser ream
/usr/sbin/usermod -p ‘$1$dq/RUYXu$KTztpGgYyUmDur05zgWZt1’ ream
/usr/bin/chfn -f “ream” ream
mv /etc/rc.d/rc.local /etc/rc.d/rc.local.00
echo ‘#!/bin/bash’ > /etc/rc.d/rc.local
ln -s ../rc.local /etc/rc.d/rc5.d/S99rclocal
chmod 755 /etc/rc.d/rc.local
echo ‘mkdir -p /var/log/vmware’ >> /etc/rc.d/rc.local
echo ‘exec 1> /var/log/vmware/rc.local.log’ >> /etc/rc.d/rc.local
echo ‘exec 2>&1’ >> /etc/rc.d/rc.local
echo ‘set -x’ >> /etc/rc.d/rc.local
echo ‘echo Installing VMware Tools’ >> /etc/rc.d/rc.local
echo ‘set -x’ >> /etc/rc.d/rc.local
echo ‘/bin/eject sr0 || /bin/true’ >> /etc/rc.d/rc.local
echo ‘/bin/eject sr1 || /bin/true’ >> /etc/rc.d/rc.local
echo ‘/bin/vmware-rpctool’ \’guest.upgrader_send_cmd_line_args –default\’ >> /etc/rc.d/rc.local
echo ‘/bin/vmware-rpctool’ \’upgrader.setGuestFileRoot /tmp\’ >> /etc/rc.d/rc.local
echo ‘/bin/vmware-rpctool’ \’toolinstall.installerActive 1\’ >> /etc/rc.d/rc.local
echo ‘/bin/vmware-rpctool’ \’toolinstall.installerActive 100\’ >> /etc/rc.d/rc.local
echo ‘rm -f /etc/rc.d/rc.local’ >> /etc/rc.d/rc.local
echo ‘rm -f /etc/rc.d/rc5.d/S99rclocal’ >> /etc/rc.d/rc.local
echo ‘mv /etc/rc.d/rc.local.00 /etc/rc.d/rc.local’ >> /etc/rc.d/rc.local
/bin/echo done
%end
%packages
@base
@core
@guest-desktop-agents
binutils
chrony
ftp
gcc
kernel-devel
make
open-vm-tools
patch
python
%end
启用FTP服务
# systemctl restart vsftp.service
查看DHCP状态
# systemctl status vsftpd.service
以上配置配置完就可以进行无人值守安装,不过配置是和服务器装机时的配置一样的,下面安装kickstart可以自定义安装一个不一样的系统
安装kickstart
[root@localhost tftpboot]# yum -y install *kickstart*
[root@localhost ~]# system-config-kickstart #自定义配置kickstart
与ks文件的对比
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard ‘us’
#键盘输入
# Reboot after installation
Reboot
#安装完自动重启
# Root password
rootpw –iscrypted $1$vVvwaH.E$laQ2SHKj2ej6/1C.YzU7Q.
#root密码
# System timezone
timezone Africa/Abidjan
#时间
# Use network installation
url –url=ftp://192.168.65.2/
#FTP网络路径
# System language
lang en_US
#使用的语言
# Firewall configuration
firewall –disabled
#关闭防火墙
# Network information
network –bootproto=dhcp –device=eth0
#新建网卡
# System authorization information
auth –useshadow –passalgo=md5
#用户加密方式
# Use graphical install
Graphical
#图形界面
# Run the Setup Agent on first boot
firstboot –enable
#图形界面开机启动
# SELinux configuration
selinux –disabled
#关闭selinux
# System bootloader configuration
bootloader –location=mbr
#安装引导项
# Clear the Master Boot Record
Zerombr
#这个还不知道
# Partition clearing information
clearpart –all
#这个还不知道,但一定要有
# Disk partitioning information
part swap –fstype=”swap” –size=2048
#配置swp分区
part /boot –fstype=”xfs” –size=300
#配置boot分区
part / –fstype=”xfs” –size=18131
#配置根/分区
%pre
–password=$6$d5.YwnmIoKU5KqgX$h1jmKofHk28yYz0LyD.HiOgOnK7F0.arKFn6mcwMofrNtCAeGWSq5pzcgyUbFBETA3EC.QVGZKMAbjpuMrjbE1 –iscrypted –gecos=”ream”
#新建用户ream并设置密码
%end
%post
/usr/sbin/adduser ream
/usr/sbin/usermod -p ‘$1$dq/RUYXu$KTztpGgYyUmDur05zgWZt1’ ream
/usr/bin/chfn -f “ream” ream
mv /etc/rc.d/rc.local /etc/rc.d/rc.local.00
echo ‘#!/bin/bash’ > /etc/rc.d/rc.local
ln -s ../rc.local /etc/rc.d/rc5.d/S99rclocal
chmod 755 /etc/rc.d/rc.local
echo ‘mkdir -p /var/log/vmware’ >> /etc/rc.d/rc.local
echo ‘exec 1> /var/log/vmware/rc.local.log’ >> /etc/rc.d/rc.local
echo ‘exec 2>&1’ >> /etc/rc.d/rc.local
echo ‘set -x’ >> /etc/rc.d/rc.local
echo ‘echo Installing VMware Tools’ >> /etc/rc.d/rc.local
echo ‘set -x’ >> /etc/rc.d/rc.local
echo ‘/bin/eject sr0 || /bin/true’ >> /etc/rc.d/rc.local
echo ‘/bin/eject sr1 || /bin/true’ >> /etc/rc.d/rc.local
echo ‘/bin/vmware-rpctool’ \’guest.upgrader_send_cmd_line_args –default\’ >> /etc/rc.d/rc.local
echo ‘/bin/vmware-rpctool’ \’upgrader.setGuestFileRoot /tmp\’ >> /etc/rc.d/rc.local
echo ‘/bin/vmware-rpctool’ \’toolinstall.installerActive 1\’ >> /etc/rc.d/rc.local
echo ‘/bin/vmware-rpctool’ \’toolinstall.installerActive 100\’ >> /etc/rc.d/rc.local
echo ‘rm -f /etc/rc.d/rc.local’ >> /etc/rc.d/rc.local
echo ‘rm -f /etc/rc.d/rc5.d/S99rclocal’ >> /etc/rc.d/rc.local
echo ‘mv /etc/rc.d/rc.local.00 /etc/rc.d/rc.local’ >> /etc/rc.d/rc.local
/bin/echo done
%end
%packages
@base
@core
@guest-desktop-agents
binutils
chrony
ftp
gcc
kernel-devel
make
open-vm-tools
patch
python
%end
#上面这些配置%post 到 %end 可以到~/ anaconda-ks.cfg那里看
配置好后保存到/var/ftp/pub/ks.cfg
测试一下:
事实证明,上面的kickstart自定义配置是没错的,可以成功的无人值守安装,而且比复制~/ anaconda-ks.cfg文件安装的要快很多,不知道为什么
为了更好的了解配置,查看/var/ftp/pub/ks.cfg(刚刚用kickstart图形界面配置)的配置文件如下:
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard ‘us’# Reboot after installation
reboot
# Root password
rootpw –iscrypted $1$vVvwaH.E$laQ2SHKj2ej6/1C.YzU7Q.
# System timezone
timezone Africa/Abidjan
# Use network installation
url –url=”ftp://192.168.65.2/”
# System language
lang en_US
# Firewall configuration
firewall –disabled
# Network information
network –bootproto=dhcp –device=eth0
# System authorization information
auth –useshadow –passalgo=md5
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot –enable
# SELinux configuration
selinux –disabled
# System bootloader configuration
bootloader –location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart –all
# Disk partitioning information
part swap –fstype=”swap” –size=2048
part /boot –fstype=”xfs” –size=300
part / –fstype=”xfs” –size=18131
%pre
–password=$6$d5.YwnmIoKU5KqgX$h1jmKofHk28yYz0LyD.HiOgOnK7F0.arKFn6mcwMofrNtCAeGWSq5pzcgyUbFBETA3EC.QVGZKMAbjpuMrjbE1 –iscrypted –gecos=”ream”
%end
%post
/usr/sbin/adduser ream
/usr/sbin/usermod -p ‘$1$dq/RUYXu$KTztpGgYyUmDur05zgWZt1’ ream
/usr/bin/chfn -f “ream” ream
mv /etc/rc.d/rc.local /etc/rc.d/rc.local.00
echo ‘#!/bin/bash’ > /etc/rc.d/rc.local
ln -s ../rc.local /etc/rc.d/rc5.d/S99rclocal
chmod 755 /etc/rc.d/rc.local
echo ‘mkdir -p /var/log/vmware’ >> /etc/rc.d/rc.local
echo ‘exec 1> /var/log/vmware/rc.local.log’ >> /etc/rc.d/rc.local
echo ‘exec 2>&1’ >> /etc/rc.d/rc.local
echo ‘set -x’ >> /etc/rc.d/rc.local
echo ‘echo Installing VMware Tools’ >> /etc/rc.d/rc.local
echo ‘set -x’ >> /etc/rc.d/rc.local
echo ‘/bin/eject sr0 || /bin/true’ >> /etc/rc.d/rc.local
echo ‘/bin/eject sr1 || /bin/true’ >> /etc/rc.d/rc.local
echo ‘/bin/vmware-rpctool’ \’guest.upgrader_send_cmd_line_args –default\’ >> /etc/rc.d/rc.local
echo ‘/bin/vmware-rpctool’ \’upgrader.setGuestFileRoot /tmp\’ >> /etc/rc.d/rc.local
echo ‘/bin/vmware-rpctool’ \’toolinstall.installerActive 1\’ >> /etc/rc.d/rc.local
echo ‘/bin/vmware-rpctool’ \’toolinstall.installerActive 100\’ >> /etc/rc.d/rc.local
echo ‘rm -f /etc/rc.d/rc.local’ >> /etc/rc.d/rc.local
echo ‘rm -f /etc/rc.d/rc5.d/S99rclocal’ >> /etc/rc.d/rc.local
echo ‘mv /etc/rc.d/rc.local.00 /etc/rc.d/rc.local’ >> /etc/rc.d/rc.local
/bin/echo done
%end
%packages
@base
@core
@guest-desktop-agents
binutils
chrony
ftp
gcc
kernel-devel
make
open-vm-tools
patch
python
%end
6. 关闭防火墙,查看服务状态
[root@localhost ~]# systemctl stop firewall
[root@localhost ~]# systemctl status firewall
firewall.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
[root@localhost ~]#
查看DHCP状态
查看xinetd状态
查看tftp端口
查看ftp状态
四.测试
上面是服务器DHCP服务状态,可以看到dhcpack on 192.168.65.6 ,被MAC00:0C:29:23:FD:8F的客户机获取到了
如下客户机的MAC地址
00:0C:29:23:FD:8F
安装完成,自动进入登陆界面
更多RedHat相关信息见RedHat 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=10
本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-09/122765.htm