本篇內容介紹了“怎么提高keystone的效率”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
在譙城等地區,都構建了全面的區域性戰略布局,加強發展的系統性、市場前瞻性、產品創新能力,以專注、極致的服務理念,為客戶提供成都網站設計、網站建設 網站設計制作按需求定制設計,公司網站建設,企業網站建設,品牌網站設計,網絡營銷推廣,成都外貿網站建設公司,譙城網站建設費用合理。
最近在測試OpenStack Havana RDO版本的時候,發現過一段時間后,整個平臺會變動的越來越慢。剛剛開始還沒什么動力去trouble shooting,畢竟就一demo的環境。昨天居然給讓我無法訪問,這就不能忍了,得看看是什么臭蟲在搗鬼。
無意中發現在Nova API調用的過程當中,在向keystone獲取Token的時間會異常的長。而當我剛剛安裝完keystone的時候,整個速度還是很不錯的。查閱了相關的資料,發現Token這塊在數據庫永久存放,而且增長速度還是很快,對keystone的數據庫的表分析如下:
切換到MySQL自帶管理庫information_schema
mysql> use information_schema; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed
查看Token的大小:
mysql> select data_length,index_length from tables where table_schema='keystone' -> and table_name='token'; +-------------+--------------+ | data_length | index_length | +-------------+--------------+ | 916455424 | 17924096 | +-------------+--------------+ 1 row in set (0.01 sec)
用比較直觀的方式查看:
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'; +----------------+-----------------+ | data_length_MB | index_length_MB | +----------------+-----------------+ | 874.00MB | 17.09MB | +----------------+-----------------+ 1 row in set (0.01 sec)
大概兩周的時間,居然有近1G的數據,當然,1G對于數據庫來說也是小case,但如果是一年,這個數據量也是不容忽視的。
在看一下keystone對于token的配置keystone.conf
,主要有幾部分:
[token] # Provides token persistence. driver = keystone.token.backends.sql.Token # driver = keystone.token.backends.memcache.Token # Controls the token construction, validation, and revocation operations. # Core providers are keystone.token.providers.[pki|uuid].Provider # provider = # Amount of time a token should remain valid (in seconds) expiration = 86400
從上述的配置可以token默認存放在數據庫中,默認過期時間為為一天。當然,在launchpad上有很多朋友提到用腳本清除數據庫即可。
這邊的話,也借鑒了一下他們的經驗去解決這個問題,下面是清除token表的腳本。
#!/bin/bash mysql_user= mysql_password= mysql_host= #這里大家可以考慮一下清除數據的時間的問題,為啥是2天 mysql -u${mysql_user} -p${mysql_password} -h${mysql_host} -e 'USE keystone ; DELETE FROM token WHERE NOT DATE_SUB(CURDATE(),INTERVAL 2 DAY) <= expires;'
當然,如果你在清除token的時候不幸遇到如下的錯誤:
ERROR 1205 (HY000) at line 1: Lock wait timeout exceeded; try restarting transaction
只需要增加innodb_lock_wait_timeout
的值:
mysql> show variables like 'innodb_lock_wait_timeout'; +--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | innodb_lock_wait_timeout | 50 | +--------------------------+-------+ 1 row in set (0.00 sec) mysql> set innodb_lock_wait_timeout=100; Query OK, 0 rows affected (0.00 sec) mysql> show variables like 'innodb_lock_wait_timeout'; +--------------------------+-------+ | Variable_name | Value | +--------------------------+-------+ | innodb_lock_wait_timeout | 100 | +--------------------------+-------+
重新運行上面的腳本即可。
當然,兄弟們不能每次自己手動去服務器上執行這個腳本,采用crontab+腳本的方式,腳本clearToken.sh
。
#!/bin/bash mysql_user=keystone mysql_password=******** mysql_host= mysql=$(which mysql) logger -t keystone-cleaner "Starting Keystone 'token' table cleanup" logger -t keystone-cleaner "Starting token cleanup" mysql -u${mysql_user} -p${mysql_password} -h${mysql_host} -e 'USE keystone ; DELETE FROM token WHERE NOT DATE_SUB(CURDATE(),INTERVAL 2 DAY) <= expires;' valid_token=$($mysql -u${mysql_user} -p${mysql_password} -h${mysql_host} -e 'USE keystone ; SELECT * FROM token;' | wc -l) logger -t keystone-cleaner "Finishing token cleanup, there is still $valid_token valid tokens..." exit 0
crontab的定時任務:
[root@controller01 keystone]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed 0 1 * * * /opt/clearToken.sh
為了給MySQL的token表瘦身,可以后端采用Memcached作為Token的存儲后端。但采用Memcached作為后端的存儲。但Memcached這塊,目前還是有些問題:
Token在Memcached中是否永久存儲?
當Memcached宕機時,Cache無法持久化
Memcached采用集群復制,如何去做?
Memcached效率如何?
安裝Memcached服務:
yum -y install memcached
修改keystone.conf
配置文件:
[token] driver = keystone.token.backends.memcache.Token
重啟服務:
service memcached restart service openstack-keystone restart
檢查是否work:
[root@controller01 ~]# lsof -i :11211 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME keystone- 6658 keystone 10u IPv4 20381693 0t0 TCP localhost:41865->localhost:memcache (ESTABLISHED) keystone- 6658 keystone 12u IPv4 19947698 0t0 TCP localhost:33995->localhost:memcache (ESTABLISHED) keystone- 6658 keystone 14u IPv4 20140990 0t0 TCP localhost:37472->localhost:memcache (ESTABLISHED) keystone- 6658 keystone 20u IPv4 20333522 0t0 TCP localhost:40973->localhost:memcache (ESTABLISHED) memcached 28336 memcached 126u IPv4 3050900 0t0 TCP *:memcache (LISTEN) memcached 28336 memcached 127u IPv4 3050902 0t0 UDP *:memcache memcached 28336 memcached 128u IPv4 20381696 0t0 TCP localhost:memcache->localhost:41865 (ESTABLISHED) memcached 28336 memcached 129u IPv4 19947701 0t0 TCP localhost:memcache->localhost:33995 (ESTABLISHED) memcached 28336 memcached 130u IPv4 20140993 0t0 TCP localhost:memcache->localhost:37472 (ESTABLISHED) memcached 28336 memcached 133u IPv4 20333525 0t0 TCP localhost:memcache->localhost:40973 (ESTABLISHED)
可以看到keystone已經和memcached建立了TCP連接。
可以用telnet查看memcached中的token的信息:
root@controller01 ~]# telnet 127.0.0.1 11211 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. stats items STAT items:9:number 1 STAT items:9:age 19766 STAT items:9:evicted 0 STAT items:9:evicted_nonzero 0 STAT items:9:evicted_time 0 STAT items:9:outofmemory 0 STAT items:9:tailrepairs 0 STAT items:11:number 62 STAT items:11:age 81982 STAT items:11:evicted 0 STAT items:11:evicted_nonzero 0 STAT items:11:evicted_time 0 STAT items:11:outofmemory 0 STAT items:11:tailrepairs 0 STAT items:15:number 1 STAT items:15:age 20365 STAT items:15:evicted 0 STAT items:15:evicted_nonzero 0 STAT items:15:evicted_time 0 STAT items:15:outofmemory 0 STAT items:15:tailrepairs 0 STAT items:17:number 1 STAT items:17:age 20287 STAT items:17:evicted 0 STAT items:17:evicted_nonzero 0 STAT items:17:evicted_time 0 STAT items:17:outofmemory 0 STAT items:17:tailrepairs 0 STAT items:18:number 8558 STAT items:18:age 7675 STAT items:18:evicted 0 STAT items:18:evicted_nonzero 0 STAT items:18:evicted_time 0 STAT items:18:outofmemory 0 STAT items:18:tailrepairs 0 STAT items:22:number 1 STAT items:22:age 81605 STAT items:22:evicted 0 STAT items:22:evicted_nonzero 0 STAT items:22:evicted_time 0 STAT items:22:outofmemory 0 STAT items:22:tailrepairs 0 STAT items:28:number 1 STAT items:28:age 81982 STAT items:28:evicted 0 STAT items:28:evicted_nonzero 0 STAT items:28:evicted_time 0 STAT items:28:outofmemory 0 STAT items:28:tailrepairs 0 STAT items:36:number 1 STAT items:36:age 82020 STAT items:36:evicted 0 STAT items:36:evicted_nonzero 0 STAT items:36:evicted_time 0 STAT items:36:outofmemory 0 STAT items:36:tailrepairs 0 END stats cachedump 18 100 ITEM token-9be5243e6765408bb67cd73f66367cdd [3827 b; 1387340643 s] ITEM token-499d93bec0a54ddebdc28ef0941ba7df [3827 b; 1387340702 s] ITEM token-186a1394b2474c998dafc752fd80d058 [3827 b; 1387340700 s] ITEM token-3de99c3d4f174d15a1546ce321d1e3a1 [3824 b; 1387340576 s] ITEM token-fcab58d23ff94369b27a8dc335340028 [3824 b; 1387340697 s] ITEM token-7092f681ebe34cae9830eba8ae7d45f3 [3824 b; 1387340636 s] ITEM token-977cf2ab85e54920b3d3b582dabba7d8 [3824 b; 1387340634 s] ITEM token-49df94c6ef7a4a1582c7539f5829b354 [3824 b; 1387340567 s] ITEM token-7b1f9646734542d5a30dd0cbc8d1937d [3824 b; 1387340569 s] ……
可以看到,目前items:18存放的是token信息。
“怎么提高keystone的效率”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注創新互聯網站,小編將為大家輸出更多高質量的實用文章!
本文名稱:怎么提高keystone的效率
本文地址:http://m.newbst.com/article22/gpjgcc.html
成都網站建設公司_創新互聯,為您提供小程序開發、面包屑導航、App設計、網頁設計公司、網站內鏈、動態網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯