A method and device for allocating a distributed lock is provided. A globally unique service process ID (SPI) is introduced for each distributed application service process while guaranteeing correctness of a distributed lock, and the SPI is used to directly manage ownership of the distributed lock. The service replacement process sends to the server a request for inheriting ownership of the distributed lock before the lifecycle of the lock file expires, the inherit request including the SPI.