Quick How-To: Install NFS Server & Client

nfs.png

In this tiny how-to I’ll explain you how to setup a machine as a NFS server and an other one as a client. This example was written based on my experiences on Mandriva, but all commands should almost be the same for other distributions.

First, on the server, install nfs-utils:

urpmi nfs-utils

The nfs-utils package provide a daemon for the kernel NFS server and related tools. It is a much higher level of performance than the traditional Linux NFS server used by most users.

Then edit the /etc/exports file to add the list of the local folders you wqnt to share:

[root@localhost ~]# cat /etc/exports
/mnt/hdd *(rw,insecure,all_squash)

Then, to apply change, restart the NFS server:

/etc/init.d/nfs restart

In this example I simply wanted to share the /mnt/big-disk directory and all its sub-folders with anybody, with read and write access. I did this because the server was in a closed LAN, with only one client, that’s why no security, authentification or credentials to manage.

By the way, on the server, the only required services to activate at startup are the following:

  • nfs
  • nfslock
  • portmap

On client side, you also need to install nfs-utils, in order to benefit nfslock:

urpmi nfs-utils

The latter is absolutely not required, but if it’s a good idea to have it on the client side.

Then to auto-mount the distant shared folder, add the following line to your /etc/fstab file:

192.168.1.22:/mnt/hdd /mnt/distant-hdd nfs user,noatime,rsize=8192,wsize=8192,soft 0 0

Important parameters of the line above are:

  • 192.168.1.22 = IP adress of the NFS server,
  • /mnt/hdd = path of the shared folder on the server,
  • /mnt/distant-hdd = local folder where the shared folder will be mounted.

Then, you have to modify services on the client to change their default activation state.

Following services must be started at boot:

  • nfslock
  • netfs
  • rpcidmapd

Services that must should be inactivated at boot:

  • portmap
  • nfs
  • rpcsvcgssd

Website Backup script: Incremental Backup feature added.

I’ve changed my backup strategy today, so I updated my website-backup.py script. You can find the latest version of the script on my script page.

I now use rdiff-backup in this script to keep 32 days of incremental backups. Beside this the script do a monthly full archive of the website in bzip2 format. This new strategy has reduced the total size of my backups from 64 GB to 6.7 GB. Roughly 90% of free space gain thanks to rdiff-backup ! If rdiff-backup is so efficient in my case, this is due to the existence on my websites of large files that are rarely modified (Mp3s, Flacs, RPMs, images, etc…).

Qemu: How-To Share Network Access with the Ghest OS

Qemu Network Sharing

Create a file /etc/qemu-ifup that contain:

#!/bin/sh
sudo modprobe tun
sudo /sbin/ifconfig $1 up 10.0.2.2 netmask 255.255.255.0 broadcast 10.0.2.255

# IP masquerade
sudo echo "1" > /proc/sys/net/ipv4/ip_forward
sudo /sbin/iptables -N nat
sudo /sbin/iptables -t nat -F
sudo /sbin/iptables -t nat -A POSTROUTING -s 10.0.2.15 -j MASQUERADE
sudo /sbin/iptables -t nat -A POSTROUTING -d 10.0.2.15 -o $1

Don’t forget to give it execution permissions:

chmod 755 /etc/qemu-ifup

Start qemu with the following parameters:

qemu /home/kevin/qemu-mdk10.1.img -n /etc/qemu-ifup

Setup the network in your ghest OS in qemu:

ifconfig eth0 10.0.2.15
route add default gw 10.0.2.2

Test the visibility of the guest OS from the host OS:

[root@localhost kevin]# ping 10.0.2.15
PING 10.0.2.15 (10.0.2.15) 56(84) bytes of data.
64 bytes from 10.0.2.15: icmp_seq=1 ttl=64 time=2.96 ms
64 bytes from 10.0.2.15: icmp_seq=2 ttl=64 time=0.295 ms
64 bytes from 10.0.2.15: icmp_seq=3 ttl=64 time=0.296 ms

--- 10.0.2.15 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.295/1.185/2.965/1.258 ms

Test the visibility of the host from the guest:

[root@localhost root]# ping 10.0.2.2
PING 10.0.2.2 (10.0.2.2) 56(84) bytes of data.
64 bytes from 10.0.2.2: icmp_seq=1 ttl=64 time=1.08 ms
64 bytes from 10.0.2.2: icmp_seq=2 ttl=64 time=0.433 ms
64 bytes from 10.0.2.2: icmp_seq=3 ttl=64 time=0.383 ms

--- 10.0.2.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.383/0.634/1.087/0.321 ms

Script de reconnection automatique PPP

Voici un petit script trivial en bash qui, couplé à cron, me permet de maintenir ma connexion internet 56kbps fournie par Free.fr (en attendant l’arrivée du modem ADSL):

#!/bin/bash
# Script de reconnection automatique

testconnect() {
  CONNECT=`ping -c 3 google.com | grep packets | cut -d' ' -f4`
}

doconnect() {
  logger -t reconnect Essai reconnection.
  /etc/init.d/internet restart
}

displayip() {
  IP=`/sbin/ifconfig | grep -A 1 ppp0 | grep inet | cut -d' ' -f12 | cut -d':' -f2`
  logger -t reconnect Adresse IP : "$IP"
}

logger -t reconnect Test connection.
testconnect
if [ "$CONNECT" = "0" ];
  then
    logger -t reconnect Connection perdue.
    doconnect
    testconnect
    if [ "$CONNECT" != "0" ];
      then
        logger -t reconnect Reconnection OK.
        displayip
      else
        logger -t reconnect Reconnection manquee.
    fi
  else
    logger -t reconnect Connection OK.
    displayip
fi

exit 0
# FIN