Cluster

GFS2 單寫多讀設置

  • April 30, 2018

我希望您對我正在實施的設置提出建議,以便允許多個主機在共享 iSCSI 儲存上共享偶爾變化的數據。我正在使用 GFS2 共享對 iSCSI 上的 LVM2 邏輯卷的訪問,我寧願避免使用 CoroSync 等設置集群的複雜性。

我已將文件系統格式化為鎖定設置為lock_nolock和單個日誌。單個節點將負責執行定期更新,這通常包括將新文件複製到卷中但不更改現有文件,並且所有其他節點會將其掛載為spectator,ro。根據手冊頁,這將:

使用一種特殊形式的只讀掛載來掛載這個文件系統。掛載不使用文件系統的日誌之一。該節點無法恢復其他節點的日誌。

我可以合理地期望這個設置是穩定和高性能的嗎?有什麼我應該注意的問題嗎?

我可以假設嘗試從多個主機掛載 R/W 會失敗,因為文件系統只有一個日誌嗎?

我已經實現了上面的設置,它工作得很好,但有一個主要限制:正在安裝 R/O 的主機無法知道共享卷已更改。從具有寫訪問權限的主機執行更新後,我需要手動同步文件系統,然後強制讀取客戶端使用類似echo -n 2 | sudo -n /bin/dd of=/proc/sys/vm/drop_caches. 請注意,如果文件內容可能發生變化,您需要寫入 3 而不是 2,才能刷新文件。

我有時會遇到的另一個問題是,R/O 客戶端可能無法以“權限被拒絕”掛載共享儲存。要解決此問題,我需要從 R/W 節點解除安裝卷,安裝在遇到問題的任何 R/O 節點上,然後再次安裝在 R/W 節點上。

下面是一個完成此任務的 Ansible 角色:

---
- name: Determine the canonical path of the shared-data directory
set_fact:
   shared_dir_real_path: "{{ shared_dir_path | realpath }}"

- debug:
   msg: "Manually forcing flushing and re-read of directories on volume at {{ shared_dir_path }} (real path: {{ shared_dir_real_path }})."
   verbosity: 1

- name: Determine shared-dir mount point
command: "/usr/bin/env stat -c '%m' {{ shared_dir_real_path }}"
register: shared_dir_mount_point
changed_when: False

- name: Determine the mount point's filesystem type and mount options
set_fact:
   "shared_dir_mount_{{ item }}": "{{ ansible_mounts | selectattr('mount', 'equalto', shared_dir_mount_point.stdout) | map(attribute = item) | join(',') }}"
with_items:
   - fstype
   - options

- name: Verify the shared-dir is mounted GFS2
assert:
   that: "'{{ shared_dir_mount_fstype }}' == 'gfs2'"

- name: Determine the access to the shared-data directory
set_fact:
   shared_dir_access_flags: "{{ ['ro', 'rw']  | intersect( shared_dir_mount_options.split(',') )}}"

- name: Verify Access mode sanity
assert:
   that: shared_dir_access_flags | length == 1

- name: Sync the shared filesystem
command: "sudo -n /bin/sync -f {{ shared_dir_real_path }}"
args:
 warn: false # Silence warning about the use of sude instead of 'become', which is here deliberate

when: "'rw' in shared_dir_access_flags"

- name: Force re-load of directory inodes
shell: "echo -n 2 | sudo -n /bin/dd of=/proc/sys/vm/drop_caches"
when: "'ro' in shared_dir_access_flags"

引用自:https://serverfault.com/questions/905226