rqlite 是个分布式关系型数据库,使用 SQLite 作为存储引擎,使用 Go 编写,基于 Raft 一致性协议。rqlite 会确保系统的每个修改都符合 SQLite 数据库的限制规则,并且非常适用于 leader elections 处理,机器故障容错。

为什么要使用 rqlite?

rqlite 提供非常健壮的特性,支持容错,复制关系型数据库,但又非常容易安装,部署和使用。rqlite 可以作为一个轻量级,可靠的关系型数据存储,可以作为大型系统的一部分,也可以是一些重要关系型数据的核心存储,无需运行一个更繁重的解决方案,比如 MySQL。

关键特性:

  • 易部署
  • 完全复制产品级别的 SQL 数据库
  • 提供一个简单易用的 HTTP(S) API,包括 leader-redirection 和 bulk-update 支持
  • 基础认证安全和用户级别许可
  • 读一致性
  • 支持事物
  • 热备份

代码托管在 GitHub:

https://github.com/rqlite/rqlite

------------------------------------- 

The lightweight, distributed relational database built on SQLite

rqlite.io

rqlite is an easy-to-use, lightweight, distributed relational database, which uses SQLite as its storage engine.

rqlite is simple to deploy, operating and accessing it is very straightforward, and its clustering capabilities provide you with fault-tolerance and high-availability. rqlite is available for Linux, macOS, and Microsoft Windows, and can be built for many target CPUs, including x86, AMD, MIPS, RISC, PowerPC, and ARM.

Check out the rqlite FAQ.

Why?

rqlite gives you the functionality of a rock solid, fault-tolerant, replicated relational database, but with very easy installation, deployment, and operation. With it you've got a lightweight and reliable distributed relational data store. Think etcd or Consul, but with relational data modelling also available.

You could use rqlite as part of a larger system, as a central store for some critical relational data, without having to run larger, more complex distributed databases.

Finally, if you're interested in understanding how distributed systems actually work, rqlite is a good example to study. Much thought has gone into its design and implementation, with clear separation between the various components, including storage, distributed consensus, and API.

How?

rqlite uses Raft to achieve consensus across all the instances of the SQLite databases, ensuring that every change made to the system is made to a quorum of SQLite databases, or none at all. You can learn more about the design here.

Key features

Quick Start

The quickest way to get running is to download a pre-built release binary, available on the GitHub releases page. Once installed, you can start a single rqlite node like so:

rqlited -node-id 1 ~/node.1

This single node automatically becomes the leader. You can pass -h to rqlited to list all configuration options.

Homebrew

brew install rqlite

Forming a cluster

While not strictly necessary to run rqlite, running multiple nodes means you'll have a fault-tolerant cluster. Start two more nodes, allowing the cluster to tolerate the failure of a single node, like so:

rqlited -node-id 2 -http-addr localhost:4003 -raft-addr localhost:4004 -join http://localhost:4001 ~/node.2
rqlited -node-id 3 -http-addr localhost:4005 -raft-addr localhost:4006 -join http://localhost:4001 ~/node.3

This demonstration shows all 3 nodes running on the same host. In reality you probably wouldn't do this, and then you wouldn't need to select different -http-addr and -raft-addr ports for each rqlite node.

With just these few steps you've now got a fault-tolerant, distributed relational database. For full details on creating and managing real clusters, including running read-only nodes, check out this documentation.

Inserting records

Let's insert some records via the rqlite CLI, using standard SQLite commands. Once inserted, these records will be replicated across the cluster, in a durable and fault-tolerant manner.

$ rqlite
127.0.0.1:4001> CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name TEXT)
0 row affected (0.000668 sec)
127.0.0.1:4001> .schema
+-----------------------------------------------------------------------------+
| sql                                                                         |
+-----------------------------------------------------------------------------+
| CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name TEXT)               |
+-----------------------------------------------------------------------------+
127.0.0.1:4001> INSERT INTO foo(name) VALUES("fiona")
1 row affected (0.000080 sec)
127.0.0.1:4001> SELECT * FROM foo
+----+-------+
| id | name  |
+----+-------+
| 1  | fiona |
+----+-------+

Limitations

  • In-memory databases are currently limited to 2GiB (2147483648 bytes) in size. You can learn more about possible ways to get around this limit in the documentation.

  • Because rqlite peforms statement-based replication certain non-deterministic functions, e.g. RANDOM(), are rewritten by rqlite before being passed to the Raft system and SQLite. To learn more about rqlite's support for non-deterministic functions, check out the documentation.

  • This has not been extensively tested, but you can directly read the SQLite file under any node at anytime, assuming you run in "on-disk" mode. However there is no guarantee that the SQLite file reflects all the changes that have taken place on the cluster unless you are sure the host node itself has received and applied all changes.

  • In case it isn't obvious, rqlite does not replicate any changes made directly to any underlying SQLite file, when run in "on disk" mode. If you change the SQLite file directly, you may cause rqlite to fail. Only modify the database via the HTTP API.

  • SQLite dot-commands such as .schema or .tables are not directly supported by the API, but the rqlite CLI supports some very similar functionality. This is because those commands are features of the sqlite3 command, not SQLite itself.

    from https://github.com/rqlite/rqlite

    -------------------------------------------

    编译:

    go install github.com/rqlite/rqlite/cmd/rqlited@latest