cockroachdb 安装试用(单机伪分布式)

1. 下载
以下地址,选择对应的操作系统版本即可
https://www.cockroachlabs.com/docs/stable/install-cockroachdb.html
2. 启动
// 启动命令
cockroach start --insecure 
--host=xxxxx

// 提示信息

	*
* WARNING: RUNNING IN INSECURE MODE!
* 
* - Your cluster is open for any client that can access xxxxxxx.
* - Any user, even root, can log in without providing a password.
* - Any user, connecting as root, can read or write any data in your cluster.
* - There is no network encryption nor authentication, and thus no confidentiality.
* 
* Check out how to secure your cluster: https://www.cockroachlabs.com/docs/stable/secure-a-cluster.html
*
CockroachDB node starting at 2017-11-15 13:21:34.967650407 +0000 UTC (took 0.7s)
build:      CCL v1.1.2 @ 2017/11/02 19:32:03 (go1.8.3)
admin:      http://xxxxxxx:8080
sql:        postgresql://root@xxxxxxxx:26257?application_name=cockroach&sslmode=disable
logs:       /opt/cockroachdb/cockroach-data/logs
store[0]:   path=/opt/cockroachdb/cockroach-data
status:     restarted pre-existing node
clusterID:  cb2be836-d9d6-4e39-826d-672490fae71d
nodeID:     1
3. 添加另一台节点
cockroach start 
--insecure 
--store=node2 
--host=xxxxx 
--port=26258 
--http-port=8081 
--join=xxxxxx:26257

输出信息
*
* WARNING: RUNNING IN INSECURE MODE!
* 
* - Your cluster is open for any client that can access xxxxx.
* - Any user, even root, can log in without providing a password.
* - Any user, connecting as root, can read or write any data in your cluster.
* - There is no network encryption nor authentication, and thus no confidentiality.
* 
* Check out how to secure your cluster: https://www.cockroachlabs.com/docs/stable/secure-a-cluster.html
*
CockroachDB node starting at 2017-11-15 13:33:36.310186654 +0000 UTC (took 0.2s)
build:      CCL v1.1.2 @ 2017/11/02 19:32:03 (go1.8.3)
admin:      http://xxxxxxxx:8081
sql:        postgresql://root@xxxxxxxxxxx:26258?application_name=cockroach&sslmode=disable
logs:       /opt/cockroachdb/node2/logs
store[0]:   path=/opt/cockroachdb/node2
status:     initialized new node, joined pre-existing cluster
clusterID:  cb2be836-d9d6-4e39-826d-672490fae71d
nodeID:     2
4. 添加第三个节点
操作类似
cockroach start 
--insecure 
--store=node3 
--host=xxxxxx 
--port=26259 
--http-port=8082 
--join=xxxxx:26257
5. 可视化操作界面
 
 集群管理界面
 
数据库界面
 
连接界面
 
6. 数据库连接操作
参考上图:

// 非安全模式连接
cockroach  sql --host=xxxxx --insecure

// 创建数据库

create database bank

// 创建表
CREATE TABLE bank.accounts (id INT PRIMARY KEY, balance DECIMAL);

// 插入数据
INSERT INTO bank.accounts VALUES (1, 1000.50);

// 查询
SELECT * FROM bank.accounts;

+----+---------+
| id | balance |
+----+---------+
|  1 | 1000.50 |
+----+---------+
(1 row)

Time: 1.074601ms
7. 总结
使用起来还是比较简单的,部署也简单,原有代码基本不需要改动就可以使用
目前百度已经有大规模的使用了,同时有百度牵头的首届社区大会前段时间也已经举行了
分布式,多云环境支持,可以将用户的查询定位到离用户最近的位置,功能很强大
8. 参考文档
https://www.cockroachlabs.com/docs/stable/start-a-local-cluster.html
https://www.cockroachlabs.com/docs/stable/install-cockroachdb.html
原文地址:https://www.cnblogs.com/rongfengliang/p/7841260.html