Skip to content

附录 B 配置文件模板

B.1 ganesha.conf 完整模板

conf
EXPORT {
    Export_Id = 1;
    Path = "/gv0";
    Pseudo = "/gv0";
    Protocols = 3, 4;
    Transports = TCP, UDP;
    Access_Type = RW;
    Squash = No_Root_Squash;
    Attr_Expiration_Time = 60;
    NFS_Commit = true;
    MaxRead = 1048576;
    MaxWrite = 1048576;
    PrefRead = 1048576;
    PrefWrite = 1048576;

    FSAL {
        Name = GLUSTER;
        Hostname = "localhost";
        Volume = "gv0";
    }
}

LOG {
    Default_Log_Level = INFO;
    Components {
        FSAL = FULL_DEBUG;
        NFS4 = EVENT;
    }
}

B.2 keepalived.conf 完整模板

Master 节点

conf
vrrp_script check_ganesha {
    script "/etc/keepalived/check_ganesha.sh"
    interval 2
    weight -50
    fall 2
    rise 2
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1234
    }
    virtual_ipaddress {
        10.0.0.100/24
    }
    track_script {
        check_ganesha
    }
    notify_master "/etc/keepalived/notify.sh master"
    notify_backup "/etc/keepalived/notify.sh backup"
    notify_fault "/etc/keepalived/notify.sh fault"
}

Backup 节点

conf
vrrp_script check_ganesha {
    script "/etc/keepalived/check_ganesha.sh"
    interval 2
    weight -50
    fall 2
    rise 2
}

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1234
    }
    virtual_ipaddress {
        10.0.0.100/24
    }
    track_script {
        check_ganesha
    }
}

健康检查脚本

bash
#!/bin/bash
if systemctl is-active --quiet nfs-ganesha; then
    exit 0
else
    exit 1
fi

B.3 prometheus.yml 模板

yaml
global:
  scrape_interval: 15s
  evaluation_interval: 15s

alerting:
  alertmanagers:
    - static_configs:
        - targets: ['localhost:9093']

rule_files:
  - /etc/prometheus/rules/*.yml

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'node-exporter'
    static_configs:
      - targets:
        - 'node1:9100'
        - 'node2:9100'
        - 'node3:9100'

  - job_name: 'gluster-exporter'
    static_configs:
      - targets:
        - 'node1:9189'
        - 'node2:9189'
        - 'node3:9189'

  - job_name: 'ganesha-exporter'
    static_configs:
      - targets:
        - 'node1:9580'
        - 'node2:9580'
        - 'node3:9580'

B.4 alert rules 模板

yaml
groups:
  - name: nfs-ha
    rules:
      - alert: NodeDown
        expr: up{job="node-exporter"} == 0
        for: 1m
        labels:
          severity: critical
        annotations:
          summary: "节点 {{ $labels.instance }} 不可达"

      - alert: DiskSpaceLow
        expr: (node_filesystem_avail_bytes / node_filesystem_size_bytes) < 0.1
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "磁盘空间不足"

      - alert: GaneshaDown
        expr: ganesha_up == 0
        for: 1m
        labels:
          severity: critical
        annotations:
          summary: "NFS-Ganesha 服务异常"

B.5 /etc/fstab NFS 挂载模板

10.0.0.100:/gv0 /mnt/nfs-ha nfs4 defaults,_netdev,hard,intr,timeo=600,retrans=3,noatime 0 0