Skip to content

Instantly share code, notes, and snippets.

@sanderpick
Last active March 7, 2022 00:12
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save sanderpick/8660d93abd7cef3c8372565081e280fe to your computer and use it in GitHub Desktop.
Save sanderpick/8660d93abd7cef3c8372565081e280fe to your computer and use it in GitHub Desktop.
Install an ipfs-cluster peer on Amazon Linux.
#!/usr/bin/env bash
set -e
[ -z "$CLUSTER_SECRET" ] && echo "Need to set CLUSTER_SECRET" && exit 1;
echo 'export IPFS_PATH=/data/ipfs' >>~/.bash_profile
echo 'export IPFS_CLUSTER_PATH=/data/ipfs-cluster' >>~/.bash_profile
source ~/.bash_profile
# ipfs daemon
wget https://dist.ipfs.io/go-ipfs/v0.4.15/go-ipfs_v0.4.15_linux-amd64.tar.gz
tar xvfz go-ipfs_v0.4.15_linux-amd64.tar.gz
rm go-ipfs_v0.4.15_linux-amd64.tar.gz
sudo mv go-ipfs/ipfs /usr/local/bin
rm -rf go-ipfs
# ipfs cluster service
wget https://dist.ipfs.io/ipfs-cluster-service/v0.4.0/ipfs-cluster-service_v0.4.0_linux-amd64.tar.gz
tar xvfz ipfs-cluster-service_v0.4.0_linux-amd64.tar.gz
rm ipfs-cluster-service_v0.4.0_linux-amd64.tar.gz
sudo mv ipfs-cluster-service/ipfs-cluster-service /usr/local/bin
rm -rf ipfs-cluster-service
# ipfs cluster ctl
wget https://dist.ipfs.io/ipfs-cluster-ctl/v0.4.0/ipfs-cluster-ctl_v0.4.0_linux-amd64.tar.gz
tar xvfz ipfs-cluster-ctl_v0.4.0_linux-amd64.tar.gz
rm ipfs-cluster-ctl_v0.4.0_linux-amd64.tar.gz
sudo mv ipfs-cluster-ctl/ipfs-cluster-ctl /usr/local/bin
rm -rf ipfs-cluster-ctl
# init ipfs
sudo mkdir -p $IPFS_PATH
sudo chown ec2-user:ec2-user $IPFS_PATH
ipfs init -p server
ipfs config Datastore.StorageMax 100GB
# uncomment if you want direct access to the instance's gateway
#ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080
# init ipfs-cluster-service
sudo mkdir -p $IPFS_CLUSTER_PATH
sudo chown ec2-user:ec2-user $IPFS_CLUSTER_PATH
ipfs-cluster-service init
if [ ! -z "$CLUSTER_BOOTSTRAP" ]; then
sed -i -e "s;\"bootstrap\": \[\];\"bootstrap\": [\"${CLUSTER_BOOTSTRAP}\"];" "${IPFS_CLUSTER_PATH}/service.json"
fi
sed -i -e 's;127\.0\.0\.1/tcp/9095;0.0.0.0/tcp/9095;' "${IPFS_CLUSTER_PATH}/service.json"
# ipfs systemctl service
sudo bash -c 'cat >/lib/systemd/system/ipfs.service <<EOL
[Unit]
Description=ipfs daemon
[Service]
ExecStart=/usr/local/bin/ipfs daemon --enable-gc
Restart=always
User=ec2-user
Group=ec2-user
Environment="IPFS_PATH=/data/ipfs"
[Install]
WantedBy=multi-user.target
EOL'
# ipfs-cluster systemctl service
sudo bash -c 'cat >/lib/systemd/system/ipfs-cluster.service <<EOL
[Unit]
Description=ipfs-cluster-service daemon
Requires=ipfs.service
After=ipfs.service
[Service]
ExecStart=/usr/local/bin/ipfs-cluster-service daemon
Restart=always
User=ec2-user
Group=ec2-user
Environment="IPFS_CLUSTER_PATH=/data/ipfs-cluster"
[Install]
WantedBy=multi-user.target
EOL'
# enable the new services
sudo systemctl daemon-reload
sudo systemctl enable ipfs.service
sudo systemctl enable ipfs-cluster.service
# start the ipfs-cluster-service daemon (the ipfs daemon will be started first)
sudo systemctl start ipfs-cluster
@sanderpick
Copy link
Author

sanderpick commented Feb 26, 2018

Usage

First node (node_0) setup

$ export CLUSTER_SECRET=$(od  -vN 32 -An -tx1 /dev/urandom | tr -d ' \n')
$ echo $CLUSTER_SECRET
<secret> <-- other nodes must also use this secret

Jump down to Run the installer.

Other nodes (node_n>0) setup

On node_0 after running the installer,

$ journalctl -u ipfs-cluster -n10

In the above log output, look under the line INFO cluster: IPFS Cluster v0.3.0 listening on: cluster.go:91 and make a note of the full non-loopback ip4 cluster multiaddress (cluster.listen_multiaddress). This will reference your instance's private IP address and will be used to bootstrap other nodes.

Back to other nodes (node_n>0),

$ export CLUSTER_SECRET=<node_0 secret>
$ export CLUSTER_BOOTSTRAP=<node_0 cluster.listen_multiaddress w/ instance private IP>

Run the installer

$ wget https://gist.github.com/sanderpick/8660d93abd7cef3c8372565081e280fe/raw/7bb5f062bd6f05b52318a95c15b671c3436a38dd/install.sh && bash install.sh

Sanity check

$ sudo systemctl status ipfs
$ sudo systemctl status ipfs-cluster

Tail Cluster Logs

$ journalctl -u ipfs-cluster --follow

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