2012年11月9日 星期五

KVM -- create a virtual machine console displayed on vnc



prepare yum server in ftp://172.16.43.248/pub62/
and kickstart file @172.16.43.248:/var/www/html/pub62/ks.cfg



  172.16.43.248               172.16.43.145 (qemu:///system)    
+------------------+     +-----------------------+      
|Yum Server        |     | Virtualization        |     
|ftp /pub62        |     | Virtualization Client |     
|http /pub62/ks.cfg|     |                       |      
|                  |     | VNCSERVERS "50:root"  |      
|                  |     |                       |      
|------------------|     |       172.16.43.149   |     
|                  |     |       +------------+  |   vnc: 172.16.43.145:0  
|                  |     |       | cent6      +--= br0 (BRIDGE eth0)    
|                  |     |       +------------+  |     
|                  |     |                       |      
|                  |     |           dhcp        |     
|                  |     |       +------------+  |   vnc: 172.16.43.145:1  
|                  |     |       |centNAT     +--= virbr0 (NAT)    
|                  |     |       +------------+  |     
+-------+----------+     +------+----------------+     
        |                       | eth0  vnc: 172.16.43.145:50         
--------+-----------------------+--------------------------+ vnc client accessable

[root@localhost ~]# yum install tigervnc-server
[root@localhost ~]# vi /etc/sysconfig/vncservers
   :
   :
# VNCSERVERS="2:myusername"
# VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -localhost"

VNCSERVERS="50:root"
[root@localhost ~]# vncpasswd
[root@localhost ~]# vncserver
New 'localhost.localdomain:50 (root)' desktop is localhost.localdomain:50

Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/localhost.localdomain:50.log

[root@localhost ~]# vncserver -kill :50
[root@localhost ~]# service vncserver start
[root@localhost ~]# chkconfig vncserver on



[root@localhost ~]# yum groupinstall 'Virtualization' 'Virtualization Client'
[root@localhost ~]# lsmod | grep kvm
kvm_intel              50380  6 
kvm                   305081  1 kvm_intel

[root@localhost ~]# service NetworkManager stop
[root@localhost ~]# chkconfig NetworkManager off


<<<<<<<<<< BRIDGE >>>>>>>>>>


[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
HWADDR="68:05:CA:08:46:F0"
#NM_CONTROLLED="yes"
ONBOOT="yes"
BOOTPROTO=static
BRIDGE=br0
#IPADDR=172.16.43.145
#NETMAS=255.255.255.0
#GATEWAY=172.16.43.1
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.16.43.145
NETMASK=255.255.255.0
GATEWAY=172.16.43.1
TYPE=Bridge
USERCTL=yes
NAME="Bridge eth0"

[root@localhost ~]# lv_create -L 100G -n lv_test VolGroup

[root@localhost ~]# cat rhel-install4.sh
#!/bin/bash
virsh destroy cent6 &> /dev/null

##vnc的port如果不指定,可避免同時安裝多台VM的listen port衝突,port便由系統配
##vnc的配置也可由--vnc(預設便是listen 127.0.0.1) 取代--graphics vnc,...
/usr/sbin/virt-install -n cent6 -r 1024 --vcpus=1 --accelerate --disk path=/dev/VolGroup/lv_test --network bridge:br0 -x "ks=http://172.16.43.248/pub62/ks.cfg ksdevice=eth0 ip=172.16.43.149 netmask=255.255.255.0 dns=168.95.1.1 gateway=172.16.43.1" -l ftp://172.16.43.248/pub62/ --graphics vnc[,port=5900],listen=0.0.0.0 &

sleep 5 
virsh autostart cent6



<<<<<<<<<< NAT >>>>>>>>>>


[root@localhost ~]# cat note-NAT 
[root@localhost ~]# lvcreate -L 100G -n lv_test2 VolGroup

[root@localhost ~]# vi /etc/sysctl.conf
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled.  See sysctl(8) and
# sysctl.conf(5) for more details.

# Controls IP packet forwarding
net.ipv4.ip_forward = 1

[root@localhost ~]# sysctl -p
net.ipv4.ip_forward = 1
  :


[root@localhost ~]# service iptables status
iptables: Firewall is not running.
[root@localhost ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination       

[root@localhost ~]# service libvirtd restart
Stopping libvirtd daemon:                                  [  OK  ]
Starting libvirtd daemon:                                  [  OK  ]
[root@localhost ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:domain 
ACCEPT     udp  --  anywhere             anywhere            udp dpt:bootps 
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:bootps 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             192.168.122.0/24    state RELATED,ESTABLISHED 
ACCEPT     all  --  192.168.122.0/24     anywhere            
ACCEPT     all  --  anywhere             anywhere            
REJECT     all  --  anywhere             anywhere            reject-with icmp-port-unreachable 
REJECT     all  --  anywhere             anywhere            reject-with icmp-port-unreachable 

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         


[root@localhost ~]# cat ./rhel-install5.sh
#!/bin/bash
virsh destroy centNAT &> /dev/null

/usr/sbin/virt-install -n centNAT -r 1024 --vcpus=1 --accelerate --disk path=/dev/VolGroup/lv_test2 --network network:default -x "ks=http://172.16.43.248/pub62/ks.cfg  ip=dhcp dns=168.95.1.1 " -l ftp://172.16.43.248/pub62/ --graphics vnc,port=5901,listen=0.0.0.0 &

sleep 5 
virsh autostart centNAT


If you found out that ksmd was run with high CPU% please do this:


service ksm stop
service ksmtuned stop

refer to : https://bugzilla.redhat.com/show_bug.cgi?id=541230

沒有留言:

張貼留言

文章分類