Get_uid is a distributed unique ID generator in this package two methods is provided the first method inspired by Twitter's Snowflake: A Sonyflake ID is composed of
39 bits for time in units of 10 msec
8 bits for a sequence number
16 bits for a machine id
the second methos is to take advantage of the key-value and strong consistency of etcd to dynamically generate a globally unique id Build
The project could be build into a Dockerized server with 'make docker-build'. An local image named 'get_uid' is available after that.
$make
$docker build -t get_uid .
About the mysql database:
If you just call the get_uid package, you should install the mysql service on a master server to provide the auto_increment data.
but if what you want is obtain the global id through the interface ,you can run the get_uid program directly.
The machine ID is generated by the self-incrementing of the mysql database,so we should start a Mysql server at first and create a 'guid' database:
$ docker run -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d --rm --name mysql mysql/mysql-server
$ docker exec -ti mysql mysql -hlocalhost -uroot -p123456 -e "create database guid"
mysql: [Warning] Using a password on the command line interface can be insecure.
$ docker exec -ti mysql mysql -hlocalhost -uroot -p123456 -e "show databases"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| guid |
| mysql |
| performance_schema |
| sys |
+--------------------+
$docker run --name container_name -p 8080:8080 get_uid
or in detached:
$docker run --name container_name -p 8080:8080 -d get_uid
You can start multiple services at the same time, by using different ports
$docker run --name container_name1 -p 8080:8080 -d get_uid
$docker run --name container_name2 -p 8081:8080 -d get_uid
$docker run --name container_name3 -p 8082:8080 -d get_uid
$curl 192.168.1.175:8080/user/getuid