Skip to content

Instantly share code, notes, and snippets.

@parkjy76
Last active April 4, 2018 01:22
Show Gist options
  • Select an option

  • Save parkjy76/22b577ef21d8fac0268fc6024bf76a10 to your computer and use it in GitHub Desktop.

Select an option

Save parkjy76/22b577ef21d8fac0268fc6024bf76a10 to your computer and use it in GitHub Desktop.
Disqueのインストール及び設定

Disque Installation & Configuration

ubuntu, disque 1.0-rc1

インストール

apt-get -y install git tcl build-essential
git clone https://github.com/antirez/disque.git
cd disque
make && make test
cp disque.conf disque.1.conf 
cp disque.conf disque.2.conf

設定

nodeを起動時に色んなオプションを指定しても良いがすでに用意されているdisque.confを二つにコピーする これを使って二つのnodeを持つクラスタを構成する。

cp disque.conf disque.1.conf 
cp disque.conf disque.2.conf

下記のdiffを参考してconfを編集

diff disque.conf disque.2.conf
< pidfile /var/run/disque.pid
---
> pidfile /var/run/disque.2.pid
45c45
< port 7711
---
> port 7712
205c205
< appendfilename "disque.aof"
---
> appendfilename "disque.2.aof"
323a324
> cluster-config-file node.2.conf

pidはデーモンで動作させる場合、appendfilenameはAOFをonにした場合に 他のnodeはかぶらないように設定する。 クラスタ構成時にcluster-config-fileも同じにかぶらないようにする。 cluster-config-fileはクラスタのnode情報が保存されるファイルでnodeを起動すると自動で生成・更新される。 もし同じファイルが指定されるとエラーでnodeが起動できなくなる。

ここでは同じマシンにportを別けてクラスタを設定する。 そのため disque.1.confは

  • port: 7711
  • cluster-config-file: node.1.conf

disque.2.confは

  • port: 7712
  • cluster-config-file: node.2.conf

に変更

node(server)の起動

デーモンではないためconsoleを別けて実行させる

src/disque-server disque.1.conf
src/disque-server disque.2.conf

実行じに警告メッセージが出たら下記の例を参考にして設定適用する。

echo "net.core.rmem_default=262144
net.core.wmem_default=262144
net.core.rmem_max=262144
net.core.somaxconn=1024
net.ipv4.tcp_max_syn_backlog=4096
net.ipv4.tcp_tw_reuse=1
net.core.wmem_max=262144
vm.swappiness=10
vm.overcommit_memory = 1
net.core.netdev_max_backlog=2048
net.ipv4.tcp_fin_timeout=30
net.ipv4.ip_local_port_range=16384 65535" >> /etc/sysctl.conf
sysctl -p
echo "#<domain>      <type>  <item>         <value>
#

*               -       nofile          65535" > /etc/security/limits.d/50-default.conf

クラスタ構成

起動時と同じにconsoleを別けて実行させる

src/disque -p 7711
src/disque -p 7712

その後各クライアントでCLUSTER INFOを入力すると下記のように出る

cluster_state:ok
cluster_known_nodes:1
cluster_reachable_nodes:0
cluster_size:1
cluster_stats_messages_sent:0
cluster_stats_messages_received:0

二つのnodeが起動中だがクラスタ化されてないためだ またCLUSTER NODESを入力して見と自分自身の情報しか表示されない

ではnode 1に接続しているクライアントを使ってCLUSTER MEETコマンドでクラスタ化して見る

127.0.0.1:7711> CLUSTER MEET 127.0.0.1 7712
OK
127.0.0.1:7711> CLUSTER INFO
cluster_state:ok
cluster_known_nodes:2
cluster_reachable_nodes:1
cluster_size:2
cluster_stats_messages_sent:60
cluster_stats_messages_received:60
127.0.0.1:7711> CLUSTER NODES
c04eed074b0b2e99323f836f09deeb652c0c00c3 127.0.0.1:7711 myself 0 0 connected
2ae8eb3b13ddf8f05546c50b43aa9720ad66d352 127.0.0.1:7712 noflags 0 1470644016992 connected

以前と違って色んな項目の値が変わっていることが分かる。 node 2に接続しているクライアントからもCLUSTER INFOCLUSTER NODESで確認して見る

そしてcluster-config-fileで指定したnode.1.confとnode.2.confの中身が変わったことも確認出来る。 さらにdisque-serverを起動したconsole両方下記のメッセージが出たことも確認出来る。

# IP address for this node updated to 127.0.0.1

クラスタから除外するときにはCLUSTER FORGET [nodeID]を使う。

特定IP帯nodeを自動で追加してくれる機能はなくクラスタを手動での管理する。 これによってsplit brainは起きないので長所の一つでもある。 でもcluster-config-fileに依存するため中身が変に変わると期待通りに動かない。

例えば 上記の構成でnode 2を停止したままnode 1の上でnode 2をCLUSTER FORGETすると問題なく出来てしまう。(cluster_reachable_nodesが更新有無とは無関係) その後node 2を起動させると node 1は単独で動作してるように表示されるがnode 2はnode 1とクラスタ化されていると表示される。 これはクラスタの情報を各nodeのcluster-config-fileで管理してさらに手動で管理されるためだ。

もちろんnode 1でnode 2をCLUSTER MEETすれば直るがCLUSTER FORGETはクラスタのすべてのnodeに問題が無い状態で実行するように注意が必要

先も簡単に言及したがcluster-config-fileに登録されているnodeとは通信が出来なくなった場合にCLUSTER INFOcluster_reachable_nodesの値が更新されるが時間が少しかかる。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment