一、配置虚拟机自动安装
1、根据yum源配置博客:http://13132323.blog.51cto.com/13122323/1951991
首先安装自动应答脚本制作工具yum install system-config-kickstart –y,然后关闭主机的防火墙,因为他会对http服务造成影响,会阻止虚拟机访问主机站点目录。
2、使用自动应答脚本制作工作开始制作脚本,将生成的脚本放到主机默认http服务的站点目录/var/www/html/下。
执行命令system-config-kickstart进入脚本制作工具(有上角有file可以保存到站点目录)
其他选项均选默认选项
我们还需修改ks.cfg脚本让他自动安装base软件包和vim,在文件结尾加入以下的命:%packages #packages需要有s
Vim-enhanced
@base #以@开头,表示他是一组软甲包
%end #每一组以%end结尾
我们可以执行命令ksvalidator命令检查ks.cfg的语发。没有语法错误我们就可以执行下面的操作:
在完成后点击右上角的file下面的保存,将其保存到站点目录,我们可以查看他的站点目录下的文件。然后写出虚拟机自动安装脚本。vim /etc/script/create.sh
/!bin/sh
virt-install \
--name $* \
--vcpus 1 \
--ram 1024 \
--file /var/lib/libvirt/p_w_picpaths/$*.qcow2\
--file-size 8 \
--location http://172.25.254.31/rhel7.0 \
--extra-args “ks=http://172.25.254.31/ks.cfg”
执行脚本,这就是简单的虚拟机一键安装功能
二、系统安装
1、怎样查看系统在安装过程中需要哪些文件?
我们可以virt-manager,双击你虚拟机的名字,将虚拟将启动改为从网卡启动,这是我们可以看到如下界面:
我们可以看到当主机的dhcp服务给他分完IP后,他到主机(172.25.254.250)tftp默认站点目录找到引导程序pxelinux.0,然后会站点目录下面的pxelinux.cfg下面找到AC19FAE文件。这时你需要安装pxelinux、tftp,dhcp服务
2、安装服务和配置安装源
yum install dhcp tftp-server syslinux –y #分别安装dhcp tftpsyslinux 这三个服务
1》 查看tftp的默认站点目录[root@foundation yum.repos.d]# rpm -ql tftp-server
/etc/xinetd.d/tftp #/etc/文加一般为配置文件
/usr/lib/systemd/system/tftp.service #一般是库文件
/usr/lib/systemd/system/tftp.socket #tftp的socket文件
/usr/sbin/in.tftpd
/usr/share/doc/tftp-server-5.2
/usr/share/doc/tftp-server-5.2/CHANGES
/usr/share/doc/tftp-server-5.2/README
/usr/share/doc/tftp-server-5.2/README.security
/usr/share/man/man8/in.tftpd.8.gz
/usr/share/man/man8/tftpd.8.gz
/var/lib/tftpboot #根据经验可以看出他为tftp的站点目录。
2》然后我们可执行rpm –ql syslinux|grep pxeliux.0可以查找到这个文件[root@foundation yum.repos.d]# rpm -ql syslinux |grep pxelinux.0
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0
#然后将pxelinux.0 复制一份到tftp的站点目录
cp /usr/share/sysliux/pxelinux.0 /var/lib/tftpboot/
3》将iso镜像中isolinux目录下的所有东西复制到tftp的站点目录,这些是安装过程中需要的安装包
cp /var/www/html/rhel7.0/isolinux/* /var/lib/tftpboot
4》创建pxelinux.cfg目录[root@foundation yum.repos.d]# rpm -ql syslinux |grep pxelinux
/usr/share/doc/syslinux-4.05/pxelinux.txt
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/gpxelinuxk.0
/usr/share/syslinux/pxelinux.0
#可以看出有一个pxelinux的阅读文件,通过他我们可以看出他会读默认的default
我们可以读less/usr/share/dos/syslinux-4.05/pxelinux.txt中可以看到他默认读的文件名为default,根据的内容为:
79 /mybootdir/pxelinux.cfg/defaultmkdir /var/lib/tftpboot/pxelinux.cfg
cp /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/defaule
#var/lib/tftpboot/isolinux.cfg 这个文件(也就是光盘文件中isolinxu目录下的isolinux.cfg)
#就是安装虚拟机的这个界面的配置文件
我们可以修改default这个的内容,来调整这个界面的背景图片,倒计时等等。optiondomain-name "westos.com" #指定客户端得到的dns
option domain-name-servers 172.25.254.
default-lease-time 600 #最短续约日期
max-lease-time 7200 #最长续约日期
27 subnet 10.152.187.0 netmask 255.255.255.0 { #将27,28行删除
28 }
subent 172.25.254.0 netmask 255.255.255.0 {
range 172.25.254.109 172.25.254.209 ;
option routers 172.25.254.250 ;#网关
#这个文件读完读下一个主机的pxelinux.0文件
next-server 172.25.254.31
filename “pxelinux.0”;
}
然后修改default中的文件 (这里是一键安装是使用ks脚本)cp /var/lib/tftpboot/pxelinux.cfg/default /var/lib/tftpboot/pxelinux.cfg/default.ori
vim /var/lib/tftpboot/pxelinux.cfg/default
#This is a system about redhat7.2.It is used by installation system
70 # append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.2\x20Server.x86_64 rd.live.check quiet
72 append initrd=initrd.img repo=http://172.25.254.31/rhel7.0 ks=http://172.25.254.31/ks.cfg quiet
在装真机时(最好不要一键安装用下面的default文件)[root@foundation pxelinux.cfg]# cat default
default vesamenu.c32
timeout 600
display boot.msg
# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title Red Hat Enterprise Linux 7.3
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13
# Border Area
menu color border * #00000000 #00000000 none
# Selected item
menu color sel 0 #ffffffff #00000000 none
# Title bar
menu color title 0 #ff7ba3d0 #00000000 none
# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none
# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none
# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none
# Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none
# Help text
menu color help 0 #ffffffff #00000000 none
# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none
# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none
# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none
# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.
menu tabmsg Press Tab for full configuration options on menu items.
menu separator # insert an empty line
menu separator # insert an empty line
label linux
menu label ^Install Red Hat Enterprise Linux 7.3
kernel vmlinuz
append initrd=initrd.img repo=http://172.25.254.7/rhel7.3 quiet
label check
menu label Test this ^media & install Red Hat Enterprise Linux 7.3
menu default
kernel vmlinuz
# append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.3\x20Server.x86_64 rd.live.check quiet
append initrd=initrd.img repo=http://172.25.254.7/rhel7.3 quiet
menu separator # insert an empty line
# utilities submenu
menu begin ^Troubleshooting
menu title Troubleshooting
label vesa
menu indent count 5
menu label Install Red Hat Enterprise Linux 7.3 in ^basic graphics mode
text help
Try this option out if you're having trouble installing
Red Hat Enterprise Linux 7.3.
endtext
kernel vmlinuz
append initrd=initrd.img repo=http://172.25.254.7/rhel7.3 xdriver=vesa nomodeset quiet
label 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.3\x20Server.x86_64 rescue quiet
label 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 memtest
menu separator # insert an empty line
label local
menu label Boot from ^local drive
localboot 0xffff
menu separator # insert an empty line
menu separator # insert an empty line
label returntomain
menu label Return to ^main menu
menu exit
menu end
配置tfpt# vi/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
}
注意:在修改配置文件的时候,一定要先备份,在修改时一定要加注释。