DRBDのユーザーズガイドを読んでみた

仮想化と、冗長化は、これからのサーバ管理で大事なポイントだっつーことで、DRBDについてユーザーズガイドを読んでみた。斜め読みしただけで使えることは使えるけど、ぜんぜん記憶にはのこらないので、対訳してみた。

Chapter 5. Configuring DRBD
DRBDユーザーズガイド 第5章 DRBDを設定する

Table of Contents
5章の目次

Preparing your lower-level storage
ストレージデバイスを用意する

Preparing your network configuration
ネットワークの設定をする

Configuring your resource
リソースの設定

    Example configuration
    設定例

    The global section
    globalの部分の設定

    The common section
    commonの部分の設定

    The resource sections
    resourceの欄の設定

Enabling your resource for the first time
初めて使うときに資源を利用可能にする

The initial device synchronization
デバイスの最初の同期を取る

Preparing your lower-level storage
ストレージデバイスを用意する

After you have installed DRBD, you must set aside a roughly identically sized storage area on both cluster nodes. This will become the lower-level device for your DRBD resource. You may use any type of block device found on your system for this purpose. Typical examples include:

DRBDのインストールが済んだら、それぞれのマシンで、だいたい同じサイズの記憶領域を用意します。これがDRBDがリソース(資源)として利用するデバイスです。
たいていのデバイスが使えます。
たとえば、

* A hard drive partition (or a full physical hard drive),
ハードディスク上に切った、普通のパーティション

* a software RAID device,
ソフトウェアRAIDデバイス

* an LVM Logical Volume or any other block device configured by the Linux device-mapper infrastructure,
論理ボリュームなどのLinuxのデバイスマップ機能で扱えるブロックデバイス

* an EVMS volume,
EVMSボリューム(って何ですか?)

* any other block device type found on your system.
その他、システムにくっついてるブロックデバイスはたいてい大丈夫

[Note] 注意

While it is possible to use loop devices as lower-level devices for DRBD, doing so is not recommended due to deadlock issues.

ファイルをマウントしてできたループデバイスもDRBDで利用可能ですが、ヘタをするとデッドロックに陥ることがあるのでお勧めしません。

Also, DRBD does not support device stacking, meaning you cannot use one DRBD device as a lower-level device for another. DRBD+, a commercially-licensed DRBD extension, does support resource stacking.

また、DRBDは「孫引き」もできません、すなはち、DRBDでできたデバイスを、他のDRBD構成で利用するということはできないのです。ただし、商用版のDRBD+では可能です。こうすれば、データのコピーが3つ以上にすることができます。

It is not necessary for this storage area to be empty before you create a DRBD resource from it. In fact it is a common use case to create a two-node cluster from a previously non-redundant single-server system using DRBD (some caveats apply ? please refer to the section called “DRBD meta data” if you are planning to do this).

ところで、利用する記憶領域は、空にしておく必要はありません。実のところ、DRBDの用途としては、すでに存在する(RAID構成でないため、冗長性が無い)データをバックアップする、というものが結構あるのです。ただし、そうするときには、第12章の「DRBDのメタデータ」の項目を理解しておく必要があります。既存のデータ領域に、DRBDが管理用に使うデータを置く場所が無いかもしれないからです。

For the purposes of this guide, we assume a very simple setup:
このガイドでは、以下のようなごく単純な構成を例にとります。
* Both hosts have a free (currently unused) partition named /dev/sda7.
二つのサーバは、空で、同じ名前(/dev/sda7)というパーティションを持つ

* We are using internal meta data.
メタデータは、それぞれのパーティションの中に保存する


Preparing your network configuration
ネットワークの設定をする

It is recommended, though not strictly required, that you run your DRBD replication over a dedicated connection. At the time of this writing, the most reasonable choice for this is a direct, back-to-back, Gigabit Ethernet connection. If and when you run DRBD over switches, use of redundant components and the Linux bonding driver (in active-backup mode) is recommended.

絶対に必要というわけではありませんが、DRBDによってデータの複製を行うためには、専用かつ切断されることのないネットワーク回線を割り当てることをお勧めします。望ましいのはギガビットイーサネットで直結する方法です。
ネットワークスイッチを介して接続する場合には、機器を冗長構成にして、ネットワークの障害に備えるようにしたほうが良いでしょう。

It is generally not recommended to run DRBD replication via routers, for reasons of fairly obvious performance drawbacks (adversely affecting both throughput and latency).

ルータを越えるようなネットワーク接続は避けるべきです。読み書きの転送速度と、時間遅れなどの性能が低下します。

In terms of local firewall considerations, it is important to understand that DRBD (by convention) uses TCP ports from 7788 upwards, with every TCP resource listening on a separate, configurable, but unchanging TCP port. DRBD uses two separate TCP connections (one in either direction) for every resource configured. For proper DRBD functionality, it is required that these connections are allowed by your firewall configuration.

サーバのファイアウォール(たとえばiptables)の設定について。DRBDは7788番以上のポートを使います。ポート番号はダイナミックに変化したりはしません。
1つのリソースにつき2つのポートを使って双方向にデータのやり取りします。
ファイアウォールは、これらの通信を通すような設定になっていなければなりません。

Security considerations other than firewalling may also apply if a Mandatory Access Control (MAC) scheme such as SELinux or AppArmor is enabled. You may have to adjust your local security policy so it does not keep DRBD from functioning properly.

セキュリティに関して、もうひとつのポイントは、SELinuxやAppArmorの設定です。場合によっては、現在使われているセキュリティポリシーを変更する必要があるかもしれません。

You must, of course, also ensure that the TCP ports you will be using for DRBD are not already being used by another application.

もちろん、DRBDが使うポートが、他のサービスに占有されていてはダメです。

[Note] Note 注意

It is not possible to configure a DRBD resource to support more than one TCP connection. If you want to provide for DRBD connection load-balancing or redundancy, you can easily do so at the Ethernet level (again, using the bonding driver).

ひとつのDRBDリソースについて、複数の接続を許すことはできません。もし、ロードバランスや冗長化を考えているのであれば、ネットワーク機器の側で対応してください。

For the purposes of this guide, we assume a very simple setup:
このガイドでは、次のようなシンプルな構成を想定しています。

* Our two DRBD hosts each have a currently unused network interface, eth1, with IP addresses 10.1.1.31 and 10.1.1.32 assigned to it, respectively.
それぞれのサーバでは、まだ使われていないネットワークカードがあり(eth1)、それぞれ10.1.1.31と10.1.1.32 のIPアドレスが割り当てられている

* No other services are using TCP ports 7788 through 7799 on either host.
他のサービスが7788から7799までのポートを使っていない

* The local firewall configuration allows both inbound and outbound TCP connections between the hosts over these ports.
サーバのファイアウォール設定は上記のTCP接続を拒否しない


Configuring your resource
リソースの設定

All aspects of DRBD are controlled by a single configuration file, /etc/drbd.conf. You should always make sure this configuration file is exactly identical on both participating cluster nodes.

DRBDの全ての機能は、/etc/drbd.conf というファイルで設定できる。この設定ファイルは、それぞれのサーバ(node)の間で同じでなければならない。

The DRBD source tarball contains an example configuration file in the scripts subdirectory. Binary installation packages will either install this example configuration directly in /etc, or in a package-specific documentation directory such as /usr/share/doc/packages/drbd.

DRBDのソースを集めたアーカイブファイルには、scripts/のサブディレクトリに設定例のファイルが入っている。バイナリーパッケージをインストールした場合でも、/etc のディレクトリか/usr/share/doc/packages/drbd のディレクトリに設定例が置かれる。


[Note] Note 注意

This section describes only those few aspects of the configuration file which are absolutely necessary to understand in order to get DRBD up and running. The configuration file's syntax and contents are documented in great detail in drbd.conf(5).

ここでは、DRBDを動かすのに必要最小限の設定項目だけを取り上げている。設定ファイルの文法や項目の意味については、drbd.conf のマニュアルをmanコマンドで読むことができる。

Example configuration
設定例

For the purposes of this guide, we assume a minimal setup in line with the examples given in the previous sections:

このガイドで、これまで設定してきた内容に沿った設定の例を示す。

global { 
  usage-count yes; 
}
common {
  protocol C;
}
resource r0 {
  on alice {
    device    /dev/drbd1;
    disk      /dev/sda7;
    address   10.1.1.31:7789;
    meta-disk internal;
  }
  on bob {
    device    /dev/drbd1;
    disk      /dev/sda7;
    address   10.1.1.32:7789;
    meta-disk internal;
  }
}

This example configures DRBD in the following fashion:
上記の例では次のようにDRBDを設定している

* You "opt in" to be included in DRBD's usage statistics (see below).
利用者が望めば、DRBDの利用の回数などの統計をとれる。(デフォルトでは統計は取らない)

* Resources are configured to use fully synchronous replication (Protocol C) unless explicitly specified otherwise.
特に指定がなければ、データが完全に同期するような設定になる(Cのプロトコルを選択する)

* Our cluster consists of two nodes, alice and bob.
冗長化クラスターはaliceとbobという2つのノード(サーバ)で構成される

* We have a resource arbitrarily named r0 which uses /dev/sda7 as the lower-level device, and is configured with internal meta data.
リソースには、r0(この名前は任意)という名前をつけた。このリソースは /dev/sda7 というパーティションをデバイスとして指定していて、このデバイスにメタデータを内包するようになっている。

* The resource uses TCP port 7789 for its network connections, and binds to the IP addresses 10.1.1.31 and 10.1.1.32, respectively.
リソースはTCPで7789というポートを利用し、それぞれ10.1.1.31と10.1.1.32というIPアドレスが割り当てられる。


The global section
globalの部分の設定

This section is allowed only once, preferrably at the very top of the configuration file. Of the few options available in this section, only one is of relevance to most users:

このセクションは、設定ファイルの中では1度だけしか指定されない。普通は設定ファイルの先頭に置かれる。ここで指定可能な項目はいくつかあるが、普通、使われるのは次のものだけである。

usage-count. The DRBD project keeps statistics about the usage of various DRBD versions. This is done by contacting an HTTP server every time a new DRBD version is installed on a system. This can be disabled by setting usage-count no;. The default is usage-count ask; which will prompt you every time you upgrade DRBD.

usage-count : DRBDプロジェクトは、どのバージョンのDRBDが利用されているかの統計を取っている。DRBDがインストールされるたびに、webサーバにアクセスすることでカウントしている。こういった方法でカウントされるのが嫌な場合には、

usage-count no;

とすればよい。デフォルトの設定は
usage-count ask;
であり、DRBDをアップグレードするたびに、ユーザに、通知するかしないかを尋ねる。

[Note] Note 注意

DRBD's usage statistics are, of course, publicly available: see http://usage.drbd.org.

DRBDの統計結果は誰でもアクセスできる。http://usage.drbd.org/


The common section
commonの部分の設定

This section provides a shorthand method to define configuration settings inherited by every resource. You may define any option you can also define on a per-resource basis.

このセクションは、どのリソースにも共通する設定をまとめて定義するために使われる。リソースについて指定できるすべての項目が指定できる。

Including a common section is not strictly required, but strongly recommended if you are using more than one resource. Otherwise, the configuration quickly becomes convoluted by repeatedly-used options.

commonセクションは無くてもよいが、複数のリソースを定義するときにはあったほうが良い。そうでないと、手間ばかり増えてしまうし、共通の指定を変えそこなう危険もある。

In the example above, we included protocol C; in the common section, so every resource configured (including r0) inherits this option unless it has another protocol option configured explicitly. For other synchronization protocols available, see the section called “Replication modes”.

上記の例では、commonのセクションに
protocol C;
の指定を含めた。したがって、どのリソースについても、この指定が引き継がれる。これを上書きすることも可能である。同期のプロトコルについては"Replication modes"の項目を参照のこと。

The resource sections
resouceセクション

Any DRBD resource you define must be named by specifying resource name in the configuration file. You may use any arbitrary identifier, however the name must not contain characters other than those found in the US-ASCII character set, and must also not include whitespace.

リソースには名前をつけておく必要がある。名前はどんなものでも良いが、英数字以外の文字や空白は使えない。

Every resource configuration must also have two on host sub-sections (one for every cluster node).

各リソースの設定は、どれも2つの host 項目が含まれる。それぞれ、クラスタを構成するノード(サーバ)を指定する。

All other configuration settings are either inherited from the common section (if it exists), or derived from DRBD's default settings.

resourceセクションに記載されていない項目については、commonセクションで指定があれば、その値を引き継ぎ、commonセクションにも指定がなければ、DRBDのデフォルトの値が使われることになる。

In fact, you can use a shorthand notation for the on host sub-sections, too: every option whose values are equal on both hosts may be specified directly in the resource section. Thus, we can further condense this section, in comparison with the example cited above:

さらに、もっと手間を省こうとすれば、それぞれのhostの項目で共通の指定があれば、resourceセクションの中で1度指定すれば済む。したがって、上記の例のresourceセクションは次のようにしてもっと簡単に書ける。

resource r0 {
  device    /dev/drbd1;
  disk      /dev/sda7;
  meta-disk internal;
  on alice {
    address   10.1.1.31:7789;
  }
  on bob {
    address   10.1.1.32:7789;
  }
}

This notation is available in DRBD versions 8.2.1 and above.
ただし、このような記法は、DRBDのバージョン8.2.1以降でないと利用できない。


Enabling your resource for the first time
初めて使うときに資源を利用可能にする

After you have completed initial resource configuration as outlined in the previous sections, you can bring up your resource.

前節で指定したように、リソースの初期設定ファイルができたら、今度はリソースを使えるようにすることができる。

[Note] Note 注意

Each of the following steps must be completed on both nodes.
これから行うそれぞれのステップは、両方のnodeで完了してから次に進むようにしなくてはいけない。

1. Create device metadata. This step must be completed only on initial device creation. It initializes DRBD's metadata:
デバイスのメタデータを作る。このステップは初めてデバイスを作成したときだけ実施する。次のようにdrdbadmコマンドを実行する。

      # drbdadm create-md リソース名
      v08 Magic number not found
      Writing meta data...
      initialising activity log
      NOT initialized bitmap
      New drbd meta data block sucessfully created.
      success

2. Attach. This step associates the DRBD resource with its backing device:
DRBDのリソースにデバイスを接続する。

      # drbdadm attach リソース名

3. Connect. This step connects the DRBD resource with its counterpart on the peer node:
ノードの接続。ここで、DRDBリソースを、他のノードのリソースと接続する。

      # drbdadm connect リソース名

[Tip] Tip ヒント

You may collapse the steps drbdadm attach and drbdadm connect into one, by using the shorthand command drbdadm up.

この2つのステップは、drdbadm upコマンドを使えば、いっぺんに行える。

4. Observe /proc/drbd. DRBD's virtual status file in the /proc filesystem, /proc/drbd, should now contain information similar to the following:

/proc/drbd を観察する。これはDRBDの状態を示すファイルである。このファイルの中身は、次のようになっているはずだ。

      # cat /proc/drbd
      version: 8.2.4 (api:88/proto:86-88)
      GIT-hash: fc00c6e00a1b6039bfcebe37afa3e7e28dbd92fa build by buildsystem@linbit, 2008-01-11 12:44:36
       0: cs:Connected st:Secondary/Secondary ds:Inconsistent/Inconsistent C r---
          ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0
              resync: used:0/31 hits:0 misses:0 starving:0 dirty:0 changed:0
              act_log: used:0/257 hits:0 misses:0 starving:0 dirty:0 changed:0

The Inconsistent/Inconsistent disk state is expected at this point.
ディスクの状態(ds)が Inconsistent/Inconsitent なのは、この段階では想定どおりで問題ない。

By now, DRBD has successfully allocated both disk and network resources and is ready for operation. What it does not know yet is which of your nodes should be used as the source of the initial device synchronization.

ここまでで、DRBDは正しくディスクとネットワークのリソースを割り当てられて、動作の準備が整った。ここで確認しておかなくてはならないのは、どちらのノードに同期させるかということだ。


The initial device synchronization
デバイスの最初の同期を取る

There are two more steps required for DRBD to become fully operational:
DRBDが完全に動作するまでにはあと2つのステップが必要だ。

1. Select an initial sync source. If you are dealing with newly-initialized, empty disk, this choice is entirely arbitrary. If one of your nodes already has valuable data that you need to preserve, however, it is of crucial importance that you select that node as your synchronization source. If you do initial device synchronization in the wrong direction, you will lose that data. Exercise caution.

初期の同期をとる元となるディスクを決める。もし、どちらのノードもまったく空のディスクを使うのなら、どちらが元でもかまわない。もし、どちらかのノードにすでにデータがあって、それをミラーリングしたいのであれば、それを同期元とする。ただし、この指定を間違うと貴重なデータが消えてしまうので、この指定には十分注意を払うこと(是非バックアップを取っておくこと)

2. Start the initial full synchronization. This step must be performed on only one node, only on initial resource configuration, and only on the node you selected as the synchronization source. To perform this step, issue this command:

初期同期を開始する。このステップは、同期の元となるノードで、1度だけ実行すること。次のようにコマンドを実行する。

      # drbdadm -- --overwrite-data-of-peer primary リソース名

After issuing this command, the initial full synchronization will commence. You will be able to monitor its progress via /proc/drbd. It may take some time depending on the size of the device.

このコマンドを実行したら、同期が始まる。同期の進行経過は /proc/drbd の内容を見て監視することができる。デバイスのサイズによっては、かなり時間がかかる。

By now, your DRBD device is fully operational, even before the initial synchronization has completed (albeit with slightly reduced performance). You may now create a filesystem on the device, use it as a raw block device, mount it, and perform any other operation you would with an accessible block device.

ここまでで、DRBDは完全に動作していて、初期の同期が完了していなくても(多少パフォーマンスは落ちるが)読み書きが可能である。

You will now probably want to continue with Chapter 6, Common administrative tasks, which describes common administrative tasks to perform on your resource.

さて、次は第6章に進んで、管理作業について知ることができる。