(1)用户中心的整体功能设计(持续更新)

实际需要,需要一套用户中心的系统,考虑种种原因,没有使用UCenter等系统,决定自己搭建一套,随记录一下:
主要功能:
用户中心
SSO

架构图(持续更新):
58B6A5C8-8ADB-4908-971F-11FC25083998

1、用户id的设计
使用Twitter’s snowflake (pysnowflake)
snowflake-64bit
pysnowflake中基准时间不是1970年,基准时间/usr/lib/python2.7/site-packages/snowflake/server/generator.py:EPOCH_TIMESTAMP = 550281600000不同版本不同,自行设定
pysnowflake配置:
http://pysnowflake.readthedocs.org/en/latest/
Snowflake的使用
安装 requests
pip install requests
安装 pysnowflake
pip install pysnowflake

启动pysnowflake服务

snowflake_start_server \
–address=192.168.137.11 \
–port=30001 \
–dc=1 \
–worker=1 \
–log_file_prefix=/tmp/pysnowflask.log
snowflake_start_server \
–address=192.168.137.11 \
–port=30001 \
–dc=1 \
–worker=1 \
–log_file_prefix=/tmp/pysnowflask.log
–address:本机的IP地址默认localhost这里解释一下参数意思(可以通过–help来获取):
–dc:数据中心唯一标识符默认为0
–worker:工作者唯一标识符默认为0
–log_file_prefix:日志文件所在位置

使用示例(这边引用官网的)

# 导入pysnowflake客户端
>>> import snowflake.client

# 链接服务端并初始化一个pysnowflake客户端
>>> host = ‘localhost’
>>> port = 88001
>>> snowflake.client.setup(host, port)
# 生成一个全局唯一的ID(在MySQL中可以用BIGINT UNSIGNED对应)
>>> snowflake.client.get_guid()
3631957913783762945
# 查看当前状态
>>> snowflake.client.get_stats()
{
‘dc’: 1,
‘worker’: 1,
‘timestamp’: 1454126885629, # current timestamp for this worker
‘last_timestamp’: 1454126890928, # the last timestamp that generated ID on
‘sequence’: 1, # the sequence number for last timestamp
‘sequence_overload’: 1, # the number of times that the sequence is overflow
‘errors’: 1, # the number of times that clock went backward
}

# 导入pysnowflake客户端
>>> import snowflake.client
# 链接服务端并初始化一个pysnowflake客户端
>>> host = ‘192.168.137.11’
>>> port = 88001
>>> snowflake.client.setup(host, port)
# 生成一个全局唯一的ID(在MySQL中可以用BIGINT UNSIGNED对应)
>>> snowflake.client.get_guid()
3631957913783762945
# 查看当前状态
>>> snowflake.client.get_stats()
{
‘dc’: 1,
‘worker’: 1,
‘timestamp’: 1454126885629, # current timestamp for this worker
‘last_timestamp’: 1454126890928, # the last timestamp that generated ID on
‘sequence’: 1, # the sequence number for last timestamp
‘sequence_overload’: 1, # the number of times that the sequence is overflow
‘errors’: 1, # the number of times that clock went backward
}