rhel6.4网络安装kvm虚拟机

ゝ一世哀愁。 2022-08-05 20:59 281阅读 0赞

本次试验环境如图1所示

Center

一:安装前提条件:

1.确保主板支持intel-VT或AMD-V

2.VMware里的rhel 6.4已经装好,并且已设置该虚拟机也支持虚拟化,设置如下所示

Center 1

3.通过命令确认是否支持intel-VT或AMD-V

[root@localhost ~]# egrep —color “vmx|svm” /proc/cpuinfo

有结果返回就说明支持,反之亦然

二:安装KVM并配置网卡桥接(桥接到eth1上),在已安装的rhel 6.4 (图 1所示)上操作

1.安装KVM

[root@localhost ~]#yum -y groupinstall Virtualization “Virtualization Client” “Virtualization Platform” “Virtualization Tools”

[root@localhost ~]# /etc/init.d/libvirtd start ; chkconfig libvirtd on

[root@localhost ~]#/etc/init.d/libvirt-guests start ; chkconfig libvirt-guests on

2.网桥设置

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1

HWADDR=00:0C:29:3F:5A:2e

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=static

IPADDR=172.16.1.1

NETMASK=255.255.255.0

BRIDGE=br0 //添加这一行

[root@localhost network-scripts]# pwd

/etc/sysconfig/network-scripts

[root@localhost network-scripts]# cp ifcfg-eth1 ifcfg-br0

[root@localhost network-scripts]# cat ifcfg-br0

DEVICE=br0 //设备名为br0

TYPE=Bridge //设别类型为Bridge

ONBOOT=yes

NM_CONTROLLED=no

BOOTPROTO=static

IPADDR=172.16.1.1

NETMASK=255.255.255.0

重启网络

[root@localhost network-scripts]#/etc/init.d/network restart

查看网桥信息

[root@localhost network-scripts]# brctl show

bridge name bridge id STP enabled interfaces

br0 8000.000c293f5a2e no eth1 //已桥接到eth1上

virbr0 8000.525400635d23 yes virbr0-nic

三:配置dhcp+tftp+vsftpd网络安装服务器

◆.安装dhcp

1.[root@localhost ~]# yum -y install dhcp

2.配置dhcp

[root@localhost ~]# grep -v “^#“/etc/dhcp/dhcpd.conf |grep ^[^$]

default-lease-time 600;

max-lease-time 7200;

next-server 172.16.1.1;

filename “pxelinux.0”;

ddns-update-style none;

log-facility local7;

subnet 172.16.1.0 netmask 255.255.255.0 {

range 172.16.1.2 172.16.1.10;

}

[root@localhost ~]#

3.启动dhcp服务

[root@localhost ~]# /etc/init.d/dhcpd start;chkconfig dhcpd on

Starting dhcpd: [ OK ]

[root@localhost ~]#

◆.安装tftp-server和syslinux

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

2.配置tftp

[root@localhost ~]# grep -v “^#“/etc/xinetd.d/tftp

service tftp

{

  1. socket\_type = dgram
  2. protocol = udp
  3. wait = yes
  4. user = root
  5. server =/usr/sbin/in.tftpd
  6. server\_args = -s/var/lib/tftpboot
  7. disable = no //把yes改为no
  8. per\_source = 11
  9. cps = 100 2
  10. flags = IPv4

}

[root@localhost tftpboot]# pwd

/var/lib/tftpboot

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

[root@localhost tftpboot]# mkdir pxelinux.cfg

[root@localhost tftpboot]# cp /media/rhel/isolinux/* ./ ///media/rhel为光盘挂载目录

[root@localhost tftpboot]# cp isolinux.cfg pxelinux.cfg/default

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

[root@localhost tftpboot]# vi pxelinux.cfg/default (其中红色为更改处)

default linux

#prompt 1

timeout 600

display boot.msg

menu background splash.jpg

menu title Welcome to Red Hat EnterpriseLinux 6.4!

menu color border 0 #ffffffff #00000000

menu color sel 7 #ffffffff #ff000000

menu color title 0 #ffffffff #00000000

menu color tabmsg 0 #ffffffff #00000000

menu color unsel 0 #ffffffff #00000000

menu color hotsel 0 #ff000000 #ffffffff

menu color hotkey 7 #ffffffff #ff000000

menu color scrollbar 0 #ffffffff #00000000

label linux

menu label ^Install or upgrade an existing system

menu default

kernel vmlinuz

append initrd=initrd.img ksdevice=eth0 ks=ftp://172.16.1.1/rhel6.4.cfg

label vesa

menu label Install system with ^basic video driver

kernel vmlinuz

append initrd=initrd.img xdriver=vesa nomodeset

label rescue

menu label ^Rescue installed system

kernel vmlinuz

append initrd=initrd.img rescue

label local

menu label Boot from ^local drive

localboot 0xffff

label memtest86

menu label ^Memory test

kernel memtest

append -

[root@localhost tftpboot]#

3.启动xinentd服务

[root@localhost ~]# /etc/init.d/xinetd start ; chkconfig xinetd on

Starting xinetd: [ OK ]

[root@localhost ~]#

◆安装vsftpd

  1. [root@localhost ~]# yum -y install vsftpd

2.启动vsftpd服务

[root@localhost ~]# /etc/init.d/vsftpd start ; chkconfig vsftpd on

Starting vsftpd for vsftpd: [ OK ]

[root@localhost ~]#

3.挂载安装光盘到ftp目录下

[root@localhost ~]# mount /dev/cdrom/ var/ftp/pub/

◆配置ks文件

1.ks文件内容如下

[root@localhost ~]# cat rhel6.4.cfg

#platform=x86, AMD64, or Intel EM64T

#version=DEVEL

# Firewall configuration

firewall —disabled

# Install OS instead of upgrade

install

# Use network installation

url —url=”ftp://172.16.1.1/pub”

# Root password

rootpw —iscrypted$1$p4HkNd7X$xOiflpAb0Rsi6Ec2R1F9l1

# System authorization information

auth —useshadow —passalgo=sha512

# Use text mode install

text

# System keyboard

keyboard us

# System language

lang en_US

# SELinux configuration

selinux —disabled

# Do not configure the X Window System

skipx

# Installation logging level

logging —level=info

# Reboot after installation

reboot

# System timezone

timezone Asia/Shanghai

# Network information

network —bootproto=dhcp —device=eth0 —onboot=on

# System bootloader configuration

bootloader —location=mbr

# Clear the Master Boot Record

zerombr

# Partition clearing information

clearpart —all —initlabel

# Disk partitioning information

part / —fstype=”ext4”—ondisk=vda —size=4000

part swap —fstype=”swap” —grow—ondisk=vda —size=1

%packages

@base

gcc

gcc-c++

libstdc++-devel

make

openssh-clients

acpid

%end

%post

echo”ttyS0”>>/etc/securetty

sed -i ‘/quiet/a\ console=ttyS0’ /boot/grub/grub.conf

sed -i ‘/quiet/N; s/\n/ /‘ /boot/grub/grub.conf

cat >>/etc/yum.repos.d/network.repo<<EOF

[Server]

name=Red Hat Enterprise Linux 6.4

baseurl=ftp://172.16.1.1/pub/Server

enabled=1

gpgcheck=0

[HighAvailability]

name=Red Hat Enterprise Linux 6.4

baseurl=ftp://172.16.1.1/pub/HighAvailability

enabled=1

gpgcheck=0

[LoadBalancer]

name=Red Hat Enterprise Linux 6.4

baseurl=ftp://172.16.1.1/pub/LoadBalancer

enabled=1

gpgcheck=0

[ResilientStorage]

name=Red Hat Enterprise Linux 6.4

baseurl=ftp://172.16.1.1/pub/ResilientStorage

enabled=1

gpgcheck=0

[ScalableFileSystem]

name=Red Hat Enterprise Linux 6.4

baseurl=ftp://172.16.1.1/pub/ScalableFileSystem

enabled=1

gpgcheck=0

EOF

[root@localhost ~]#

注:ks文件制作这里不做演示,我已提前做好

2.复制rhel6.4.cfg到/var/ftp/目录下

[root@localhost ~]# cp rhel6.4.cfg /var/ftp/

四:开始安装虚拟机,virt-manager图形界面安装在这里不做演示,这里只演示通过ks文件安装

1.location+”extra-args”方式安装

[root@localhost ~]# virt-install \

—name rhel6.4-1 \

—ram 1024 \

—vcpus 1 \

—os-type=linux \ //可以不需要这句,只支持URL方式

—os-variant=rhel6 \ //可以不需要这句,只支持URL方式

—network bridge=br0 \

—file /var/lib/libvirt/images/rhel6.4-1.img \

—file-size 5 \

—nonsparse \

—location ftp://172.16.1.1/pub/ \

—extra-args “ks=ftp://172.16.1.1/rhel6.4.cfg”

2.通过pxe方式安装

[root@localhost~]# virt-install \

—name rhel6.4-1 \

—ram 1024 \

—vcpus 1 \

—os-type=linux \ //可以不需要这句,只支持URL方式

—os-variant=rhel6 \ //可以不需要这句,只支持URL方式

—network bridge=br0 \

—file /var/lib/libvirt/images/rhel6.4-1.img \

—file-size 5 \

—nonsparse \

—pxe

注:以上两种方法可任选一种

3.正在格式化硬盘,如下图所示

Center 2

4.正在安装,如下图所示

Center 3

5.安装完成后,可通过virshconsole “虚拟机名”来控制虚拟机

[root@localhost ~]# virsh console rhel6.4-1

6.关于控制虚拟机的一些常用命令

[root@localhost ~]# virsh list //列出正在运行或暂停的虚拟机

[root@localhost ~]# virsh list —all //列出所有的虚拟机包括已关机的

[root@localhost ~]# virsh start rhel6.4-1 //开启名为rhel6.4-1这台虚拟机

[root@localhost ~]# virsh shutdown rhel6.4-1 //关闭名为rhel6.4-1这台虚拟机

[root@localhost ~]# virsh reboot rhel6.4-1 //重启名为rhel6.4-1这台虚拟机

[root@localhost ~]# virsh destroy rhel6.4-1 //强行关闭名为rhel6.4-1这台虚拟机

[root@localhost ~]# virsh dominfo rhel6.4-1 //列出名为rhel6.4-1这台虚拟机的相关信息

关于更详细的命令可以查看virsh的man手册页

发表评论

表情:
评论列表 (有 0 条评论,281人围观)

还没有评论,来说两句吧...

相关阅读

    相关 KVM虚拟网络配置

    kvm虚拟机的网络配置有两种模式:桥接模式和NAT模式。 > 两种模式区别如下: > 1)NAT模式:也是用户模式,数据包由NAT方式通过主机的接口进行传送,可以访问公网

    相关 kvm虚拟迁移

    说明:kvm虚拟机迁移我的总结分为三种: 冷迁移 热迁移 图形迁移   下面说各种迁移的步骤和注意事项: 冷迁移: 这个和克隆还是有区别的:克隆是把源虚拟机关闭,

    相关 KVM 安装windows 虚拟

    KVM 安装windows 虚拟机 家里有台linux电脑, 一直当文件服务器和下载机使用。 所谓下载机就是装1个xware用迅雷远程下载, 但是最近迅雷关闭了第三方机