lost and found ( for me ? )

KVM : CentOS6 : set up a serial console when using upstart ( virsh console )


KVM host : CentOS6

Guest : CentOS6

KVM host
# /usr/libexec/qemu-kvm –version
QEMU PC emulator version 0.12.1 (qemu-kvm-0.12.1.2), Copyright (c) 2003-2008 Fabrice Bellard

# libvirtd --version
libvirtd (libvirt) 0.9.10

# uname -ri
2.6.32-279.2.1.el6.x86_64 x86_64

# cat /etc/centos-release
CentOS release 6.3 (Final)


Guest
# uname -ri
2.6.32-279.2.1.el6.x86_64 x86_64

# cat /etc/redhat-release
CentOS release 6.3 (Final)


CentOS6 is using upstart and the configuration for serial ports settings is different from previous ver.

install upstart on your VM if you have not installed it
VM # yum install upstart –y

VM # rpm -qa | grep upstart
upstart-0.6.5-12.el6.x86_64


upstart configuration files are under /etc/init directory.
VM # ls /etc/init/
control-alt-delete.conf  quit-plymouth.conf       serial.conf
init-system-dbus.conf    rc.conf                  splash-manager.conf
kexec-disable.conf       rcS-emergency.conf       start-ttys.conf
plymouth-shutdown.conf   rcS-sulogin.conf         tty.conf
prefdm.conf              rcS.conf


edit /etc/securetty
VM # echo "ttyS0" >> /etc/securetty


create a serial-ttyS0.conf file under /etc/init directory.
VM# vi /etc/init/serial-ttyS0.conf


add the following lines.
VM# cat /etc/init/serial-ttyS0.conf
stop on runlevel [016]
start on runlevel [345]

respawn
instance /dev/ttyS0
exec /sbin/mingetty /dev/ttyS0

VM# initctl start serial-ttyS0
serial-ttyS0 (/dev/ttyS0) start/running, process 1418


“initctl list” output the lists which are controlled by upstart.
VM # initctl list
rc stop/waiting
tty (/dev/tty3) start/running, process 1321
tty (/dev/tty2) start/running, process 1319
tty (/dev/tty1) start/running, process 1317
tty (/dev/tty6) start/running, process 1331
tty (/dev/tty5) start/running, process 1325
tty (/dev/tty4) start/running, process 1323
plymouth-shutdown stop/waiting
control-alt-delete stop/waiting
rcS-emergency stop/waiting
kexec-disable stop/waiting
quit-plymouth stop/waiting
rcS stop/waiting
prefdm stop/waiting
init-system-dbus stop/waiting
serial-ttyS0 (/dev/ttyS0) start/running, process 1418
splash-manager stop/waiting
start-ttys stop/waiting
rcS-sulogin stop/waiting
serial stop/waiting


connect to the VM from the KVM host with virsh console
virsh # console centos6-64-1
Connected to domain centos6-64-1
Escape character is ^]


CentOS release 6.3 (Final)
Kernel 2.6.32-279.2.1.el6.x86_64 on an x86_64

centos6-64-1 login:

install KVM on CentOS 6.3 , use SPICE

[ install KVM on CentOS 6.3 ]


# cat /etc/centos-release
CentOS release 6.3 (Final)

# uname -rn
centos6-1.localdomain 2.6.32-279.2.1.el6.x86_64

# yum groupinstall Virtulization "Virtualization Platform" "Virtualization Client" "Virtualization Tools"

# /usr/libexec/qemu-kvm --version
QEMU PC emulator version 0.12.1 (qemu-kvm-0.12.1.2), Copyright (c) 2003-2008 Fabrice Bellard

# virt-manager --version
0.9.0

# libvirtd --version
libvirtd (libvirt) 0.9.10

start libvirtd
# /etc/init.d/libvirtd start
Starting libvirtd daemon:                                  [  OK  ]


connect to hypervisor with virsh to confirm whether or not libvirtd and virsh work.
# virsh --connect qemu:///system
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
      'quit' to quit

virsh # quit

connect to the hypervisor with root user.
If you try this with regular users , you will see the following error
$ LANG=C virsh --connect qemu:///system
error: authentication failed: Authorization requires authentication but no agent is available.

error: failed to connect to the hypervisor


Same issue will occur with virt-manager.

root user
# virt-manager


connect to the hypervisor


non root user
$ virt-manager


can’t 
connect

error messages are like this:

File "/usr/lib64/python2.6/site-packages/libvirt.py", line 102, in openAuth
   if ret is None:raise libvirtError('virConnectOpenAuth() failed')
libvirtError: authentication failed: Authorization requires authentication but no agent is available.


add a bridge interface ( not mandatory )
trun on network and turn off NetworkManager.
# chkconfig NetworkManager off
# chkconfig network on

# chkconfig --list | grep -i network
NetworkManager  0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off


I’ll associate eth0 with br0.
# pwd
/etc/sysconfig/network-scripts

# cp ifcfg-eth0 ifcfg-br0


edit ifcfg-eth0 like this:
# egrep -v ^# ifcfg-eth0
TYPE=Ethernet
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="Auto eth0"
DEVICE="eth0"
UUID=zzz
ONBOOT=yes
HWADDR=zz
BRIDGE="br0"


edit ifcfg-br0 like this:
# egrep -v ^# ifcfg-br0
TYPE=Bridge
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="br0"
DEVICE="br0"
UUID=zz
ONBOOT=yes
HWADDR=zz
IPADDR=x.x.x.x
PREFIX=24
GATEWAY=z.z.z.z
DNS1=y.y.y.y


stop NetworkManager and start network.
# /etc/init.d/NetworkManager stop;/etc/init.d/network restart

Okay , I could create bridge interface which is associated with eth0.
# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.002655e1aefa       no              eth0
virbr0          8000.525400fd7ade       yes             virbr0-nic


[ build a CentOS 6 VM with virt-manager and SPICE ]

install spice packages
# yum install spice-server spice-client spice-protocol –y


change display settings to Spice from VNC





# virsh list --all
Id    Name                           State
----------------------------------------------------
1     centos6-64-1                   running

# virsh dumpxml 1 | grep -i spice
   <channel type='spicevmc'>
     <target type='virtio' name='com.redhat.spice.0'/>
   <graphics type='spice' port='5900' autoport='yes' keymap='ja'/>


connect to the VM with spice client
# spicec -h 127.0.0.1 -p 5900


virsh # list --all
Id    Name                           State
----------------------------------------------------
3     centos6-64-1                   running

virsh # qemu-monitor-command 3 --hmp 'info spice'
Server:
    address: 127.0.0.1:5900
       auth: none
Channel:
    address: 127.0.0.1:50420
    session: 1714636915
    channel: 1:0
Channel:
    address: 127.0.0.1:50421
    session: 1714636915
    channel: 6:0
Channel:
    address: 127.0.0.1:50422
    session: 1714636915
    channel: 5:0
Channel:
    address: 127.0.0.1:50423
    session: 1714636915
    channel: 4:0
Channel:
    address: 127.0.0.1:50424
    session: 1714636915
    channel: 2:0
Channel:
    address: 127.0.0.1:50425
    session: 1714636915
    channel: 3:0


virsh #




httrack : copy web contents

httrack copies web contents you want to copy.


[root@fc17 ~]# uname -ri
3.4.6-2.fc17.x86_64 x86_64

[root@fc17 ~]# cat /etc/fedora-release
Fedora release 17 (Beefy Miracle)

install httrack via yum
[root@fc17 ~]# yum install httrack -y

create a directory to store web contents
$ mkdir web-copy

I’ll copy my blog site.
Please take care of copyright matters , bandwidth , load etc when you copy web contents.

run httrack
$ httrack

Welcome to HTTrack Website Copier (Offline Browser) 3.43-9+libhtsjava.so.2
Copyright (C) Xavier Roche and other contributors
To see the option list, enter a blank line or try httrack --help

Enter project name :my-blog-copy

Base path (return=/home/hattori/websites/) :/home/hattori/web-copy

Enter URLs (separated by commas or blank spaces) :http://lost-and-found-narihiro.blogspot.jp

Action:
(enter) 1 Mirror Web Site(s)
2 Mirror Web Site(s) with Wizard
3 Just Get Files Indicated
4 Mirror ALL links in URLs (Multiple Mirror)
5 Test Links In URLs (Bookmark Test)
0 Quit
: 1

Proxy (return=none) :

You can define wildcards, like: -*.gif +www.*.com/*.zip -*img_*.zip
Wildcards (return=none) :

You can define additional options, such as recurse level (-r<number>), separed by blank spaces
To see the option list, type help
Additional options (return=none) :

---> Wizard command line: httrack http://lost-and-found-narihiro.blogspot.jp  -O "/home/hattori/web-copy/my-blog-copy"  -%v   

Ready to launch the mirror? (Y/n) :y

Mirror launched on Tue, 24 Jul 2012 23:56:52 by HTTrack Website Copier/3.43-9+libhtsjava.so.2 [XR&CO'2010]
mirroring http://lost-and-found-narihiro.blogspot.jp with the wizard help..



Here’s a capture data
User-Agent Header seems to be Mozilla.
Hypertext Transfer Protocol
   GET /2012/01/linux-mint-12-configure-ip-aliases.html HTTP/1.1\r\n
       [Expert Info (Chat/Sequence): GET /2012/01/linux-mint-12-configure-ip-aliases.html HTTP/1.1\r\n]
           [Message: GET /2012/01/linux-mint-12-configure-ip-aliases.html HTTP/1.1\r\n]
           [Severity level: Chat]
           [Group: Sequence]
       Request Method: GET
       Request URI: /2012/01/linux-mint-12-configure-ip-aliases.html
       Request Version: HTTP/1.1
   Referer: http://lost-and-found-narihiro.blogspot.jp/\r\n
   Cookie: $Version=1; blogger_TID=xxx; $Path=/\r\n
   Connection: Keep-Alive\r\n
   Host: lost-and-found-narihiro.blogspot.jp\r\n
   User-Agent: Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)\r\n
   Accept: image/png, image/jpeg, image/pjpeg, image/x-xbitmap, image/svg+xml, image/gif;q=0.9, */*;q=0.1\r\n
   Accept-Language: en, *\r\n
   Accept-Charset: iso-8859-1, iso-8859-*;q=0.9, utf-8;q=0.66, *;q=0.33\r\n
   Accept-Encoding: gzip, identity;q=0.9\r\n
   \r\n
   [Full request URI: http://lost-and-found-narihiro.blogspot.jp/2012/01/linux-mint-12-configure-ip-aliases.html]


after finishing copying web contents , web contents will be stored under “~/web-copy/my-blog-copy” directory.
[root@fc17 my-blog-copy]# pwd
/home/hattori/web-copy/my-blog-copy

[root@fc17 my-blog-copy]# ls
backblue.gif  hts-in_progress.lock  lost-and-found-narihiro.blogspot.jp
fade.gif      hts-log.txt
hts-cache     index.html


open index.html with an web browser.




or

you could copy web contents with wget command like this:

$ wget --user-agent=Mozilla --mirror --wait=1 http://zzzzz

C programming : how to create a zombie process



# gcc --version | head -1
gcc (GCC) 4.4.6 20120305 (Red Hat 4.4.6-4)

# cat /etc/centos-release
CentOS release 6.3 (Final)

# uname -ri
2.6.32-279.1.1.el6.i686 i386

# cat create-zombie.c -n
    1  #include <stdio.h>
    2  #include <sys/types.h>
    3  #include <unistd.h>
    4  #include <stdlib.h>
    5
    6  int main()
    7  {
    8          pid_t c_pid;
    9
   10          c_pid=fork(); /* crete a child process */
   11
   12          if (c_pid > 0) { /* child process */
   13                  printf("Parent PID : %d\r\n", getpid());
   14                  printf("Child PID  %d is zombie process \r\n", c_pid);
   15                  sleep (1000);
   16          }
   17          else {
   18                  return 0;
   19          }
   20  return 0;
   21  }

compile it.

# gcc create-zombie.c -o create-zombie.o

run
# ./create-zombie.o
Parent PID : 1688
Child PID 1689 is zombie process

check whether or not child process is zombie.

# pstree -p 1688
create-zombie.o(1688)---create-zombie.o(1689)

PID 1689 is marked as a zombie process.

# ps aux | awk '{ print $8 " " $2 }' | grep -w Z
Z+ 1689

# top -b -n 1
top - 20:43:31 up 28 min,  2 users,  load average: 0.00, 0.00, 0.00
Tasks: 100 total,   1 running,  98 sleeping,   0 stopped,   1 zombie

# egrep -i state /proc/1689/status
State:  Z (zombie)