??xml version="1.0" encoding="utf-8" standalone="yes"?> So now you have: The percent utilization will be Y / (X x C) * 100 d|桥 使用openvswitch建立|桥Qkvm使用Q命令如下: 建立|桥br #ovs-vsctl add-br br0 把eth0(物理Z|的|卡)d到br0 #ovs-vsctl add-port br0 eth0 如果不出意外的话现在机器׃能上|了Q可以按照以下方法解?/p> 删除eth0的配|?/p> #ifconfig eth0 0 为br0分配ip #dhclient br0 因ؓ我用的是dhcp获取ip的,所以执行了此命令,如果你的ip是自己手动配|的Q请把eth0的配|写到br0上?/p>
]]>
]]>
import java.util.concurrent.*;
osx = ManagementFactory.getOperatingSystemMXBean();
cores = osx.getAvailableProcessors(); // Factorial to keep the process busy so we can see some actual activity
factorial = { n -> int fact = 1; int i = 1; while(i <= n) { i++; fact *= i; } return fact; }
long elapsedTime = -1, startTime = -1; long elapsedCpu = -1, startCpu = -1;;
for(i in 0..20) { startTime = System.nanoTime(); startCpu = osx.getProcessCpuTime(); CountDownLatch latch = new CountDownLatch(cores); for(x in 1..cores) { Thread.startDaemon() { factorial(1000000); latch.countDown(); } } latch.await(); elapsedTime = System.nanoTime()-startTime; elapsedCpu = osx.getProcessCpuTime()-startCpu; percUsage = (elapsedCpu / (elapsedTime* cores)) *100; println "Percent Usage:$percUsage %"; }
]]>
]]>
]]>
]]>
]]>
]]>
]]>
tip:
]]>
iso:
]]>
MD5Digest();
byte[] bytes = "111111".getBytes();
dig.update(bytes, 0, bytes.length);
byte[] md5 = new byte[dig.getDigestSize()];
dig.doFinal(md5, 0);
System.out.println(new String(Base64.encode(md5)));
1、官Ҏ?基本用户手册Qhttp://directory.apache.org/apacheds/basic-user-guide.html 主要介绍了安装以及基本操作、登录等?/p>
2、官Ҏ?高用户手册Qhttp://directory.apache.org/apacheds/advanced-user-guide.html 介绍了代码编译、系l结构、服务配|以及服务权限管理,q里吐槽一下,真的很难懂,q且各种TODOQ?/p>
3、看h像官方的文档Qhttp://joacim.breiler.com/apacheds/book.html 介绍得很详尽Q例子也很丰富?/p>
4、访问控制实?nbsp;FR20_ApacheDS_Access_Control_Administration_The_X.500_Way.pdf
=============================================================================================================
常用的名词解析:
DIT Directory Information Tree
AA administrative areas
AP administrative points
AAA autonomous administrative area 有自L的管理区域,所有的实体均统一理
SAA specific administrative area 特定理区域
IAA inner administrative area 内部理区域
SAP specific administrative point
ACI Access Control Information
Usually an entry is selected as the administrative point and marked with an operational attribute. The attributeType of the operational attribute is 'administrativeRole'.
通过d一个可选属性来使一个实体成为管理点
ACSA access control specific area
=================================================================================================================
实战演练
需求:
1、LDAP理员,理LDAP上的所有数据;
2、匿名用户可以查看用户信息;
3、用户分为开发、测试和q维三组Q?/p>
4、通过用户l授?/p>
操作指南Q?/p>
1、安装ApacheDS服务端;
下蝲地址Q?a target="_blank" style="color: #6a3906; text-decoration: none;">apacheds-2.0.0-M15-64bit.bin 下蝲到目?home/apacheds/
2、安装Apache Directory Studio
本次使用Eclipse插gQ详?http://directory.apache.org/studio/installation-in-eclipse.htmlQ也支持Eclipse market安装?/p>
3、连接与配置
切换到Eclipse的LDAP视图Q新?/p>
hostname:199.155.122.90 portQ?0389 encryption method: nocryption Q不同加密算法端口注意)
authentication method: simple user:uid=admin,ou=system passwd:secret Q默认的最高权限用P
OpenConfiguration启用Access ControlQ禁用匿名登?/p>
重启apacheds服务生效
4、分|?/p>
pȝ默认example分区Q我们删除之Qƈ新徏Q本ơ创建dc=xxx.com
5、新建ou=usersQ新建ou=groups?/p>
//---
System.out.println(TimeZone.getDefault()); //
输出当前默认时区
final TimeZone zone = TimeZone.getTimeZone("GMT+8"); //
获取中国时区
TimeZone.setDefault(zone); //
讄时区
System.out.println(TimeZone.getDefault()); //
输出验证
//---
除了上面的解x法外Q还可以Q?/p>
?/p>
TOMCAT
?/p>
JAVA
q行参数d
-Duser.timezone=Asia/Shanghai
或者,如果有启动的定时器或首次执行的代码,可以使用语句
System.setProperty("user.timezone","Asia/Shanghai");
来设|?/p>
但是x区问题,
q样~码实在太烦Q?/p>
所以你要知道如何从Ҏ上解决问题:
tomcat的catalina.sh:
JAVA_OPTS="$JAVA_OPTS -Duser.timezone=Asia/Shanghai"
开发的软g产品在交付用的时候,往往会授权一D|间的试用期,q个时候license派上用Z。不同于在代码中直接加上旉U束Q需要重新授权的时候用license可以避免修改源码Q改动部|Ԍ授权方直接生成一个新的license发送给使用Ҏ换掉原来的license文g卛_。下面将讲述使用truelicense来实现license的生成和使用。Truelicense是一个开源的证书理引擎Q详l介l见https://truelicense.java.net/
一、首先介l下license授权机制的原理:
1?生成密钥对,Ҏ有很多?/p>
2?授权者保留私钥,使用U钥对包含授权信息(如用截止日期,MAC地址{)的licenseq行数字{?/p>
3?公钥l用者(攑֜验证的代码中使用Q,用于验证license是否W合使用条g?/p>
接下来是本例制作license的具体步骤:
二、第一步:使用keytool生成密钥?/p>
以下命o在dos命o行执行,注意当前执行目录Q最后生成的密钥对即在该目录下:
1、首先要用KeyTool工具来生成私匙库Q(-alias别名 –validity 3650表示10q有效)
keytool -genkey -alias privatekey -keystoreprivateKeys.store -validity 3650
2、然后把U匙库内的公匙导出到一个文件当中:
keytool -export -alias privatekey -file certfile.cer -keystore privateKeys.store
3、然后再把这个证书文件导入到公匙库:
keytool -import -alias publiccert -file certfile.cer -keystore publicCerts.store
最后生成文件privateKeys.store、publicCerts.store拯出来备用?/p>
三、第二步Q生成证书(该部分代码由授权者独立保执行)
1?首先LicenseManagerHolder.javac:
package cn.melina.license; import de.schlichtherle.license.LicenseManager; import de.schlichtherle.license.LicenseParam; /** * LicenseManager?????? * @author melina */ public class LicenseManagerHolder { private static LicenseManager licenseManager; public static synchronized LicenseManager getLicenseManager(LicenseParam licenseParams) { if (licenseManager == null) { licenseManager = new LicenseManager(licenseParams); } return licenseManager; } }
2?然后是主要生成license的代码CreateLicense.javaQ?/p>
package cn.melina.license; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Properties; import java.util.prefs.Preferences; import javax.security.auth.x500.X500Principal; import de.schlichtherle.license.CipherParam; import de.schlichtherle.license.DefaultCipherParam; import de.schlichtherle.license.DefaultKeyStoreParam; import de.schlichtherle.license.DefaultLicenseParam; import de.schlichtherle.license.KeyStoreParam; import de.schlichtherle.license.LicenseContent; import de.schlichtherle.license.LicenseParam; import de.schlichtherle.license.LicenseManager; /** * CreateLicense * @author melina */ public class CreateLicense { //common param private static String PRIVATEALIAS = ""; private static String KEYPWD = ""; private static String STOREPWD = ""; private static String SUBJECT = ""; private static String licPath = ""; private static String priPath = ""; //license content private static String issuedTime = ""; private static String notBefore = ""; private static String notAfter = ""; private static String consumerType = ""; private static int consumerAmount = 0; private static String info = ""; // Z方便直接用的API里的例子 // X500Princal是一个证书文件的固有格式Q详见API private final static X500Principal DEFAULTHOLDERANDISSUER = new X500Principal( "CN=Duke、OU=JavaSoft、O=Sun Microsystems、C=US"); public void setParam(String propertiesPath) { // 获取参数 Properties prop = new Properties(); InputStream in = getClass().getResourceAsStream(propertiesPath); try { prop.load(in); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } PRIVATEALIAS = prop.getProperty("PRIVATEALIAS"); KEYPWD = prop.getProperty("KEYPWD"); STOREPWD = prop.getProperty("STOREPWD"); SUBJECT = prop.getProperty("SUBJECT"); KEYPWD = prop.getProperty("KEYPWD"); licPath = prop.getProperty("licPath"); priPath = prop.getProperty("priPath"); //license content issuedTime = prop.getProperty("issuedTime"); notBefore = prop.getProperty("notBefore"); notAfter = prop.getProperty("notAfter"); consumerType = prop.getProperty("consumerType"); consumerAmount = Integer.valueOf(prop.getProperty("consumerAmount")); info = prop.getProperty("info"); } public boolean create() { try { /************** 证书发布者端执行 ******************/ LicenseManager licenseManager = LicenseManagerHolder .getLicenseManager(initLicenseParams0()); licenseManager.store((createLicenseContent()), new File(licPath)); } catch (Exception e) { e.printStackTrace(); System.out.println("客户端证书生成失?"); return false; } System.out.println("服务器端生成证书成功!"); return true; } // q回生成证书旉要的参数 private static LicenseParam initLicenseParams0() { Preferences preference = Preferences .userNodeForPackage(CreateLicense.class); // 讄对证书内容加密的对称密码 CipherParam cipherParam = new DefaultCipherParam(STOREPWD); // 参数1,2从哪个Class.getResource()获得密钥?参数3密钥库的别名;参数4密钥库存储密?参数5密钥库密? KeyStoreParam privateStoreParam = new DefaultKeyStoreParam( CreateLicense.class, priPath, PRIVATEALIAS, STOREPWD, KEYPWD); LicenseParam licenseParams = new DefaultLicenseParam(SUBJECT, preference, privateStoreParam, cipherParam); return licenseParams; } // 从外部表单拿到证书的内容 public final static LicenseContent createLicenseContent() { DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); LicenseContent content = null; content = new LicenseContent(); content.setSubject(SUBJECT); content.setHolder(DEFAULTHOLDERANDISSUER); content.setIssuer(DEFAULTHOLDERANDISSUER); try { content.setIssued(format.parse(issuedTime)); content.setNotBefore(format.parse(notBefore)); content.setNotAfter(format.parse(notAfter)); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } content.setConsumerType(consumerType); content.setConsumerAmount(consumerAmount); content.setInfo(info); // 扩展 content.setExtra(new Object()); return content; } }
3?试E序licenseCreateTest.javaQ?/p>
package cn.melina.license; import cn.melina.license.CreateLicense; public class licenseCreateTest { public static void main(String[] args){ CreateLicense cLicense = new CreateLicense(); //获取参数 cLicense.setParam("./param.properties"); //生成证书 cLicense.create(); } }
4?生成时用到的param.properties文g如下Q?/p>
##########common parameters########### #alias PRIVATEALIAS=privatekey #key(该密码生成密钥对的密码,需要妥善保,不能让用者知? KEYPWD=bigdata123456 #STOREPWD(该密码是在用keytool生成密钥Ҏ讄的密钥库的访问密? STOREPWD=abc123456 #SUBJECT SUBJECT=bigdata #licPath licPath=bigdata.lic #priPath priPath=privateKeys.store ##########license content########### #issuedTime issuedTime=2014-04-01 #notBeforeTime notBefore=2014-04-01 #notAfterTime notAfter=2014-05-01 #consumerType consumerType=user #ConsumerAmount consumerAmount=1 #info info=this is a license
Ҏproperties文g可以看出Q这里只单设|了使用旉的限Ӟ当然可以自定义添加更多限制。该文g中表C授权者拥有私钥,q且知道生成密钥对的密码。ƈ且设|?/span>license的内宏V?/span>
四、第三步Q验证证书(使用证书Q(该部分代码结合需要授权的E序使用Q?/p>
1?首先LicenseManagerHolder.javac,同上?/p>
2?然后是主要验证license的代码VerifyLicense.javaQ?/p>
package cn.melina.license; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import java.util.prefs.Preferences; import de.schlichtherle.license.CipherParam; import de.schlichtherle.license.DefaultCipherParam; import de.schlichtherle.license.DefaultKeyStoreParam; import de.schlichtherle.license.DefaultLicenseParam; import de.schlichtherle.license.KeyStoreParam; import de.schlichtherle.license.LicenseParam; import de.schlichtherle.license.LicenseManager; /** * VerifyLicense * @author melina */ public class VerifyLicense { //common param private static String PUBLICALIAS = ""; private static String STOREPWD = ""; private static String SUBJECT = ""; private static String licPath = ""; private static String pubPath = ""; public void setParam(String propertiesPath) { // 获取参数 Properties prop = new Properties(); InputStream in = getClass().getResourceAsStream(propertiesPath); try { prop.load(in); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } PUBLICALIAS = prop.getProperty("PUBLICALIAS"); STOREPWD = prop.getProperty("STOREPWD"); SUBJECT = prop.getProperty("SUBJECT"); licPath = prop.getProperty("licPath"); pubPath = prop.getProperty("pubPath"); } public boolean verify() { /************** 证书使用者端执行 ******************/ LicenseManager licenseManager = LicenseManagerHolder .getLicenseManager(initLicenseParams()); // 安装证书 try { licenseManager.install(new File(licPath)); System.out.println("客户端安装证书成?"); } catch (Exception e) { e.printStackTrace(); System.out.println("客户端证书安装失?"); return false; } // 验证证书 try { licenseManager.verify(); System.out.println("客户端验证证书成?"); } catch (Exception e) { e.printStackTrace(); System.out.println("客户端证书验证失?"); return false; } return true; } // q回验证证书需要的参数 private static LicenseParam initLicenseParams() { Preferences preference = Preferences .userNodeForPackage(VerifyLicense.class); CipherParam cipherParam = new DefaultCipherParam(STOREPWD); KeyStoreParam privateStoreParam = new DefaultKeyStoreParam( VerifyLicense.class, pubPath, PUBLICALIAS, STOREPWD, null); LicenseParam licenseParams = new DefaultLicenseParam(SUBJECT, preference, privateStoreParam, cipherParam); return licenseParams; } }
3?试E序licenseVerifyTest.javaQ?/p>
package cn.melina.license; public class licenseVerifyTest { public static void main(String[] args){ VerifyLicense vLicense = new VerifyLicense(); //获取参数 vLicense.setParam("./param.properties"); //验证证书 vLicense.verify(); } }
4?验证时用到的Properties文g如下Q?/p>
##########common parameters########### #alias PUBLICALIAS=publiccert #STOREPWD(该密码是在用keytool生成密钥Ҏ讄的密钥库的访问密? STOREPWD=abc123456 #SUBJECT SUBJECT=bigdata #licPath licPath=bigdata.lic #pubPath pubPath=publicCerts.store
Ҏ该验证的properties可以看出Q用者只拥有公钥Q没有私钥,q且也只知道讉K密钥库的密码Q而不能知道生成密钥对的密码?/p>
五、说明:
注意实际操作中,公钥、私钥、证书等文g的存放\径?/p>
以上代码需要用到truelicense的一些包Q可以自行网上搜Q也可以下蝲我的完整工程Q里面附带了所需的jar包?/p>
以上两个完整工程提供下蝲Q?a rel="nofollow" target="_blank" style="margin: 0px; padding: 0px; color: #3377aa; text-decoration: none;">http://download.csdn.net/detail/luckymelina/7141131
GOOD LUCK!伙伴们加aQ欢q与我交?/p>