挂载nfs,更改挂载点

showmount -e 10.246.29.41
mount -t nfs
mount -t nfs 10.246.29.41:/data/nfs /apps/sharedstorage/jtproduction
mount -t nfs 10.246.29.18:/data/nfs /apps/sharedstorage/jtproduction-hlw
mount -t nfs 10.246.29.43:/data/nfs /apps/sharedstorage/jtproduction-zq
echo " nfs  defaults        0 0">> /etc/fstab
echo "10.246.29.41:/data/nfs /apps/sharedstorage/jtproduction  nfs defaults        0 0" >> /etc/fstab
echo "10.246.29.18:/data/nfs /apps/sharedstorage/jtproduction-hlw  nfs defaults        0 0" >> /etc/fstab
echo "10.246.29.43:/data/nfs /apps/sharedstorage/jtproduction-zq  nfs defaults        0 0" >> /etc/fstab




mount /dev/nvme0n1 /root/data0
mount /dev/nvme1n1 /root/data1
/dev/nvme0n1 /root/data0    xfs     defaults        0 0
/dev/nvme1n1 /root/data1    xfs     defaults        0 0

使用ansible实现批量挂载

ansible nfs -m file -a "path=/data/nfs state=directory"
ansible test -m mount -a 'src=192.168.20.17:/data/nfs  path=/opt fstype=nfs opts=defaults state=mounted'
ansible test -m mount  -a 'src=/dev/nvme0n1  path=/root/data0 fstype=xfs opts=defaults state=mounted'

实现开机自动挂载的palybook (###是需要修改的地方 #是解释说明)

- name: Mount NFS share
  hosts: yourhost                                        ###修改
  become: true
  vars:
    nfs_share: "10.246.29.41:/data/nfs"                  ###修改
    mount_path: "/apps/sharedstorage/jtproduction"       ###修改
    mount_opts: "defaults"
  tasks:
    - name: Create directory                            #创建目录
      file:
        path: "{{ mount_path }}"
        state: directory
        mode: 0755
    - name: Mount NFS share                             #挂载nfs
      mount:
        path: "{{ mount_path }}"
        src: "{{ nfs_share }}"
        fstype: nfs
        opts: "{{ mount_opts }}"
        state: mounted


    - name: Add entry to /etc/fstab                      #实现开机自动挂载
      lineinfile:
        path: /etc/fstab                                 
        line: "10.246.29.18:/data/nfs /apps/sharedstorage/jtproduction-hlw nfs defaults 0 0"         ###修改
      become: yes

切换nfs挂载点的playbook

描述:/apps/sharedstorage/jtproduction-hlw 10.246.29.6:/data/nfs---------->10.246.29.18:/data/nfs

#代表解释说明 ###代表根据实际情况修改

---
- name: Update NFS mount point
  hosts: all-nodes
  become: yes
  tasks:
    - name: Unmount old NFS mount point                 #先取消挂载
      mount:
        path: /apps/sharedstorage/jtproduction-hlw      ###修改
        state: unmounted
      become: yes

    - name: Mount new NFS mount point
      mount:
        fstype: nfs
        src: 10.246.29.18:/data/nfs                      ###修改nfs的ip以及共享目录
        path: /apps/sharedstorage/jtproduction-hlw       ###修改
        state: mounted
      become: yes
     
    - name: Add entry to /etc/fstab                      #实现开机自动挂载
      lineinfile:
        path: /etc/fstab                                 
        line: "10.246.29.18:/data/nfs /apps/sharedstorage/jtproduction-hlw nfs defaults 0 0"         ###修改
      become: yes
      
    - name: Comment out the NFS mount                   #把原来的nfs共享目录注释掉
      lineinfile:
        path: /etc/fstab
        regexp: '^10\.246\.29\.6:/data/nfs /apps/sharedstorage/jtproduction-hlw nfs'                ###修改
        line: '# 10.246.29.6:/data/nfs /apps/sharedstorage/jtproduction-hlw nfs defaults 0 0'       ###修改
      become: yes

  • 11
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值