远程安装虚拟机

###########################

###### 一、通过脚本安装 ######

###########################

安装前提:

1.安装有http,防火墙关闭

2.需要system-config-kickstart 软件进行设置安装的一些条件,最后生成ks.cfg文件,将它复制在/var/www/html/ 目录下,同时修改该文件:

在末尾加上:

%packages

@base

%end

3.所需脚本:

#!/bin/bash
virt-install \
--name $1 \
--ram 1024 \
--file /var/lib/libvirt/images/$1.qcow2 \
--file-size 8 \
--location http://172.25.254.67/rhel \
--extra-args "ks=http://172.25.254.67/ks.cfg" &

安装操作:

哪台主机需要安装虚拟机,就执行脚本


##########################

######二、通过网卡安装 ######

##########################

#################  所需软件  ##############

system-config-kickstart        ##自动应答脚本制作工具
syslinux            ##获得pxelinux.0文件安装包
dhcp                ##分配ip给客户机的服务
tftp-server 和 xinetd        ##提供tftp协议的服务
http                ##安装源共享服务


#################  操作   #################
  1 systemctl stop firewalld    ##关闭虚拟机
  2 systemctl disble firewalld
  3 vim /etc/systemconfig/network-scripts/ifcfg-eth0 ##配置网卡
  4 systemctl restart network       ##使本机能和yum源连接
  5 vim /etc/yum.repos.d/rhel.repo  ##修改yum源,让本机能安装所需要的软件
  6 yum clean all                   ##清除缓存
  7 yum install dhcp        ##安装dhcp
  8 yum install system-config-kickstart    ##安装
  9 yum whatprovides *./pxelinux.0    ##查找有这个文件的软件
 10 yum install syslinux    ##找到,安装
 11 yum install xinetd        ##安装
 12 yum install tftp-server    ##安装
 13 yum install http        ##安装
 14 systemctl start httpd    ##开启http
 15 system-config-kickstart     ##运行软件,保存在/var/www/html/
 16 vim /var/www/html/ks.cfg    ##修改配置文件
 17 ##在最后加上:
 %packages
  @base
  %end
  #####
 18 cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf    ##复制
 19 vim /etc/dhcp/dhcpd.conf    ##修改dhcp服务的配置文件
 ##配置文件如下:
 option domain-name "example.com";        ##域名
 option domain-name-servers xxx.xxx.xxx.xxx;    ##dns
 default-lease-time 600;            ##默认租约期
 max-lease-time 7200;                ##最长租约期
 ....
 log-facility local7;                ##日志级别
 ....
 subnet xxx.xxx.xxx.0 netmask 255.255.255.0 {    ##网段,子网掩码
  range xxx.xxx.xxx.xxx xxx.xxx.xxx.xxx;    ##地址范围
  option routers xxx.xxx.xxx.xxx;        ##网关
  filename "pxelinux.0";            ##pxe启动程序
  next-server xxx.xxx.xxx.xxx;            ##tftp主机地址
 }
 ##结束(该文件除了这些就只有说明,其他删除)
 20 systemctl restart dhcpd    ##重启dhcp服务
 21 vim /etc/xinetd.d/tftp    ##修改tftp服务的配置文件
 ##配置文件如下:
 service tftp
 {
        socket_type        = dgram
        protocol           = udp
        wait               = yes
        user               = root
        server             = /usr/sbin/in.tftpd
        server_args        = -s /var/lib/tftpboot
        disable            = <<<<<<<<<yes--->no>>>>>> ##yes改为no
        per_source         = 11
        cps                = 100 2
        flags              = IPv4
 }
 ##结束
 22 chkconfig --list        ##列出系统所有的服务启动情况
 ##显示:
 ....
 xinetd based services:
 ....
 tftp:    on
 ....
 ##结束
 23 systemctl resatrt xinetd    ##重启
 24 cd /var/lib/tftpboot/
 25 scp root@175.25.254.15:/var/www/html/rhel7.2/isolinux/* /var/lib/tftpboot/    ##从安有yum源主机中复制文件到指定位置
 26 cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/    ##复制文件,该文件是在安装了syslinux软件后出现的
 27 mkdir pxelinux.cfg    ##新建目录
 28 cp /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default        ##复制文件
 29 vim /var/lib/tftpboot/pxelinux.cfg/default    ##修改文件(修改内容见下)
 30 systemctl stop firewalld    ##关闭防火墙
 31 setenforce 0        ##关闭加强防火墙

vim /var/lib/tftplinux.cfg/default
config the file of /var/lib/tftpboot/pxelinux.cfg/default like this:
========================================================================================
default vesamenu.c32
timeout 60                        ##等待时间改为6s,60就是6秒

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.2            ##大标题
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.2    ##小标题
   menu default        ##默认标题设定,直接安装
  kernel vmlinuz    ##检测能否安装
  append initrd=initrd.img repo=http://172.25.254.100/soucre ks=http://172.25.254.100/ks.cfg    ##安装源和ks,如果yum源和ks.cfg安装脚本在不同的主机就是不同的ip

label check
  menu label Test this ^media & install Red Hat Enterprise Linux 7.2
  #menu default
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.2\x20Server.x86_64 rd.live.check 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.2 in ^basic graphics mode
  text help
    Try this option out if you re having trouble installing
    Red Hat Enterprise Linux 7.2.
  endtext
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.0\x20Server.x86_64 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.0\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


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值