1. 程式人生 > >記錄一下nas盤掛載(ansible)

記錄一下nas盤掛載(ansible)

AD sta fst nta ifs 怎麽 note 文件類型 指定

一個nas盤(群輝設備)準備掛載到2臺LINXU服務器上。途中踩了N多自己挖的坑,自己記錄一下,萬一將來再踩到,可以快速找到答案。順便重新對ansible mount梳理一下:

第一掛載方案當然是直接使用nfs掛在,畢竟nas本身就是一個NFS服務。坑的的事情是。。怎麽也掛不上去。

最終發現群輝設備上並沒有開啟NFS服務。。。

好吧,一定要記住先檢查服務是不是可用。。。

因為開始並沒有發現NFS服務並沒有開啟,所以我選擇了第二種掛載方案,使用cifs,這裏也記錄一下用。

1如果是單臺服務器操作,那麽很簡單了。

直接調用:

mount -t cifs -o username="colinshi",password="123456" //192.168.1.2/mydata /mydata

並且在/etc/fstab文件中最後添加一行

echo ‘//192.168.1.2/mydata /mydata cifs username=colinshi,password=00000000 0 0‘ >> /etc/fstab

這裏-t選項不是必須的我發現不是用-t 指明type也可以掛在上去,然後這裏有一個小坑就是username和password之間是使用逗號隔開,而不是使用空格。而且在man mount.cifs裏這個有明確說明,但是為什麽他的實例裏卻沒有說明。

Note that a password which contains the delimiter character (i.e. a comma ′,′) will fail to be parsed correctly on the command line. However, the same password defined in the
PASSWD environment variable or via a credentials file (see below) or entered at the password prompt will be read correctly.

證明學好英文是很重要的。

因為準備掛載到多臺設備上所以準備使用ansible操作

ansible本身提供了一個mount模塊用來掛載各種設備

ansible all -m mount -a ‘state={mounted|unmouted|absent|present} src=(源資源位置://192.168.1.2/mydata) name=(掛載點的位置) fstype=(掛載文件類型:cifs|nfs|ext4) opts=(參數選項:"username=colinshi,password=123456")‘

fstype: # 文件系統類型,當state={present|mounted}的時候必選項
opts: # 想到與mount命令行-o的參數
path: # 必選項,掛載點,在2.3版本之前這個選項只能用作 `dest‘, `destfile‘,`name‘.
src: # 掛載指定路徑的設備,state={present|mounted}的時候必選項
state:必須項,{mounted|unmouted|absent|present}4種狀態。mounted掛載,unmouted卸載,absent只卸載fstab文件內的不影響當前狀態,present只裝載fstab文件內的不影響當前狀態

記錄一下nas盤掛載(ansible)