1. 将token存放至memcached
由于token在每次访问都会产生,默认有效期是24小时,增长速度非常快,token表数据越来越多,很可能一天就产生几百MB的数据。这种情况下,可以考虑写个定时脚本清理token表。更好的方法是将token放到memcaced中,利用memcached特性,自动删除不使用的缓存,有关memcached的配置参考《ubuntu 14.04 memcached配置》,http://blog.csdn.net/nanhai_happy/article/details/46434265。keystone的配置如下:
vim /etc/keystone/keystone.conf
[token]
provider = keystone.token.providers.uuid.Provider
driver = keystone.token.persistence.backends.memcache.Token
[memcache]
servers = localhost:11211
2. 优化性能,keystone部署到apache
参考《Ubuntu 14.04一步一步安装Openstack Kilo版本-7》内容部分,http://blog.csdn.net/nanhai_happy/article/details/46424357#t5
其中processes和threads可以根据实际情况进行修改
3. token flush
发现使用Horizon创建或查询数据速度变慢,或者mysql占用CPU过高,亦或备份数据库尤其是备份keystone数据库时耗时太长,这时候要考虑清理keystone数据库中token表。
keystone默认使用SQL数据库存储token,token默认有效期为1天。
但是Openstack中每个组件执行的每次命令(请求),都需要token来验证,这就造成keystone创建了大量的token,随着时间的推移,无效的记录越来越多,企业私有云几天的量就可以几万条、几十万条。这么多无效的token导致针对token表的SQL语句变慢。
mysql中查看token大小,MySQL自带管理库information_schema
mysql>use information_schema;
mysql>select concat(round(sum(data_length/1024/1024),2),'MB') as data_length_MB,concat(round(sum(index_length/1024/1024),2),'MB') as index_length_MB from tables where table_schema='keystone' and table_name='token';
keystone里提供了一个工具,定时清理过期的token,建议在crontab中定时执行。
把这条命令加入到crontab里,根据需要运行就可以了,例如每小时运行一次。
* */1 * * * /usr/bin/keystone-manage token_flush >/dev/null 2>&1
在token上我再补充一些内容,鉴于PKI过于庞大,不仅对Keystone,对Horizon上的HTTP的负载也会加大,所以在私有云环境下我们完全可以用UUID来代替默认的PKI。
[token]
provider = keystone.token.providers.uuid.Provider
driver = keystone.token.persistence.backends.sql.Token
4. 使用PKI格式token