On this page
- What is Couchbase Server and what does it need?
- How do you prepare the operating system?
- How do you install Couchbase on Ubuntu or Debian?
- How do you install Couchbase on Rocky Linux or AlmaLinux?
- How do you keep the ports closed?
- How do you initialize the node?
- How do you create a bucket, a user and a first query?
- How do you back up and upgrade Couchbase?
- Questions
What is Couchbase Server and what does it need?
Couchbase Server stores JSON documents with a built-in memory cache in front of disk, and lets you query them with SQL++ (a SQL dialect for JSON). It also offers key-value access, full-text search and eventing, each as a separate service you can enable per node.
It is heavier than a typical single-purpose database. Every service reserves its own memory quota, and the server keeps a lot of working data in RAM, so plan for at least 4 GB of memory for a practical single node with the data, index and query services. A small swap file is still useful as a cushion, but the vendor advice is to keep swapping to a minimum.
This guide installs the Community Edition, which is free to use. Some features, such as encryption between cluster nodes, are reserved for the commercial edition, which shapes the network advice further down.
How do you prepare the operating system?
Turn off transparent huge pages and lower swappiness before installing. Both are standard recommendations for Couchbase, because huge pages and aggressive swapping cause latency spikes.
sudo tee /etc/systemd/system/disable-thp.service >/dev/null <<'EOF'
[Unit]
Description=Disable transparent huge pages
Before=couchbase-server.service
[Service]
Type=oneshot
ExecStart=/bin/sh -c "echo never > /sys/kernel/mm/transparent_hugepage/enabled; echo never > /sys/kernel/mm/transparent_hugepage/defrag"
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now disable-thp
cat /sys/kernel/mm/transparent_hugepage/enabled
echo "vm.swappiness = 1" | sudo tee /etc/sysctl.d/90-couchbase.conf
sudo sysctl --systemThe cat line should show [never] selected. Also make sure your server has a real hostname and a matching DNS record if you will connect to it from elsewhere; see the hostname guide.
How do you install Couchbase on Ubuntu or Debian?
Download and install the small release package, which adds the repository and signing key, then install the server package.
cd /tmp
curl -fsSLO https://packages.couchbase.com/releases/couchbase-release/couchbase-release-1.0-noarch.deb
sudo dpkg -i ./couchbase-release-1.0-noarch.deb
sudo apt update
apt policy couchbase-server-community
sudo apt install -y couchbase-server-community
cat /opt/couchbase/VERSION.txt
sudo systemctl status couchbase-server --no-pagerLook at the candidate version from apt policy and compare it with the supported platforms list in the Couchbase release notes for your Ubuntu or Debian release. The service starts at once; everything lives under /opt/couchbase, with data in /opt/couchbase/var/lib/couchbase/data.
How do you install Couchbase on Rocky Linux or AlmaLinux?
The steps mirror the Debian route, with an RPM release package and dnf.
cd /tmp
curl -fsSLO https://packages.couchbase.com/releases/couchbase-release/couchbase-release-1.0.noarch.rpm
sudo rpm -i ./couchbase-release-1.0.noarch.rpm
sudo dnf list available couchbase-server-community
sudo dnf install -y couchbase-server-community
sudo systemctl enable --now couchbase-server
cat /opt/couchbase/VERSION.txtThe packaged unit works with SELinux in enforcing mode. Add the command-line tools to your path to save typing:
echo 'export PATH=$PATH:/opt/couchbase/bin' >> ~/.bashrc
source ~/.bashrc
couchbase-cli --versionHow do you keep the ports closed?
Couchbase listens on many ports on all interfaces (8091 to 8096 for the web console and services, 11210 for key-value traffic, and more), so the firewall must keep them closed to the public. Only SSH needs to be open.
Ubuntu and Debian
sudo ufw default deny incoming
sudo ufw allow OpenSSH
sudo ufw enable
sudo ss -tlnp | grep -E "beam|memcached|indexer|cbq" | headRocky Linux and AlmaLinux
sudo firewall-cmd --list-allThe default firewalld zone already blocks the Couchbase ports. If an application server elsewhere must connect, allow only its address on the ports it uses, for example sudo ufw allow from 198.51.100.40 to any port 8091:8096 proto tcp and the same for 11210, and turn on TLS in the client SDK (Couchbase serves encrypted versions of its ports such as 18091 and 11207). For a multi-node cluster across public addresses, the Community Edition cannot encrypt traffic between nodes, so link the nodes through a WireGuard tunnel and let them talk only over that.
How do you initialize the node?
Run cluster-init once with the services and memory quotas you want. You can do the same in the web console, but the command is easier to repeat and document.
read -rsp "Admin password: " CBPASS; echo
couchbase-cli cluster-init -c 127.0.0.1 --cluster-username Administrator --cluster-password "$CBPASS" --cluster-name main --services data,index,query --cluster-ramsize 1536 --cluster-index-ramsize 512 --index-storage-setting default
couchbase-cli server-list -c 127.0.0.1 -u Administrator -p "$CBPASS"The quotas are in megabytes. On a 4 GB server, 1536 for data plus 512 for indexes leaves room for the query service and the operating system; on a larger plan raise both. Reading the password into a variable keeps it out of your shell history.
To open the web console, create a tunnel from your computer with ssh -N -L 8091:127.0.0.1:8091 deploy@198.51.100.24 and browse to http://localhost:8091.
How do you create a bucket, a user and a first query?
Create a bucket for your application, a user that can reach only that bucket, and a primary index so ad hoc queries work.
couchbase-cli bucket-create -c 127.0.0.1 -u Administrator -p "$CBPASS" --bucket shop --bucket-type couchbase --bucket-ramsize 512 --enable-flush 0
read -rsp "App password: " APPPASS; echo
couchbase-cli user-manage -c 127.0.0.1 -u Administrator -p "$CBPASS" --set --rbac-username shopapp --rbac-password "$APPPASS" --roles "bucket_full_access[shop]" --auth-domain local
cbq -e http://127.0.0.1:8091 -u Administrator -p "$CBPASS"Inside the cbq shell, try SQL++:
CREATE PRIMARY INDEX ON `shop`;
INSERT INTO `shop` (KEY, VALUE) VALUES ("order::1001", {"customer": "deploy", "total": 42.5, "status": "paid"});
SELECT META().id, s.* FROM `shop` s WHERE s.status = "paid";
\QUIT;A primary index is handy while exploring but scans everything; for production queries create secondary indexes on the fields you filter by, such as CREATE INDEX idx_status ON `shop`(status);.
How do you back up and upgrade Couchbase?
Export bucket data regularly and take a copy before every upgrade. The tools in /opt/couchbase/bin handle exports; list them with ls /opt/couchbase/bin | grep ^cb to see which ship with your edition.
sudo mkdir -p /var/backups/couchbase
sudo /opt/couchbase/bin/cbexport json -c couchbase://127.0.0.1 -u Administrator -p "$CBPASS" -b shop -f lines -o /var/backups/couchbase/shop-$(date +%F).json
ls -lh /var/backups/couchbasecbimport json loads such a file back. Copy exports off the server or combine them with the daily backups add-on. To upgrade, read the release notes for the supported upgrade path, export first, then run sudo apt install --only-upgrade couchbase-server-community or sudo dnf upgrade couchbase-server-community and check the version file again.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Couchbase Server
How much RAM does Couchbase need?
For a single node running data, index and query services, 4 GB is a practical minimum and 8 GB is more comfortable. Each service has a quota, and the operating system needs memory on top.
Can I run a cluster across cities?
Yes, but between public addresses the Community Edition sends node traffic unencrypted. Put the nodes on a WireGuard tunnel and allow the Couchbase ports only on that interface.
Why can I not reach the web console?
Port 8091 is closed in the firewall on purpose. Open an SSH tunnel and use http://localhost:8091 on your own computer.
What is the difference between Couchbase Server and CouchDB?
They are separate projects with a shared history. CouchDB is an Apache project with an HTTP API and multi-master sync; Couchbase Server is a memory-first database with SQL++ and SDKs. The CouchDB guide covers the other one.
Which bucket type should I choose?
Use the couchbase type for data that must persist. The ephemeral type keeps data only in memory and suits caches.
More in Databases
- Install MySQL 8
- Install MariaDB
- Install PostgreSQL
- Install MongoDB
- PostgreSQL JSON, arrays and special types
- PostgreSQL views, triggers and CTEs
- PostgreSQL full-text search and encryption
- MySQL keys, indexes and full-text search
- MySQL JSON, views and stored procedures
- Apache Solr search server
- Install Redis or Valkey
- Install Memcached
- Apache Cassandra cluster
- Install Apache CouchDB
- InfluxDB for time series
- Install Elasticsearch
- Back up and restore MySQL and MariaDB
- Back up and restore PostgreSQL
- MySQL users, roles and passwords
- PostgreSQL roles and permissions
- Repair a crashed MySQL table
- PostgreSQL streaming replication
- MongoDB replica set
- PostGIS for location data
- Database insight with PgHero
- ArangoDB multi-model database
- Remote database access over SSH