Technology Sharing

Centos uses nfs to configure a shared directory to make all container logs in the docker cluster uniformly accessible to the host

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Centos uses nfs to configure a shared directory so that all container logs in the docker cluster are stored in a shared directory on the host for developers to access and view.

  1. Prepare two or more Centosserver
    1. 192.168.0.1 nfs服务器
    2. 192.168.0.2 nfs客户端
  2. As rootUser login 192.168.0.1Server, do the following
    1. 注意先关闭防火墙;
    2. service firewalld stop
    3. systemctl disable firewalld
    4. # 1、安装nfs
    5. yum -y install nfs-utils rpcbind
    6. # 2、设置开机启动
    7. systemctl enable nfs.service
    8. systemctl enable rpcbind.service
    9. # 3、启动rpcbind和nfs
    10. systemctl restart nfs.service
    11. systemctl restart rpcbind.service
    12. # 4、编辑共享配置
    13. vi /etc/exports
    14. # 5、写入共享目录(根据实际情况修改,chmod 777 权限)
    15. /share *(rw,sync,no_root_squash)
    16. # 6、重新加载
    17. exportfs -rv
    18. # 7、查看本机共享的nfs目录
    19. showmount -e

  3. As rootUser login 192.168.0.2Server, perform the following operations to mount the shared directory
    1. 安装 nfs-utils
    2. yum install nfs-utils
    3. # 1、查看服务器发布的nfs目录
    4. showmount -e 192.168.0.1
    5. # 2、创建本地挂载目录(根据实际情况修改),chmod 777 权限
    6. mkdir -p /share
    7. # 3、挂载服务器目录
    8. mount -t nfs -o nolock 192.168.0.1:/share /share

  4. docker -v mount to container

    docker run -v <宿主机路径>:<容器内路径> <其他选项> <镜像名>