Aller au contenu

Feuille de chaleur Apache CouchDB

Apache CouchDB - Base de données de documents

Couch Apache DB est une base de données NoSQL orientée vers des documents ouverts qui utilise JSON pour les documents, HTTP pour l'API et JavaScript pour les requêtes MapReduce. Il fournit la sémantique ACID et éventuellement la cohérence via le contrôle de la concurrence multi-version.

Copier toutes les commandes Générer PDF

Sommaire

  • [Installation] (LINK_1)
  • [Opérations de base] (LINK_1)
  • [Gestion des bases de données] (LINK_1)
  • [Exploitation des documents] (LINK_1)
  • Vues et questions
  • [Mango demande] (LINK_1)
  • [Réplication] (LINK_1)
  • [Sécurité] (LINK_1)
  • [Clustering] (LINK_1)
  • [Alignement du rendement] (LINK_1)
  • [Surveiller] (LINK_1)
  • [Meilleures pratiques] (LINK_1)

Installation

Installation Ubuntu/Debian

# Add CouchDB repository
curl -L https://couchdb.apache.org/repo/keys.asc | sudo apt-key add -
echo "deb https://apache.jfrog.io/artifactory/couchdb-deb/ focal main" | sudo tee /etc/apt/sources.list.d/couchdb.list

# Update package index
sudo apt update

# Install CouchDB
sudo apt install couchdb

# Configure CouchDB during installation
# Choose standalone or clustered mode
# Set admin password

# Start CouchDB service
sudo systemctl start couchdb
sudo systemctl enable couchdb

# Check status
sudo systemctl status couchdb

# Verify installation
curl http://127.0.0.1:5984/

CentOS/RHEL Installation

# Add EPEL repository
sudo yum install epel-release

# Add CouchDB repository
sudo tee /etc/yum.repos.d/couchdb.repo << EOF
[couchdb]
name=CouchDB
baseurl=https://apache.jfrog.io/artifactory/couchdb-rpm/el7/\$basearch/
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://couchdb.apache.org/repo/keys.asc
EOF

# Install CouchDB
sudo yum install couchdb

# Start CouchDB service
sudo systemctl start couchdb
sudo systemctl enable couchdb

# Check status
curl http://127.0.0.1:5984/
```_

### Installation Docker
```bash
# Pull CouchDB image
docker pull couchdb:latest

# Run CouchDB container
docker run -d \
  --name couchdb \
  -p 5984:5984 \
  -e COUCHDB_USER=admin \
  -e COUCHDB_PASSWORD=password \
  -v couchdb-data:/opt/couchdb/data \
  couchdb:latest

# Check CouchDB
curl http://admin:password@localhost:5984/

# Docker Compose setup
cat > docker-compose.yml << EOF
version: '3.8'
services:
  couchdb:
    image: couchdb:latest
    container_name: couchdb
    ports:
      - "5984:5984"
    environment:
      - COUCHDB_USER=admin
      - COUCHDB_PASSWORD=password
    volumes:
      - couchdb-data:/opt/couchdb/data
      - couchdb-config:/opt/couchdb/etc/local.d
    restart: unless-stopped

volumes:
  couchdb-data:
  couchdb-config:
EOF

docker-compose up -d
```_

### Installation manuelle
```bash
# Download CouchDB
wget https://downloads.apache.org/couchdb/source/3.3.3/apache-couchdb-3.3.3.tar.gz

# Extract
tar -xzf apache-couchdb-3.3.3.tar.gz
cd apache-couchdb-3.3.3

# Install dependencies (Ubuntu/Debian)
sudo apt install build-essential pkg-config erlang \
  libicu-dev libmozjs-78-dev libcurl4-openssl-dev

# Configure and compile
./configure
make release

# Install
sudo cp -r rel/couchdb /opt/
sudo useradd -d /opt/couchdb couchdb
sudo chown -R couchdb:couchdb /opt/couchdb

# Create systemd service
sudo tee /etc/systemd/system/couchdb.service << EOF
[Unit]
Description=Apache CouchDB
After=network.target

[Service]
Type=simple
User=couchdb
ExecStart=/opt/couchdb/bin/couchdb
Restart=always

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl start couchdb
sudo systemctl enable couchdb

Opérations de base

Bases de l'API HTTP

# Check CouchDB status
curl http://localhost:5984/

# Get server information
curl http://localhost:5984/_up

# Get all databases
curl http://localhost:5984/_all_dbs

# Get server stats
curl http://localhost:5984/_stats

# Get active tasks
curl http://localhost:5984/_active_tasks

# Get cluster membership
curl http://localhost:5984/_membership

# Get node information
curl http://localhost:5984/_node/_local/_stats

# Authentication
curl -u admin:password http://localhost:5984/

# Using session authentication
curl -X POST http://localhost:5984/_session \
  -H "Content-Type: application/json" \
  -d '{"name": "admin", "password": "password"}'

# Get current user
curl http://localhost:5984/_session

Configuration

# Get configuration
curl http://admin:password@localhost:5984/_node/_local/_config

# Get specific configuration section
curl http://admin:password@localhost:5984/_node/_local/_config/httpd

# Set configuration value
curl -X PUT http://admin:password@localhost:5984/_node/_local/_config/httpd/bind_address \
  -d '"0.0.0.0"'

# Delete configuration value
curl -X DELETE http://admin:password@localhost:5984/_node/_local/_config/httpd/bind_address

# Restart CouchDB
curl -X POST http://admin:password@localhost:5984/_node/_local/_restart

# Common configuration locations
# /opt/couchdb/etc/local.ini
# /opt/couchdb/etc/local.d/

# Example local.ini configuration
cat > /opt/couchdb/etc/local.d/custom.ini << EOF
[httpd]
bind_address = 0.0.0.0
port = 5984

[ssl]
enable = true
cert_file = /path/to/cert.pem
key_file = /path/to/key.pem

[log]
level = info

[couchdb]
max_dbs_open = 500
EOF

Gestion des bases de données

Création et gestion de bases de données

# Create database
curl -X PUT http://admin:password@localhost:5984/mydb

# Check if database exists
curl -I http://admin:password@localhost:5984/mydb

# Get database information
curl http://admin:password@localhost:5984/mydb

# Get database stats
curl http://admin:password@localhost:5984/mydb/_stats

# List all databases
curl http://admin:password@localhost:5984/_all_dbs

# Delete database
curl -X DELETE http://admin:password@localhost:5984/mydb

# Compact database
curl -X POST http://admin:password@localhost:5984/mydb/_compact

# Get database security
curl http://admin:password@localhost:5984/mydb/_security

# Set database security
curl -X PUT http://admin:password@localhost:5984/mydb/_security \
  -H "Content-Type: application/json" \
  -d '{
    "admins": {
      "names": ["admin"],
      "roles": ["admin"]
    },
    "members": {
      "names": ["user1"],
      "roles": ["user"]
    }
  }'

# Get database changes
curl http://admin:password@localhost:5984/mydb/_changes

# Get changes with filter
curl http://admin:password@localhost:5984/mydb/_changes?include_docs=true&limit=10

# Continuous changes feed
curl http://admin:password@localhost:5984/mydb/_changes?feed=continuous

Informations sur la base de données

'``baisse

Obtenez des informations détaillées sur la base de données

boucler http://admin:password@localhost:5984/mydb.

Exemple de réponse:

{ "db_name": "mydb", L'ensemble des activités de l'UE dans le domaine de l'éducation et de la formation tout au long de la vie ont été menées à bien.