Raspberry Pi instances: 2 Pi R

Source: Internet
Author: User
Tags glusterfs gluster

Many people are interested in Raspberry Pi's hardware hack function, one thing I see is Raspberry Pi's low power consumption function. I can use it to replace the Linux Server currently in use. In my previous articles, I have introduced how to use Raspberry Pi to replace these servers to manage my beer fridge and a Raspberry Pi I hosted in Australia. After hosting Raspberry Pi, I began to think about the single point of failure (spofs) of the server I was using and considered to solve it. When you see "2 Pi R" in the title of the article, you may think of the formula for calculating the circumference (C = 2PiR, Pi is the circumference rate, R is the radius), but in this article, "R" means "redundancy (redundancy )". Of course, a Raspberry Pi cannot be redundant. It must be at least two. Next I will introduce how to use two Raspberry Pi for redundancy.

This article will build an underlying framework to provide basic services for the two Raspberry Pi to achieve redundancy. First, I will use GlusterFS to build a cluster network file system. In subsequent articles, I will also introduce how to use shared storage to create other redundant services. Note that although Raspberry Pi is used in this article, the following configuration operations are also applicable to other hardware.

Configure Raspberry Pi

Download the latest Linux release from the Raspberry Pi official website and install it on two SD cards. Connect Raspberry Pi to the TV, select the kernel image and start the system as instructed in the document, and check whether the SSH service is started (SSH should be started by default ). You can use the raspi-config command to increase the root partition space to make full use of the capacity of the SD card. After confirming that the system is working and SSH is started, I can access it. I disconnected Raspberry Pi from the TV and connected it to the vswitch. I restarted the system and no interface was displayed.

By default, Raspbian obtains its network information through DHCP. However, when setting redundant services, we want Raspberry Pi to use the same IP address every time it is started. In my environment, I set up my DHCP server, which will assign them a fixed IP address when Raspberry Pi is started. You can edit the/etc/network/interfaces file:

Iface eth0 inet dhcp

Modify:

Auto eth0
Iface eth0 inet static
Address 192.168.0.121
Netmask 255.255.255.0
Gateway 192.168.0.1

Of course, you need to change the above parameters to your own parameters to ensure that each Raspberry Pi uses a different IP address. I changed the host names of the two Raspberry Pi instances so that they can be distinguished during (over SSH) login. How can I change the host name? Edit the/etc/hostname file as root. Finally, restart the system and confirm that Raspberry Pi uses the correct network configuration and host name.

Configure the GlusterFS Server

GlusterFS is a user-mode cluster file system. I chose it because it is convenient to configure a shared network file system. Select a Raspberry Pi as the master device ). You need to perform Initialization on the master device. After initialization, the master device automatically performs failover. The following is my environment:

Master hostname: pi1
Master IP: 192.168.0.121
Master brick path:/srv/gv0
Secondary hostname: pi2
Secondary IP: 192.168.0.122
Secondary brick path:/srv/gv0

Before you start, log on to the two Raspberry Pi and install the glusterfs-server package:

$ Sudo apt-get install glusterfs-server

GlusterFS stores data in devices called blocks. A "Block" is a system path that you specify for gluster. GlusterFS combines all "blocks" into a storage volume for the client. GlusterFS splits the file data into multiple parts and stores them in different "blocks. So although a "Block" seems to be a normal path, you 'd better not operate it directly in Raspberry Pi. Instead, you should access the GlusterFS service through the client to allow GlusterFS operations. In this article, I create a/srv/gv0 directory in both Raspberry Pi as the "Block" of GlusterFS ":

$ Sudo mkdir/srv/gv0

In my environment, I share the root file system on the SD card, and you may need to share a larger storage space. If so, connect the two Raspberry Pi to the USB hard disk, format the disk, and mount it to/srv/gv0. Edit the/etc/fstab file to ensure that your USB hard disk is mounted every time the system starts. The blocks on the two Raspberry Pi do not necessarily need the same name or path name, but it is no harm to set them to the same value.

Configure the "Block" path, install the glusterfs-server software package, confirm that both Raspberry Pi are working properly, and then log on to the Raspberry Pi you set as the master device, enter the "gluster peer probe" command to add the secondary device to the cluster. In my environment, I use an IP address to represent the second node. If you have more personality and have set DNS, you can also use the host name to represent this node.

Pi @ pi1 ~ $ Sudo gluster peer probe 192.168.0.122
Probe successful

So far, my pi1 (192.168.0.121) has trusted pi2 (192.168.0.122). I can create a storage volume and have all the names ready: gv0. Run the "gluster volume create" command on the master device ":

Pi @ pi1 ~ $ Sudo gluster volume create gv0 replica 2 192.168.0.121:/srv/gv0 192.168.0.122:/srv/gv0
Creation of volume gv0 has been successful. Please start
The volume to access data.

Here we will explain the meaning of the command. "Gluster volume create" is to create a new volume; "gv0" is the volume name, which will be used on the client; "replica 2" indicates that the data in this volume will be redundant between two "blocks", instead of splitting the data into two copies and saving them in two "blocks ". This command ensures that the data in the volume is copied into two copies and saved in two blocks respectively. Finally, I define two independent "blocks" as the storage space of the volume:/srv/gv0 on 192.168.0.121 and/srv/gv0 on 192.168.0.122.

Now, the volume is successfully created. I only need to start it:

Pi @ pi1 ~ $ Sudo gluster volume start gv0
Starting volume gv0 has been successful

Then I can use the "volume info" command on any Raspberry Pi to view the status:

$ Sudo gluster volume info

Volume Name: gv0
Type: Replicate
Status: Started
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: 192.168.0.121:/srv/gv0
Brick2: 192.168.0.122:/srv/gv0

Configure the GlusterFS Client

The volume has been started. Now I can mount it as a GlusterFS file system on a client that supports GlusterFS. First, I want to mount the volume on the two Raspberry Pi, so I created a mount point on both Raspberry Pi and mounted the volume with the following command:

$ Sudo mkdir-p/mnt/gluster1
$ Sudo mount-t glusterfs 192.168.0.121:/gv0/mnt/gluster1
$ Df
Filesystem 1K-blocks Used Available Use % Mounted on
Rootfs 1804128 1496464 216016 88%/
/Dev/root 1804128 1496464 216016 88%/
Devtmpfs 86184 0 86184 0%/dev
Tmpfs 18888 216 18672 2%/run
Tmpfs 5120 0 5120 0%/run/lock
Tmpfs 37760 0 37760 0%/run/shm
/Dev/mmcblk0p1 57288 18960 38328 34%/boot
192.168.0.121:/gv0 1804032 1496448 215936/mnt/gluster1

If you are a reader, you may ask: "What if I have specified an IP address and 192.168.0.121 is on the machine ?". Don't worry, this IP address is only used to specify which volume to use. When we access this volume, two "blocks" in the volume will be accessed.

After mounting the file system, try creating a file in it and check the path of the block:/srv/gv0. You should be able to see the files you created in/mngt/gluster1, which appear on the/srv/gv0 of the two Raspberry Pi, do not write data in/srv/gv0 ):

You can add the following section on/etc/fstab to automatically mount the GlusterFS volume at system startup:

192.168.0.121:/gv0/mnt/gluster1 glusterfs defaults, _ netdev 0 0

Note: If you want to access this GlusterFS volume through other clients, you only need to install a GlusterFS client (in the Debian-based release, this client is called glusterfs-client ), next, follow the instructions above to create a mount point and mount the volume.

Redundancy Test

Now let's test this redundant file system. Our goal is to access the files in the GlusterFS volume when one of the nodes fails. First, I configure an independent client to mount the GlusterFS volume, and then create a simple script file to put it in the volume. The file name is "glustertest ":

#! /Bin/bash

While [1]
Do
Date>/mnt/gluster1/test1
Cat/mnt/gluster1/test1
Sleep 1
Done

This script runs an infinite loop and prints the system time every one second. When I run this script, I can see the following information:

# Chmod a + x/mnt/gluster1/glustertest
Root @ moses :~ #/Mnt/gluster1/glustertest
Sat Mar 9 13:19:02 PST 2013
Sat Mar 9 13:19:04 PST 2013
Sat Mar 9 13:19:05 PST 2013
Sat Mar 9 13:19:06 PST 2013
Sat Mar 9 13:19:07 PST 2013
Sat Mar 9 13:19:08 PST 2013

I found that this script occasionally skips 1 second, probably because the date command is not exactly printed every second, so sometimes the output time is not used.

When I run this script, I log on to a Raspberry Pi and enter "sudo reboot" to restart the device. This script is running all the time. If the output time is not used to it, I don't know whether it is an accidental phenomenon. After the first Raspberry Pi was started, I restarted the second Raspberry Pi and confirmed that a node in the system was lost, and my program still worked properly. This redundant system requires only a few commands. If you need a redundant system, this is a good choice.

Now you have implemented a redundant file system consisting of 2 Pi R. In my next article, I will add a new redundancy service to make full use of this shared storage system.

Recommended reading:

Raspberry Pi build LAMP Server

Install a game simulator on Raspberry Pi

Install Weston on Raspberry Pi

Linux OS for Raspberry Pi is available

Raspberry Pi (Raspberry Pi) trial note

Introduction to Raspberry Pi (Raspberry Pi) installation, IP configuration, and software source

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.