kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

ubuntu安装kvm虚拟机

1
sudo apt-get install qemu-kvm libvirt-bin virt-manager

用 virt-manager

参考 http://nmszh.blog.51cto.com/4609205/1539502


http://www.sysstem.at/category/linux/

问题一:

1
2
3
ERROR internal error: Process exited while reading console log output: char device redirected to /dev/pts/45 (label charserial0)
ioctl(KVM_CREATE_VM) failed: 16 Device or resource busy
failed to initialize KVM: Device or resource busy

This is mostly because you have either VirtualBox or VMware running on the same machine. The reason (at least that’s what I think) is that the kernel module of VirtualBox or VMware and KVM can’t take Advantage of Intel VT-x or AMD-V at the same time.

关闭virtualbox等其他虚拟机就好


http://ask.xmodulo.com/hda-duplex-not-supported-in-this-qemu-binary.html

问题二:

1
Unable to complete install: 'unsupported configuration: hda-duplex not supported in this QEMU library
Solution One: Virt-Manager

On virt-manager, open the VM’s virtual hardware details menu, go to sound device section, and change the device model from default to ac97.

Click on “Apply” button to save the change. See if you can start the VM now.

也就是 最后一步 “勾选安装之前配置“,完成,然后将声卡改成ac97即可

Solution Two: Virsh

If you are using virsh, not virt-manager, you can edit the VM’s XML file accordingly. Look for sound section inside section, and change the sound model to ac97 as follows.

1
2
3
4
5
6
7
  <devices>
	. . .
	<sound model='ac97'>
	  <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
	</sound>
	. . .
  </device>

http://wiki.ubuntu.org.cn/Kvm%E6%95%99%E7%A8%8B

centos安装kvm虚拟机

  • 最好在centos6装

  • TODO 虚拟机网桥连接没试

http://docs.openstack.org/zh_CN/image-guide/content/virt-install.html

安装

1
yum install qemu-kvm libvirt virt-manager

管理界面

1
virt-manager

图形化安装过程见: http://nmszh.blog.51cto.com/4609205/1539502

命令行创建安装

1
qemu-img create -f qcow2 ttt.img 10G
1
2
3
4
5
6
7
8
9
10
11
12
virt-install --virt-type kvm --name centos-6.4 --ram 1024 \
--cdrom=/data/CentOS-6.4-x86_64-netinstall.iso \
--disk path=/data/centos-6.4.qcow2,size=10,format=qcow2 \
--network network=default \
--graphics vnc,listen=0.0.0.0 --noautoconsole \
--os-type=linux --os-variant=rhel6

Starting install...
Creating
domain...  |    0 B     00:00
Domain installation still in progress. You can reconnect to
the console to complete the installation process.

KVM 虚拟化使用 centos-6.4 名称,1024MB内存启动虚拟机。虚拟机还有一个关联文件/data/CentOS-6.4-x86_64-netinstall.iso 的虚拟的 CD-ROM,并拥有 10GB 的qcow2格式的硬盘,硬盘文件位置在 /data/centos-6.4.qcow2。虚拟机配置了网络使用 libvirt 的默认网络。且 VNC 服务监听所有的网卡,并且 libvirt 不会自动启动 VNC 客户端也不会显示字符界面控制台(–no-autoconsole)。最后,libvirt 将尝试以RHEL 6.x 发行版来优化虚拟机配置。

运行

1
virt-install --os-variant list

命令查看 --os-variant 允许的选项范围。

使用命令获取 VNC 端口号。

1
2
3
4
virsh vncdisplay vm-name

  # virsh vncdisplay centos-6.4
  :1

在上面的示例中,虚拟机 centos-6.4 使用 VNC 显示器 :1,对应的 TCP 端口是 5901。你应该使用本地 VNC 客户端连接到远程服务器的 :1 显示器并且完成安装步骤。

用vncviewer连接虚拟机完成安装

1
vncviewer IP:5901
  • 装好后会生成 /etc/libvirt/qemu/ttt.xml 配置文件,可以修改

http://os.51cto.com/art/201404/435193.htm

http://tianhao936.blog.51cto.com/1043670/1343767

虚拟机操作

常用virsh指令

1
2
3
4
5
6
7
8
9
1)virsh list               列出当前虚拟机列表,不包括未启动的
2)virsh list --all         列出所有虚拟机,包括所有已经定义的虚拟机
3)virsh start vm-name      启动虚拟机
4)virsh destroy vm-name    关闭虚拟机  
5)virsh undefine vm-name   删除虚拟机
6)virsh shutdown vm-name   停止虚拟机
7)virsh reboot vm-name     重启虚拟机
8)virsh edit vm-name       编辑虚拟机xml文件
9)virsh autostart vm-name  虚拟机随宿主机启动 

http://blog.csdn.net/justlinux2010/article/details/8977705

http://www.centoscn.com/image-text/config/2014/0801/3407.html


错误

1
Could not initialize SDL(No available video device) - exiting

需要在桌面环境运行qemu-kvm

vnc远程连接,远程登录服务器或者虚拟机

http://blog.csdn.net/gg296231363/article/details/6899655

服务器端

1 安装

1
yum install vnc* tigervnc tigervnc-server pixman pixman-devel libXfont

2

1
vi /etc/sysconfig/vncservers

修改成

1
2
VNCSERVERS="2:root"
VNCSERVERARGS[2]="-geometry 800x600"

3 设置登录密码

1
vncpasswd

4

1
2
service vncserver start
service iptables stop

客户机端

1
vncviewer IP:PORT

centos5 有可能出现的错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ vncviewer 127.0.0.1:5900

VNC Viewer Free Edition 4.1.2 for X - built Apr 20 2011 12:04:25
Copyright (C) 2002-2005 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.

Mon Jul  6 14:16:43 2015
 CConn:       connected to host 127.0.0.1 port 5900
 CConnection: Server supports RFB protocol version 3.8 
 CConnection: Using RFB protocol version 3.8 
 TXImage:     Using default colormap and visual, TrueColor, depth 24. 
 CConn:       Using pixel format depth 6 (8bpp) rgb222
 CConn:       Using ZRLE encoding

Mon Jul  6 14:16:44 2015
 CConn:       Throughput 20000 kbit/s - changing to hextile encoding
 CConn:       Throughput 20000 kbit/s - changing to full colour
 CConn:       Using pixel format depth 24 (32bpp) little-endian rgb888
 CConn:       Using hextile encoding
unknown message type 98
 main:        unknown message type

加上 -FullColor 选项就好

1
$ vncviewer -FullColor 127.0.0.1:5900

不是必需

5

1
2
3
4
5
vi ~/.vnc/xstartup
gnome-session &   //添加gnome,使用gnome图形界面登录
#twm &            //注销默认的窗口管理器 简陋而且很多图形显示不了

service vncserver restart