linux12企业实战 -- 13多主机磁盘挂载

文章目录

一、多台机器挂载到磁盘

0、准备条件(前提安装好ansible)

[root@k8s-m-01 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.10.110  k8s-m-01 m1
192.168.10.111  k8s-n-01 n1
192.168.10.112  k8s-n-02 n2
[root@k8s-m-01 ~]# cat /etc/ansible/hosts 
[k8s]
172.16.1.111  ansible_ssh_pass='123'
172.16.1.112  ansible_ssh_pass='123'
192.168.10.110 ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass='123'

1、创建目录

[root@k8s-m-01 ~]# ansible k8s -m shell -a 'mkdir -p /data'
[root@k8s-m-01 ~]# ansible k8s -m shell -a 'ls  /data'
172.16.1.112 | CHANGED | rc=0 >>

172.16.1.111 | CHANGED | rc=0 >>

192.168.10.110 | CHANGED | rc=0 >>

2、格式化文件系统

[root@k8s-m-01 ~]# ansible k8s -m shell -a 'echo "y"| mkfs.ext4  /dev/sdb'  (否则就是交互式的)

3、挂载

[root@k8s-m-01 ~]# ansible k8s -m shell -a 'mount /dev/sdb /data'
172.16.1.112 | CHANGED | rc=0 >>

172.16.1.111 | CHANGED | rc=0 >>

192.168.10.110 | CHANGED | rc=0 >>

4、加入开机挂载

[root@k8s-m-01 ~]# ansible k8s -m shell -a "echo '`blkid |grep /dev/sdb|awk '{print$2}'` /data ext4 defaults 0 1' >> /etc/fstab"

5、查看

[root@k8s-m-01 ~]# ansible k8s -m shell -a 'tail -1 /etc/fstab'
172.16.1.111 | CHANGED | rc=0 >>
UUID="X9QWvD-OWHE-lhTd-Gtxm-lGuX-3nSC-WhvBMN" /data ext4 defaults 0 1
172.16.1.112 | CHANGED | rc=0 >>
UUID="X9QSSD-OWHE-lhTd-Gtxm-lGuX-3nSC-WhvBMN" /data ext4 defaults 0 1
192.168.10.110 | CHANGED | rc=0 >>
UUID="X9QOvD-OWHE-lhTd-Gtxm-lGuX-3nSC-WhvBMN" /data ext4 defaults 0 1
上一篇:fiddler提示"The system proxy was changed,click to reenable fiddler capture"的解决方法


下一篇:索引的失效