2015-02-23

Realtime bandwidth motinoring in one line

To get traffic RX/TX in Mb/s on Linux

IF=eth0 ;echo "RX\tTX" ; while true ; do A=$(awk "/$IF:/ {print \$2,\$10}" /proc/net/dev) && sleep 8 && B=$(awk "/$IF:/ {print \$2,\$10}" /proc/net/dev) && echo -n "$A $B" |awk '{print ($3 - $1)/2^20,($4 - $2)/2^20}';done

2015-02-21

How to clone machine with failing drive to another machine

A server's main disk is about to fail, you see a lot os I/O error in the /var/log/messages, it's not good.

Let's clone that server before it dies. I've choosen to clone it into a VM but the steps are exactly the same with another physical machine/disk

Create or use any existing linux machine, I'm using a toolbox VM running Ubuntu on a Xen hypervisor. Create a disk about the same size as the failing one and attach it to your toolbox machine.

If the old disk is OK, copy the whole disk using dd over the network (netcat or ssh), there is a dedicated tutorial for that here : http://matfrapp.blogspot.com/2015/01/how-to-clone-disk-using-dd-over-network.html

If the old disk is not good looking and you cannot read everything but the machine still works, here is the procedure :

- Backup the MBR ```dd if=/dev/sda of=/root/mbr bs=514 count=1```
Save the UUID of the partition on a notepad, you will need it:
ls -l /dev/disk/by-uuid

-Copy it on the new host using scp for example and restore it on the new drive
```scp failingmachine:/root/mbr /tmp/oldmbr
dd if=/tmp/oldmbr of=/dev/<freshlyattacheddrive> bs=514 count=1```

Reboot the toolbox machine so the new MBR can be read. Using fdik -l, format the partitions with the same filesystem than before.
```
mkfs.ext3 /dev/xvb2
mkfs.ext4 /dev/xvb3
mkswap /dev/xvdb4
```

Change the UUID of the freshly formated partitions to match the previous UUID
EG.  tune2fs /dev/xvdb3 -U 20e9a9d5-809c-4773-8d33-a0434c712345

Mount the partitions and Launch the copy
```
mount /dev/xvdb3 /mnt/newmachine
rsync -avP --numeric-ids --exclude='/dev' --exclude='/proc' --exclude='/sys' root@failingmachine:/ /mnt/newmachine
```
Remember to manually  create a /dev, /proc, /sys paritition otherwise the system won't boot.
```
mkdir /mnt/newmachine/proc
mkdir /mnt/newmachine/sys
mkdir /mnt/newmachine/dev
```

Delete the /mnt/newmachine/etc/udev/rules.d/70-persistent-net.rules file
edit the /mnt/newmachine/etc/network/interfaces file to match the new NIC names if the configuration if different.

That's it

2015-01-22

How to clone a disk using dd over network

!Warning: This method is hardcore and may not be used on production machines! There is a cleaner procedure at the bottom.

Required tools : dd, nc (or ssh is the link is not trusted) and one of these following tools:

  • If you have a lot of bandwith, I recommand the use of lz4
  • If you have a lot of CPU and less bandwith, go with gzip
  • If you have a extremely tiny bandwith and huge amount of CPU, use lzma but I don't recommand it


First, login on the machine you want to clone.

dd bs=16M if=/dev/vda |lz4c -c |nc 172.30.12.6 12345


Create a machine in your new environment.
Create a disk about the same size of you source disk
Attach it to a third party machine in your new environement.
root@tranfert:~# nc -l 13245|lz4 -d|dd bs=16M of=/dev/vdc


Clean Procedure:
Take a snapshot of a volume, mount this snapshot to a linux machine




2014-11-08

Installing WSO2 Identity-Server on Ubuntu 14.04

Because it's not packaged, here are the steps to install WSO2 Identity Server on Ubuntu 14.04
This tutorial is a no brain compilation of this two websites:
https://docs.wso2.com/display/IS500/WSO2+Identity+Server+Documentation
http://ubuntuhandbook.org/index.php/2014/02/install-oracle-java-6-7-or-8-ubuntu-14-04/

Use it carefully !!!


Let's go root, we'll create a user for wso2 later
$ sudo -s

Install Sun JAVA JDK 7
# add-apt-repository ppa:webupd8team/java
# apt-get update
# apt-get install oracle-java7-installer
# apt-get -y install oracle-java7-set-default
# apt-get -y install activemq unzip subversion maven

Let's create a wso2 user to run the app
# useradd --home /opt/wso2
# cd /opt/wso2
# wget http://product-dist.wso2.com/products/identity-server/5.0.0/wso2is-5.0.0.zip
# unzip wso2is-5.0.0.zip
# chown -R wso2 /opt/wso2


Let's enable boot start
# echo '#! /bin/sh
export JAVA_HOME="/usr/lib/jvm/java-7-oracle"
startcmd="/opt/wso2/wso2is-5.0.0/bin/wso2server.sh start > /dev/null &"
restartcmd="/opt/wso2/wso2is-5.0.0/bin/wso2server.sh restart > /dev/null &"
stopcmd="/opt/wso2/wso2is-5.0.0/bin/wso2server.sh stop > /dev/null &"

case "$1" in
start)
   echo "Starting WSO2 Application Server ..."
   su -c "${startcmd}" wso2
;;
restart)
   echo "Re-starting WSO2 Application Server ..."
   su -c "${restartcmd}" wso2
;;
stop)
   echo "Stopping WSO2 Application Server ..."
   su -c "${stopcmd}" wso2
;;
*)
   echo "Usage: $0 {start|stop|restart}"
exit 1
esac' > /etc/init.d/wso2-is

# chmod +x /etc/init.d/wso2-is
# update-rc.d wso2-is defaults

Finally start the service:
# service wso2-is start

and point you browser on https://[YourServerIP]:9443

Then read this documentation:
https://docs.wso2.com/display/IS500/Running+the+Product

To add soon
Add a custom SSL certificate

2014-08-05

IPv6 router behind AT&T U-Verse Motorola NVG510

I've tried for a long time to use IPv6 on a PfSense router behind the modem. The closet tutorial I found was this one on PfSense forum but I could not make it work the way I wanted. So I'll explain here how I managed to finally route my given IPv6 subnet.



AT&T Provide a /60 subnet which could easily be 'cut' into 8 pieces of /64. Only the first /64 is used by the modem for connected users so we'll play with the 7 other pieces of the cake. This should give us enough space for 129 127 208 515 967 000 000 machines.

Let's explain this with a simple table:


First, let's connect the WAN Interface of our router to any port of the modem and activate DHCPv6 client:

I could not make the subnet delegation options work properly so let's simply disable it:




By default every IPv6 compatible machine will have at least two addresses:

  • the public one
  • the link local one which is used for communications within the LAN.

Now I'm gonna grab the Link Local address of my PFSense WAN Interface


And we gonna tell the modem to send the /64 subnet to this address. To do that, let's open a console on the modem itself. I used that trick to get a CLI access on the modem:
http://earlz.net/view/2012/06/07/0026/rooting-the-nvg510-from-the-webui


After that, I just had to fire a shell by pressing ! and add these ipv6 routes :

ip -6 route add 2602:301:xxxx:xx1::/64 via fe80::215:60ff:fe0e:xxxx dev br1
ip -6 route add 2602:301:xxxx:xx2::/64 via fe80::215:60ff:fe0e:xxxx dev br1
ip -6 route add 2602:301:xxxx:xx3::/64 via fe80::215:60ff:fe0e:xxxx dev br1

That's it ! Of course the routes will be lost at the next reboot. I'm still trying to find a way to make these changes permanent without breaking the modem


Now let's use our available IPv6 subnet on the LAN side of our Router :



I'm assigning the IPv6 manually, taking the first available IP of the first subnet. Due to AT&T IPv6 in IPv4 encapsulation we should decrease the MTU to 1472 and the MSS to 1412.

Now let's setup the DHCP Server and Router advertisement on the LAN side :




Here is the result :



Popular posts