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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM