单机安装
yum install nfs-utils -y
sudo systemctl enable rpcbind
sudo systemctl enable nfs
启动
sudo systemctl restart rpcbind
sudo systemctl restart nfs
数据共享
mkdir /data/nfs
chmod 755 /data/nfs
vi /etc/exports
/data/nfs/ *(rw,sync,no_root_squash,no_all_squash)
systemctl restart nfs
showmount -e localhost
安装nfs的playbook,实现开机自启
- name: Install and configure NFS server
hosts: modify ###如果共享目录是/data/nfs,就只需修改这里
tasks:
- name: Install NFS server package
yum:
name: nfs-utils
state: present
- name: ensure and start nfs
systemd:
name: nfs
enabled: yes
state: started
- name: Create shared directory
file:
path: /data/nfs
state: directory
mode: '0755'
- name: Configure NFS exports
lineinfile:
path: /etc/exports
line: "/data/nfs *(rw,sync,no_root_squash)"
state: present
handlers:
- name: restart nfs
service:
name: nfs
state: restarted