lost and found ( for me ? )

Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

KVM : add a device with virsh attach-device

small tips.

prepare an xml file

$ cat network-add.xml
<interface type='network'>
  <source network='net-192.168.42'/>
  <model type='virtio'/>
</interface>

$ virsh dumpxml m-node03 | grep network
    <interface type='network'>
      <source network='net-192.168.40'/>
    <interface type='network'>
      <source network='net-192.168.41'/>
$
$ virsh attach-device m-node03 network-add.xml --config
Device attached successfully

$
$ virsh dumpxml m-node03 | grep network
    <interface type='network'>
      <source network='net-192.168.40'/>
    <interface type='network'>
      <source network='net-192.168.41'/>
    <interface type='network'>
      <source network='net-192.168.42'/>
$

CentOS6.4 ssh-agent : access to SSH servers without entering password

referred to http://www.atmarkit.co.jp/flinux/rensai/linuxtips/447nonpassh.html

Both SSH server and SSH client are CentOS6.4.
I have already installed openssh on both boxes.
SSH server allows accesses from remote boxes with root user.

on the SSH server, create keys
# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:

here are keys
# pwd
/root/.ssh

# ls id*
id_rsa  id_rsa.pub

id_rsa: private key
id_rsa.pub: public key

on the SSH server, make authorized_keys by using id_rsa.pub key.
# cat id_rsa.pub >> ~/.ssh/authorized_keys
# chmod 600 ~/.ssh/authorized_keys

copy id_rsa key to SSH client from SSH server.

confirm the key is the same on both boxes.

on the SSH server
# md5sum id_rsa
a79523e3e7cdbe1fbfc822d26f80b427  id_rsa

on the SSH client
# md5sum id_rsa
a79523e3e7cdbe1fbfc822d26f80b427  id_rsa

on the SSH client, start ssh-agent
# ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-muDsy12684/agent.12684; export SSH_AUTH_SOCK;
SSH_AGENT_PID=12685; export SSH_AGENT_PID;
echo Agent pid 12685;

on the client, add id_rsa key.
error..
# ssh-add id_rsa
Could not open a connection to your authentication agent.

Googling this error, the solutions on this seems to be:

stop ssh-agent daemon
# ps aux | grep ssh-agent | grep -v grep
root     12685  0.0  0.0  57360   708 ?        Ss   16:23   0:00 ssh-agent
# kill 12685

start ssh-agent again.
Okey, I was able to add id_rsa
# eval `ssh-agent -s`
Agent pid 12709

# ssh-add id_rsa
Enter passphrase for id_rsa:
Identity added: id_rsa (id_rsa)

# ssh-add -l
2048 xx:xx:xx id_rsa (RSA)

access to the server.
required to enter password..
# ssh root@192.168.10.211 'whoami'
root@192.168.10.211's password:
root

Oops, I need to use hostname instead of IP
# ssh root@sshserver 'whoami'
root



dstat, netstat, sar and pidstat

here are small tips how to monitor system resources.

many thanks!

[ monitor network info with netstat ]

IP,TCP,UDP
root@ubuntu:~# netstat -s
Ip:
   150665 total packets received
   0 forwarded
   0 incoming packets discarded
   149429 incoming packets delivered
   117790 requests sent out
<snip>



TCP
root@ubuntu:~# netstat -st
IcmpMsg:
   InType3: 28
   OutType3: 582
Tcp:
   3376 active connections openings
   1 passive connection openings
   3 failed connection attempts
   421 connection resets received
   52 connections established
   138317 segments received
   106504 segments send out
<snip>

UDP
root@ubuntu:~# netstat -su
IcmpMsg:
   InType3: 28
   OutType3: 584
Udp:
   9955 packets received
   584 packets to unknown port received.
   0 packet receive errors
   10143 packets sent
UdpLite:
IpExt:
   InMcastPkts: 154
   OutMcastPkts: 168
   InOctets: 153334177
<snip>

[ monitor network info with dstat ]

install dstat
root@ubuntu:~# apt-get install dstat



root@ubuntu:~# dstat --tcp
----tcp-sockets----
lis act syn tim clo
 9   7   0   1   0
 9   7   0   1   0
 9   7   0   1   0^C
root@ubuntu:~#
root@ubuntu:~#
root@ubuntu:~# dstat --udp
--udp--
lis act
14   0
14   0
14   0
14   0^C
root@ubuntu:~#
root@ubuntu:~# dstat --net
-net/total-
recv  send
  0     0
  0     0
 60B   42B^C





[ monitor CPU, I/O resource with dstat  ]

CPU , Disk , Network etc
root@ubuntu:~# dstat -a -T
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system-- --epoch---
usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw |  epoch   
 5   1  93   0   0   0|  90k   87k|   0     0 |   0     0 |1271  2624 |1373561131
 1   1  99   0   0   0|   0     0 |   0     0 |   0     0 | 252   500 |1373561132
 1   0  99   0   0   0|   0     0 |  60B   54B|   0     0 | 229   440 |1373561133^C



root@ubuntu:~# dstat --top-cpu 1 3
-most-expensive-
 cpu process   
chromium-brow1.4
X            0.2
gnome-termina0.2
kworker/3:4  0.2




[ monitor I/O with dstat ]

block I/O , I/O
root@ubuntu:~# dstat --top-bio
----most-expensive----
 block i/o process   
init
       65k 1131B
                     
jbd2/dm-1-8   0  4096B
                     
chromium-br   0    16k^C
root@ubuntu:~#
root@ubuntu:~#
root@ubuntu:~# dstat --top-io
----most-expensive----
    i/o process      
chromium-br  50k   78k
X          3600B 1720B
X          4856B  956B^C



[ sar ]

install sysstat
root@ubuntu:~# apt-get install sysstat atsar

error
root@ubuntu:~# sar
open /var/log/atsar/atsa12: No such file or directory

change “ENABLED” option to true from false
root@ubuntu:~# egrep -i ^enable /etc/default/sysstat
ENABLED="true"

restart sysstat
root@ubuntu:~# service sysstat restart



root@ubuntu:~# sar -u 1 3

Linux  ubuntu  3.8.0-26-generic  #38-Ubuntu SMP Mon Jun 17 21:43:33 UTC 2013  x86_64  07/12/2013

01:52:45  cpu %usr %nice   %sys %irq %softirq    %wait %idle             _cpu_
01:52:45  all    1     0      2    0        0        0    98
           0    0     0      0    0        0        0   100
           1    0     0      3    0        0        0    97
           2    0     0      3    0        0        0    97
           3    0     0      0    0        0        0   100
01:52:46  all    0     0      0    0        0        0   100
           0    1     0      0    0        0        0    99
           1    0     0      0    0        0        0   100
           2    1     0      0    0        0        0    99
           3    1     0      0    0        0        0    99
01:52:47  all    0     0      0    0        0        0   100
           0    0     0      1    0        0        0    99
           1    1     0      0    0        0        0    99
           2    0     0      0    0        0        0   100
           3    0     0      0    0        0        0   100

[ pidstat ]

monitor specific processes
root@ubuntu:~# unbound-control status | grep -i pid
unbound (pid 1393) is running...

root@ubuntu:~# pidstat -u -p 1393 1 3
Linux 3.8.0-26-generic (ubuntu) 07/12/2013 _x86_64_ (4 CPU)

01:54:42 AM       PID    %usr %system  %guest    %CPU   CPU  Command
01:54:43 AM      1393    0.00    0.00    0.00    0.00     2  unbound
01:54:44 AM      1393    0.00    0.00    0.00    0.00     2  unbound
01:54:45 AM      1393    0.00    0.00    0.00    0.00     2  unbound
Average:         1393    0.00    0.00    0.00    0.00     -  unbound
root@ubuntu:~#