Google Code Prettify
2018年6月3日 星期日
2016年7月14日 星期四
Generate Swagger Specification
在網路上與官方網站的範例大多是在 Application Server 上產生 swagger.json
但這種方法會讓 Server 浪費資源,也有漏洞的風險
Swagger高危漏洞,影響Html、PHP、Java和 Ruby等開發應用
原文網址:https://read01.com/Lz7eJg.html
最近終於找到能獨立產出 swagger.json 的方式,程式碼如下
但這種方法會讓 Server 浪費資源,也有漏洞的風險
Swagger高危漏洞,影響Html、PHP、Java和 Ruby等開發應用
原文網址:https://read01.com/Lz7eJg.html
最近終於找到能獨立產出 swagger.json 的方式,程式碼如下
2016年3月5日 星期六
Distributed Load Testing Tool
Tsung http://tsung.erlang-projects.org/
這一套壓力測式的工具,設定相當方便 也提供相關數據圖表
需在每個 Client Node 安裝 Tsung 與 設定 SSH Authorized 登入,才能順利分散壓力
這一套壓力測式的工具,設定相當方便 也提供相關數據圖表
需在每個 Client Node 安裝 Tsung 與 設定 SSH Authorized 登入,才能順利分散壓力
SSH Authorized 設定範例
- cd /root
- ssh-keygen -t rsa
- cd .ssh
- cat id_rsa.pub > authorized_keys
- chmod 600 authorized_keys
- ssh-copy-id root@ClientNode
Tsung Install
- yum install erlang gnuplot libtemplate-perl liberation-sans-fonts perl-Template-Toolkit
- wget http://tsung.erlang-projects.org/dist/tsung-1.6.0.tar.gz
- tar zxvf tsung-1.6.0.tar.gz
- cd tsung-1.6.0
- ./configure && make && make install
Tsung Load Test Commond
- tsung -k -f test.xml start
Tsung Load Test Report Site
- http://testsite:8091/es/ts_web:status
2016年2月29日 星期一
wildfly 10 add postgresql jdbc driver
1. ./bin/jboss-cli.sh --connect
2. module add --name=org.postgresql --slot=main --resources=/software/java/postgresql-9.4.1208.jar --dependencies=javax.api,javax.transaction.api
3. /subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
執行完這3個步驟,回傳 {"outcome" => "success"}
即為增加成功
2. module add --name=org.postgresql --slot=main --resources=/software/java/postgresql-9.4.1208.jar --dependencies=javax.api,javax.transaction.api
3. /subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql",driver-class-name=org.postgresql.Driver)
即為增加成功
2016年2月21日 星期日
Apache Kafka 9.0 需注意的地方
Apache Kafka 9.0
Documentation http://kafka.apache.org/documentation.html
kafka 雖然沒限制 topics 的數量,但在機器數量少時 還是需要避免這種設計方式
因為kafka 是使用 file 的儲存方式,每一個topics 至少會產生1個目錄與2個檔案
kafka cluster 中的所有檔案數量是:
(topics * partition * replication-factor * 2) + (offsets * n)
100K topics 在 3台 kafka 主機裡,至少會產生:
(100K * 1 * 1 * 2) +(N) = 200k + N
每台 kafka 至少要產生 200K / 3 (約66666) 的檔案,超過一般linux fs.file-max = 65536 的設定,當然這還是有辦法解決
但在每個 partition 都需要相對應的 thread 來處理,這就比較麻煩了
100K 需要多少 thread 來處理才能夠即時回應,不造成timeout?
每台硬體都要有足夠的RAM 跟 夠好的 CPU時 也許可行, 但還是避掉這種設計會比較好
在設定檔有幾個需要注意的地方
server.properties
Documentation http://kafka.apache.org/documentation.html
kafka 雖然沒限制 topics 的數量,但在機器數量少時 還是需要避免這種設計方式
因為kafka 是使用 file 的儲存方式,每一個topics 至少會產生1個目錄與2個檔案
kafka cluster 中的所有檔案數量是:
(topics * partition * replication-factor * 2) + (offsets * n)
100K topics 在 3台 kafka 主機裡,至少會產生:
(100K * 1 * 1 * 2) +(N) = 200k + N
每台 kafka 至少要產生 200K / 3 (約66666) 的檔案,超過一般linux fs.file-max = 65536 的設定,當然這還是有辦法解決
但在每個 partition 都需要相對應的 thread 來處理,這就比較麻煩了
100K 需要多少 thread 來處理才能夠即時回應,不造成timeout?
每台硬體都要有足夠的RAM 跟 夠好的 CPU時 也許可行, 但還是避掉這種設計會比較好
在設定檔有幾個需要注意的地方
server.properties
- broker.id 需特別注意編號 每台主機不可重覆
- 如果需要 delete topic,需增加 delete.topic.enable=true
- client.id 在每個 thread 不能重覆
consumer.properties
可參考 http://myjeeva.com/zookeeper-cluster-setup.html
設定 zookeeper cluster id
- group.id=PG 修改預設的group id
- offsets.storage=kafka 設定 offset 資料存在 kafka
可參考 http://myjeeva.com/zookeeper-cluster-setup.html
修改 zookeeper.properties
設定 zookeeper cluster id
mkdir /tmp/zookeeper/
echo 1 > /tmp/zookeeper/myid (id 需特別注意編號,跟zookeeper.properties 需對應)
2016年2月15日 星期一
Jetty 參數修改
關閉 http dir view
修改 etc/webdefault.xml, dirAllowed value 設為 false設定 classloading 優先讀 jetty resources
修改 etc/jetty-deploy.xml,在 WebAppProvider 下增加預設classloading 順序為 webapps > jetty resources > jetty lib
改完參數則會變為 jetty lib > jetty resources > webapps
webapps 下的檔案, 如果 xml 跟 war 名稱不一致 會重覆載入
Server thread 設定max thread參考計算
thread.max > (http.acceptors + http.selectors + [http.request=1])
PostgreSQL Multi-Master 雙向複寫
安裝 PostgreSQL BDR 版本
What's BDR?
http://2ndquadrant.com/en-us/resources/bdr/
What's BDR?
http://2ndquadrant.com/en-us/resources/bdr/
Yum Install
- yum install http://packages.2ndquadrant.com/postgresql-bdr94-2ndquadrant/yum-repo-rpms/postgresql-bdr94-2ndquadrant-redhat-1.0-2.noarch.rpm
- yum install postgresql-bdr94-bdr
設定PostgreSQL lib
vi /etc/profile 增加下方資訊
export PATH=/usr/pgsql-9.4/bin:$PATH
Init DB
- service postgresql-9.4 initdb -E UTF8 --no-locale --locale=C LC_COLLATE='C' LC_CTYPE='C' -A trust -U postgres
- cd /var/lib/pgsql/9.4-bdr/
- vi data/pg_hba.conf
- vi data/postgresql.conf
- service postgresql-9.4 start
- chkconfig postgresql-9.4 on
Create DB
- CREATE ROLE message LOGIN ENCRYPTED PASSWORD 'yourpassword md5' VALID UNTIL 'infinity';
- CREATE DATABASE message WITH ENCODING='UTF8' OWNER=message TEMPLATE=template0 LC_COLLATE='C' LC_CTYPE='C' CONNECTION LIMIT=-1;
message DB, BDR Setting
##first node
CREATE EXTENSION btree_gist;
CREATE EXTENSION bdr;
SELECT bdr.bdr_group_create(
local_node_name := 'centos1',
node_external_dsn := 'host=centos1 dbname=message'
);
##second node
CREATE EXTENSION btree_gist;
CREATE EXTENSION bdr;
SELECT bdr.bdr_group_join(
local_node_name := 'centos2',
node_external_dsn := 'host=centos2 dbname=message',
join_using_dsn := 'host=centos1 dbname=message'
);
更多設定可參考quictstart
2016年2月13日 星期六
Distributed Lock
這幾年一直在碰 HA 相關的系統
一直有一些需求,希望這個程式能在一個 cluster 環境中,只有一台主機執行
不想用DB存相關資料,但一直找不到簡單方便的解決方法
終於發現有一個能跟 java 結合,不需另外寫script
jgroups 提供一個 LockService , 可以實現 DistributedLock
DistributedLock 可以用來做什麼?
一直有一些需求,希望這個程式能在一個 cluster 環境中,只有一台主機執行
不想用DB存相關資料,但一直找不到簡單方便的解決方法
終於發現有一個能跟 java 結合,不需另外寫script
jgroups 提供一個 LockService , 可以實現 DistributedLock
DistributedLock 可以用來做什麼?
- Transaction lock , 補足一些 NoSQL 不支援的問題
- Service running lock, 讓 Master Node 執行 job, 其它Node 則是一直等待
- other lock ???
寫了一個sample code 放在 git
2015年8月24日 星期一
PostgreSQL 9.3 HA Script
PostgreSQL 9.3 已經內建 Hot Standby 的機制
這時只要在加上 Linux Virtual Host, 就能達到 High Availability DB
寫了一個 shell script 在 git 上
https://github.com/yulinliu/postgres_ha
在加上網路、DB 的基本設定就可正常運作
這時只要在加上 Linux Virtual Host, 就能達到 High Availability DB
寫了一個 shell script 在 git 上
https://github.com/yulinliu/postgres_ha
在加上網路、DB 的基本設定就可正常運作
2015年8月19日 星期三
RESTful Services 幾項重點
1. HTTP Method 對應Server處理方式
2. Server Response Content Type
3. 透過 HTTP Authorization 限制使用者存取資源的權限,也可用其它方式(ip、cookie)
| HTTP Method | Data operate | Description |
|---|---|---|
| POST | Create | Create a resource without id. |
| GET | Read | Get a resource. |
| PUT | Update | Update a resource or create a resource with id if not existed. |
| DELETE | Delete | Delete a resource |
JSON or XML or Text
4. response status code、error code 直接參考 http status code
5. REST 中的資源 一般是名詞 (podcasts, customers, user, accounts 等) 而不是動詞 (getPodcast, deleteUser 等)
2014年9月5日 星期五
2014年5月2日 星期五
Cross-origin resource sharing
參考網址:
http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing
https://developer.mozilla.org/en- US/docs/Web/HTTP/Access_control_CORS
Cross domain issue
目前遇到無法正常運作的情形
解決方式
Server 端增加回傳 Header
http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing
https://developer.mozilla.org/en- US/docs/Web/HTTP/Access_control_CORS
Cross domain issue
目前遇到無法正常運作的情形
- Ajax 取回不同domain主機的檔案
- Canvas.toDataURL()
解決方式
Server 端增加回傳 Header
- Access-Control-Allow-Origin "*"
- Access-Control-Allow-Methods "GET"
Client 端使用 Image 時
- img.crossOrigin = "anonymous";
2013年12月24日 星期二
Apache Shiro Password Hashing
SHA 512 Hash
Sha512Hash s = new Sha512Hash("password", "salt string", 1024);
UsernamePasswordToken token = new UsernamePasswordToken("milla", s.toString());
Subject subject = SecurityUtils.getSubject();
subject.login(token);
Apache Shiro Cryptography Features
http://shiro.apache.org/cryptography-features.html2013年10月8日 星期二
Apache Shiro Use Cache Server
Apache Shiro 已經有內建 Cache 機制,http://shiro.apache.org/caching.html
但也能自行 implement,整合其它的 Cache Server (JCache, Ehcache, JCS, OSCache, JBossCache, TerraCotta, Coherence, GigaSpaces)
implement 方式,可以參考這個網址
http://www.java2s.com/Open-Source/Java/Authentication-Authorization/shrio/org/apache/shiro/cache/ehcache/Catalogehcache.htm
使用時,需在 shiro.ini 增加幾行資料
#Use Infinispan HotRod Cache
cacheManager = com.test.cache.SessionCacheManager
securityManager.cacheManager = $cacheManager
sessionDAO = org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO
securityManager.sessionManager.sessionDAO = $sessionDAO
但也能自行 implement,整合其它的 Cache Server (JCache, Ehcache, JCS, OSCache, JBossCache, TerraCotta, Coherence, GigaSpaces)
implement 方式,可以參考這個網址
http://www.java2s.com/Open-Source/Java/Authentication-Authorization/shrio/org/apache/shiro/cache/ehcache/Catalogehcache.htm
使用時,需在 shiro.ini 增加幾行資料
#Use Infinispan HotRod Cache
cacheManager = com.test.cache.SessionCacheManager
securityManager.cacheManager = $cacheManager
sessionDAO = org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO
securityManager.sessionManager.sessionDAO = $sessionDAO
Apache Shiro JdbcRealm and RememberMe
僅需要在 shiro.ini 增加幾行資料
#Setting JdbcRealm
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
#取得帳號密碼
jdbcRealm.authenticationQuery = select user_pass from users where user_name = ?
#取得Roles資料
jdbcRealm.userRolesQuery = select role_name from user_roles where user_name = ?
#使用JNDI DataSource
dataSource = org.apache.shiro.jndi.JndiObjectFactory
dataSource.resourceName = java:/comp/env/jdbc/EmployeeDB
jdbcRealm.dataSource = $dataSource
securityManager.realms = $jdbcRealm
#-----------------------------------------------------------------------------------------
#Setting RememberMe
rememberMeManager = org.apache.shiro.web.mgt.CookieRememberMeManager
securityManager.rememberMeManager = $rememberMeManager
securityManager.rememberMeManager.cookie.name = remember_me
#設定cookie.maxAge = blah , cookie會無法正常寫入
#securityManager.rememberMeManager.cookie.maxAge = blah
securityManager.rememberMeManager.cookie.domain = testdomain.com
#Setting JdbcRealm
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
#取得帳號密碼
jdbcRealm.authenticationQuery = select user_pass from users where user_name = ?
#取得Roles資料
jdbcRealm.userRolesQuery = select role_name from user_roles where user_name = ?
#使用JNDI DataSource
dataSource = org.apache.shiro.jndi.JndiObjectFactory
dataSource.resourceName = java:/comp/env/jdbc/EmployeeDB
jdbcRealm.dataSource = $dataSource
securityManager.realms = $jdbcRealm
#-----------------------------------------------------------------------------------------
#Setting RememberMe
rememberMeManager = org.apache.shiro.web.mgt.CookieRememberMeManager
securityManager.rememberMeManager = $rememberMeManager
securityManager.rememberMeManager.cookie.name = remember_me
#設定cookie.maxAge = blah , cookie會無法正常寫入
#securityManager.rememberMeManager.cookie.maxAge = blah
securityManager.rememberMeManager.cookie.domain = testdomain.com
2013年5月29日 星期三
Cloudera Manager Free 監控
本來想利用別人寫好的 https://github.com/cloudera/ cm_api
但安裝時遇到些問題,CentOS 5 的 Python 只有 2.4.3
上面的套件需要 2.5以上 才能使用
只好自己來囉,Cloudera Manager 本身就有提供 API,透過HTTP,即可取得相關資料
文件在 http://unimelb.sportalhosting.com/static/apidocs/tutorial.html
只要先取得 clusters 資料,在依序取得 services 資料就行了
Service的回傳JSON資料,可參考 http://unimelb.sportalhosting.com/static/apidocs/ns0_apiService.html
但安裝時遇到些問題,CentOS 5 的 Python 只有 2.4.3
上面的套件需要 2.5以上 才能使用
只好自己來囉,Cloudera Manager 本身就有提供 API,透過HTTP,即可取得相關資料
文件在 http://unimelb.sportalhosting.com/static/apidocs/tutorial.html
只要先取得 clusters 資料,在依序取得 services 資料就行了
Service的回傳JSON資料,可參考 http://unimelb.sportalhosting.com/static/apidocs/ns0_apiService.html
2013年5月22日 星期三
Hive 備忘錄
HIVE文件存儲格式的測試比較
http://hugh-wangp.iteye.com/blog/1404708
Hive index
http://blog.csdn.net/yfkiss/article/details/7863577
Hive JDBC
https://cwiki.apache.org/Hive/hivejdbcinterface.html
https://cwiki.apache.org/confluence/display/Hive/HiveClient
http://ccfangle.iteye.com/blog/1775936
http://www.cloudera.com/content/cloudera-content/cloudera-docs/CDH4/4.2.0/CDH4-Installation-Guide/cdh4ig_topic_18_2.html
Hive Gzip 壓縮
http://www.ifshall.com/tag/rcfile/
Hive Data Types
https://cwiki.apache.org/Hive/languagemanual-types.html
Hive DML
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML
http://hugh-wangp.iteye.com/blog/1404708
Hive index
http://blog.csdn.net/yfkiss/article/details/7863577
Hive JDBC
https://cwiki.apache.org/Hive/hivejdbcinterface.html
https://cwiki.apache.org/confluence/display/Hive/HiveClient
http://ccfangle.iteye.com/blog/1775936
http://www.cloudera.com/content/cloudera-content/cloudera-docs/CDH4/4.2.0/CDH4-Installation-Guide/cdh4ig_topic_18_2.html
Hive Gzip 壓縮
http://www.ifshall.com/tag/rcfile/
Hive Data Types
https://cwiki.apache.org/Hive/languagemanual-types.html
Hive DML
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DML
HBase 大量寫入
Server 在有限的記憶體下,Memstore的控制相當重要
HBase 在大量寫入時,可能會造成 Out Of Memory
盡可能使用批量寫入的方式
參考下列文章
http://blog.linezing.com/2012/03/hbase-performance-optimization
http://www.cnblogs.com/panfeng412/archive/2012/03/08/hbase-performance-tuning-section3.html
HBase 在大量寫入時,可能會造成 Out Of Memory
盡可能使用批量寫入的方式
參考下列文章
http://blog.linezing.com/2012/03/hbase-performance-optimization
http://www.cnblogs.com/panfeng412/archive/2012/03/08/hbase-performance-tuning-section3.html
HTML5 Canvas Scale Smoothing
Canvas 預設 放大/縮小 會做 Smoothing,但反而造成不必要的模糊
在 Chrome 、 Firefox 提供關閉的方式
ctx.imageSmoothingEnabled = false;
ctx.webkitImageSmoothingEnabled = false;
ctx.mozImageSmoothingEnabled = false;
測試網址如下:
http://jsfiddle.net/saviski/pGs4f/12/
http://jsfiddle.net/P36cS/2/
在 Chrome 、 Firefox 提供關閉的方式
ctx.imageSmoothingEnabled = false;
ctx.webkitImageSmoothingEnabled = false;
ctx.mozImageSmoothingEnabled = false;
測試網址如下:
http://jsfiddle.net/saviski/pGs4f/12/
http://jsfiddle.net/P36cS/2/
C10M 備忘錄
The C10M problem
解決方式: http://c10m.robertgraham.com/p/blog-page.html
相關文章
簡中: http://www.open-open.com/lib/view/open1369096743247.html
原文:http://highscalability.com/blog/2013/5/13/the-secret-to-10-million-concurrent-connections-the-kernel-i.html
C10M Google 論壇
https://groups.google.com/forum/#!topic/mechanical-sympathy/ao44gonVdAY
改善 TCP封包遺失,穩定網路封包的套件
http://www.ntop.org/products/pf_ring/
PF_RING 測試文章
http://www.metaflows.com/technology/pf-ring/
http://codet.net/wordpress/285.html
訂閱:
文章 (Atom)
