centos mounts cos cloud storage server, and centos file directory mounts docker to realize sharing operation steps

Posted by JDBurnZ on Sun, 16 Jan 2022 08:45:28 +0100

Preparations: Tencent cloud configuration (at present, individuals can apply for 6-month free file storage server), centos 7, dokcer on centos, Git on centos

Tencent cloud configuration: accessKey, secretKey, bucketName, regionName

centos: Git installation (pull cosfs source code)

Operation on Cos

The cos cloud storage bucket creates a new file directory as the file mount point, and creates a new subdirectory for storing files, such as the new directory / dev/

 

Operation on Centos (reference document: https://www.ioiox.com/archives/65.html)  

  1. Install COSFS tools on the server (git is used here to download dependencies and save them to / user/cosfs directory)
    git clone https://github.com/tencentyun/cosfs /usr/cosfs
  2. Install dependent software
    sudo yum install automake gcc-c++ git libcurl-devel libxml2-devel fuse-devel make openssl-devel fuse
  3. Compile and install cosfs (if the cosfs version information is displayed normally, the installation and compilation are successful)
    cd /usr/cosfs        # Enter cosfs storage directory
    ./autogen.sh
    ./configure
    make
    sudo make install
    cosfs --version      # Check the cosfs file version installation. If the corresponding version is displayed, the installation is successful
  4. Configure cos key file and set file permissions
    Formula: echo < bucketname appid >: < secretid >: < secretkey > / etc / passwd cosfs

    # Write configuration information to passwd_cosfs file
    echo luotj-1254274: AKIDIislOlrRzGGzRcMuJ: sVNp2C4f0WA > /etc/passwd-cosfs
    
    # Set permissions for the profile
    chmod 640 /etc/passwd-cosfs
  5. Create the directory where the server is mounted

    mkdir -p /data/sahre
  6. Mount the COS subdirectory, and the whole system has been mounted at
    cosfs <BucketName-APPID> <MountPoint> -ourl=<CosDomainName> -odbglevel=info
    -o nonempty # when the local directory is not empty
    -oallow_other # allows other users to access and download directly from the Web

    cosfs luotj-125427:/dev /data/share -ourl=https://cos.ap-guangzhou.myqcloud.com -odbglevel=info -onoxattr -oallow_other
    
    /dev It is a subdirectory to mount. If you do not need to mount, the current subdirectory can be empty,If it is empty, the entire bucket is mounted
    
    /data/share by centos Directory of files mounted on the server
    
    https://cos.ap-guangzhou.myqcloud.com is the area address of centos file storage object

  7. Delete the mounted directory (if you do not need to mount, you can delete the mount point)
     

    umount -l /data/share
    
    /data/share by centos Mounted directory

  8. A new file is added under the / dev directory on the file storage. If there is the same file under the / data/share file directory of centos, the loading is successful

  9. Pull centos image (the following steps are to realize the file sharing function of docker and server. If you don't need to study deeply, you can ignore the following steps and refer to the document: https://blog.csdn.net/weixin_42739916/article/details/106551307)

    docker pull centos
    
    Pull one centos Image operation. If a similar image can be mounted, the current step can be ignored
  10. Start the image (and enable the shared folder to share / data/share of the host and / opt/video file directory in the container)

    docker run -d --name my-test -v /data/share:/opt/video centos
    
    my-test     Alias for the current boot container
    /data/share Is the file directory of the host
    /opt/share  The mount directory within the container
  11. Enter the Docker container to operate

    docker exec -it container ID /bin/bash
    
    container ID Can pass dokcer ps Command to view the generated container after starting the container ID

Docker container operation

  1. Enter the container directory / opt/video
    cd /opt/video
  2. Create a new file test. In the mount directory mp4
    touch test.mp4
  3. Check whether test is generated under the centos directory / data/share file directory MP4 file, if any, indicates that the mount is successful. If the cos bucket is mounted at the same time, there is also a test in the / dev directory in the bucket MP4 file directory.

 

Topics: Linux Docker