How to create a unique identifier in a cluster of web servers

In the following scenario:

1 Database 4 Web Servers

How do web servers generate a unique identifier for the database to be unique? Yes, it is possible to use Auto-increment, but it is too easy to scan / guess / etc. Thus, auto-increment is currently not an option.

+3
source share
5 answers

Use the UUID ( http://www.ietf.org/rfc/rfc4122.txt ). Collisions are unlikely and can be considered when they occur by regenerating a new UUID, or they can be prevented by combining a unique identifier for each server (for example, MAC address): -

StringBuilder sb = new StringBuilder(UUID.randomUUID());
InetAddress address = InetAddress.getLocalHost();
String uid = sb.append(NetworkInterface.getByInetAddress(address).getHardwareAddress());
+15
source

You can use UUID:

import java.util.UUID;        

UUID uuid = UUID.randomUUID();
System.out.println(uuid.toString());
+3
source

, . , / .

+1

? , ? ?

, , , .

+1

, . , ""? , , , - ?

, , UUID, .

  • , , . , : , 12345678, 0 12345678-1 .

  • , . , , , , , . , .

, , , , -. , - " ", , - , . , 3 . , , , . id , , IP- - .

+1
source

Source: https://habr.com/ru/post/1721498/


All Articles