076、创建Rex-Ray volume (2019-04-23 周二)

 
前面我们安装部署了 Rex-Ray ,并且成功配置 Virtualbox backend ,今天学习如何创建和使用 Rex-Ray volume
 
在 docker1 或 docker2 上执行如下命令创建 volume
 
rexray volume create --size 2 'c:\share\mysqldata'
 
--size 指定创建volume的大小,单位GB
 
最后是创建volume的绝对路径,因为 \ 是特殊字符,需要用单引号引起来
 
root@docker1:~# rexray volume create --size 2 'c:\share\mysqldata'
ID                                    Name       Status     Size
cd335365-dea0-4e22-95ce-daa0258595e8  mysqldata  available  2
root@docker1:~# rexray volume ls
ID                                    Name          Status       Size
c2b3c553-dc43-4df1-8a72-faa26a9ee861  docker1.vmdk  attached     20
cec5b10d-8bc1-4326-bb9b-e3add075f3f1  docker2.vmdk  unavailable  20
cd335365-dea0-4e22-95ce-daa0258595e8  mysqldata     available    2
root@docker1:~# docker volume ls
DRIVER              VOLUME NAME
rexray              docker1.vmdk
rexray              docker2.vmdk
rexray              mysqldata
 
 
 
创建mysql容器并使用Rex-Ray volume
 
root@docker1:~# docker run --name mydb_on_docker1 -v mysqldata:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=passw0rd -d mysql
 
root@docker1:~# docker volume inspect mysqldata
[
    {
        "CreatedAt": "0001-01-01T00:00:00Z",
        "Driver": "rexray",
        "Labels": null,
        "Mountpoint": "",
        "Name": "mysqldata",
        "Options": null,
        "Scope": "global",
        "Status": {
            "availabilityZone": "",
            "fields": null,
            "iops": 0,
            "name": "mysqldata",
            "server": "virtualbox",
            "service": "virtualbox",
            "size": 2,
            "type": "HardDisk"
        }
    }
]
root@docker1:~# docker inspect mydb_on_docker1 | jq .[0].Mounts
[
  {
    "Type": "volume",
    "Name": "mysqldata",
    "Source": "",
    "Destination": "/var/lib/mysql",
    "Driver": "rexray",
    "Mode": "",
    "RW": true,
    "Propagation": ""
  }
]
 
 
下图可以看到 Rex-Ray volume mysqldata 已经挂载到docker1 上
 
 
 
当前实验拓扑如下图所示:
 
 
下面登录数据库,并对数据库就行一些修改,然后销毁mysql容器
 
root@docker1:~# docker exec -it mydb_on_docker1 bash
root@f00b063008f8:/# mysql -p    #    登录数据库
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.15 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> use mysql    #    切换到mysql库
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed
mysql> create table my_id(id int(4));    #       创建表
Query OK, 0 rows affected (0.03 sec)
 
mysql> insert my_id values(111);    #    在表中插入数据
Query OK, 1 row affected (0.01 sec)
 
mysql> select * from my_id;    #    查询表中数据
+------+
| id   |
+------+
|  111 |
+------+
1 row in set (0.00 sec)
 
mysql> exit
Bye
root@f00b063008f8:/# exit
root@docker1:~# docker stop mydb_on_docker1    #    stop容器
mydb_on_docker1
root@docker1:~# docker rm  mydb_on_docker1    #    销毁容器
mydb_on_docker1
 
 
最后可以看到,mysqldata 自动从docker1 上卸载了
 
 
posted @ 2019-04-21 03:00  三角形  阅读(185)  评论(0编辑  收藏  举报