הגדרת יציאות NFS במכונות וירטואליות של לקוחות

בדף הזה מוסבר איך להגדיר את הפורטים של שדי ה-statd ו-nlockmgr במכונות הווירטואליות של הלקוח כדי להקל על הגדרת חומת האש.

‫Filestore משתמש בדמונים nlockmgr ו-statd כדי לאפשר נעילת קבצים. צריך לחשוף את הפורטים של השירותים האלה במכונות הווירטואליות של הלקוח באמצעות כללים בחומת האש, כדי שהלקוחות יוכלו להשתמש בנעילות בצורה תקינה. מומלץ להגדיר את הפורטים statd ו-nlockmgr כך שיהיו עקביים בכל מכונות ה-VM של הלקוח, כדי להקל על הגדרת כללי חומת האש של הכניסה.

למידע נוסף על קביעה אם צריך להגדיר כלל חומת אש עבור רשת ה-VPC, אפשר לקרוא את המאמר בנושא הגדרת כללים של חומת אש.

בדיקת הגדרות הניוד

כדי לבדוק מהם הערכים שמוגדרים כרגע ליציאות statd ו-nlockmgr, מריצים את הפקודות הבאות במכונת ה-VM של הלקוח. אם הקבצים לא קיימים או אם לא מוגדרים ערכים לאפשרויות, היציאות לא מוגדרות. במקרה כזה, לשדים מוקצים באופן דינמי יציאות שרירותיות שזמינות.

‫Debian/Ubuntu

  1. כדי לראות את הפורט statd, מריצים את הפקודה הבאה ומסתכלים על הערך STATDOPTS:

    cat /etc/default/nfs-common
    
  2. כדי לקבוע את יציאת nlockmgr, מריצים את הפקודה הבאה ומסתכלים על הערכים של nlm_tcpport ו-nlm_udpport:

    cat /etc/modprobe.d/lock.conf
    

RHEL/CentOS

  1. כדי לראות את הפורט statd, מריצים את הפקודה הבאה ומסתכלים על הערך STATD_PORT:

    cat /etc/sysconfig/nfs
    
  2. כדי לקבוע את יציאת nlockmgr, מריצים את הפקודה הבאה ומסתכלים על הערכים של nlm_tcpport ו-nlm_udpport:

    cat /etc/modprobe.d/lock.conf
    

SUSE

מריצים את הפקודה הבאה:

cat /etc/sysconfig/nfs

היציאה statd מופיעה בקטע STATD_PORT והיציאה nlockmgr מופיעה בקטע LOCKD_TCPPORT וLOCKD_UDPPORT.

Windows

אין צורך להגדיר יציאות NFS ב-Windows.

הגדרת יציאות

כדי להגדיר את הפורטים statd ו-nlockmgr, מריצים את הפקודות הבאות במופע של מכונת הלקוח הווירטואלית. בדוגמאות האלה נעשה שימוש בעורך הטקסט nano, אבל אפשר להשתמש בכל עורך טקסט. בדוגמאות האלה נעשה שימוש גם ב-2046 כיציאה ל-statd וב-4045 כיציאה ל-nlockmgr, כי אלה ערכים נפוצים. אתם יכולים להשתמש ביציאות שונות בהתאם להגדרות הרשת שלכם. במקרה כזה, כללי חומת האש של תעבורת נתונים נכנסת (ingress) צריכים לאפשר תעבורה ליציאות הספציפיות שבהן אתם משתמשים.

‫Debian/Ubuntu

  • מגדירים את היציאה statd:

    1. פותחים את קובץ /etc/default/nfs-common לעריכה:

      sudo nano /etc/default/nfs-common
      
    2. מגדירים את האפשרות STATDOPTS:

      STATDOPTS="-p 2046"
      
    3. שומרים את הקובץ ויוצאים.

  • מגדירים את היציאה nlockmgr:

    1. יוצרים את הקובץ /etc/modprobe.d/lock.conf:

      sudo nano /etc/modprobe.d/lock.conf
      
    2. מגדירים את האפשרויות nlm_tcpport ו-nlm_udpport:

      options lockd nlm_tcpport=4045
      options lockd nlm_udpport=4045
      
    3. שומרים את הקובץ ויוצאים.

RHEL/CentOS

  • מגדירים את היציאה statd:

    1. פותחים את קובץ /etc/sysconfig/nfs לעריכה:

      sudo nano /etc/sysconfig/nfs
      
    2. מגדירים את האפשרות STATD_PORT:

      STATD_PORT=2046
      
    3. שומרים את הקובץ ויוצאים.

  • מגדירים את היציאה nlockmgr:

    1. יוצרים את הקובץ /etc/modprobe.d/lock.conf:

      sudo nano /etc/modprobe.d/lock.conf
      
    2. מגדירים את האפשרויות nlm_tcpport ו-nlm_udpport:

      options lockd nlm_tcpport=4045
      options lockd nlm_udpport=4045
      
    3. שומרים את הקובץ ויוצאים.

SUSE

הגדרת היציאות statd ו-nlockmgr:

  1. פותחים את קובץ /etc/sysconfig/nfs לעריכה:

    sudo nano /etc/sysconfig/nfs
    
  2. מגדירים את האפשרויות STATD_PORT, LOCKD_TCPPORT ו-LOCKD_UDPPORT:

    STATD_PORT=2046
    LOCKD_TCPPORT=4045
    LOCKD_UDPPORT=4045
    
  3. שומרים את הקובץ ויוצאים.

Windows

אין צורך להגדיר יציאות NFS ב-Windows.

אימות היציאות הפתוחות

כדי לוודא שהיציאות של NFS נפתחו בצורה תקינה, מבצעים את השלבים הבאים.

  1. מתקינים את יחסי התלות הבאים.

    ‫Debian/Ubuntu

    מזינים את הפקודה הבאה בשורת הפקודה:

    sudo apt install nfs-common tcpdump tshark
    

    RHEL/CentOS

    מזינים את הפקודה הבאה בשורת הפקודה:

    sudo yum install nfs-utils tcpdump wireshark
    

    SUSE

    מזינים את הפקודה הבאה בשורת הפקודה:

    sudo zypper install nfs-client tcpdump wireshark
    

    Windows

    תהליך האימות הזה לא נתמך ב-Windows.

  2. יוצרים קובץ סקריפט בשם verify-nfs-port-script.sh, מעתיקים את הסקריפט הבא ומדביקים אותו בתוך הקובץ, ושומרים אותו באופן מקומי במחשב. שימו לב למיקום הקובץ ושמרו אותו לשלב הבא.

    #!/bin/bash
    
    # This script is intended to run on client machines to verify that the ports
    # are properly open to allow the reception of NLM GRANT messages from the server.
    
    set -eu
    
    function kill_descendants() {
       for pid in $(ps -o pid= --ppid "$1")
       do
       kill_descendants "$pid"
       done
       if [[ $1 -ne $$ ]]; then
       kill "$1" 2>/dev/null | true
       fi
    }
    
    function cleanup {
       set +eu
    
       # Kill all background jobs and wait for it to end, makes sure locks are released
       kill_descendants $$
    
       # Wait for jobs to die and locks to be released, so mount is not busy
       sleep 2
    
       umount -f "$MNT1"
       umount -f "$MNT2"
    
       rmdir "$MNT1" 2&> /dev/null || true
       rmdir "$MNT2" 2&> /dev/null || true
    }
    
    function print_help {
       echo "$0 [server_ip] [mount_path]"
       echo -e "\t For example, if you mount a server using:"
       echo -e "\t\t \"mount 10.0.0.1:share /mnt/mount_point\""
       echo -e "\t Run the script: "
       echo -e "\t\t \"$0 10.0.0.1 share\""
    }
    
    if [ $# -ne 2 ]; then
       print_help
       exit 1
    fi
    
    if [ $(id -u) -ne 0 ]; then
       echo "Failure! This script needs to run as root, use \"sudo $@\""
       exit 1
    fi
    
    if ! [ -x "$(command -v tshark)" ]; then
       echo "The 'tshark' command does not exist and is needed for the script. Please install it"
       exit 1
    fi
    
    if ! [ -x "$(command -v tcpdump)" ]; then
       echo "The 'tcpdump' command does not exist and is needed for the script. Please install it"
       exit 1
    fi
    
    SERVER_IP=$1
    MOUNT_PATH=$2
    
    MNT1=$(mktemp -d)
    MNT2=$(mktemp -d)
    
    trap cleanup EXIT
    
    echo "Mounting..."
    mount -o nosharecache "$SERVER_IP":"$MOUNT_PATH" "$MNT1"
    mount -o nosharecache "$SERVER_IP":"$MOUNT_PATH" "$MNT2"
    
    REC_FILE=$(mktemp /tmp/nlm_recording_XXXXXXXX.pcap)
    tcpdump -i any -s0 -w "$REC_FILE" "host $SERVER_IP" &
    TCPDUMP_PID=$!
    echo "Recording TCP dump to $REC_FILE"
    
    sleep 5 # wait for tcpdump to start running
    
    echo "Running test..."
    flock "$MNT1"/lock_file -c "echo -n \"Got first lock: \" && date && sleep 5 && echo -n \"Releasing first lock: \" && date" &
    sleep 2 # Wait for the first lock to actually be taken
    
    echo "Waiting for second lock: $(date)"
    flock "$MNT2"/lock_file -c "echo -n \"Got second lock: \" && date"
    
    sleep 2 # Wait for tcpdump to record everything
    kill $TCPDUMP_PID
    
    # For quick analysis inspect recording with tshark, if you don't have it just inspect with Wireshark
    echo "Inspecting results in $REC_FILE with TShark"
    tshark -r "$REC_FILE" -Y nlm # First, print the output
    
    tshark -r "$REC_FILE" -Y nlm 2>/dev/null | grep -q GRANTED
    EXIT_CODE=0
    if [ $? -eq 0 ]; then
       echo "The NLM GRANT message is working properly!"
       EXIT_CODE=0
    else
    echo "The NLM GRANT message is not working properly!"
    EXIT_CODE=1
    fi
    echo "For debugging, please provide the printed output of the script, and $REC_FILE"
    exit ${EXIT_CODE}
    
  3. מזינים את הפקודה הבאה:

    chmod +x SCRIPT_PATH
    

    מחליפים את מה שכתוב בשדות הבאים:

    • SCRIPT_PATH: הנתיב שבו נמצא קובץ הסקריפט. צריך להריץ את הפקודה הזו כ-root, אחרת צריך להוסיף sudo לתחילת הפקודה.
  4. מזינים את הפקודה הבאה:

    SCRIPT_PATH INSTANCE_IP SHARE_NAME
    

    מחליפים את מה שכתוב בשדות הבאים:

    • SCRIPT_PATH: הנתיב שבו נמצא קובץ הסקריפט. צריך להריץ את הפקודה הזו כ-root, אחרת צריך להוסיף sudo לתחילת הפקודה.
    • INSTANCE_IP: כתובת ה-IP של מופע Filestore
    • SHARE_NAME: השם של שיתוף הקבצים

    אם היציאה פתוחה, הסקריפט מחזיר את התגובה הבאה:

    The NLM GRANT message is working properly!
    

    אם היציאה לא פתוחה, הסקריפט מחזיר את השגיאה הבאה:

    The NLM GRANT message is not working properly!
    

המאמרים הבאים