简体   繁体   English

如何在Linux或Perl中为每台计算机创建唯一标识符?

[英]How can I create unique identifiers for each machine in Linux or Perl?

I have a Perl script running in many machines, the script will store some data into a MySQL Database. 我在许多机器上运行一个Perl脚本,该脚本会将一些数据存储到MySQL数据库中。 I need to know the source of data. 我需要知道数据源。

I cannot use hostname , because some machines's hostname is 'localhost'. 我不能使用hostname,因为某些计算机的主机名是'localhost'。

ifconfig gives random devices and IP, some eth0 ,some eth1 ,some other device name. ifconfig给出随机设备和IP,一些eth0 ,一些eth1 ,一些其他设备名称。

Is there any other way to create unique identifiers for each machine? 还有其他方法可以为每台计算机创建唯一标识符吗? And everytime I run the Perl script, this unique identifier does not change. 而且,每次我运行Perl脚本时,此唯一标识符都不会更改。

You can try uuid. 您可以尝试使用uuid。

uuid - DCE compatible Universally Unique Identifier library uuid-DCE兼容的通用唯一标识符库

here 这里

除了先前对genhostid的调用之外,还应该使用hostid ,该调用将生成并存储机器的唯一ID(因此,每次调用该ID都不会改变)。

The output from dmidecode provides a number of hardware UUID & serial numbers which your perl script could take advantage of. dmidecode的输出提供了许多硬件UUID和序列号,您的perl脚本可以利用这些序列号。 To quote the man page for dmidecode: 引用dmidecode的手册页:

  dmidecode is a tool for dumping a computer's DMI (some say SMBIOS) table contents in a human-readable format. This table contains a description of the system's hardware components, as well as other useful pieces of information such as serial numbers and BIOS revision. 

The best way I've found is to generate a file with a random ID the first time, and use the file contents once the file exists. 我发现最好的方法是第一次生成具有随机ID的文件,并在文件存在后使用文件内容。 I put it in /etc somewhere, but it doesn't matter. 我把它放在/ etc的某个地方,但这没关系。

This is tolerant of system configuration changes, but requires some extra work to interrogate remotely. 这可以容忍系统配置更改,但是需要一些额外的工作才能进行远程查询。

take MAC address and modify it? 取MAC地址并修改它?

ipconfig -a

or 要么

arp

and parse? 解析?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM