[AIX 네트워크 관리 37] NFS (6) 네트워크 잠금 관리자(rpc.lockd·rpc.statd), NFS 포트 범위, NFS 보안

핵심 정리

  • 네트워크 잠금 관리자(rpc.lockd, 커널 스레드)와 상태 감시자(rpc.statd, 사용자 프로세스)가 NFS 위에서 System V 방식의 권고 잠금을 제공합니다. 강제 잠금은 지원하지 않고, NFS 버전 2·3 전용입니다(v4는 프로토콜 자체에 잠금이 있음).
  • 원격 파일 잠금은 클라이언트의 잠금 관리자가 서버에 RPC로 보내며, 처음 요청 때 양쪽이 statd에 상대를 등록합니다. 클라이언트가 죽으면 서버는 그 잠금을 풀고, 서버가 죽었다 살아나면 클라이언트가 잠금을 다시 보내 유예 기간(기본 45초) 안에 되찾습니다. 상대 목록은 /var/statmon/sm, sm.bak에 둡니다.
  • 시작 순서가 중요합니다. 언제나 rpc.statd를 먼저 시작합니다. /etc/rc.nfs의 해당 줄이 주석 처리되어 있지 않은지 확인합니다.
  • "clnttcp_create: RPC: Remote System error - Connection refused"는 statd가 sm.bak의 호스트에 복구를 알리지 못해 생깁니다. 상대 서버의 데몬을 띄우거나, 그 호스트가 잠금에 관여하지 않는다고 확실할 때만 클라이언트에서 데몬을 멈추고 sm.bak의 항목을 지운 뒤 다시 시작합니다.
  • 잠금을 못 얻으면 ping과 /var/statmon/hosts의 이름 일치를 확인하고, 두 데몬을 서버 먼저, 클라이언트 다음으로 다시 시작하며, 그래도 안 되면 rpc.lockd -d1로 syslog에 진단을 남깁니다. 클라이언트 원본 포트는 /etc/environment의 NFS_PORT_RANGE=udp[…]:tcp[…]로 제한합니다.
항목 내용
버전 AIX 5.3, AIX 6.1 (6.1에서 포트 범위 주의 문장이 더해짐)
원문 Networks and communication management — 5.3판 423427쪽, 6.1판 530534쪽
파일 /etc/rc.nfs, /var/statmon/sm, /var/statmon/sm.bak, /var/statmon/hosts, /etc/environment, /etc/services
관련 명령어 rpc.lockd, rpc.statd, startsrc, stopsrc, lssrc, ping

네트워크 잠금 관리자는 NFS(Network File System)와 협력해 네트워크 너머로 System V 방식의 권고(advisory) 파일·레코드 잠금을 제공하는 기능입니다.

네트워크 잠금 관리자(rpc.lockd)와 네트워크 상태 감시자(rpc.statd)는 네트워크 서비스 데몬입니다. rpc.statd 데몬은 사용자 수준 프로세스이고, rpc.lockd 데몬은 (NFS 서버처럼) 커널 스레드 묶음으로 구현되어 있습니다. 두 데몬 모두 커널이 기본 네트워크 서비스를 제공하는 데 꼭 필요합니다.

주:

  1. 강제(mandatory, enforced) 잠금은 NFS에서 지원하지 않습니다.
  2. 네트워크 잠금 관리자는 NFS 버전 2와 버전 3 전용입니다.
영어 원문

Network lock manager

The network lock manager is a facility that works in cooperation with the Network File System (NFS) to provide a System V style of advisory file and record locking over the network.

The network lock manager (rpc.lockd) and the network status monitor (rpc.statd) are network-service daemons. The rpc.statd daemon is a user level process while the rpc.lockd daemon is implemented as a set of kernel threads (similar to the NFS server). Both daemons are essential to the ability of the kernel to provide fundamental network services.

Note

  1. Mandatory or enforced locks are not supported over NFS.

  2. Network Lock Manager is specific to NFS Version 2 and Version 3.

네트워크 잠금 관리자 구조

네트워크 잠금 관리자에는 서버 기능과 클라이언트 기능이 모두 있습니다.

클라이언트 기능은 응용 프로그램의 요청을 처리하고 서버의 네트워크 잠금 관리자에 요청을 보내는 일을 맡습니다. 서버 기능은 클라이언트의 잠금 요청을 받아 서버에서 알맞은 잠금 호출을 만드는 일을 맡습니다. 그런 다음 서버가 클라이언트의 잠금 요청에 응답합니다.

상태가 없는 NFS와 달리 네트워크 잠금 관리자에는 암묵적인 상태가 있습니다. 곧 네트워크 잠금 관리자는 클라이언트가 지금 잠금을 갖고 있는지 기억해야 합니다. 네트워크 상태 감시자 rpc.statd는 네트워크 잠금 관리자가 네트워크의 다른 기계 상태를 감시하게 하는 간단한 프로토콜을 구현합니다. 정확한 상태 정보가 있으므로 네트워크 잠금 관리자는 상태 없는 NFS 환경 안에서도 일관된 상태를 유지할 수 있습니다.

영어 원문

Network lock manager architecture

The network lock manager contains both server and client functions.

The client functions are responsible for processing requests from the applications and sending requests to the network lock manager at the server. The server functions are responsible for accepting lock requests from clients and generating the appropriate locking calls at the server. The server will then respond to the locking request of the client.

In contrast to NFS, which is stateless, the network lock manager has an implicit state. In other words, the network lock manager must remember whether the client currently has a lock. The network status monitor, rpc.statd, implements a simple protocol that allows the network lock manager to monitor the status of other machines on the network. By having accurate status information, the network lock manager can maintain a consistent state within the stateless NFS environment.

네트워크 파일 잠금 과정

응용 프로그램이 로컬 파일에 잠금을 얻으려 할 때는 lockf, fcntl, flock 서브루틴으로 커널에 요청을 보냅니다.

그러면 커널이 잠금 요청을 처리합니다. 그러나 NFS 클라이언트의 응용 프로그램이 원격 파일에 잠금을 요청하면, 네트워크 잠금 관리자 클라이언트가 요청을 처리하도록 서버에 RPC(Remote Procedure Call)를 만듭니다.

클라이언트는 처음 원격 잠금 요청을 받으면 클라이언트의 rpc.statd 데몬에 서버에 대한 관심을 등록합니다. 서버의 네트워크 잠금 관리자도 마찬가지입니다. 클라이언트에서 처음 요청을 받으면 로컬 네트워크 상태 감시자에 그 클라이언트에 대한 관심을 등록합니다.

영어 원문

Network file locking process

When an application wants to obtain a lock on a local file, it sends its request to the kernel using the lockf, fcntl, or flock subroutines.

The kernel then processes the lock request. However, if an application on an NFS client makes a lock request for a remote file, the Network Lock Manager client generates a Remote Procedure Call (RPC) to the server to handle the request.

When the client receives an initial remote lock request, it registers interest in the server with the client's rpc.statd daemon. The same is true for the network lock manager at the server. On the initial request from a client, it registers interest in the client with the local network status monitor.

충돌 복구 과정

각 기계의 rpc.statd 데몬은 다른 모든 기계의 rpc.statd 데몬에 자기 활동을 알립니다. rpc.statd 데몬은 다른 기계가 충돌했거나 복구되었다는 알림을 받으면 자기 rpc.lockd 데몬에 알립니다.

서버가 충돌하면 잠긴 파일이 있는 클라이언트가 잠금을 되찾을 수 있어야 합니다. 클라이언트가 충돌하면 그 서버들은 클라이언트가 복구하는 동안 클라이언트 잠금을 지켜야 합니다. 또 NFS의 전체 투명성을 지키려면 응용 프로그램 자체의 개입 없이 충돌 복구가 이루어져야 합니다.

충돌 복구 절차는 간단합니다. 클라이언트의 실패가 감지되면, 서버는 클라이언트 응용 프로그램이 필요할 때 다시 잠금을 요청할 것이라고 가정하고 실패한 클라이언트의 잠금을 풉니다. 서버의 충돌과 복구가 감지되면, 클라이언트 잠금 관리자는 전에 서버가 허락한 모든 잠금 요청을 다시 보냅니다. 서버는 이렇게 다시 보낸 정보로 유예 기간 동안 잠금 상태를 다시 만듭니다. (유예 기간은 기본 45초이며, 서버가 클라이언트에게 잠금을 되찾을 수 있게 하는 기간입니다.)

rpc.statd 데몬은 /var/statmon/sm과 /var/statmon/sm.bak에 보관한 호스트 이름으로, 기계가 작업을 복구해야 할 때 어떤 호스트에 알려야 하는지 추적합니다.

영어 원문

Crash recovery process

The rpc.statd daemon on each machine notifies the rpc.statd daemon on every other machine of its activities. When the rpc.statd daemon receives notice that another machine crashed or recovered, it notifies its rpc.lockd daemon.

If a server crashes, clients with locked files must be able to recover their locks. If a client crashes, its servers must hold the client locks while it recovers. Additionally, to preserve the overall transparency of NFS, the crash recovery must occur without requiring the intervention of the applications themselves.

The crash recovery procedure is simple. If the failure of a client is detected, the server releases the failed client locks on the assumption that the client application will request locks again as needed. If the crash and recovery of a server is detected, the client lock manager retransmits all lock requests previously granted by the server. This retransmitted information is used by the server to reconstruct its locking state during a grace period. (The grace period, 45 seconds by default, is a time period within which a server allows clients to reclaim their locks.)

The rpc.statd daemon uses the host names kept in /var/statmon/sm and /var/statmon/sm.bak to keep track of which hosts must be informed when the machine needs to recover operations.

네트워크 잠금 관리자 시작

기본으로 /etc/rc.nfs 스크립트가 다른 NFS 데몬과 함께 rpc.lockd와 rpc.statd 데몬을 시작합니다.

NFS가 이미 실행 중이면 NFS 데몬의 현재 상태 보기의 지시에 따라 rpc.lockd와 rpc.statd 데몬이 실행 중인지 확인할 수 있습니다. 두 데몬의 상태는 active여야 합니다. rpc.lockd와 rpc.statd 데몬이 활성이 아니어서 실행 중이 아니면 다음과 같이 합니다.

  1. 좋아하는 텍스트 편집기로 /etc/rc.nfs 파일을 엽니다.
  2. 다음 줄을 찾습니다.
text
if [ -x /usr/sbin/rpc.statd ]; then
       startsrc -s rpc.statd
fi
if [ -x /usr/sbin/rpc.lockd ]; then
       startsrc -s rpc.lockd
fi
  1. 이 줄들 가운데 맨 앞에 파운드 기호(#)가 있는 것이 있으면 그 문자를 지우고 파일을 저장한 뒤 빠져나옵니다. 그런 다음 NFS 데몬 시작의 지시에 따라 rpc.statd와 rpc.lockd 데몬을 시작합니다.

    참고: 순서가 중요합니다. 언제나 statd 데몬을 먼저 시작합니다.

  2. NFS가 실행 중이고 /etc/rc.nfs 파일의 항목이 올바르면, NFS 데몬 정지와 NFS 데몬 시작의 지시에 따라 rpc.statd와 rpc.lockd 데몬을 멈췄다 다시 시작합니다.

    참고: 순서가 중요합니다. 언제나 statd 데몬을 먼저 시작합니다.

그래도 rpc.statd와 rpc.lockd 데몬이 실행되지 않으면 네트워크 잠금 관리자 문제 해결을 봅니다.

영어 원문

Starting the network lock manager

By default, the /etc/rc.nfs script starts the rpc.lockd and rpc.statd daemons along with the other NFS daemons.

If NFS is already running, you can verify that the rpc.lockd and rpc.statd daemons are running by following the instructions in Getting the current status of the NFS daemons. The status of these two daemons should be active. If the rpc.lockd and rpc.statd daemons are not active, and therefore not running, do the following:

  1. Using your favorite text editor, open the /etc/rc.nfs file.

  2. Search for the following lines:

text
if [ -x /usr/sbin/rpc.statd ]; then
       startsrc -s rpc.statd
fi
if [ -x /usr/sbin/rpc.lockd ]; then
       startsrc -s rpc.lockd
fi
  1. If there is a pound sign (#) at the beginning of any of these lines, delete the character, then save and exit the file. Then start the rpc.statd and rpc.lockd daemons by following the instructions in Starting the NFS daemons.

Note: Sequence is important. Always start the statd daemon first.

  1. If NFS is running and the entries in the /etc/rc.nfs file are correct, stop and restart the rpc.statd and rpc.lockd daemons by following the instructions in Stopping the NFS daemons and Starting the NFS daemons.

Note: Sequence is important. Always start the statd daemon first.

If the rpc.statd and rpc.lockd daemons are still not running, see “Troubleshooting the network lock manager.”

네트워크 잠금 관리자 문제 해결

네트워크 잠금 관리자에서 만나는 일부 문제는 다음 요령으로 풀 수 있습니다.

클라이언트에서 다음과 비슷한 메시지를 받으면:

text
clnttcp_create: RPC: Remote System error - Connection refused
rpc.statd:cannot talk to statd at {server}

기계는 복구 조치를 해야 할 수 있다고 알려야 할 다른 기계가 있다고 생각하고 있는 것입니다. 기계가 다시 시작하거나 rpc.lockd와 rpc.statd 데몬을 멈췄다 다시 시작하면, 기계 이름이 /var/statmon/sm에서 /var/statmon/sm.bak으로 옮겨지고, rpc.statd 데몬은 /var/statmon/sm.bak의 각 항목에 해당하는 기계에 복구 절차가 필요하다고 알리려 합니다.

rpc.statd 데몬이 그 기계에 닿으면 /var/statmon/sm.bak의 해당 항목이 지워집니다. 닿지 못하면 일정한 간격으로 계속 시도합니다. 기계가 응답하지 않을 때마다 시간 초과로 위 메시지가 생깁니다. 잠금 무결성을 위해 데몬은 계속 시도하지만, 이것이 잠금 성능에 나쁜 영향을 줄 수 있습니다. 처리 방법은 대상 기계가 단지 응답하지 않는 것인지, 거의 영구적으로 운영에서 빠진 것인지에 따라 다릅니다. 메시지를 없애려면:

  1. NFS 데몬의 현재 상태 보기의 지시에 따라 서버의 statd와 lockd 데몬이 실행 중인지 확인합니다. (두 데몬의 상태는 active여야 합니다.)

  2. 이 데몬들이 실행 중이 아니면 NFS 데몬 시작의 지시에 따라 서버에서 rpc.statd와 rpc.lockd 데몬을 시작합니다.

    참고: 순서가 중요합니다. 언제나 statd 데몬을 먼저 시작합니다. 데몬을 다시 시작한 뒤에는 유예 기간이 있다는 것을 기억합니다. 이 시간 동안 lockd 데몬은 전에 서버와 잠금을 갖고 있던 다른 클라이언트의 되찾기 요청을 받아들이므로, 데몬을 시작한 바로 뒤에는 새 잠금을 얻지 못할 수 있습니다.

또는 다음과 같이 메시지를 없앱니다.

  1. NFS 데몬 정지의 지시에 따라 클라이언트에서 rpc.statd와 rpc.lockd 데몬을 멈춥니다.
  2. 클라이언트에서 다음을 입력해 /var/statmon/sm.bak에서 대상 기계 항목을 지웁니다.
text
rm /var/statmon/sm.bak/ TargetMachineName

이렇게 하면 대상 기계가 잠금 복구에 참여해야 할 수 있다는 것을 알지 못하게 됩니다. 그 기계에 영향을 받는 기계와 네트워크 잠금에 참여하는 응용 프로그램이 실행되고 있지 않다고 판단할 수 있을 때만 써야 합니다. 3. NFS 데몬 시작의 지시에 따라 클라이언트에서 rpc.statd와 rpc.lockd 데몬을 시작합니다.

클라이언트에서 잠금을 얻을 수 없으면 다음과 같이 합니다.

  1. ping 명령으로 클라이언트와 서버가 서로 닿고 알아보는지 확인합니다. 두 기계가 모두 실행 중이고 네트워크가 멀쩡하면 각 기계의 /var/statmon/hosts 파일에 나열된 호스트 이름을 확인합니다. 기계를 알아보려면 서버와 클라이언트의 호스트 이름이 정확히 맞아야 합니다. 호스트 이름 풀이에 이름 서버를 쓰면 호스트 정보가 /var/statmon/hosts 파일의 것과 정확히 같은지 확인합니다.

  2. NFS 데몬의 현재 상태 보기의 지시에 따라 클라이언트와 서버 모두에서 rpc.lockd와 rpc.statd 데몬이 실행 중인지 확인합니다. 두 데몬의 상태는 active여야 합니다.

  3. 활성이 아니면 NFS 데몬 시작의 지시에 따라 rpc.statd와 rpc.lockd 데몬을 시작합니다.

  4. 활성이면 클라이언트와 서버 모두에서 재설정해야 할 수 있습니다. 그러려면 잠금을 요청하는 응용 프로그램을 모두 멈춥니다.

  5. 다음으로 NFS 데몬 정지의 지시에 따라 클라이언트와 서버 모두에서 rpc.statd와 rpc.lockd 데몬을 멈춥니다.

  6. 이제 NFS 데몬 시작의 지시에 따라 rpc.statd와 rpc.lockd 데몬을 서버에서 먼저, 그다음 클라이언트에서 다시 시작합니다.

    참고: 순서가 중요합니다. 언제나 statd 데몬을 먼저 시작합니다.

이 절차로 잠금 문제가 풀리지 않으면 다음과 같이 lockd 데몬을 디버그 모드로 실행합니다.

  1. NFS 데몬 정지의 지시에 따라 클라이언트와 서버 모두에서 rpc.statd와 rpc.lockd 데몬을 멈춥니다.
  2. NFS 데몬 시작의 지시에 따라 클라이언트와 서버에서 rpc.statd 데몬을 시작합니다.
  3. 다음을 입력해 클라이언트와 서버에서 rpc.lockd 데몬을 시작합니다.
text
/usr/sbin/rpc.lockd -d1

-d1 플래그로 실행하면 lockd 데몬이 syslog에 진단 메시지를 남깁니다. 처음에는 유예 기간에 관한 메시지가 여럿 나오니 시간이 다 될 때까지 기다립니다. 서버와 모든 클라이언트에서 유예 기간이 끝나면 잠금 문제가 있는 응용 프로그램을 실행하고, 잠금 요청이 클라이언트에서 서버로, 서버에서 클라이언트로 전송되는지 확인합니다.

/var/statmon/environment 파일에 NFS_PORT_RANGE 변수를 설정해, NFS 클라이언트가 NFS 서버와 통신하는 데 쓰는 IP 포트 번호 범위를 제한할 수 있습니다.

영어 원문

Troubleshooting the network lock manager

Some network lock manager problems you encounter can be solved by using the following tips.

If you receive a message on a client similar to:

text
clnttcp_create: RPC: Remote System error - Connection refused
rpc.statd:cannot talk to statd at {server}

then the machine thinks there is another machine which needs to be informed that it might have to take recovery measures. When a machine restarts, or when the rpc.lockd and the rpc.statd daemons are stopped and restarted, machine names are moved from /var/statmon/sm to /var/statmon/sm.bak and the rpc.statd daemon tries to inform each machine corresponding to each entry in /var/statmon/sm.bak that recovery procedures are needed.

If the rpc.statd daemon can reach the machine, then its entry in /var/statmon/sm.bak is removed. If the rpc.statd daemon cannot reach the machine, it will keep trying at regular intervals. Each time the machine fails to respond, the timeout generates the above message. In the interest of locking integrity, the daemon will continue to try; however, this can have an adverse effect on locking performance. The handling is different, depending on whether the target machine is just unresponsive or semi-permanently taken out of production. To eliminate the message:

  1. Verify that the statd and lockd daemons on the server are running by following the instructions in Getting the current status of the NFS daemons. (The status of these two daemons should be active.)

  2. If these daemons are not running, start the rpc.statd and rpc.lockd daemons on the server by following the instructions in Starting the NFS daemons.

Note: Sequence is important. Always start the statd daemon first. After you have restarted the daemons, remember that there is a grace period. During this time, the lockd daemons allow reclaim requests to come from other clients that previously held locks with the server, so you might not get a new lock immediately after starting the daemons.

Alternatively, eliminate the message by:

  1. Stop the rpc.statd and rpc.lockd daemons on the client by following the instructions in Stopping the NFS daemons.

  2. On the client, remove the target machine entry from /var/statmon/sm.bak file by entering:

text
rm /var/statmon/sm.bak/ TargetMachineName

This action keeps the target machine from being aware that it might need to participate in locking recovery. It should only be used when it can be determined that the machine does not have any applications running that are participating in network locking with the affected machine.

  1. Start the rpc.statd and rpc.lockd daemons on the client by following the instructions in Starting the NFS daemons.

If you are unable to obtain a lock from a client, do the following:

  1. Use the ping command to verify that the client and server can reach and recognize each other. If the machines are both running and the network is intact, check the host names listed in the /var/statmon/hosts file for each machine. Host names must exactly match between server and client for machine recognition. If a name server is being used for host name resolution, make sure the host information is exactly the same as that in the /var/statmon/hosts file.

  2. Verify that the rpc.lockd and rpc.statd daemons are running on both the client and the server by following the instructions in Getting the current status of the NFS daemons. The status of these two daemons should be active.

  3. If they are not active, start the rpc.statd and rpc.lockd daemons by following the instructions in Starting the NFS daemons.

  4. If they are active, you might need to reset them on both clients and servers. To do this, stop all the applications that are requesting locks.

  5. Next, stop the rpc.statd and rpc.lockd daemons on both the client and the server by following the instructions in Stopping the NFS daemons.

  6. Now, restart the rpc.statd and rpc.lockd daemons, first on the server and then on the client, by following the instructions in Starting the NFS daemons.

Note: Sequence is important. Always start the statd daemon first.

If the procedure does not alleviate the locking problem, run the lockd daemon in debug mode, by doing the following:

  1. Stop the rpc.statd and rpc.lockd daemons on both the client and the server by following the instructions in Stopping the NFS daemons.

  2. Start the rpc.statd daemon on the client and server by following the instructions in Starting the NFS daemons.

  3. Start the rpc.lockd daemon on the client and server by typing:

text
/usr/sbin/rpc.lockd -d1

When invoked with the -d1 flag, the lockd daemon provides diagnostic messages to syslog. At first, there will be a number of messages dealing with the grace period; wait for them to time out. After the grace period has timed out on both the server and any clients, run the application that is having lock problems and verify that a lock request is transmitted from client to server and server to client.

You can restrict the number range of IP ports used by the NFS client for communication with the NFS server by setting the NFS_PORT_RANGE variable in the /var/statmon/environment file.

NFS 포트 범위

NFS_PORT_RANGE 환경 변수로 클라이언트가 서버로 하는 네트워크 호출의 출발지 포트를 제한할 수 있습니다.

쓴다면 이 환경 변수는 /etc/environment 파일에 더해야 합니다. 환경 변수의 형식은 다음과 같습니다.

text
NFS_PORT_RANGE=udp[4000-5000]:tcp[7000-8000]

이 예에서 클라이언트가 보내는 UDP 패킷의 출발지 포트는 40005000 범위이고, TCP 연결의 출발지 포트는 70008000 범위입니다. (6.1) 포트 재사용 문제를 피하려면 이 범위에 지정한 포트 번호를 /etc/services 파일에서 어떤 NFS 데몬의 고정 포트 번호로도 쓰면 안 됩니다.

영어 원문

NFS port ranges

The NFS_PORT_RANGE environment variable can be used to limit the source port of network calls the client makes to the server.

If used, this environment variable must be added to the /etc/environment file. The format of the environment variable is as follows:

text
NFS_PORT_RANGE=udp[4000-5000]:tcp[7000-8000]

In this example, UDP packets sent by the client have a source port in the range 4000 - 5000, and TCP connections have a source port in the range 7000 - 8000. To avoid port reuse problems, the port numbers that are specified in this range must not be used as fixed port numbers for any of the Network File System (NFS) daemons in the /etc/services file.

NFS 보안

NFS 보안에 관한 정보는 여러 곳에 있습니다.

DES 보안의 자세한 내용은 Security의 Network File System security 항목이 설명합니다. Kerberos 보안에 관한 정보는 RPCSEC-GSS용 네트워크 설정을 봅니다.

영어 원문

NFS security

Information about NFS security can be found in several places.

The Network File System security topic in Security explains the details about DES security. For information about Kerberos security, see Setting up a network for RPCSEC-GSS.