You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Ubuntu 16.04 AWS EC2实例上运行两个不同端口的CouchDB 2.1实例

Hey there! Let's walk through setting up two separate CouchDB 2.1 instances on your Ubuntu 16.04 AWS EC2 instance, each running on a different port. Here's a step-by-step guide that should get you sorted:

1. Prepare Your EC2 Instance & Install the First CouchDB Instance

First, let's get your system updated and install the base CouchDB 2.1 package:

  • Update your package list and upgrade existing packages:
    sudo apt-get update && sudo apt-get upgrade -y
    
  • Install required dependencies for adding external repositories:
    sudo apt-get install -y apt-transport-https ca-certificates
    
  • Add CouchDB's official GPG key to verify package integrity:
    curl https://apache.bintray.com/couchdb-deb/bintray-pubkey.asc | sudo apt-key add -
    
  • Add the CouchDB repository to your system:
    echo "deb https://apache.bintray.com/couchdb-deb xenial main" | sudo tee /etc/apt/sources.list.d/couchdb.list
    
  • Install CouchDB 2.1.1 (we'll specify the exact version to avoid unexpected updates):
    sudo apt-get update && sudo apt-get install -y couchdb=2.1.1
    

During installation, you'll be prompted to configure the first instance:

  • Set the bind address to 0.0.0.0 (so it's accessible from your EC2 instance's network)
  • Keep the default port 5984 unless you have a reason to change it
  • Set an admin username and password (make sure to note these down!)
2. Configure the Second CouchDB Instance

We need a separate set of directories and config files for the second instance to avoid conflicts:

  • Create dedicated directories for data, config, and logs:
    sudo mkdir -p /var/lib/couchdb2 /etc/couchdb2 /var/log/couchdb2
    
  • Copy the default CouchDB config files to the new config directory:
    sudo cp /etc/couchdb/*.ini /etc/couchdb2/
    
  • Set proper ownership so the couchdb user can access these directories:
    sudo chown -R couchdb:couchdb /var/lib/couchdb2 /etc/couchdb2 /var/log/couchdb2
    

Now edit the second instance's config file (/etc/couchdb2/local.ini) with these key changes:

  • Change the port: Look for the port field under the [httpd] section and set it to 5985 (or any other unused port)
  • Update data directory: Modify database_dir under [couchdb] to /var/lib/couchdb2
  • Update log path: Under [log], change file to /var/log/couchdb2/couchdb.log
  • Generate a unique UUID: Run uuidgen in your terminal to create a new UUID, then replace the uuid field under [couchdb] with this value (prevents conflicts between instances)
  • Optional: Set a different admin: If you want separate admin credentials for the second instance, update the admin field under [admins]
3. Set Up a Systemd Service for the Second Instance

To manage the second instance easily (start/stop/auto-start on boot), create a systemd service file:

  • Create the service file:
    sudo nano /etc/systemd/system/couchdb2.service
    
  • Paste the following content into the file:
    [Unit]
    Description=CouchDB 2.1 Instance (Port 5985)
    Documentation=https://couchdb.apache.org/docs/2.1.0/
    After=network.target
    
    [Service]
    Type=simple
    User=couchdb
    Group=couchdb
    ExecStart=/usr/bin/couchdb -c /etc/couchdb2/local.ini
    Restart=always
    RestartSec=5
    
    [Install]
    WantedBy=multi-user.target
    
  • Save and exit, then reload systemd to recognize the new service:
    sudo systemctl daemon-reload
    
  • Start the second instance and enable it to launch on boot:
    sudo systemctl start couchdb2 && sudo systemctl enable couchdb2
    
4. Verify Both Instances Are Running

Let's confirm everything works as expected:

  • Check the first instance (port 5984):
    curl http://localhost:5984/
    
    You should get a JSON response like this:
    {"couchdb":"Welcome","version":"2.1.1","git_sha":"non-git","uuid":"your-first-uuid","features":["scheduler"],"vendor":{"name":"The Apache Software Foundation"}}
    
  • Check the second instance (port 5985):
    curl http://localhost:5985/
    
    You'll get a similar response, but with the unique UUID you set earlier.

If you need to access these instances from outside your EC2 instance, make sure your AWS security group allows inbound traffic on ports 5984 and 5985. You can then test access using your EC2 public IP:

curl http://<your-ec2-public-ip>:5984/
curl http://<your-ec2-public-ip>:5985/
5. Quick Tips
  • Port conflicts: If either instance fails to start, check if the port is in use with netstat -tulpn | grep 598
  • Web interface: Access the Fauxton web UI for each instance at http://<your-ip>:5984/_utils and http://<your-ip>:5985/_utils (use your admin credentials to log in)
  • Resource limits: Ensure your EC2 instance has enough CPU and memory to handle both instances—start with a t2.medium if you're unsure
  • Backup: Regularly back up both data directories (/var/lib/couchdb and /var/lib/couchdb2) or use CouchDB's built-in backup tools

内容的提问来源于stack exchange,提问作者shikhar bansal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:53:53