From 1fb3b6d77419750829b74849d65e1568f2dfea10 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 11 Mar 2019 16:07:08 +0000 Subject: [PATCH] docs: add docs on running multiple IPFS nodes (#1916) resolves #1858 License: MIT Signed-off-by: Alan Shaw --- examples/running-multiple-nodes/README.md | 66 +++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 examples/running-multiple-nodes/README.md diff --git a/examples/running-multiple-nodes/README.md b/examples/running-multiple-nodes/README.md new file mode 100644 index 0000000000..9683075b53 --- /dev/null +++ b/examples/running-multiple-nodes/README.md @@ -0,0 +1,66 @@ +# Running multiple JS IPFS nodes + +This example takes you through the process needed to run 2 or more JS IPFS nodes on the same computer. + +## Via the CLI + +Firstly, you'll want to use the `IPFS_PATH` env variable to get a different repo for each instance. Initialise a new IPFS repo like this: + +```sh +# IPFS_PATH by default is `~/.jsipfs`. +# The following instructs JS IPFS to use the path `~/.jsipfs2` instead: +IPFS_PATH=~/.jsipfs2 jsipfs init + +# Repeat this for as many nodes as you want to run... +``` + +Secondly, you'll need them to bind to different ports because otherwise bad things happen. + +With the CLI, after you've run `ipfs init` you can either edit the config file at `~/.jsipfs/config` (replacing `~/.jsipfs` with the repo path you specified above) or use the config command to update the config e.g. `ipfs config Addresses.API /ip4/0.0.0.0/tcp/4012`. Then start the node with `ipfs daemon`: + +```sh +# edit the address ports +vi ~/.jsipfs2/config + +# OR + +IPFS_PATH=~/.jsipfs2 jsipfs config Addresses.API /ip4/127.0.0.1/tcp/5012 + +# Repeat this for as many nodes as you want to run... +``` + +```sh +# ...and then start the daemon +IPFS_PATH=~/.jsipfs2 jsipfs daemon + +# Repeat this for as many nodes as you want to run... +``` + +## Programmatically + +Firstly, you'll want to pass the [`repo`](https://github.com/ipfs/js-ipfs#optionsrepo) option to the constructor to get a different repo for each instance: + +```js +// The repo path by default is `os.homedir() + '/.jsipfs'`. +new IPFS({ repo: os.homedir() + '/.jsipfs2' }) +``` + +Secondly, you'll need them to bind to different ports because otherwise bad things happen. + +To do this, simply pass the different ports to the [`config`](https://github.com/ipfs/js-ipfs#optionsconfig) constructor option. All together: + +```js +new IPFS({ + repo: os.homedir() + '/.jsipfs2', + config: { + Addresses: { + Swarm: [ + '/ip4/0.0.0.0/tcp/4012', + '/ip4/127.0.0.1/tcp/4013/ws' + ], + API: '/ip4/127.0.0.1/tcp/5012', + Gateway: '/ip4/127.0.0.1/tcp/9191' + } + } +}) +```