设为首页 收藏本站
查看: 1607|回复: 0

[经验分享] rhel6.4网络安装kvm虚拟机

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-12-5 08:50:11 | 显示全部楼层 |阅读模式

本次试验环境如图1所示

Center.jpg

一:安装前提条件:

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

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

Center.jpg

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

[iyunv@localhost ~]# egrep --color "vmx|svm" /proc/cpuinfo

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


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

1.安装KVM

[iyunv@localhost ~]#yum -y groupinstall Virtualization "Virtualization Client" "Virtualization Platform" "Virtualization Tools"

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

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


2.网桥设置

[iyunv@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                                                                                      //添加这一行


[iyunv@localhost network-scripts]# pwd

/etc/sysconfig/network-scripts

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

[iyunv@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            

重启网络

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

查看网桥信息

[iyunv@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.[iyunv@localhost ~]# yum -y install dhcp


2.配置dhcp

[iyunv@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;

}

[iyunv@localhost ~]#


3.启动dhcp服务

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

Starting dhcpd:                                           [  OK  ]

[iyunv@localhost ~]#


◆.安装tftp-server和syslinux

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


2.配置tftp

[iyunv@localhost ~]# grep -v "^#"/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                                                                                    //把yes改为no

       per_source              = 11

       cps                     = 100 2

       flags                   = IPv4

}

[iyunv@localhost tftpboot]# pwd

/var/lib/tftpboot

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

[iyunv@localhost tftpboot]# mkdir pxelinux.cfg

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

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

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

[iyunv@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 -

[iyunv@localhost tftpboot]#


3.启动xinentd服务

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

Starting xinetd:                                           [  OK  ]

[iyunv@localhost ~]#


◆安装vsftpd

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

2.启动vsftpd服务

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

Starting vsftpd for vsftpd:                                [  OK  ]

[iyunv@localhost ~]#

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

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


◆配置ks文件

1.ks文件内容如下

[iyunv@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

[iyunv@localhost ~]#


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


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

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


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

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

[iyunv@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方式安装

[iyunv@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.jpg

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

Center.jpg

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

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


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

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

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

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

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

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

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

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


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



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-36179-1-1.html 上篇帖子: kvm中的cpu配置 下篇帖子: kvm虚拟机在线迁移 虚拟机 网络
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表