• NOSQL数据库使用存储卷


    创建存储卷容器

    docker run -d  --volume /var/lib/cassandra/data --name cass-shared alpine echo Data Container
    

    容器创建后将立即停止,我们会在创建运行新的Cassandra 新容器时,使用这个存储卷。

    docker run -d --volumes-from cass-shared --name cass1 cassandra:2.2
    

    接下来从cassandra:2.2镜像中启动容器,运行Cassandra客户端工具,并连接正在进行运行的服务器:

    docker run -it --rm --link cass1:cass cassandra:2.2 cqlsh cass
    

    终端返回界面:

    Connected to Test Cluster at cass:9042.
    [cqlsh 5.0.1 | Cassandra 2.2.10 | CQL spec 3.3.1 | Native protocol v4]
    Use HELP for help.
    cqlsh> 
    

    现在,我们可以用CQLSH命令行检查或修改Cassandra数据库。
    首先查找一个名为docker_hello_world 的 键空间:

    cqlsh> select * 
    ... from system.schema_keyspaces 
    ... where keyspace_name = 'docker_hello_world';
    

    查询结果:

     keyspace_name | durable_writes | strategy_class | strategy_options
    ---------------+----------------+----------------+------------------
    (0 rows)
    

    Cassadra 返回一个空列表。

    接下来用以下命令创建键空间:

    cqlsh> create KEYSPACE docker_hello_world
    ... with replication = {
    ... 'class' : 'SimpleStrategy',
    ... 'replication_factor': 1
    ... };
    
    cqlsh> select *
    ... FROM system.schema_keyspaces 
    ... where keyspace_name = 'docker_hello_world';
    

    显示结果:

     keyspace_name      | durable_writes | strategy_class                              | strategy_options
     --------------------+----------------+---------------------------------------------+----------------------------
    docker_hello_world |           True | org.apache.cassandra.locator.SimpleStrategy | {"replication_factor":"1"}
    
    (1 rows)
    

    执行命令行 quit 退出CQLSH程序并停止客户端容器

    cqlsh> quit   #Leave and stop the crurrent container
    

    通过停止和去除所创建的Cassandra 节点, 清理该示例的第一部分

     docker stop cass1
     docker rm -vf cass1
    

    创建一个新的Cassandra 节点,连接客户端,并查询键空间。

    docker run -d --volumes-from cass-shared --name cass2 cassandra:2.2
    docker run -it --rm --link cass2:cass cassandra:2.2 cqlsh cass
    select *
    from system.schema_keyspaces
    where keyspace_name = 'docker_hello_world';
    

    效果如下图:
    ![效果图](./Screenshot from 2017-09-04 13-33-37.png)
    最后一个命令返回单个条目,将会和你前面一个容器中创建的键空间相匹配,这证实了存储卷可以被用于创建持久化的系统。
    先退出CALSH程序并清理工作区。确保删除该存储容器:

    quit
    docker rm -vf cass2 cass-shared
  • 相关阅读:
    并发实现-Callable/Future 实现返回值控制的线程
    Sql Server查询,关闭外键约束的sql
    Kettle-动态数据链接,使JOB得以复用
    Python爬虫实践~BeautifulSoup+urllib+Flask实现静态网页的爬取
    javaAPI操作Hbase
    Linux下的网络环境配置
    DataCleaner(4.5)第二章
    DataCleaner(4.5)第一章
    SpringBoot 使用 MyBatisPlus-Generator 快速生成model实体类
    Java 使用hutool工具类代替commons-text进行Json 中文 Unicode转换
  • 原文地址:https://www.cnblogs.com/Ethan2lee/p/7473180.html
Copyright © 2020-2023  润新知