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

[经验分享] CentOS 5.6下创建KVM虚拟机

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-6-16 14:02:40 | 显示全部楼层 |阅读模式
首先要保证你的CPU支持虚拟化。执行以下命令查看CPU的flag信息,里面包含svm的flag就说明支持虚拟化:
[iyunv@localhost ~]# egrep '(vmx|svm)' --color=always /proc/cpuinfoflags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy misalignsseflags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm 3dnowext 3dnow pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy misalignsse安装KVM运行所需要的软件包:
yum install kvm kmod-kvm qemu kvm-qemu-img virt-viewer virt-manager ibvirt libvirt-python python-virtinst                                                                                                                                     或者用下面这句也行:yum groupinstall KVM另外,如果后面想用virt-manager图形化安装和管理虚拟机的话,CentOS 5.6需要作一些配置和改动。由于我在安装前就选择了gnome图形化界面,所以我想用Xmanager 3.0图形化管理此机器,过程如下:
一、添加XDMCP协议支持,让服务器打开177端口
我们可以更改/etc/gdm/custom.conf文件,在
[xdmcp]项下添加
Enable=1二、服务器自身关闭iptables及SElinux
三、保证服务器以图形化界面启动,即运行在5模式下
以下是更改CentOS 5.6的认证模块
vim /etc/pam.d/login 注释第一行 #auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so vim /etc/pam.d/remote 注释第一行 #auth       required     pam_securetty.so重新启动服务器即可,可用lsof -i:177命令查看端口是否开放。
在服务器上增加一个br0网桥设备,方便与虚拟机直连,步骤如下:
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /root/.cd /etc/sysconfig/network-scripts/cp ifcfg-eth0 ifcfg-br01.If your network card is configured with a static IP address,your original network script file should look similar to the followingexample:
DEVICE=eth0 BOOTPROTO=static HWADDR=00:14:5E:C2:1E:40 IPADDR=10.10.1.152 NETMASK=255.255.255.0 ONBOOT=yes
The following table shows the contents ofthe network configuration scripts for eth0 and br0.Edit your scripts as shown in the following example.
Table 1. Bridgingnetwork files comparison
/etc/sysconfig/network-scripts/ifcfg-eth0
etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=eth0 TYPE=EthernetHWADDR=00:14:5E:C2:1E:40 ONBOOT=yes NM_CONTROLLED=noBRIDGE=br0DEVICE=br0TYPE=BridgeNM_CONTROLLED=noBOOTPROTO=static IPADDR=10.10.1.152 NETMASK=255.255.255.0 ONBOOT=yesIn the left column is the network script file for networkcard (eth0).  The pre-existing information about this networkcard stays the same, but three items are added:
  • TYPE
    The device type.
  • NM_CONTROLLED=no
    Specifies that the card is not controlled by the Network Manager.In order for the bridge to work, only one device can be controlledby the Network Manager.
  • BRIDGE=br0
    Associates this card with the bridge.

In the right column is the network script forthe bridge (br0).  The following changes are reflected:
  • DEVICE
    The device name.
  • TYPE
    The device type. Bridge is case-sensitive andmust be added exactly as represented here with an upper case 'B' andlower case 'ridge'.
  • NM_CONTROLLED=no
    Specifies that the bridge is not controlled by the Network Manager.In order for the bridge to work, only one device can be controlledby the Network Manager.

The other settings are retained from the network cardconfiguration file.
Note: There should not be a hardware address inthis file.  These values set up the bridge to behave like the networkcard: the ifcfg-br0 file acting as an extension of the ifcfg-eth0 filewhere the BRIDGE=br0 is pointing to the ifcfg-br0 file.

2.If your network card is configured with a dynamic IP address,your original network script file should look similar to the followingexample:
DEVICE=eth0 BOOTPROTO=dhcpHWADDR=00:14:5E:C2:1E:40 ONBOOT=yes
The following table shows the contents ofthe configuration scripts for eth0 and br0. Edit yourscripts as shown in the following example.
Table 2. Bridgingnetwork files comparison
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=eth0 TYPE=EthernetHWADDR=00:14:5E:C2:1E:40 ONBOOT=yes NM_CONTROLLED=noBRIDGE=br0DEVICE=br0TYPE=BridgeNM_CONTROLLED=no BOOTPROTO=dhcpONBOOT=yes# service network restart
  • Reload the kernel parameters with the sysctl command:
    # sysctl -p net.ipv4.ip_forward = 0 ...net.bridge.bridge-nf-call-ip6tables = 0 net.bridge.bridge-nf-call-iptables = 0 net.bridge.bridge-nf-call-arptables = 0
Youcan also see this bridge by running the following command:
brctl showbridge name     bridge id               STP enabled     interfacesvirbr0          8000.000000000000       yesbr0             8000.000e0cb30550       no              eth0接下来的话,我们就可以直接在服务器上用图形化命令Virt-manager来创建一个CentOS 5.6的虚拟机了。由于要用到物理机本身的光驱,所以这里需要挂载下:
mount /dev/cdrom /mnt记得将CentOS 5.6的DVD光盘放进光驱里。
然后在终端下执行命令virt-manager创建虚拟机,由于操作与vmware server类似,都是基于图形化的操作。


我们成功创建完第一个虚拟机后,我由于测试的需要,还需要创建三个虚拟机,我们可以在终端下依次输入命令,复制虚拟机:
virt-clone --connect=qemu:///system -o centos1 -n centos2 -f /datata/kvm/centos2.imgvirt-clone --connect=qemu:///system -o centos1 -n centos3 -f /datata/kvm/centos3.imgvirt-clone --connect=qemu:///system -o centos1 -n centos4 -f /datata/kvm/centos4.img-o表示旧的虚拟机名称,-n表示新的虚拟机名称,-f表示新的虚拟机路径。
我们全部运行后,可以看下virt-manager的效果图,如下:
1001563.jpg
系统稳定运行一段时间后,我们可以通过uptime命令观测系统负载,它们不是特别大。
[iyunv@kvm centos10m]# uptime00:43:08 up 2:04, 1 user, load average: 0.92, 0.77, 0.81这样的话,我们就在这台服务器上成功运行了四台64bit CentOS 5.6的机器,KVM环境搭建成功。


运维网声明 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.yunweiku.com/thread-20619-1-1.html 上篇帖子: KVM部署及硬件参数更改 下篇帖子: KVM 虚拟机克隆 虚拟机
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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