Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a host unique ID?

I have several applications which works together and need to communicate.

These applications can be installed on different host, which can be in different local networks, but all are connected together via a global network.

The host can be Linux (CenOS, Debian, Ubuntu) or Windows (7/10).

Now, I need to identify which host is running an application.

The requirements are : - every application running on the same host have the same "host ID" - every "host ID" is unique among all hosts

Since the host can be physical machines, virtual machines or even docker instances, I don't think I can use the hostname as a "global unique ID".

Since the host can be in different local networks, I don't think I can use local IP address as a "global unique ID".

So, which data can I use ? Maybe the Network adapter MAC address ? Is it guaranteed to be unique, even between multiple instances of the same docker ?

Thanks.

like image 401
Aurelien Avatar asked Jan 07 '23 01:01

Aurelien


1 Answers

On modern / recent Linux distro, linux generates for you a unique id in the /etc/machine-id file when the system is created the first time. Some distributed services such as etcd rely on this file to identify machines in a cluster.

Nothing prevents you from creating and persisting on disk something like a uuid. You can use uuidgen command on Linux for that.

like image 98
Christophe Schmitz Avatar answered Jan 08 '23 14:01

Christophe Schmitz