Quick and Easy Way to Setup OpenBazaar Server on Amazon AWS
It's been only a few weeks since OpenBazaar was open for business and it's already growing at a steady pace. This means an influx of often not very technical sellers that struggle with setting up their stores.
Installing OpenBazaar server manually is already well covered, but it takes more than that to run a server (any kind of server).
I will go through all the necessary steps to make sure your selling experience is as smooth as possible.
This tutorial is written for Ubuntu running on Amazon AWS. However, you will be able to use the info for any kind of Ubuntu and possibly any kind of Linux distribution with just very little tweaking.
Before You Start
Make sure you have an Amazon AWS account.
If you don't expect a lot of traffic I'd suggest you get the free tier for 1 year to cut the cost.
I won't go into details as the whole process is very well covered on AWS page (just make sure you choose Ubuntu for your instance):
Install OpenBazaar Server
Amazon AWS currently uses Ubuntu 14.04 LTS (Longterm Support) so I will specifically use it in my example.
SSH to your freshly installed server and make sure your run as an ordinary user (in my case "ubuntu").
whoami ubuntu
Install Dependencies
In order to run OB server separately from the client app, we need to download some more libraries.
There's a script to automate this task, but I found it didn't work well for me.
Copy and paste the following commands in your ssh terminal.
Add a Repository And Update the System
sudo add-apt-repository ppa:chris-lea/libsodium sudo apt-get update && sudo apt-get upgrade
Install All Necessary Apps, Dev-tools And Libraries
sudo apt-get install git build-essential libssl-dev libffi-dev python-dev openssl python-pip autoconf pkg-config libtool libzmq3-dev libsodium-dev
Install Crypto Package
sudo pip install cryptography
Install libzmq From Source
Go to your root home directory, download the lib, compile it from the source and install. This may take some time so be patient, please.
cd ~
git clone https://github.com/zeromq/libzmq
cd libzmq
./autogen.sh && ./configure && make -j 4
make check && sudo make install && sudo ldconfig
Install the Server
Go to your root home directory again, download the source code from the Github repository and install it.
cd ~
git clone https://github.com/OpenBazaar/OpenBazaar-Server.git
cd OpenBazaar-Server
sudo pip install -r requirements.txt
Set up OpenBazaar Server
Before you will be able to run the server we need to make sure it's configured, the service is installed and all the necessary ports are open.
Create Username And Password
To make sure no one else can connect to your server make sure you set up a custom username and password.
Replace "your_username" and "your_password" with your desired information.
sed -i -e "s/username/your_username/g; s/password/your_password/g" ob.cfg sed -i -e "s/#USERNAME/USERNAME/g; s/#PASSWORD/PASSWORD/g" ob.cfg
Open Ports
If you want to be able to connect to the server from outside of your AWS machine, you need to open specific ports.
Sign in to your AWS console and select EC2 settings from the list of Amazon Web Services.
Click "Security Groups", choose any active group ("launch-wizard-1" in my case), click "Inbound" and "Edit". A window with existing inbound traffic rules will pop up.
Add the following rules:
- UDP on port 18467
- TCP on ports 18466, 18469-18470
Start the Service
In an ideal setup, you would only need to run python openbazaard.py start -da 0.0.0.0
, but as with any services, OpenBazaar may crash from time to time.
In that case, we need to register it as a service so it starts automatically after a crash or the system reboot.
Register Upstart Service (option 1)
I've written a simple Upstart script for this. If you haven't customized the AWS setup then you just need to download the script and run it. Otherwise, make sure to modify it according to your needs.
cd /etc/init
sudo wget https://gist.githubusercontent.com/mariodian/d2f3e20b9e83d3bf339cf7da66b33f1f/raw/bde389b5810dd007a1c760bc316b93a6c39d7d68/openbazaar.conf
sudo chmod 644 openbazaar.conf
If you made any changes to the file please make sure the syntax is valid:
init-checkconf -d /etc/init/openbazaar.conf
Register Systemd (option 2)
Recent versions of Ubuntu moved over to Systemd. If you get errors running the above script you'll need to install the following one.
cd /lib/systemd/system/
sudo wget https://gist.github.com/mariodian/0bec5f6671ae56b283fcf769bd4f55d9/raw/f5a7a565ac0406db3c82af788e3c130304ef44c1/openbazaar.service
sudo chmod 644 openbazaar.service
sudo systemctl enable openbazaar.service
Please change it according to your system environment. Pay extra attention to commands ExecStart
and ExecStop
.
ExecStart=/bin/sh /home/pi/bin/ob.sh start
ExecStop=/bin/sh /home/pi/bin/ob.sh stop
I had some problems running OB directly from the service script. So I made a simple script which runs OB instance instead.
It's a nasty hack but it works.
In case you wanna use it run the following:
mkdir ~/bin
cd ~/bin
wget https://gist.github.com/mariodian/b70d8753e23441abb2bead2bbcce93f1/raw/e990c74f04798eac51f48b80addfcf34c84bc61a/ob.sh
chmod 755 ob.sh
Register SysV Service (option 3)
If you cannot use any of above scripts for some reason I've written a SysV script for the more traditional approach.
However, SysV will not start your service automatically after a crash!
cd /etc/init.d
sudo wget https://gist.githubusercontent.com/mariodian/bf42adc0f374ddfdc9c1979da72211bb/raw/d1fda059b06ced4173618ab436801743aae58ed7/openbazaar
sudo chmod 755 openbazaar
sudo update-rc.d openbazaar enable
Run the Service
Everything's good, start the service now.
sudo service openbazaar start
If it doesn't output any error, you can jump straight to the next step. If it does, leave a comment below and maybe I'll be able to help you.
Connect to Your Server
It's time to test your OpenBazaar setup.
Open up your AWS console again, go to "EC2" and view your instance.
In a "Description" tab look for a "Public IP" field. That's your IP address you want to connect to with your OpenBazaar client.
Open your OB client, fill out the login form with the above IP, username and password you set up earlier and click "Save Changes".
If you did everything correctly you should be connected in a few seconds.
Please let me know in the comments below if you run into problems. For an immediate help, please visit OpenBazaar's slack channel.
P.S. OpenBazar 2.0 alpha is out. Have a look at my tutorial on how to install it.
Do You Struggle with Amazon AWS?
Check out this great book that will teach you about the most important services on AWS.
You will also learn about best practices regarding automation, security, high availability, and scalability.
Amazon Web Services in Action, Third Edition: An in-depth guide to AWS
Amazon Web Services in Action: An in-depth guide to AWS has helped thousands of developers succeed with the AWS cloud. This hands-on guide gives a complete introduction to computing, storage, and networking, along with best practices for all core AWS services.