pirmdiena, 2012. gada 23. jūlijs

MegaCli uz Ubuntu 12.04 64

apt-get install alien
wget http://www.lsi.com/downloads/Public/MegaRAID%20Common%20Files/8.04.07_MegaCLI.zip
unzip 8.04.07_MegaCLI.zip
unzip CLI_Lin_8.04.07.zip
unzip MegaCliLin.zip
alien -k  MegaCli-8.04.07-1.noarch.rpm
apt-get install libsysfs2
ln -s /lib/libsysfs.so.2.0.1 /lib/libsysfs.so.2.0.2
/opt/MegaRAID/MegaCli/MegaCli64 -AdpAllInfo -a

svētdiena, 2012. gada 1. jūlijs

OpenVZ on KVM virtual machine. Network configuration

Required scenario:

  • Build Linux machines as OpenVZ containers  (CT101, CT102, ... ) on OpenVZ host, which itself is a KVM virtual machine KvmH on KVM virtualization host HstA
  • Both OpenVZ host KvmH and KVM host HstA uses internal network by default, but OVZ virtual hosts should be direct connected to external net or other internal nets, which are separated by VLAN's. 
  • The KVM host HstA should be connected to switch with two ethernet cards, which are bonded for redundancy/bandwidth/NAS reasons. 

HstA network configuration

OS - Ubuntu 12.04 server

... install ifenslave, bridge-utils, vlan ...

/etc/network/interfaces:
# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or
# /usr/share/doc/ifupdown/examples for more information.

auto lo 

iface lo inet loopback

auto bond0
iface bond0 inet manual
    post-up    ifenslave bond0 eth0 eth1
    pre-down ifenslave -d bond0 eth0 eth1
    dns-nameservers 10.0.0.1
    dns-search internal.example.com

## - br0 IntLAN A  - on default VLAN
auto br0
iface br0 inet manual
    up ifconfig  bond0 up
    up brctl addbr br0
    up brctl addif br0 bond0
    up brctl stp  br0 on
    up ifconfig br0 10.0.0.11 netmask 255.255.0.0
    up route add default gw 10.0.0.1
    down brctl delbr br0

## - br4 - on tagged ExtLAN VLAN4 -  (192.0.2.0/24)
auto vlan4
iface vlan4 inet manual
    up ifconfig vlan4 up
    vlan_raw_device bond0

auto br4
iface br4 inet manual
    up ifconfig vlan4 up
    up brctl addbr br4
    up brctl addif br4 vlan4
    up brctl stp br4 on
    up ifconfig br4 0.0.0.0 up
    down brctl delif br4 vlan4
    down brctl delbr br4

## - br6 - on tagged intLAN B VLAN6 -  (192.168.1.0/24)
auto vlan6
iface vlan6 inet manual
    up ifconfig vlan6 up
    vlan_raw_device bond0

auto br6
iface br6 inet manual
    up ifconfig vlan6 up
    up brctl addbr br6
    up brctl addif br6 vlan6
    up brctl stp br6 on
    # up ifconfig br6 192.168.1.2 netmask 255.255.255.0
    up ifconfig br6 0.0.0.0 up
    down brctl delif br6 vlan6
    down brctl delbr br6

##  - br8 - on tagged intLAN C VLAN8 (192.168.2.0/24)
auto vlan8
iface vlan8 inet manual
    up ifconfig vlan8 up
    vlan_raw_device bond0

auto br8
iface br8 inet manual
    up ifconfig vlan8 up
    up brctl addbr br8
    up brctl addif br8 vlan8
    up brctl stp br8 on
    # up ifconfig br8 192.168.2.2 netmask 255.255.255.0
    up ifconfig br8 0.0.0.0 up
    down brctl delif br8 vlan8
    down brctl delbr br8


/etc/modprobe.d/bonding.conf
alias bond0 bonding
options bonding mode=4 miimon=100

KvmH network configuration:


OS - CentOS 6.2

Virtual NIC eth0 is connected to br0 on HstA
Virtual NIC eth1 is connected to br4 on HstA

... install vzkernel vzctl vzquota bridge-utils ...
... configure/disable iptables, allow ip_forwarding via systctl ...

/etc/sysconfig/network-scripts/ifcfg-eth0:
DEVICE="eth0"
TYPE="Ethernet"
HWADDR="52:54:00:E3:AB:CD"
BOOTPROTO=none
ONBOOT="yes"
NM_CONTROLLED="no"
TYPE="Ethernet"
BRIDGE=vzbr0

/etc/sysconfig/network-scripts/ifcfg-vzbr0:
DEVICE=vzbr0
TYPE=Bridge
IPADDR=10.0.0.4
NETMASK=255.255.0.0
ONBOOT=yes
BOOTPROTO=static
NM_CONTROLLED=no
DEALAY=0

/etc/sysconfig/network-scripts/ifcfg-eth1:
DEVICE="eth1"
TYPE="Ethernet"
BOOTPROTO=none
ONBOOT="yes"
NM_CONTROLLED="no"
TYPE="Ethernet"
BRIDGE=vzbr4

/etc/sysconfig/network-scripts/ifcfg-vzbr4:
DEVICE=vzbr4
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=static
NM_CONTROLLED=no
DEALAY=0

/etc/sysconfig/network:
NETWORKING=yes
HOSTNAME=kvmh.int.test
GATEWAY=10.0.0.1

Prepare VZ to automatically add configured container veth interfaces to host bridges 

http://wiki.openvz.org/Virtual_Ethernet_device#Making_a_bridged_veth-device_persistent

Just create /etc/vz/vznet.conf containing the following.
#!/bin/bash
EXTERNAL_SCRIPT="/usr/sbin/vznetaddbr"

Build containers:


Download OpenVZ template:

cd /vz/template/cache
wget http://download.openvz.org/template/precreated/ubuntu-12.04-x86.tar.gz

Create container:

vzctl create 101 --ostemplate ubuntu-12.04-x86

Add veth interface:

vzctl set 101 --netif_add eth0,,,,vzbr0 --save

Start container and check if veth101.0 is added to bridge vzbr0
vzctl start 101
brctl show

Go inside container 101 (vzctl enter 101), and configure eth0 as usualy ( .. /etc/network/interfaces)

Add other containers and bridges:

vzctl create 102 --ostemplate ubuntu-12.04-x86
vzctl set 102 --netif_add eth0,,,,vzbr4 --save

vzctl create 145 --ostemplate ubuntu-12.04-x86
vzctl set 145 --netif_add eth0,,,,vzbr0 --save
vzctl set 145 --netif_add eth1,,,,vzbr4 --save




pirmdiena, 2012. gada 27. februāris

Tīkla karšu apvienošana, pieslēgšana Procurve slēdzim ar statisko LACP maģistrāli.

Angliski nosaukums varētu skanēt sekojoši:
Network interface bonding with Procurve LACP static trunk and VLAN tagging.

Ja serverim ir 2 vai vairāk tīkla kartes, tad varētu būt lietderīgi tās apvienot (NIC bonding, teaming), lai sasniegtu lielāku caurlaides spēju, kā arī nodrošinātu bojājumpiecietību.

Sekojošais tika veikts uz Ubuntu servera un Procurve tīkla slēdža.

Uz servera

Uzstādam ifenslave,  moduli un parametrus.
apt-get install ifenslave 
echo alias bond0 bonding >  /etc/modprobe.d/bonding.conf 
echo options bonding mode=4 miimon=100 >>  /etc/modprobe.d/bonding.conf
Pārbaudām, kā ielādējies bonding modulis:

===== cat /proc/net/bonding/bond0 ======
Ethernet Channel Bonding Driver: v3.2.3 (December 6, 2007)


Bonding Mode: IEEE 802.3ad Dynamic link aggregation
Transmit Hash Policy: layer2 (0)
MII Status: down
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0


802.3ad info
LACP rate: slow
bond bond0 has no active aggregator
=============================================

Konfigurējam tīkla saskarni bond0, rediģējot failu /etc/network/interfaces:


===== cat /etc/network/interfaces ======
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).


# The loopback network interface
auto lo
iface lo inet loopback


# The primary network interface
auto bond0
iface bond0 inet static
  address 10.0.0.4
netmask 255.255.0.0
gateway 10.0.0.1
post-up ifenslave bond0 eth0 eth1
pre-down ifenslave -d bond0 eth0 eth1
==============================================


Uz Procurve


Tranka izveidošana


Ja nevēlas izmantot VLAN'us, tad var vienkārši salikt visus interesējošos slēdža portus LACP active vai passive(?) modē - un piespraužot konfigurētā servera tīkla portus, autormātiski tiks izveidoti dinamiskie tranki kā Dyn1 u.t.t.. Diemžēl uz dinamiskajiem trankiem nav iespējams uzlikt VLAN marķējumus, tāpēc ir jāveido statiskie tranki:

config t 
trunk 9-10 trk5 lacp

Lai pārbaudītu izveidoto tranku:
show lacp
....

                           LACP


   PORT   LACP      TRUNK     PORT      LACP      LACP
   NUMB   ENABLED   GROUP     STATUS    PARTNER   STATUS
   ----   -------   -------   -------   -------   -------
   9      Active    Trk5      Down      No        Success
   10     Active    Trk5      Down      No        Success


VLAN'a pieslēgšana


Tos pieslēdz kā parasti, bet slēdža porta vietā jānorāda Trk5, piem.,:

vlan 8 tagged Trk5

Servera pieslēgšana trankam

Serveri pārslēgt no viena vada pieslēguma uz LACP tranku iespējams "hotswap" režīmā:

1. Pieslēdzam tīkla vadu no līdz šim neizmantotās tīkla saskarnes (piem., eth1)  Trk5 portam (piem. 10)
2. Uz servera apturam darbojošos esošo tīkla saskarni eth0 un uzreiz startējam bond0 -
 ifconfig eth0 down
 ifconfig bond0 up
3. Pēc 1-2 sekunžu pātraukuma sāk darboties bond0 tīkla saskarne
4. Pārslēdzam arī līdz šim izmantotās tīkla saskarnes (eth0)  uz jauno tranku (9. tīkla slēdža portam).

Kad serveris pieslēgts:


==== cat /proc/net/bonding/bond0  =====
Ethernet Channel Bonding Driver: v3.2.3 (December 6, 2007)


Bonding Mode: IEEE 802.3ad Dynamic link aggregation
Transmit Hash Policy: layer2 (0)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0


802.3ad info
LACP rate: slow
Active Aggregator Info:
Aggregator ID: 2
Number of ports: 2
Actor Key: 17
Partner Key: 289
Partner Mac Address: 00:1f:fe:1f:92:c0


Slave Interface: eth0
MII Status: up
Link Failure Count: 5
Permanent HW addr: 00:15:17:5e:d8:34
Aggregator ID: 2


Slave Interface: eth1
MII Status: up
Link Failure Count: 2
Permanent HW addr: 00:15:17:5e:d8:35
Aggregator ID: 2
========================================
 





piektdiena, 2011. gada 14. oktobris

Svītru kodi komandrindas režīmā

Ģenerājam PS failu ar svītru kodiem, kas atrodas failā kodi.txt.
barcode -i kodi.txt -e code39 -o mee.ps -t 7x18+5+18-5-10 -u mm

svētdiena, 2011. gada 31. jūlijs

How to create PDF photo album with ImageMagick


rinda=""; a=1 ; p=1 ;
for fails in ./*JPG
do
rinda=$rinda" "$fails[200x150]
a=$(($a+1))
if [ $a == 37 ]
then
echo "processing $p set"
montage -label '%f' -tile 6x $rinda -page A4 index-$p.pdf
a=1 ; p=$(($p+1)) ; rinda=""
fi
done
echo "processing last set"
montage -label '%f' $rinda -page A4 index-$p.pdf


Update
OMG. The following simple line just works and puts all thumbnails in one PDF file - 35 frames per PDF page.

montage -label "%f" -tile 5x7 -page A4 ../*JPG[200x150] index.pdf

piektdiena, 2011. gada 15. jūlijs

DHCP kļūda pie LTSP instalēšanas

Vasarā lēnām migrējam serverus uz jaunām versijām un virtuālām mašīnām.
Pēc DHCP servera pārcelšanas no Debian Etch uz Debian Squeeze vairs nestartējās LTSP mašīnas - LTSP Etherboot saņem gan IP adresi gan PXE, bet tālāk turpinot ielādi - apstājas.

Ar Wireshark tika noskaidrots, ka "vainīgais" ir atkārtots DHCP pieprasījums no LTSP klienta. Ja DHCPD3 uz Etch deva atpakaļ pieprasītos datus, tad DHCPD3 (isc-dhcp-server 4.1.1-P1-15+squeeze2) atmeta šādu atbildi:

...
Unexpected hash function at hash.c:53.
DHCPDISCOVER from 08:00:27:36:2e:d3 via eth0
DHCPOFFER on 10.0.3.41 to 08:00:27:36:2e:d3 via eth0
DHCPREQUEST for 10.0.3.41 (10.0.0.1) from 08:00:27:36:2e:d3 via eth0: lease 10.0.3.41 unavailable.
DHCPNAK on 10.0.3.41 to 08:00:27:36:2e:d3 via eth0
...


Risinājums tika atrasts te: http://www.nubae.com/logs/ltsp20110317_pg2.html

Jeb, failam /var/lib/tftpboot/ltsp/i386/pxelinux.cfg/default galā ir jāpieraksta "IPAPPEND 3" un tā saturs ir šāds:
default ltsp
label ltsp
kernel vmlinuz
append ro initrd=initrd.img quiet splash nbdport=2000
IPAPPEND 3

trešdiena, 2011. gada 18. maijs

Total traffic counter from MRTG log files

Script to count total traffic for last day for switch port from MRTG log files, and output file name, if total traffic is more than 10GB.


# period
sakums=`date -d -1day +%s`
# 1GB
ttrafic=$((1024*1024*1024))

pushd /var/www/mrtg
for fails in `find *log -mtime -1`
do tail -n +4 $fails |
awk -vsakums=$sakums -vfails=$fails -vttrafic=$ttrafic '{ if ($1 > sakums)
{intr += ($2*300); outtr += ($3*300) }}
END { if (outtr > 10000000000)
printf("%s\t%10.2f\t%10.2f\n",fails,intr/ttrafic,outtr/ttrafic) }'
done