[nfs无法挂载问题] mount.nfs: access denied by server while mounting localhost:/data/dev/mysql

Posted Dream_it_possible!

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[nfs无法挂载问题] mount.nfs: access denied by server while mounting localhost:/data/dev/mysql相关的知识,希望对你有一定的参考价值。

        centos 7 使用nfs挂载数据卷时出现报错:localhost kubelet: mount.nfs: access denied by server while mounting localhost:/data/dev/mysql

       执行Create时,mysql容器一直处于creating状态,mysql-dev-nfs.yaml

apiVersion: v1
kind: ReplicationController
metadata:
  name: mysql-dev
  labels:
    name: mysql-dev
spec:
  replicas: 1
  selector:
    name: mysql-dev
  template:
    metadata:
      labels:
        name: mysql-dev
    spec:
      containers:
        - name: mysql
          image: nacos/nacos-mysql:5.7
          ports:
            - containerPort: 3307
          volumeMounts:
            - name: mysql-data
              mountPath: /var/lib/mysql
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: "root"
            - name: MYSQL_DATABASE
              value: "nacos_devtest"
            - name: MYSQL_USER
              value: "nacos"
            - name: MYSQL_PASSWORD
              value: "nacos"
      volumes:
        - name: mysql-data
          nfs:
            server: localhost
            path: /data/dev/mysql
---
apiVersion: v1
kind: Service
metadata:
  name: mysql-dev
  labels:
    name: mysql-dev
spec:
  ports:
    - port: 3307
      targetPort: 3307
      nodePort: 30070
  selector:
    name: mysql-dev
  type: NodePort

        我想把mysql-data挂载到本机的/data/dev/mysql目录下,使用命令 cat /var/log/messages | grep mount 查看mount相关的日志, 上面一直报错access denied, 下面是解决问题后的日志。

解决方法:
1. 检查系统中是否装有有nfs service, 可使用systemctl status  <service_name>查看。

2. 将挂载的目录设置为insecure属性, 执行命令

vim  /etc/exports

添加如下内容,表示给/data目录赋予权限和insecure。

/data *(insecure,rw,async,no_root_squash) 

编辑完后,保存,重启nfs service。 

 systemctl restart nfs

 3. 重新执行 kubectl  apply -f  service 命令,查看pods是否正常运行。

以上是关于[nfs无法挂载问题] mount.nfs: access denied by server while mounting localhost:/data/dev/mysql的主要内容,如果未能解决你的问题,请参考以下文章

mount+nfs远程挂载

linux的nfs问题

nfs客户端挂载出错 mount.nfs access denied by server while mounting

nfs-utils bug导致nfs挂载失败

解决centos下挂载目录报mount.nfs: Stale file handle

解决centos下挂载目录报mount.nfs: Stale file handle