栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

ansible-play举例:安装nfs客户端和服务器端并进行挂载

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ansible-play举例:安装nfs客户端和服务器端并进行挂载

#使用ansible安装并配置nfs服务
服务端:192.168.200.2  操作ansible的主机
客户端: 192.168.200.100 192.168.200.200 受控主机

第一步:编辑ansible操作计算机的/etc/ansible/hosts文件,在末尾添加以下几行:

[webservers]
192.168.200.100 ansible_user=root
192.168.200.200 ansible_user=root

[nfsserver]
192.168.200.2 ansible_user=root

第二步:编写yaml文件:

[root@proxy nfs]# vim nfs.yaml
- hosts: nfsserver
  remote_user: root
  tasks:
    - name: Install NFS Server
      yum: name=nfs-utils state=present


    - name: Shutdown Firewall
      service: name=firewalld state=stopped

    - name: Configure NFS Server
      copy: src=./exports.j2 dest=/etc/exports backup=yes

    - name: Create NFS Group
      group: name=nfs gid=888

    - name: Create NFS User
      user: name=nfs uid=888 group=888 shell=/sbin/nologin create_home=no

    - name: Create NFS Data Directory
      file: path=/nfsserver state=directory owner=nfs group=nfs recurse=yes

    - name:  Service nfs Server
      service: name=nfs state=started enabled=yes


- hosts: webservers
  tasks:
    - name: Client Create NFS Data
      file: path=/nfsclient state=directory

    - name: Install NFS Client
      yum: name=nfs-utils state=present

    - name: Shutdown Firewall
      service: name=firewalld state=stopped

    - name: Client Mount NFS Server
      mount:
        src: 192.168.200.2:/nfsserver
        path: /nfsclient
        fstype: nfs
        opts: defaults
        state: mounted
 

第三步:编写本地配置文件exports.j2

[root@proxy nfs]# cat exports.j2
/nfsserver 192.168.200.0/24(rw,sync,all_squash,anonuid=888,anongid=888)

第四步: 执行ansible-playbook nfs.yaml

执行过程如下:

检查本地主机和受控主机,本地主机上多了一个/nfsserver的目录,而在两台受控主机上都多了一个/nfsclient的目录。

用df -h检查两台受控主机的挂载情况:

web01:192.168.200.100

web02:192.168.200.200

检查受控主机的/etc/fstab文件:

web01

 

web02

 

在本地主机上/nfsserver下写一个file.txt的文件: 

检查两台受控主机的/nfsclient目录,都出现了一个file.txt文件,其内容为hello nfs

 

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/731262.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号