Author Archives: James Coyle

Map a Network Drive from the Windows Command Line

Get Social!

Screen Shot 2014-01-16 at 15.21.41

The windows command line can be very useful to quickly perform repetitive tasks.

It is easy to write batch scripts which combine actions and can be easily triggered from the command line.

Mapping a network drive in Windows in a common task and can be done from the command line.  The syntax is:

net use [drive letter]: /persistent:[yes|no] "\\path\to\share"

The persistent command will make the mapped drive persist over reboots.

The below example maps drive Z to a server called fileserver.jamescoyle.net and the share homes.

net use z: /persistent:yes "\\fileserver.jamescoyle.net\homes"

Synchronise a GlusterFS volume to a remote site using geo replication

Get Social!

gluster-orange-antGlusterFS can be used to synchronise a directory to a remote server on a local network for data redundancy or load balancing to provide a highly scalable and available file system.

The problem is when the storage you would like to replicate to is on a remote network, possibly in a different location, GlusterFS does not work very well. This is because GlusterFS is not designed to work when there is a high latency between replication nodes.

GlusterFS provides a feature called geo replication to perform batch based replication of a local volume to a remote machine over SSH.

The below example will use three servers:

  • gfs1.jamescoyle.net is one of the two running GlusterFS volume servers.
  • gfs2.jamescoyle.net is the second of the two running GlusterFS volume servers. gfs1 and gfs2 both server a single GlusterFS replicated volume called datastore.
  • remote.jamescoyle.net is the remote file server which the GlusterFS volume will be replicated to.

GlusterFS uses an SSH connection to the remote host using SSH keys instead of passwords. We’ll need to create an SSH key using ssh-keygen to use for our connection. Run the below command and press return when asked to enter the passphrase to create a key without a passphrase. 

ssh-keygen -f /var/lib/glusterd/geo-replication/secret.pem

The output will look like the below:

Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/lib/glusterd/geo-replication/secret.pem.
Your public key has been saved in/var/lib/glusterd/geo-replication/secret.pem.pub.
The key fingerprint is:
46:ba:02:fd:2f:9c:b9:39:ec:6c:90:50:d8:ec:7b:00 root@gfs1
The key's randomart image is:
+--[ RSA 2048]----+
|   +             |
|  E +            |
|   +    .        |
|  ..o  o         |
|  ...+. S        |
|   .+..o         |
|    .=oo         |
|     oOo         |
|     o=+.        |
+-----------------+

Now you need to copy the public certificate to your remote server in the authorized_keys file. The remote user must be a super user (currently a limitation of GlusterFS) which is root in the below example. If you have multiple GlusterFS volumes in a cluster then you will need to copy the key to all GlusterFS servers.

cat /var/lib/glusterd/geo-replication/secret.pem.pub | ssh [email protected] "cat >> ~/.ssh/authorized_keys"

Make sure the remote server has glusterfs-server installed. Run the below command to install glusterfs-server on remote.jamescoyle.net. You may need to use yum instead of apt-get for Red Hat versions of Linux.

apt-get install glusterfs-server

Create a folder on remote.jamescoyle.net which will be used for the remote replication. All data which transferrs to this machine will be stored in this folder.

mkdir /gluster
mkdir /gluster/geo-replication

Create the geo-replication volume with Gluster and replace the below values with your own:

  • [SOURCE_DATASTORE] – is the local Gluster data volume which will be replicated to the remote server.
  • [REMOTE_SERVER] – is the remote server to receive all the replication data.
  • [REMOATE_PATH] – is the path on the remote server to store the files.
gluster volume geo-replication [SOURCE_DATASTORE] [REMOTE_SERVER]:[REMOTE_PATH] start

Example:

gluster volume geo-replication datastore remote.jamescoyle.net:/gluster/geo-replication/ start

Starting geo-replication session between datastore & remote.jamescoyle.net:/gluster/geo-replication/ has been successful

Sometimes on the remote machine, gsyncd (part of the GlusterFS package) may be installed in a different location to the local GlusterFS nodes.

Your log file may show a message similar to below:

Popen: ssh> bash: /usr/lib/x86_64-linux-gnu/glusterfs/gsyncd: No such file or directory

In this scenario you can specify the config command the remote gsyncd location.

gluster volume geo-replication datastore remote.jamescoyle.net:/gluster/geo-replication config remote-gsyncd /usr/lib/glusterfs/glusterfs/gsyncd

You will then need to run the start command to start the volume synchronisation.

gluster volume geo-replication datastore remote.jamescoyle.net:/gluster/geo-replication/ start

You can view the status of your replication task by running the status command.

gluster volume geo-replication datastore remote.jamescoyle.net:/gluster/geo-replication/ status

You can stop your volume replication at any time by running the stop command.

gluster volume geo-replication datastore remote.jamescoyle.net:/gluster/geo-replication/ stop

View Available Exports on an NFS server

Tags :

Category : How-to

Get Social!

Linux penguinThere is a handy command called showmount which displays all the active folder exports on an NFS server. This can be handy when trying to connect to a new NFS export from a remote machine as you can see if the export is available in the NFS server.

Run the showmount command with the server name to check which NFS exports are available. In this example, localhost is the server name.

showmount -e localhost

The output shows the available exports and the IP which they are available from. The below example shows 3 exports available from the 10.10.10.0 IP range.

Export list for localhost:
/tmp                 10.10.10.0/24
/zfs/volume1         10.10.10.0/24
/zfs/volume2         10.10.10.0/24

Simple Bonnie++ Example

Category : How-to

Get Social!

Linux penguinBonnie++ is a disk and file system benchmarking tool for measuring I/O performance. With Bonnie++ you can quickly and easily produce a meaningful value to represent your current file system performance.

Before using Bonnie++ make sure that you have it installed on your system. In Ubuntu, use apt-get to install the bonnie++ package.

apt-get install bonnie++

Run the bonnie++ command  with the following attributes:

  • [TEST_LOCATION] – is where bonnie++ will create the benchmark operations.
  • [TEST_SIZE] – the size of the test file – this should be greater than double the RAM in your system.
  • [TEST_NAME] – this is simply a label which will be written out with the results.
  • [TEST_USER] – the user who should perform the test. This is not required if you are not running as root.
bonnie++ -d [TEST_LOCATION] -s [TEST_SIZE] -n 0 -m [TEST_NAME] -f -b -u [TEST_USER]

For example:

bonnie++ -d /tmp -s 4G -n 0 -m TEST -f -b -u james

Using uid:1000, gid:1000.
Writing intelligently...done
Rewriting...done
Reading intelligently...done
start 'em...done...done...done...done...done...
Version  1.96       ------Sequential Output------ --Sequential Input- --Random-
Concurrency   1     -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
TEST             4G           374271  39 214541  19           392015  17 +++++ +++
Latency                         167ms   89125us             52047us    4766us

1.96,1.96,TEST,1,1387339401,4G,,,,374271,39,214541,19,,,392015,17,+++++,+++,,,,,,,,,,,,,,,,,,,167ms,89125us,,52047us,4766us,,,,,,

The easiest way to understand the results of a bonnie++ test is to run the output  through the bon_csv2html utility. This perl script uses the bonnie++ results and generates a HTML page which you can later open with your web browser.

Copy the last line of the bonnie++ output into the echo command to replace [RESULTS] and alter the [OUTPUT] path to point to where you would like to save your results.

echo "[RESULTS]" | bon_csv2html > [OUTPUT]

Example command:

echo "1.96,1.96,TEST,1,1387339401,4G,,,,374271,39,214541,19,,,392015,17,+++++,+++,,,,,,,,,,,,,,,,,,,167ms,89125us,,52047us,4766us,,,,,," | bon_csv2html > /tmp/test.html

Finally open the output file with your web browser.

bonnie-results-html

See my other post on using bonnie++ to benchmark your file system.


Create a default nginx site rule

Tags :

Category : How-to

Get Social!

nginx-logoUsually a web server can be accessed by multiple paths, such as the DNS entry of the server (eg. as www.jamescoyle.net) and the IP address of the server (eg. 10.10.10.1). This is a problem when it comes to presenting a single entry point to your website.

If you use Nginx to serve your website you can add a ‘catch-all’ entry to respond to requiests which do not match an IP based or server_name attribute.

Let’s say you had an Nginx sites-enabled site which responded to www.jamescoyle.net specified by the server_name attribute.

server {
        listen       80;
        server_name  www.jamescoyle.net;
        location / {
                ...

Without a catch all entry, all requests to the server would be served as if they were requesting www.jamescoyle.net when in fact they could be using the web server IP address. Ideally, we want to handle all requests coming to www.jamescoyle.net and redirect any other requests to www.jamescoyle.net. The default_server statement in the listen command specifies that this server code block will respond if no other code blocks do. In the above example, that code block will handle all reuests to www.jamescoyle.net and all other requests will be issued a redirect.

The following code will redirect all unanswered requests to http://www.jamescoyle.net.

server {
    listen 80 default_server;
    return 301 http://www.jamescoyle.net;
}

Script to Automatically Detect and Restart Linux PPTP Client

Category : How-to

Get Social!

Linux penguinThe default PPTP client for Linux does not automatically start on boot, or restart on a failed or dropped connection. I have written a short script to ping your VPN server gateway IP address and start the PPTP client if a ping does not succeed.

See my other post if you have not yet set up your PPTP VPN client.

Create this script and make it executable:

vi /root/cron/pptp_cron.sh
chmod +x /root/cron/pptp_cron.sh

Add the below script to the file and change the following attributes for your own values:

  • your-vpn-host-or-ip-address
  • your-vpn-username
  • your-vpn-password
#!/bin/bash

HOST=your-vpn-host-or-ip-address
PPTPUSER=your-vpn-username
PPTPPASS=your-vpn-password

DATE=`date`
PINGRES=`ping -c 2 $HOST`
PLOSS=`echo $PINGRES : | grep -oP '\d+(?=% packet loss)'`
echo "$DATE : Loss Result : $PLOSS"

if [ "100" -eq "$PLOSS" ];
then
    echo "$DATE : Starting : $HOST"
    /usr/sbin/pptp pty file /etc/ppp/options.pptp user $PPTPUSER password $PPTPPASS
    echo "$DATE : Now running : $HOST"
else
    echo "$DATE : Already running : $HOST"
fi

Add the following entry to your cron to execute the script every minute.

crontab -e
 */1  * * * * /root/cron/pptp_cron.sh >> /var/log/pptp_pinger.log 2>&1

See my other post if you have not yet set up your PPTP VPN client.


Visit our advertisers

Quick Poll

Which type of virtualisation do you use?
  • Add your answer

Visit our advertisers