install kvm hosts use vnc in CentOS 6

本文描述在centos6中部署kvm虚拟机, 使用vnc连接到服务器, 再使用vncviewer连接到kvm vnc安装界面.

(原本打算直接连接到kvm vnc安装界面的, 没有成功, 会闪退)

在服务器安装必要的包

# yum install -y qemu-img qemu-kvm virt-manager libvirt libvirt-python python-virtinst libvirt-client tigervnc-server libvirt libvirt-client virt-what virt-viewer
# yum groupinstall -y desktop

创建一个虚拟磁盘目录

# mkdir /data03/kvmdisk

创建虚拟磁盘, 用于虚拟机的系统盘

# qemu-img create -f qcow2 -o encryption=off,cluster_size=2M,preallocation=full /data03/kvmdisk/disk01.img 32G

下载安装镜像

# mkdir /data03/iso
# cd iso
# wget http://mirrors.aliyun.com/centos/6.6/isos/x86_64/CentOS-6.6-x86_64-bin-DVD1.iso

启动libvirtd

# service libvirtd start
# chkconfig libvirtd on
# chkconfig libvirt-guests off

查看当前启动的网桥

# brctl show
bridge name     bridge id               STP enabled     interfaces
virbr0          8000.5254001263b0       yes             virbr0-nic

# ifconfig
em1       Link encap:Ethernet  HWaddr 00:22:19:60:77:8F
          inet addr:172.16.3.150  Bcast:172.16.3.255  Mask:255.255.255.0
          inet6 addr: fe80::222:19ff:fe60:778f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5469716 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2830916 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:5147311077 (4.7 GiB)  TX bytes:198552462 (189.3 MiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:79073 errors:0 dropped:0 overruns:0 frame:0
          TX packets:79073 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:24506711 (23.3 MiB)  TX bytes:24506711 (23.3 MiB)

virbr0    Link encap:Ethernet  HWaddr 52:54:00:12:63:B0
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

网桥地址配置

# grep -r 192.168.122 /etc/libvirt
/etc/libvirt/qemu/networks/default.xml:  <ip address="192.168.122.1" netmask="255.255.255.0">
/etc/libvirt/qemu/networks/default.xml:      <range start="192.168.122.2" end="192.168.122.254" />
/etc/libvirt/qemu/networks/autostart/default.xml:  <ip address="192.168.122.1" netmask="255.255.255.0">
/etc/libvirt/qemu/networks/autostart/default.xml:      <range start="192.168.122.2" end="192.168.122.254" />

安装KVM虚拟机, 开启VNC.

# virt-install \
   --name=centos6_6_x64 \
   --disk path=/data03/kvmdisk/disk01.img,device=disk,bus=virtio,perms=rw,cache=writethrough \
   --graphics vnc,listen=0.0.0.0,port=5901,password=digoal \
   --vcpus=4 --ram=4096 \
   --cdrom=/data03/iso/CentOS-6.6-x86_64-bin-DVD1.iso \
   --network bridge=virbr0 \
   --os-type=linux \
   --os-variant=rhel6

# ps -ewf|grep kvm
root       967     2  0 15:05 ?        00:00:00 [kvm-irqfd-clean]
qemu      3582     1  7 15:15 ?        00:00:00 /usr/libexec/qemu-kvm -name centos6_6_x64 -S -M rhel6.6.0 -enable-kvm -m 4096 -realtime mlock=off -smp 4,sockets=4,cores=1,threads=1 -uuid e55d318c-5b3c-a0c0-e694-799c618787ac -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/centos6_6_x64.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc -no-reboot -no-shutdown -device ich9-usb-ehci1,id=usb,bus=pci.0,addr=0x4.0x7 -device ich9-usb-uhci1,masterbus=usb.0,firstport=0,bus=pci.0,multifunction=on,addr=0x4 -device ich9-usb-uhci2,masterbus=usb.0,firstport=2,bus=pci.0,addr=0x4.0x1 -device ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,addr=0x4.0x2 -drive file=/data03/kvmdisk/disk01.img,if=none,id=drive-virtio-disk0,format=raw,cache=writethrough -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x5,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=2 -drive file=/data03/iso/CentOS-6.6-x86_64-bin-DVD1.iso,if=none,media=cdrom,id=drive-ide0-1-0,readonly=on,format=raw -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0,bootindex=1 -netdev tap,fd=22,id=hostnet0,vhost=on,vhostfd=23 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:5d:70:bd,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -device usb-tablet,id=input0 -vnc 0.0.0.0:1,password -vga cirrus -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 -msg timestamp=on
root      3593     2  0 15:15 ?        00:00:00 [kvm-pit-wq]
root      3605  2457  0 15:16 pts/2    00:00:00 grep kvm

# netstat -anp|grep 5901
tcp        0      0 0.0.0.0:5901                0.0.0.0:*                   LISTEN      3582/qemu-kvm    

虽然监听了5901, 但是在外部主机不能连到这个VNC, 会闪退.

在服务器本地可以连接正常.

在服务端启动vncserver

# vncserver :2
# vi ~/.vnc/xstartup
#twm &
gnome-session &

# vncserver -kill :2
# vncserver :2

使用笔记本连接到服务端vnc, 然后在服务端的vnc窗口中使用vncviewer再连接本地的vnc 5901.

安装过程略.

其他, 如果要删除虚拟机, 需要删除配置, 重启libvirtd.

# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     centos6_6_x64                  running

# virsh destroy 1

# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     centos6_6_x64                  shut off

# rm -f /etc/libvirt/qemu/centos6_6_x64.xml
# service libvirtd restart

# virsh list --all
 Id    Name                           State
----------------------------------------------------

[问题]

1. 无法直接使用笔记本连接virt-install提供的vnc端口, 必须在服务端连, 目前不知原因.

[参考]

1. https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Getting_Started_Guide/ch05.html#idp8381488

2. man virt-install

3. man virsh

4. man qemu-kvm

5. man qemu-img

6. https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Installation_Guide/index.html

时间: 2025-01-21 16:31:07

install kvm hosts use vnc in CentOS 6的相关文章

install kvm hosts use kickstart in CentOS 6 in text mode

和前面一篇文章类似,  http://blog.163.com/digoal@126/blog/static/16387704020153142253971/ 本文讲述使用kickstart文件安装kvm虚拟机, 因此不需要连接图形界面. 在服务器安装必要的包, 不再需要图形相关的包. # yum install -y qemu-img qemu-kvm virt-manager libvirt libvirt-python python-virtinst libvirt-client libv

How To Install Zabbix Server 3.0 on CentOS/RHEL 7/6/5

Zabbix is an open source software for networks and application monitoring. Zabbix provides agents to monitor remote hosts as well as Zabbix includes support for monitoring via SNMP, TCP and ICMP checks. Click here to know more about zabbix. This arti

CloudStack 4.4+KVM之通过ISO文件创建CentOS虚拟机

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://koumm.blog.51cto.com/703525/1564958 CloudStack 4.4+KVM之管理服务器安装   http://koumm.blog.51cto.com/703525/1558660     CloudStack 4.4+KVM之KVM计算节点安装    http://koumm.blog.51cto.com/703525/1558670    

Install Apache, PHP And MySQL On CentOS 7 (LAMP)

原文 Install Apache, PHP And MySQL On CentOS 7 (LAMP) This tutorial shows how you can install an Apache2 webserver on a CentOS 7.0 server with PHP5 support (mod_php) and MySQL support. LAMP is short for Linux, Apache,MySQL, PHP. 1 Preliminary Note In t

linux vps新手入门教程:kvm架构通过vnc安装Debian系统

kvm 架构还是比较流行的,期性能比OpenVZ要好,和xen架构一样属于全硬件虚拟化,使用起来稍微复杂一些,下单默认开通是没有安装系统的,默认情况需要自己安装系统,我都知道kvm 架构的vps 价格要稍高点,性能又不错,所以很多朋友可能会选择低配套餐,如128M 内存的套餐 就不适宜我们常用的CentOS 系统,256M内存及以下,CentOS 6X 系统也是无法安装的,所以我们需要安装暂用内存资源更小的 Debian系统,一样是款非常优秀的系统,使用率也挺高,而且也支持中文. 下面就跟我来一

OTRS install and configure from source on CentOS 6.5 x64

1. 安装perl yum install -y perl 2. 下载help desk源码 wget http://ftp.otrs.org/pub/otrs//otrs-3.3.7.tar.bz2 3. 解压到/opt/ tar -jxvf otrs-3.3.7.tar.bz2 4. 重命名为otrs mv otrs-3.3.7 /opt/otrs 5. 创建一个普通用户, 用于运行otrs. 同时需要将它的HOME目录设置为/opt/otrs useradd -r -d /opt/otrs

Install Ganglia core (gmond &amp; gmetad) in CentOS 6.x x64

下载最新稳定版的源码 http://ganglia.sourceforge.net/ # wget http://downloads.sourceforge.net/project/ganglia/ganglia%20monitoring%20core/3.6.0/ganglia-3.6.0.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fganglia%2Ffiles%2Fganglia%2520monitoring%2520core%2F

Linux中如何克隆KVM虚拟机

Linux中如何克隆KVM虚拟机 作者 digoal 日期 2016-11-11 标签 Linux , KVM , 虚拟化 , 克隆 背景 当需要批量部署虚拟机时,通常有几种做法,使用模板重新安装. 或者使用已有的虚拟机克隆. 使用模板安装可以参考kickstart脚本的编写方法. <install kvm hosts use kickstart in CentOS 6 in text mode> 本文介绍一下在已经安装好的虚拟机上,克隆虚拟机的方法. 从0开始安装一个虚拟机 在服务器安装必要

centos系统中kvm qemu 虚拟机安装配置教程

二,安装配置KVM  代码如下 复制代码 # yum -y install kvm python-virtinst libvirt bridge-utils \  virt-manager qemu-kvm-tools virt-viewer virt-v2v qemu-kvm tunctl    [root@localhost ~]#vim /etc/sysconfig/selinux //关闭selinux    SELINUX=disabled    [root@localhost ~]#