美文网首页
Centos7.6NFS利用剧本安装,卸载

Centos7.6NFS利用剧本安装,卸载

作者: Unlucky丶 | 来源:发表于2019-07-26 21:52 被阅读0次

剧本价值及作用

1.可以将多个批量操作模块功能整合
2.简化运维工作复杂度


操作前准备


1.备份服务器 IP:172.16.1.41
2.nfs服务器 IP:172.16.1.31
3.web服务器 IP:172.16.1.7

1.修改主机清单

vim /etc/ansible/hosts
#NFS服务
[nfs:children]
nfs_server
nfs_client
[nfs_server]
172.16.1.31
[nfs_client]
172.16.1.41
172.16.1.7

2.创建脚本存放脚本的目录

mkdir /etc/ansible/ansible_playbook  --- 创建剧本汇总目录

3.创建rsync安装剧本文件(nfs_xxx.yaml)

- hosts: nfs_server
      tasks:
        - name: 01:install nfs rpcbind --- 安装rpcbind服务
          yum:
            name:
              - rpcbind
              - nfs-utils
            state: installed
        - name: 02:copy conf file   --- 将本地的配置文件传输到被管理端的配置文件里
          copy: src=/etc/ansible/ansible_playbook/nfs.conf  dest=/etc/exports
        - name: 03:create data dir   --- 创建共享目录
          file: path=/data/ state=directory owner=nfsnobody group=nfsnobody
        - name: 04:boot server rpcbind  ---启动rpcbind服务
          service: name=rpcbind state=started enabled=yes
        - name: 04:boot server nfs   --- 启动nfs服务
          service: name=nfs state=restarted enabled=yes
    - hosts: nfs_client
      tasks:
        - name: 01:install nfs   --- 安装nfs服务
          yum: name=nfs-utils state=installed
        - name: 02:mount data dir   --- 将共享目录挂载到被管理端的/mnt目录下面
          mount: src=172.16.1.31:/data/ path=/mnt fstype=nfs state=mounted

4.创建rsync清空环境剧本文件(nfs_xxx.yaml)

- hosts: nfs_server 
      tasks:
        - name: 01:install nfs rpcbind   --- 卸载rpcbind服务
          yum:
            name:
              - rpcbind
              - nfs-utils
            state: removed
        - name: 02:copy conf file   --- 清空配置文件
          shell: echo "" >/etc/exports
        - name: 03:create data dir   --- 删除共享目录
          file: path=/data/ state=absent
    - hosts: nfs_client
      tasks:
        - name: 01:uninstall nfs   --- 卸载nfs服务
          yum: name=nfs-utile state=removed
        - name: 02:mount data dir   --- 卸载挂载的共享目录
          mount: src=172.16.1.31:/data/ path=/mnt fstype=nfs state=unmounted

以上就是所有内容

相关文章

网友评论

      本文标题:Centos7.6NFS利用剧本安装,卸载

      本文链接:https://www.haomeiwen.com/subject/udljrctx.html