Skip to content

Instantly share code, notes, and snippets.

@wallyqs
Last active December 13, 2017 05:24
Show Gist options
  • Save wallyqs/426e7719f8d95f5edcfd to your computer and use it in GitHub Desktop.
Save wallyqs/426e7719f8d95f5edcfd to your computer and use it in GitHub Desktop.

Revisions

  1. Waldemar Quevedo revised this gist Aug 13, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion docker-gnatsd-cluster.org
    Original file line number Diff line number Diff line change
    @@ -147,7 +147,7 @@ cluster {
    Then start server B:

    #+BEGIN_SRC sh
    docker run -it -p 0.0.0.0:4222:4222 -p 0.0.0.0:7244:7244 --rm -v $(pwd)/conf/gnatsd-A.conf:/tmp/cluster.conf apcera/gnatsd -c /tmp/cluster.conf -p 4222 -D -V
    docker run -it -p 0.0.0.0:4222:4222 -p 0.0.0.0:7244:7244 --rm -v $(pwd)/conf/gnatsd-B.conf:/tmp/cluster.conf apcera/gnatsd -c /tmp/cluster.conf -p 4222 -D -V
    #+END_SRC

    Finally, we create another Node C. We now know the routes of A and B
  2. wallyqs revised this gist Jun 27, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion docker-gnatsd-cluster.org
    Original file line number Diff line number Diff line change
    @@ -108,7 +108,6 @@ In this scenario:
    First, we create the Node A and start up a gnatsd server with the following config:

    #+BEGIN_SRC conf :tangle conf/gnatsd-A.conf
    # Copyright 2012-2015 Apcera Inc. All rights reserved.

    # Cluster Server A

  3. wallyqs revised this gist Jun 27, 2015. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions docker-gnatsd-cluster.org
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,6 @@ Each one of those files have the following content below:
    **** gnatsd-A

    #+BEGIN_SRC conf :tangle conf/gnatsd-A.conf
    # Copyright 2012-2015 Apcera Inc. All rights reserved.

    # Cluster Server A

    @@ -44,7 +43,6 @@ cluster {
    **** gnatsd-B

    #+BEGIN_SRC conf :tangle conf/gnatsd-B.conf
    # Copyright 2012-2015 Apcera Inc. All rights reserved.

    # Cluster Server B

    @@ -64,7 +62,6 @@ cluster {
    **** gnatsd-C

    #+BEGIN_SRC conf :tangle conf/gnatsd-C.conf
    # Copyright 2012-2015 Apcera Inc. All rights reserved.

    # Cluster Server C

    @@ -133,7 +130,6 @@ Then we proceed to create the next node. We realize that the first node has ip:
    to the =routes= configuration as follows:

    #+BEGIN_SRC conf :tangle conf/gnatsd-B.conf
    # Copyright 2012-2015 Apcera Inc. All rights reserved.

    # Cluster Server B

    @@ -159,7 +155,6 @@ Finally, we create another Node C. We now know the routes of A and B
    so we can add it to its configuration:

    #+BEGIN_SRC conf :tangle conf/gnatsd-C.conf
    # Copyright 2012-2015 Apcera Inc. All rights reserved.

    # Cluster Server C

  4. wallyqs revised this gist Jun 23, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions docker-gnatsd-cluster.org
    Original file line number Diff line number Diff line change
    @@ -19,6 +19,8 @@ conf
    Each one of those files have the following content below:
    (Here I am using ip =192.168.59.103= as an example, so just replace with the proper ip from your server)

    *** Example: Setting up a cluster on 3 different servers provisioned beforehand

    **** gnatsd-A

    #+BEGIN_SRC conf :tangle conf/gnatsd-A.conf
  5. wallyqs revised this gist Jun 23, 2015. 1 changed file with 101 additions and 0 deletions.
    101 changes: 101 additions & 0 deletions docker-gnatsd-cluster.org
    Original file line number Diff line number Diff line change
    @@ -97,3 +97,104 @@ docker run -it -p 0.0.0.0:8222:8222 -p 0.0.0.0:7246:7246 --rm -v $(pwd)/conf/gna
    #+BEGIN_SRC sh
    docker run -it -p 0.0.0.0:9222:9222 -p 0.0.0.0:7248:7248 --rm -v $(pwd)/conf/gnatsd-C.conf:/tmp/cluster.conf apcera/gnatsd -c /tmp/cluster.conf -p 9222 -D -V
    #+END_SRC

    *** Example: Setting a gnatsd cluster one by one

    In this scenario:

    - We bring up A and get its ip (=nats-route://192.168.59.103:7244=)
    - Then create B and then use address of A in its configuration.
    - Get the address of B =nats-route://192.168.59.104:7246= and create C and use the addresses of A and B.

    First, we create the Node A and start up a gnatsd server with the following config:

    #+BEGIN_SRC conf :tangle conf/gnatsd-A.conf
    # Copyright 2012-2015 Apcera Inc. All rights reserved.

    # Cluster Server A

    port: 4222

    cluster {
    host: '0.0.0.0'
    port: 7244

    }
    #+END_SRC

    #+name: gnatsd-A
    #+BEGIN_SRC sh
    docker run -it -p 0.0.0.0:4222:4222 -p 0.0.0.0:7244:7244 --rm -v $(pwd)/conf/gnatsd-A.conf:/tmp/cluster.conf apcera/gnatsd -c /tmp/cluster.conf -p 4222 -D -V
    #+END_SRC

    Then we proceed to create the next node. We realize that the first node has ip:port as =192.168.59.103:7244= so we add this
    to the =routes= configuration as follows:

    #+BEGIN_SRC conf :tangle conf/gnatsd-B.conf
    # Copyright 2012-2015 Apcera Inc. All rights reserved.

    # Cluster Server B

    port: 4222

    cluster {
    host: '0.0.0.0'
    port: 7244

    routes = [
    nats-route://192.168.59.103:7244
    ]
    }
    #+END_SRC

    Then start server B:

    #+BEGIN_SRC sh
    docker run -it -p 0.0.0.0:4222:4222 -p 0.0.0.0:7244:7244 --rm -v $(pwd)/conf/gnatsd-A.conf:/tmp/cluster.conf apcera/gnatsd -c /tmp/cluster.conf -p 4222 -D -V
    #+END_SRC

    Finally, we create another Node C. We now know the routes of A and B
    so we can add it to its configuration:

    #+BEGIN_SRC conf :tangle conf/gnatsd-C.conf
    # Copyright 2012-2015 Apcera Inc. All rights reserved.

    # Cluster Server C

    port: 4222

    cluster {
    host: '0.0.0.0'
    port: 7244

    routes = [
    nats-route://192.168.59.103:7244
    nats-route://192.168.59.104:7244
    ]
    }
    #+END_SRC

    Then start it:

    #+name: gnatsd-C
    #+BEGIN_SRC sh
    docker run -it -p 0.0.0.0:4222:4222 -p 0.0.0.0:7244:7244 --rm -v $(pwd)/conf/gnatsd-C.conf:/tmp/cluster.conf apcera/gnatsd -c /tmp/cluster.conf -p 9222 -D -V
    #+END_SRC

    Now, the following should work: make a subscription to Node A then publish to Node C.
    You should be able to to receive the message without problems.

    #+BEGIN_SRC
    nats-sub -s "nats://192.168.59.103:7222" hello &

    nats-pub -s "nats://192.168.59.105:7222" hello world

    [#1] Received on [hello] : 'world'

    # GNATSD on Node C logs:
    [1] 2015/06/23 05:20:31.100032 [TRC] 192.168.59.103:7244 - rid:2 - <<- [MSG hello RSID:8:2 5]

    # GNATSD on Node A logs:
    [1] 2015/06/23 05:20:31.100600 [TRC] 10.0.2.2:51007 - cid:8 - <<- [MSG hello 2 5]
    #+END_SRC

  6. wallyqs revised this gist Jun 23, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion docker-gnatsd-cluster.org
    Original file line number Diff line number Diff line change
    @@ -81,7 +81,7 @@ cluster {

    *** Starting the containers

    Then on each one of your servers, yoう should be able to start the gnatsd image as follows:
    Then on each one of your servers, you should be able to start the gnatsd image as follows:

    #+name: gnatsd-A
    #+BEGIN_SRC sh
  7. wallyqs revised this gist Jun 23, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion docker-gnatsd-cluster.org
    Original file line number Diff line number Diff line change
    @@ -81,7 +81,7 @@ cluster {

    *** Starting the containers

    Then on each one of your servers, yo should be able to start the gnatsd image as follows:
    Then on each one of your servers, yoう should be able to start the gnatsd image as follows:

    #+name: gnatsd-A
    #+BEGIN_SRC sh
  8. wallyqs created this gist Jun 23, 2015.
    99 changes: 99 additions & 0 deletions docker-gnatsd-cluster.org
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,99 @@
    #+title: Docker GNATSD Cluster example
    #+property: header-args :mkdirp true

    Below is an example of how to setup gnatsd cluster using Docker.

    I have put 3 different configurations (one per gnatsd server) under a folder named =conf= as follows:

    #+BEGIN_SRC sh :results output code
    tree conf
    #+END_SRC

    #+BEGIN_SRC sh
    conf
    |-- gnatsd-A.conf
    |-- gnatsd-B.conf
    `-- gnatsd-C.conf
    #+END_SRC

    Each one of those files have the following content below:
    (Here I am using ip =192.168.59.103= as an example, so just replace with the proper ip from your server)

    **** gnatsd-A

    #+BEGIN_SRC conf :tangle conf/gnatsd-A.conf
    # Copyright 2012-2015 Apcera Inc. All rights reserved.

    # Cluster Server A

    port: 7222

    cluster {
    host: '0.0.0.0'
    port: 7244

    routes = [
    nats-route://192.168.59.103:7246
    nats-route://192.168.59.103:7248
    ]
    }
    #+END_SRC

    **** gnatsd-B

    #+BEGIN_SRC conf :tangle conf/gnatsd-B.conf
    # Copyright 2012-2015 Apcera Inc. All rights reserved.

    # Cluster Server B

    port: 8222

    cluster {
    host: '0.0.0.0'
    port: 7246

    routes = [
    nats-route://192.168.59.103:7244
    nats-route://192.168.59.103:7248
    ]
    }
    #+END_SRC

    **** gnatsd-C

    #+BEGIN_SRC conf :tangle conf/gnatsd-C.conf
    # Copyright 2012-2015 Apcera Inc. All rights reserved.

    # Cluster Server C

    port: 9222

    cluster {
    host: '0.0.0.0'
    port: 7248

    routes = [
    nats-route://192.168.59.103:7244
    nats-route://192.168.59.103:7246
    ]
    }
    #+END_SRC

    *** Starting the containers

    Then on each one of your servers, yo should be able to start the gnatsd image as follows:

    #+name: gnatsd-A
    #+BEGIN_SRC sh
    docker run -it -p 0.0.0.0:7222:7222 -p 0.0.0.0:7244:7244 --rm -v $(pwd)/conf/gnatsd-A.conf:/tmp/cluster.conf apcera/gnatsd -c /tmp/cluster.conf -p 7222 -D -V
    #+END_SRC

    #+name: gnatsd-B
    #+BEGIN_SRC sh
    docker run -it -p 0.0.0.0:8222:8222 -p 0.0.0.0:7246:7246 --rm -v $(pwd)/conf/gnatsd-B.conf:/tmp/cluster.conf apcera/gnatsd -c /tmp/cluster.conf -p 8222 -D -V
    #+END_SRC

    #+name: gnatsd-C
    #+BEGIN_SRC sh
    docker run -it -p 0.0.0.0:9222:9222 -p 0.0.0.0:7248:7248 --rm -v $(pwd)/conf/gnatsd-C.conf:/tmp/cluster.conf apcera/gnatsd -c /tmp/cluster.conf -p 9222 -D -V
    #+END_SRC