NFS–network file system 可以在linux/unix系统之间共享,支持多节点同时挂载以及并发写入。如果大家有那种web集群(httpd/tomcat/nginx),可以用nfs挂载,方便管理网页信息
我写了一个yml文件,供参考
1 安装ansible,配置inventory
yum -y install ansible
2 建立一个***.yaml 文件,位置我放在了root下
复制该文本请记得修改挂载点的 ip,nfs_info目录位置随意,但它下面的文件index.html 中后缀不可以出错。
vim nfs.yml
--- - name: initial preparations hosts: all tasks: - name: stop firewalld service: name: firewalld state: stopped - name: disable selinux shell: setenforce 0 - name: for nfs hosts: nfs tasks: - name: install nfs-utils yum: name: nfs-utils state: present - name: make directory for storig info file: path: /opt/nfs_info state: directory - name: copy random contents to /nfs_info copy: content: "testing" dest: /opt/nfs_info/index.html - name: for /etc/exports copy: content: "/opt/nfs_info 192.168.122.163(rw)" dest: /etc/exports - name: start nfs-server service: name: nfs-server state: started enabled: yes - name: for webs hosts: web tasks: - name: install apps yum: name: nfs-utils,httpd state: present - name: start nfs-server service: name: nfs-server state: started enabled: yes - name: start httpd service: name: httpd state: started enabled: yes - name: mount mount: path: /var/www/html src: 192.168.122.163:/opt/nfs_info fstype: nfs state: mounted
3 ansible执行剧本
ansible-playbook nfs.yml #执行上面的剧本,具体名字根据剧本名字来 ansible all -m shell -a 'lsblk' ansibel all -m shell -a 'df -Th' # 查询挂载是否成功