CouchDB 安装和使用

CouchDB 安装和使用

一、前言

CouchDB是用Erlang开发的面向文档的数据库系统,2010年7月14日发布了1.0版本。CouchDB不是一个传统的关系数据库,而是面向文档的数据库,其数据存储方式有点类似lucene的index文件格式,CouchDB最大的意义在于它是一个面向web应用的新一代存储系统,事实上,CouchDB的口号就是:下一代的Web应用存储系统。

CouchDB 可以安装在大部分 POSIX 系统上,包括 Linux® 和 Mac OS X。Version 2.2.0开始正式支持Windows (x64)。CouchDB 可以从源文件安装,也可以使用包管理器安装(比如在 Mac OS X 上使用 MacPorts)。

CouchDB 是一个顶级 Apache Software Foundation 开源项目,根据 Apache 许可 V2.0 发布。这个开源许可允许在其他软件中使用这些源代码,并根据需要进行修改,但前提是遵从版权需知和免责声明。与许多其他开源许可一样,这个许可允许用户根据需求使用、修改和分发该软件。不一定由同一个许可包含所有修改,因为我们仅维护一个 Apache 代码使用许可需知。

数据库引擎选型-db-engines

Editorial information provided by DB-Engines
NameCouchDB info XMongoDB X
DescriptionA native JSON - document store inspired by Lotus Notes, scalable from globally distributed server-clusters down to mobile phones.One of the most popular document stores available both as a fully managed cloud service and for deployment on self-managed infrastructure
Primary database modelDocument storeDocument store
Secondary database modelsSpatial DBMS infoSpatial DBMS Search engine info Time Series DBMS info
DB-Engines Ranking inforanking trendTrend ChartScore16.80Rank#40 Overall#6 Document storesScore487.35Rank#5 Overall#1 Document stores
Websitecouchdb.apache.orgwww.mongodb.com
Technical documentationdocs.couchdb.org/­en/­stabledocs.mongodb.com/­manual
DeveloperApache Software Foundation infoMongoDB, Inc
Initial release20052009
Current release3.1.1, September 20205.0, July 2021
License infoOpen Source infoOpen Source info
Cloud-based only infonono info
DBaaS offerings (sponsored links) infoMongoDB Atlas: Global multi-cloud database with unmatched data distribution and mobility across AWS, Azure, and Google Cloud, built-in automation for resource and workload optimization, and so much more.ScaleGrid for MongoDB: Fully managed hosting for MongoDB database on AWS, Azure and DigitalOcean with high availability and SSH access on the #1 multi-cloud DBaaS.
Implementation languageErlangC++
Server operating systemsAndroid BSD Linux OS X Solaris WindowsLinux OS X Solaris Windows
Data schemeschema-freeschema-free info
Typing infonoyes info
XML support infono
Secondary indexesyes infoyes
SQL infonoRead-only SQL queries via the MongoDB Connector for BI
APIs and other access methodsRESTful HTTP/JSON APIproprietary protocol using JSON
Supported programming languagesC C# ColdFusion Erlang Haskell Java JavaScript Lisp Lua Objective-C OCaml Perl PHP PL/SQL Python Ruby SmalltalkActionscript info C C# C++ Clojure info ColdFusion info D info Dart info Delphi info Erlang Go Groovy info Haskell Java JavaScript Lisp info Lua info MatLab info Perl PHP PowerShell info Prolog info Python R info Ruby Rust Scala Smalltalk info Swift
Server-side scripts infoView functions in JavaScriptJavaScript
Triggersyesyes info
Partitioning methods infoSharding infoSharding info
Replication methods infoMulti-source replication Source-replica replicationMulti-Source deployments with MongoDB Atlas Global Clusters Source-replica replication
MapReduce infoyesyes
Consistency concepts infoEventual ConsistencyEventual Consistency Immediate Consistency info
Foreign keys infonono info
Transaction concepts infono infoMulti-document ACID Transactions with snapshot isolation
Concurrency infoyes infoyes
Durability infoyesyes info
In-memory capabilities infonoyes info
User concepts infoAccess rights for users can be defined per databaseAccess rights for users and roles

二、软件下载及安装

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://couchdb.apache.org/repo/couchdb.repo
sudo yum install -y couchdb

三、系统配置

1.防火墙设置

Port NumberProtocolRecommended bindingUsage
5984tcpAs desired, by default localhostStandard clustered port for all HTTP API requests
4369tcpAll interfaces by defaultErlang port mapper daemon (epmd)
Random above 1024 (see below)tcpAutomaticCommunication with other CouchDB nodes in the cluster
  • 单机
firewall-cmd --zone=public --add-port=5984/tcp --permanent
firewall-cmd --reload
  • 集群
firewall-cmd --zone=public --add-port=5984/tcp --permanent
firewall-cmd --zone=public --add-port=4369/tcp --permanent
firewall-cmd --zone=public --add-port=9100-9200/tcp --permanent
firewall-cmd --reload

注意:9100-9200范围端口(默认1024以上的随机端口)需要额外配置etc/vm.args

ports-and-firewalls

2.关闭SeLinux

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
sed -i 's/SELINUX=permissive/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
getenforce

四、软件配置

1.修改couchdb配置文件

local.ini文件中行注释使用;开头

cd /opt/couchdb/etc
vim local.ini
  • 开放对外访问

[chttpd]属性组增加如下内容

port = 5984
bind_address = 0.0.0.0
  • 增加admin超级管理员(注意:此处必须配置,否则服务无法正常启动!),CouchDB支持Basic认证、Cookie认证、代理认证、JWT认证。

[admins]属性组增加如下内容,然后重启couchdb服务,再次查看该属性发现已被成功加密

admin = 123456

加密结果

[admins]
admin = -pbkdf2-b09c0c717e94dbde090764cffab07be6c0137449,04549b1e4d812eb9d6c8e2f255765657,10
  • 修改数据目录
mkdir -p /home/couchdb
chown -R couchdb:couchdb /home/couchdb

默认数据目录和view索引目录为/var/lib/couchdb,可通过在[couchdb]属性组增加如下内容

[couchdb]
database_dir = /home/couchdb
view_index_dir = /home/couchdb
  • 日志目录

默认配置在/opt/couchdb/etc/default.d/10-filelog.ini(默认值/var/log/couchdb/couchdb.log),可在local.ini配置文件中覆盖该配置。

cat /var/log/couchdb/couchdb.log

2.修改erlang启动配置文件(集群模式)

  • 集群端口范围设置
cd /opt/couchdb/etc
vim vm.args

追加如下内容

-kernel inet_dist_listen_min 9100
-kernel inet_dist_listen_max 9200
  • 集群节点名称设置,注意节点名称在集群中必须唯一,因此不可使用couchdb@127.0.0.1,可使用具体IP或者域名。
-name couchdb@node1

五、启动和关闭服务

1.启动

sudo systemctl start couchdb

2.状态

sudo systemctl status couchdb

3.关闭

sudo systemctl stop couchdb

4.开机启动

sudo systemctl enable couchdb

六、API使用

CouchDB API通过以_开头,api 文档

curl http://localhost:5984/

用户界面

1.数据库列表

curl http://192.168.63.17:5984/_all_dbs

2.UUID

curl http://192.168.63.17:5984/_uuids?count=5

API接口太多就不一一列举了 😺

参考:

官方文档

CouchDB是一个开源的面向文档的NoSQL数据库,它使用JSON格式存储数据,并提供了灵活的查询复制功能。下面是在Linux系统上安装CouchDB的步骤: 1. 打开终端,使用以下命令安装CouchDB的依赖项: ``` sudo apt-get update sudo apt-get install -y build-essential pkg-config erlang libicu-dev libmozjs185-dev libcurl4-openssl-dev ``` 2. 下载CouchDB的源代码包,可以从CouchDB的官方网站(https://couchdb.apache.org/)或者GitHub上获取最新版本。 3. 解压源代码包,并进入解压后的目录: ``` tar -zxvf couchdb-x.x.x.tar.gz cd couchdb-x.x.x ``` 4. 编译安装CouchDB: ``` ./configure make sudo make install ``` 5. 创建CouchDB的系统用户组: ``` sudo adduser --system --no-create-home --shell /bin/bash --group --gecos "CouchDB Administrator" couchdb ``` 6. 设置文件目录的权限: ``` sudo chown -R couchdb:couchdb /usr/local/var/lib/couchdb /usr/local/var/log/couchdb /usr/local/var/run/couchdb sudo chmod -R 0770 /usr/local/var/lib/couchdb /usr/local/var/log/couchdb /usr/local/var/run/couchdb ``` 7. 配置CouchDB: ``` sudo cp /usr/local/etc/default/couchdb /etc/default/couchdb sudo nano /etc/default/couchdb ``` 在打开的文件中,找到以下行并修改为: ``` COUCHDB_USER=couchdb COUCHDB_GROUP=couchdb ``` 8. 启动CouchDB服务: ``` sudo systemctl start couchdb ``` 9. 验证CouchDB是否成功安装: 打开浏览器,访问http://localhost:5984/_utils/,如果能够看到CouchDB的管理界面,则表示安装成功。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

搬山境KL攻城狮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值