【问题标题】:GCE "create-with-container --container-mount-disk" flag mounts disk as read-onlyGCE“create-with-container --container-mount-disk”标志将磁盘安装为只读
【发布时间】:2020-02-19 09:23:04
【问题描述】:

我正在尝试在 GCE 上为 MongoDB 使用 Percona Docker 映像,但是我遇到了 Mongo 的问题,说安装的路径是只读的。我尽可能地环顾四周,但我不知道可能是什么问题。

gcloud compute instances create-with-container mongo-svr \
--create-disk name=disk-1,size=1GB \
--container-mount-disk mount-path="/data/mongodb",mode=rw \
--container-image=docker.io/percona/percona-server-mongodb:4.2

我使用了上面的命令,它创建了我的实例。然后我 SSH 进入服务器,连接到正在运行的 mongo 实例关闭,然后我运行:docker exec -it [NAME] mongod --configsvr --replSet rs0 --dbpath=/data/mongodb --bind_ip localhost

这会吐出一个错误说明:

CONTROL  [initandlisten] options: { net: { bindIp: "localhost" }, replication: { replSet: "rs0" }, sharding: { clusterRole: "configsvr" }, storage: { dbPath: "/data/mongodb" } }
STORAGE  [initandlisten] exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /data/mongodb, terminating

此时,我一直在使用不同的参数重新创建实例,但到目前为止没有任何效果。有人知道我缺少什么吗?

已更新命令输出

gcloud compute instances create-with-container mongo-config-f --zone us-central1-f --create-disk name=disk-1,size=1GB --container-mount-disk mount-path="/data/mongodb" --container-image=docker.io/percona/percona-server-mongodb:4.2 --machine-type=f1-micro
WARNING: Default device-name for disk name [disk-1] will be [disk-1] because it is being mounted to a container with [`--container-mount-disk`]
Created [https://www.googleapis.com/compute/v1/projects/[PROJECT_NAME]/zones/us-central1-f/instances/mongo-config-f].
NAME            ZONE           MACHINE_TYPE  PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP     STATUS
mongo-config-f  us-central1-f  f1-micro                   xx.xx.xx.xx  xx.xx.xx.xx     RUNNING

【问题讨论】:

  • 我知道 mode=rw 不是必需的,但由于没有任何效果,因此希望明确。运行带有/不带有它的命令会导致相同的结果。至于挂载, /data/mongodb 没有挂载。但是,我的理解是,您为--create-disk (disk-1) 使用的名称将导致/mnt/disks/gce-containers-mounts/gce-persistent-disks/disk-1,这将是docker 容器的安装点,内部映射到/data/mongodb。所以调用mount 不会显示该路径,而是显示/mnt/disks/ 路径。

标签: mongodb docker google-compute-engine gce-persistent-disk


【解决方案1】:

我尝试在我的测试项目中复制您的问题并发现:

  • 永久性磁盘已按预期创建并以读写模式挂载;

    bash-4.2$ mount 
    ...
    /dev/sdb on /data/mongodb type ext4 (rw,relatime)
    
  • docker 在我们的虚拟机中正常运行容器;

  • 运行docker exec -it [NAME] mongod --configsvr --replSet rs0 --dbpath=/data/mongodb --bind_ip localhost时出错的原因是mongodb容器内的权限:

    bash-4.2$ ls -l /data/        
    ...
    drwxr-xr-x 3 root    root 4096 Feb 19 15:33 mongodb
    

作为一种解决方法,可以使用 root 权限执行命令

$ docker exec -it --user root klt-mongo-svr-upd-wowt mongod --configsvr --replSet rs0 --db path=/data/mongodb

请在下面找到更多详细信息和我的步骤:

  1. 创建虚拟机:

    $ gcloud compute instances create-with-container mongo-svr \
    --create-disk name=disk-1,size=1GB \                                                                                 
    --container-image docker.io/percona/percona-server-mongodb:4.2 \
    --container-mount-disk mount-path="/data/mongodb"                               
    WARNING: Default device-name for disk name [disk-1] will be [disk-1] because it is being mounted to a container with [`--container-mount-disk`]
    Created [https://www.googleapis.com/compute/v1/projects/test-prj/zones/europe-west3-a/instances/mongo-svr].
    NAME           ZONE            MACHINE_TYPE   PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP     STATUS
    mongo-svr-upd  europe-west3-a  n1-standard-1               10.156.0.9   35.XXX.155.XXX  RUNNING
    
  2. SSH 到实例;

  3. 检查容器是否正在运行:

    $ docker ps
    CONTAINER ID        IMAGE                                                                COMMAND                  CREATED              STATUS              PORTS               NAMES
    dfad9c10235d        percona/percona-server-mongodb:4.2                                   "/entrypoint.sh mong…"   About a minute ago   Up About a minute                       klt-mongo-svr-upd-wowt
    bbe02c8e8621        gcr.io/stackdriver-agents/stackdriver-logging-agent:0.2-1.5.33-1-1   "/entrypoint.sh /usr…"   About a minute ago   Up About a minute                       stackdriver-logging-agent
    

    此时一切看起来都不错;

  4. 尝试以用户身份运行命令:

     $ docker exec -it klt-mongo-svr-upd-wowt mongod --configsvr --replSet rs0 --dbpath=/data/mongodb --bind_ip localhost
    

    并观察到同样的错误:

    2020-02-19T15:37:53.176+0000 I  STORAGE  [initandlisten] exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /data/mongodb, terminating
    

    这里键只读目录:/data/mongodb;

  5. 检查容器内的挂载和权限:

    $ docker exec -it klt-mongo-svr-upd-wowt /bin/bash
    bash-4.2$ mount 
    ...
    /dev/sdb on /data/mongodb type ext4 (rw,relatime)
    ...
    

    正如我们所料磁盘已创建并以读写模式安装到容器

    bash-4.2$ ls -l /data/        
    total 8
    drwxr-xr-x 4 mongodb root 4096 Feb 19 15:36 db
    drwxr-xr-x 3 root    root 4096 Feb 19 15:33 mongodb
    bash-4.2$ 
    

    但要使用/data/mongodb,您需要root 权限;

  6. 尝试以 root 身份运行命令:

    $ docker exec -it --user root klt-mongo-svr-upd-wowt mongod --configsvr --replSet rs0 --dbpath=/data/mongodb
    2020-02-19T15:45:24.970+0000 I  CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
    2020-02-19T15:45:24.973+0000 I  CONTROL  [initandlisten] MongoDB starting : pid=119 port=27019 dbpath=/data/mongodb 64-bit host=mongo-svr-upd
    2020-02-19T15:45:24.974+0000 I  CONTROL  [initandlisten] db version v4.2.2-3
    2020-02-19T15:45:24.974+0000 I  CONTROL  [initandlisten] git version: 2cdb6e50913583f627acc5de35dc4e04dbfe196f
    2020-02-19T15:45:24.974+0000 I  CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2k-fips  26 Jan 2017
    2020-02-19T15:45:24.974+0000 I  CONTROL  [initandlisten] allocator: tcmalloc
    2020-02-19T15:45:24.974+0000 I  CONTROL  [initandlisten] modules: none
    2020-02-19T15:45:24.974+0000 I  CONTROL  [initandlisten] build environment:
    2020-02-19T15:45:24.975+0000 I  CONTROL  [initandlisten]     distarch: x86_64
    2020-02-19T15:45:24.975+0000 I  CONTROL  [initandlisten]     target_arch: x86_64
    2020-02-19T15:45:24.975+0000 I  CONTROL  [initandlisten] options: { replication: { replSet: "rs0" }, sharding: { clusterRole: "configsvr" }, storage: { dbPath: "/data/mongodb" } }
    2020-02-19T15:45:24.976+0000 I  STORAGE  [initandlisten] Detected data files in /data/mongodb created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
    ...
    

    并且它正在使用 root 权限

【讨论】:

    猜你喜欢
    • 2020-07-04
    • 2020-08-12
    • 1970-01-01
    • 2020-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-26
    • 2020-10-26
    相关资源
    最近更新 更多