centos安装nfs(包含ansible playbook)

主要内容


  • centos安装nfs
  • NFS软件包:
    • nfs-utils:NFS主程序,包含两个deamons:
      • rpc.nfsd
      • rpc.mount
    • rpcbind:RPC主程序

具体步骤

  • server节点(192.168.0.100)
# 查看是否安装NFS相关的软件包
$ rpm -qa  | egrep "nfs|rpcbind"
rpcbind-0.2.0-47.el7.x86_64
nfs-utils-1.3.0-0.61.el7.x86_64
libnfsidmap-0.25-19.el7.x86_64

# 如果未安装
$ yum install -y nfs-utils rpcbind

# 启动 NFS 服务
$ systemctl restart rpcbind && systemctl enable rpcbind 
$ systemctl restart nfs && systemctl enable nfs

# 查看 RPC 服务的注册状况
$ rpcinfo -p localhost

#showmount测试
$ showmount -e 192.168.0.100
  • client节点
$ yum -y install nfs-utils
$ systemctl start nfs && systemctl enable nfs

配置NFS

# 我们挂载/data目录
$ vim /etc/exports
/data *(rw,no_root_squash,sync)

# 配置生效
$ exportfs -r 

# 查看生效
$ exportfs

# /etc/exports写法介绍:
# [共享目录]  [客户端地址(权限)]  

附录

参数 说明
ro 只读访问
rw 读写访问
sync 所有数据在请求时写入共享
async nfs在写入数据前可以响应请求
secure nfs通过1024以下的安全TCP/IP端口发送
insecure nfs通过1024以上的端口发送
wdelay 如果多个用户要写入nfs目录,则归组写入(默认)
no_wdelay 如果多个用户要写入nfs目录,则立即写入,当使用async时,无需此设置
hide 在nfs共享目录中不共享其子目录
no_hide 共享nfs目录的子目录
subtree_check 如果共享/usr/bin之类的子目录时,强制nfs检查父目录的权限(默认)
no_subtree_check 不检查父目录权限
all_squash 共享文件的UID和GID映射匿名用户anonymous,适合公用目录
no_all_squash 保留共享文件的UID和GID(默认)
root_squash root用户的所有请求映射成如anonymous用户一样的权限(默认)
no_root_squash root用户具有根目录的完全管理访问权限
anonuid=xxx 指定nfs服务器/etc/passwd文件中匿名用户的UID
anongid=xxx 指定nfs服务器/etc/passwd文件中匿名用户的GID

ansible playbook

---
- hosts: nfs-server
  user: root
  tasks:
    - name: nfs install
      yum: name={{ item }} state=installed
      with_items:
        - nfs-utils
        - rpcbind
    - name: CentOS7 system start
      shell: systemctl start nfs rpcbind;systemctl enable nfs rpcbind
    - name: modify nfsexports
      shell: [ -e /etc/exports ] && echo '/data *(rw,no_root_squash,sync)' > /etc/exports && exportfs -r
- hosts: nfs-client
  user: root
  tasks:
    - name: nfs install
      yum: name={{ item }} state=installed
      with_items:
        - nfs-utils
    - name: CentOS7 system start
      shell: systemctl start nfs;systemctl enable nfs 

你可能感兴趣的:(Centos,Helm)