阅读背景:

yugabyte cloud native db 基本试用

来源:互联网 

备注:

  测试环境使用docker进行安装试用

 

1. 安装

a. Download

 mkdir ~/yugabyte && cd ~/yugabyte
 wget https://downloads.yugabyte.com/yb-docker-ctl && chmod +x yb-docker-ctl

b. install

 docker ps && python --verions
 docker pull yugabytedb/yugabyte

2. 创建数据库集群

备注:使用yb-docker-ctl 创建
a. create

./yb-docker-ctl create
操作日志如下:
docker run --name yb-master-n1 --privileged -p 7000:7000 --net yb-net --detach yugabytedb/yugabyte:latest /home/yugabyte/bin/yb-master --fs_data_dirs=/mnt/disk0,/mnt/disk1 --replication_factor=3 --master_addresses=yb-master-n1:7100,yb-master-n2:7100,yb-master-n3:7100 --rpc_bind_addresses=yb-master-n1:7100
Adding node yb-master-n1
docker run --name yb-master-n2 --privileged --net yb-net --detach yugabytedb/yugabyte:latest /home/yugabyte/bin/yb-master --fs_data_dirs=/mnt/disk0,/mnt/disk1 --replication_factor=3 --master_addresses=yb-master-n1:7100,yb-master-n2:7100,yb-master-n3:7100 --rpc_bind_addresses=yb-master-n2:7100
Adding node yb-master-n2
docker run --name yb-master-n3 --privileged --net yb-net --detach yugabytedb/yugabyte:latest /home/yugabyte/bin/yb-master --fs_data_dirs=/mnt/disk0,/mnt/disk1 --replication_factor=3 --master_addresses=yb-master-n1:7100,yb-master-n2:7100,yb-master-n3:7100 --rpc_bind_addresses=yb-master-n3:7100
Adding node yb-master-n3
docker run --name yb-tserver-n1 --privileged -p 9000:9000 -p 9042:9042 -p 6379:6379 --net yb-net --detach yugabytedb/yugabyte:latest /home/yugabyte/bin/yb-tserver --fs_data_dirs=/mnt/disk0,/mnt/disk1 --tserver_master_addrs=yb-master-n1:7100,yb-master-n2:7100,yb-master-n3:7100 --rpc_bind_addresses=yb-tserver-n1:9100 --yb_num_shards_per_tserver=2
Adding node yb-tserver-n1
docker run --name yb-tserver-n2 --privileged --net yb-net --detach yugabytedb/yugabyte:latest /home/yugabyte/bin/yb-tserver --fs_data_dirs=/mnt/disk0,/mnt/disk1 --tserver_master_addrs=yb-master-n1:7100,yb-master-n2:7100,yb-master-n3:7100 --rpc_bind_addresses=yb-tserver-n2:9100 --yb_num_shards_per_tserver=2
Adding node yb-tserver-n2
docker run --name yb-tserver-n3 --privileged --net yb-net --detach yugabytedb/yugabyte:latest /home/yugabyte/bin/yb-tserver --fs_data_dirs=/mnt/disk0,/mnt/disk1 --tserver_master_addrs=yb-master-n1:7100,yb-master-n2:7100,yb-master-n3:7100 --rpc_bind_addresses=yb-tserver-n3:9100 --yb_num_shards_per_tserver=2
Adding node yb-tserver-n3
PID        Type       Node                 URL                       Status          Started At
9666       tserver    yb-tserver-n3        https://192.168.16.7:9000  Running         2018-02-11T02:23:04.064743772Z
9498       tserver    yb-tserver-n2        https://192.168.16.6:9000  Running         2018-02-11T02:23:03.799704303Z
9368       tserver    yb-tserver-n1        https://192.168.16.5:9000  Running         2018-02-11T02:23:03.537778672Z
9231       master     yb-master-n3         https://192.168.16.4:9000  Running         2018-02-11T02:23:03.2530083Z
9135       master     yb-master-n2         https://192.168.16.3:9000  Running         2018-02-11T02:23:03.003740203Z
9053       master     yb-master-n1         https://192.168.16.2:9000  Running         2018-02-11T02:23:02.746672273Z

其中 cql service 端口 localhost:9042  redis localhost:6379

b. 检测集群状态
./yb-docker-ctl status
PID        Type       Node                 URL                       Status          Started At
9666       tserver    yb-tserver-n3        https://192.168.16.7:9000  Running         2018-02-11T02:23:04.064743772Z
9498       tserver    yb-tserver-n2        https://192.168.16.6:9000  Running         2018-02-11T02:23:03.799704303Z
9368       tserver    yb-tserver-n1        https://192.168.16.5:9000  Running         2018-02-11T02:23:03.537778672Z
9231       master     yb-master-n3         https://192.168.16.4:9000  Running         2018-02-11T02:23:03.2530083Z
9135       master     yb-master-n2         https://192.168.16.3:9000  Running         2018-02-11T02:23:03.003740203Z
9053       master     yb-master-n1         https://192.168.16.2:9000  Running         2018-02-11T02:23:02.746672273Z
 

 参考管理界面

admin ui 

 

 

master ui

 

 

 

3. 数据库链接

a. cql

 I.连接
 docker exec -it yb-tserver-n3 /home/yugabyte/bin/cqlsh

Connected to local cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.9-SNAPSHOT | CQL spec 3.4.2 | Native protocol v4]
Use HELP for help.
cqlsh> describe keyspaces;

system_schema  system_auth  system

cqlsh>
II. 创建表
CREATE KEYSPACE myapp;
CREATE TABLE myapp.stock_market (
  stock_symbol text,
  ts text,
  current_price float,
  PRIMARY KEY (stock_symbol, ts)
)

III. insert data
INSERT INTO myapp.stock_market (stock_symbol,ts,current_price) VALUES ('AAPL','2017-10-26 09:00:00',157.41);
INSERT INTO myapp.stock_market (stock_symbol,ts,current_price) VALUES ('AAPL','2017-10-26 10:00:00',157);
INSERT INTO myapp.stock_market (stock_symbol,ts,current_price) VALUES ('FB','2017-10-26 09:00:00',170.63);
INSERT INTO myapp.stock_market (stock_symbol,ts,current_price) VALUES ('FB','2017-10-26 10:00:00',170.1);
INSERT INTO myapp.stock_market (stock_symbol,ts,current_price) VALUES ('GOOG','2017-10-26 09:00:00',972.56);
INSERT INTO myapp.stock_market (stock_symbol,ts,current_price) VALUES ('GOOG','2017-10-26 10:00:00',971.91);
IV. 查询数据
SELECT * FROM myapp.stock_market WHERE stock_symbol = 'AAPL';
 stock_symbol | ts                  | current_price
--------------+---------------------+---------------
         AAPL | 2017-10-26 09:00:00 |        157.41
         AAPL | 2017-10-26 10:00:00 |           157

b. redis 

 I.连接
 docker exec -it yb-tserver-n3 /home/yugabyte/bin/redis-cli
 II. 操作
127.0.0.1:6379>
127.0.0.1:6379> set name dalong
OK
127.0.0.1:6379> get name
"dalong"
 
 

创建结果可以从UI界面查看

 

 

4. 类似工具

tidb  cockroachdb  vitess
总之,数据库变化越来越大了,同时对于以前需要关注的分库分表,基本上已经不用管理,平台自己处理了,同时我们对于我们只需要关注业务实现
官方也提供了kubernetes 的运行配置脚本
 
 

5. 参考资料

https://docs.yugabyte.com/quick-start/create-local-cluster/
 
 
 
 

分享到: