I recently set up Couchbase Sync Gateway on DigitalOcean. This is a note about setting Couchbase Sync Gateway with Couchbase Server on Ubuntu/DigitalOcean.
Step 1: Create Virtual Server on DigitalOcean
Before Step 1, please sign up DigitalOcean. DigitalOcean is super user friendly hosting. To create the virtual server, simply follow the tutorial How To Create Your First DigitalOcean Droplet Virtual Server.
Points:
- Size: $5/mo is good enough for development/experiment
- Droplet Region: Select closest region from my actual location. Response times from New York and San Francisco are different.
- Droplet Image: Select Ubuntu 14.04 x64. Couchbase Server 3.0.x does not support 32bit.
Step 2: Setting up Ubuntu 14.04
For setting up Ubuntu such as create new user or configure firewall, I just followed the Tutorial Series New Ubuntu 14.04 Server Checklist.
- How To Connect To Your Droplet with SSH
- Initial Server Setup with Ubuntu 14.04
- Additional Recommended Steps for New Ubuntu 14.04 Servers
Points:
- Basic Firewall: Couchbase server admin UI uses port 8091 as default, and Couchbase Sync Gateway uses 4984 for replication and 4985 for admin UI. I recommend to open these three ports (4984, 4985 and 8091) in addition to SSH port 22.
My sample configuration for opening ports
$ sudo ufw show added Added user rules (see 'ufw status' for running firewall): ufw allow 22 ufw allow 80/tcp ufw allow 443/tcp ufw allow 8091/tcp ufw allow 4984/tcp ufw allow 4985/tcp $
Step 3: Install Couchbase Server 3.0.2
1. Download Couchbase Server
Couchbase Server is downloadable from Couchbase Download. Currently (03/21/2015) Couchbase Server 3.0.2 is only for Enterprise Edition only. Go to Version 3.0.1. Select 64-bit and Community Edition, then grab download URL from Download button for Ubuntu 12.04. By using wget command, download installation package to Ubuntu server. See following command.
$ wget http://packages.couchbase.com/releases/3.0.1/couchbase-server-community_3.0.1-ubuntu12.04_amd64.deb
2. Install Couchbase Server
Install the package using the dpkg command as a privileged user under sudo.
$ sudo dpkg -i couchbase-server-community_3.0.1-ubuntu12.04_amd64.deb
3. Confirm installation
Open the URL, http://<IP address of Ubuntu server>:8091/, from your favorite browser. You can see welcome page of Couchbase Server
4. Setup Couchbase Server
As a development server, I just use all default settings. For “Per Server RAM Quota:”, I set half of hosting server’s memory. For my case, it is 256MB. Although it is lower than recommended size, I think it is good enough for development.
5. Create Data Bucket for Sync Gateway
Select “Data Buckets” Menu on the top bar. Before creating new bucket for Sync Gateway, I deleted “default” bucket because no plan to use it. After that, click “Create New Data Bucket” button. For Bucket Name, I chose “sync_gateway”. And set 256MB for “Per Node RAM Quota”.
Step 4: Install Couchbase Sync Gateway
1. Download Couchbase Sync Gateway
Couchbase Sync Gateway is also downloadable from Couchbase Download Link. You can find download link for Sync Gateway at middle of page. Current latest version of Sync Gateway is 1.0.3 (1.0.4 should be officially released soon). Select 64bit and Community Edition. For my case, if I download Sync Gateway installation package using wget and tried to install package, it fails. So I downloaded Sync Gateway installation package locally through my browser, then scp it from local computer to Ubuntu server.
2. Install Couchbase Sync Gateway
Install the package using the dpkg command as a privileged user under sudo.
$ sudo dpkg -i couchbase-sync-gateway-community_1.0.3_x86_64.deb
3. Sync Gateway configuration
The link is a default sync gateway configuration. The default setting does not allow GUEST user to access. So I created following configuration file. The difference is Authorizing Users setting.
{ "interface":":4984", "adminInterface":":4985", "log":["REST"], "databases":{ "sync_gateway":{ "users": {"GUEST": {"disabled": false, "all_channels": ["*"], "admin_channels": ["*"]}}, "server":"http://localhost:8091", "bucket":"sync_gateway", "sync":`function(doc) {channel(doc.channels);}` } } }
4. Start Sync Gateway
Following is how to start sync gateway
/opt/couchbase-sync-gateway/bin/sync_gateway ./config.json
Output just after started sync gateway
$ /opt/couchbase-sync-gateway/bin/sync_gateway ./config.json 20:03:14.925870 Enabling logging: [REST] 20:03:14.926411 ==== Couchbase Sync Gateway/1.0.3(81;fa9a6e7) ==== 20:03:14.926520 Opening db /sync_gateway as bucket "sync_gateway", pool "default", server <http://localhost:8091> 20:03:14.926674 Opening Couchbase database sync_gateway on <http://localhost:8091> 20:03:15.182813 Reset guest user to config 20:03:15.182843 Starting admin server on :4985 20:03:15.192678 Starting server on :4984 ...
5. Confirm Sync Gateway Running
To confirm replication port, open the URL, http://<IP address of Ubuntu server>:4984/, from your favorite browser. You can see welcome page of Couchbase Sync Gateway. See following.
{ "couchdb":"Welcome", "vendor":{"name":"Couchbase Sync Gateway","version":1}, "version":"Couchbase Sync Gateway/1.0.3(81;fa9a6e7)" }
To confirm admin port, pen the URL, http://<IP address of Ubuntu server>:4985/_admin/, from your favorite browser. You can see admin UI of Sync Gateway.
Next Step:
I will write about How to sync with Couchbase Lite.
dpkg -i
gives following error:
dpkg -i couchbase-sync-gateway-community_1.2.0-79_x86_64.deb
dpkg-deb: error: ‘couchbase-sync-gateway-community_1.2.0-79_x86_64.deb’ is not a debian format archive
dpkg: error processing archive couchbase-sync-gateway-community_1.2.0-79_x86_64.deb (–install):
subprocess dpkg-deb –control returned error exit status 2
Errors were encountered while processing:
couchbase-sync-gateway-community_1.2.0-79_x86_64.deb
From your article I learned a lot.Thank you very much!
What is the safe way to use CouchbaseLite with CouchDB?
@faissaal7,
Couchbase Lite supports CouchDB REST API. Couchbase Lite can directly replicates with CouchDB.
hello 🙂 I am a total Couchbase noob but after some time I got Couchbase server to run on digital ocean. in fact I could follow the steps until 4.2, the sync gateway installation on the server. Now comes the point. I completely don’t understand the further steps with the config file. I want to develop an iOS app out of interest in the technology. but do I understand it right that the config file is located on the Mac and stays there?? how is it linked to the app later? or do you only need the config file once to update the config on the server? could someone please explain to me how this works and how to do the steps 4.3 and 4.4 please? im completely lost
Hi @Sebastian_Pet,
You don’t need to write the complicated Sync Gateway configuration file if you just need basic features of Sync Gateway and Couchbase Server.
You could refer Sync Gateway Configuration file documentation.
Your iOS application just needs to know IP or hostname of Sync Gateway and Database name. These URL should be set when you create Replicators.
Couchbase Lite Replication Documentation.
Thanks,
Hideki
Hey @Hideki,
Thanks a lot for your really fast answer! but what if I want (in a later state of developing) to add something to the config file. thats the point I don’t understand. what should I do then? and the other thing I don’t understand, is the thing with the IP+ DBName. I got the ip and the port of my Couchbase server and of Sync Gateway. But I don’t have a DBName, only the Data Bucket name I created. so when I want the enter for my example http://:4984/ I only get the error {“error”:”not_found”,”reason”:”no such database \”\””}
Best regards,
Sebastian
If you have any sync gateway question, I strongly recommend posting the question to Couchbase Forum in Sync Gateway Category.
URL: https://forums.couchbase.com/c/mobile/sync-gateway
Sync Gateway URL -> http://:/. The database name is the name which is configured in sync gateway configuration file. This is not same with Couchbase Server bucket name. Couchbase Lite can not directly replicate with Couchbase Server. It can communicate with only Sync Gateway. You could use same DB name for Sync Gateway and Couchbase Server bucket name. In my sample, 4.3 sync gateway configuration file “DB name” is “sync_gateway”. I also created bucket name, “sync_gateway” in Couchbase Server.
I hope this helps you.
there went something wrong with the links above in my comment -.- it should be: [ip of server]:4984/[Name of Bucket]
and the error: {“error”:”not_found”,”reason”:”no such database \[Bucket name]\””}
Hope the links are formatted now correctly sorry
Can you post your sync gateway configuration file with hiding IP address and confidential information?
I took the configuration of your description above
{
“interface”:”:4984″,
“adminInterface”:”:4985″,
“log”:[“REST”],
“databases”:{
“sync_gateway”:{
“users”: {“GUEST”: {“disabled”: false, “all_channels”: [“*”], “admin_channels”: [“*”]}},
“server”:”[IP of Server on Digital Ocean]:8091″,
“bucket”:”sync_gateway”,
“sync”:`function(doc) {channel(doc.channels);}`
}
}
}
but the config file is on my mac on the desk, but how do i get the sync_gateway from digital ocean to adopt this configuration from the local file once, so that i can use the sync_gateway from wherever I want to after this one time? sorry if I annoy you
From config file, the database name on Sync Gateway is `sync_gateway`. Also, you need to create `sync_gateway` bucket on Couchbase Server.
You should copy this configuration file to the machine on the digital ocean. Then you can run with following command:
“`
./bin/sync_gateway ./config.json
“`
Ok thank you very much for your help, now I understand how it all works. but could you please tell me one thing, how and where to copy the config file to the digital ocean server?
@Sebastian_Pet,
> how and where to copy the config file to the digital ocean server?
You can put config file any place you want. Just Sync Gateway needs to have a read access right.