n2n: a Layer Two Peer-to-Peer VPN

[不指定 2010/02/25 00:02 | by ipaddr ]

http://www.ntop.org/n2n/

n2n is a layer-two peer-to-peer virtual private network (VPN) which allows users to exploit features typical of P2P applications at network instead of application level. This means that users can gain native IP visibility (e.g. two PCs belonging to the same n2n network can ping each other) and be reachable with the same network IP address regardless of the network where they currently belong. In a nutshell, as OpenVPN moved SSL from application (e.g. used to implement the https protocol) to network protocol, n2n moves P2P from application to network level.

The main n2n design features are:

  • An n2n is an encrypted layer two private network based on a P2P protocol.
  • Encryption is performed on edge nodes using open protocols with user-defined encryption keys: you control your security without delegating it to companies as it happens with Skype or Hamachi.
  • Each n2n user can simultaneously belong to multiple networks (a.k.a. communities).
  • Ability to cross NAT and firewalls in the reverse traffic direction (i.e. from outside to inside) so that n2n nodes are reachable even if running on a private network. Firewalls no longer are an obstacle to direct communications at IP level.
  • n2n networks are not meant to be self-contained, but it is possible to route traffic across n2n and non-n2n networks.

The n2n architecture is based on two components:

  • edge nodes: applications installed on user PCs that allow the n2n network to be build. Practically each edge node creates a tun/tap device that is then the entry point to the n2n network.
  • an supernode: it is used by edge nodes at startup or for reaching nodes behind symmetrical firewalls. This application is basically a directory register and a packet router for those nodes that cannot talk directly.

Edge nodes talk by means of virtual tap interfaces. Each tap interface is an n2n edge node. Each PC can have multiple tap interfaces, one per n2n network, so that the same PC can belong to multiple communities.
...

SSH Public-Key Authentication HOWTO

[不指定 2010/02/05 17:54 | by ipaddr ]

On Windows with SecureCRT

  1. Select Tools -> Create Public Key...
  2. Hit NEXT
  3. Select DSA, hit NEXT
  4. Leave Passphrase empty, and remove anything in Comment
  5. Select key length, 1024 is OK
  6. Move mouse around as instructed
  7. Save files to default locations, usually C:\Documents and Settings\YOU\Application Data\VanDyke\Identity and Identity.pub
  8. If prompted to use the key as your global key select yes.
  9. Use a text editor to view your public key Identity.pub
  10. Using your password credentials log into the server and paste the contents of the Identity.pub file into a test file, test.pub is fine. Do this as your user, not root.
  11. Run this as yourself from your home directory:
ssh-keygen -i -f test.pub >> .ssh/authorized_keys 
  1. Log out and edit the properties of the session you just used to connect.
    1. Under Connection -> Authentication : Change Primary to PublicKey then hit Properties...
    2. Enable "Use global public key setting"
    3. Enable "Use identity file"
    4. Make sure the file selected is NOT your public key, it should be C:\Documents and Settings\YOU\Application Data\VanDyke\Identity by default
    5. Hit OK
  2. You should now be able to connect using your SSH key.

On Unix with OpenSSH

  • Create users on the local and remote machines with the same username (and same UID/GID if possible)
  • On the local machine run:
Username@LOCAL_HOST $ ssh-keygen -t dsa 
  • Enter no passphrase, save keys to default locations (.ssh/id_dsa)
  • Copy the contents of
    • ~/.ssh/id_dsa.pub from the local machine
      • to:
    • ~/.ssh/authorized_keys on the remote machine.
DONE! Now you can connect without a password.
  • Using SCP (from your home directory)
Username@LOCAL_HOST $ scp -i .ssh/id_dsa File_To_Copy Username@REMOTE_HOST:/path/to/destination/File_Name 
  • Using SSH (from your home directory)
Username@LOCAL_HOST $ ssh -i .ssh/id_dsa REMOTE_HOST 

notes

  • Using the same setup as above you can copy files from the remote system to the local system:
Copy /path/path/file on remote system to current directory on local system
LOCAL_HOST$ scp -i /home/username/.ssh/id_dsa username@REMOTE_HOST:/path/path/file . 
Copy /path/path/file on remote system to /other/path/file2 on local system
LOCAL_HOST$ scp -i /home/username/.ssh/id_dsa username@REMOTE_HOST:/path/path/file /other/path/file2 


How to make SSH2 work with OpenSSH


The commercial version of SSH2 uses a different key format than the OpenSSH. This guide shows how to make them inter-operate with each other with public key authentication. It is based on descriptions from this website.

Case 1. OpenSSH server and SSH2 client

Suppose you already generated an RSA2 key pair on your SSH2 client machine, and the public key is stored at ~/.ssh2/id_rsa_1024_a.pub.
The following procedure applies to DSA key pairs too.
  1. Copy your SSH2 public key from your SSH2 client machine to your OpenSSH server like:
scp ~/.ssh2/id_rsa_1024_a.pub server:.ssh/rsa_ssh2.pub
  1. Run the OpenSSH version of ssh-keygen on the server to convert the SSH2 public key to into the format needed by OpenSSH:
ssh-keygen -i -f ~/.ssh/rsa_ssh2.pub > ~/.ssh/rsa_openssh.pub
  1. Append this newly generated OpenSSH public key to your authorization file on the server:
cat ~/.ssh/rsa_openssh.pub >> ~/.ssh/authorized_keys2 
  1. Once this is done, the .pub files you created are no longer needed so you can remove them if you like. 
Now your SHH2 client should be able to connect to the OpenSSH server with the public key authentication.

Case 2. SSH2 server and OpenSSH client

Note that RSA2 is not working on ISI's SSH2 servers at the the time the guide is written. DSA works fine, so you should generate a DSA key pair with the ssh-keygen on your OpenSSH client machine. By default, the public key is stored at ~/.ssh/id_dsa.pub.
  1. Run the OpenSSH version of ssh-keygen on the OpenSSH client machine to convert the OpenSSH public key into the format needed by SSH2: 
ssh-keygen -e -f ~/.ssh/id_dsa.pub > ~/.ssh/dsa_ssh2.pub 
  1. Copy this SSH2 public key to your .ssh2 directory on the SSH2 server:
scp ~/.ssh/dsa_ssh2.pub server:.ssh2/dsa_ssh2.pub
  1. Add this new pub key to the authorization on the server:
echo Key dsa_ssh2.pub >> ~/.ssh2/authorization 
  1. Once this is done, the temporary .pub file you created on the OpenSSH client is no longer needed so you can remove it. DO NOT remove the .pub file you just copied to the SSH2 server.
Now your OpenSSH client should be able to connect to the SSH2 server with the DSA public key authentication.

JVM调优总结

[不指定 2010/01/12 17:26 | by ipaddr ]
  1. 堆大小设置
    JVM 中最大堆大小有三方面限制:相关操作系统的数据模型(32-bt还是64-bit)限制;系统的可用虚拟内存限制;系统的可用物理内存限制。32位系统下,一般限制在1.5G~2G;64为操作系统对内存无限制。我在Windows Server 2003 系统,3.5G物理内存,JDK5.0下测试,最大可设置为1478m。
    典型设置:
    • java -Xmx3550m -Xms3550m -Xmn2g -Xss128k
      -
      Xmx3550m:设置JVM最大可用内存为3550M。
      -Xms3550m
      :设置JVM促使内存为3550m。此值可以设置与-Xmx相同,以避免每次垃圾回收完成后JVM重新分配内存。
      -Xmn2g
      :设置年轻代大小为2G。整个JVM内存大小=年轻代大小 + 年老代大小 + 持久代大小。持久代一般固定大小为64m,所以增大年轻代后,将会减小年老代大小。此值对系统性能影响较大,Sun官方推荐配置为整个堆的3/8。
      -Xss128k
      :设置每个线程的堆栈大小。JDK5.0以后每个线程堆栈大小为1M,以前每个线程堆栈大小为256K。更具应用的线程所需内存大小进行调整。在相同物理内存下,减小这个值能生成更多的线程。但是操作系统对一个进程内的线程数还是有限制的,不能无限生成,经验值在3000~5000左右。
    • java -Xmx3550m -Xms3550m -Xss128k -XX:NewRatio=4 -XX:SurvivorRatio=4 -XX:MaxPermSize=16m -XX:MaxTenuringThreshold=0
      -XX:NewRatio=4
      :设置年轻代(包括Eden和两个Survivor区)与年老代的比值(除去持久代)。设置为4,则年轻代与年老代所占比值为1:4,年轻代占整个堆栈的1/5
      -XX:SurvivorRatio=4
      :设置年轻代中Eden区与Survivor区的大小比值。设置为4,则两个Survivor区与一个Eden区的比值为2:4,一个Survivor区占整个年轻代的1/6
      -XX:MaxPermSize=16m:设置持久代大小为16m。
      -XX:MaxTenuringThreshold=0:设置垃圾最大年龄。如果设置为0的话,则年轻代对象不经过Survivor区,直接进入年老代。对于年老代比较多的应用,可以提高效率。如果将此值设置为一个较大值,则年轻代对象会在Survivor区进行多次复制,这样可以增加对象再年轻代的存活时间,增加在年轻代即被回收的概论。
  2. 回收器选择
    JVM给了三种选择:串行收集器、并行收集器、并发收集器,但是串行收集器只适用于小数据量的情况,所以这里的选择主要针对并行收集器和并发收集器。默认情况下,JDK5.0以前都是使用串行收集器,如果想使用其他收集器需要在启动时加入相应参数。JDK5.0以后,JVM会根据当前系统配置进行判断。
    1. 吞吐量优先的并行收集器
      如上文所述,并行收集器主要以到达一定的吞吐量为目标,适用于科学技术和后台处理等。
      典型配置
      • java -Xmx3800m -Xms3800m -Xmn2g -Xss128k -XX:+UseParallelGC -XX:ParallelGCThreads=20
        -XX:+UseParallelGC
        :选择垃圾收集器为并行收集器。此配置仅对年轻代有效。即上述配置下,年轻代使用并发收集,而年老代仍旧使用串行收集。
        -XX:ParallelGCThreads=20:配置并行收集器的线程数,即:同时多少个线程一起进行垃圾回收。此值最好配置与处理器数目相等。
      • java -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseParallelGC -XX:ParallelGCThreads=20 -XX:+UseParallelOldGC
        -XX:+UseParallelOldGC:配置年老代垃圾收集方式为并行收集。JDK6.0支持对年老代并行收集。
      • java -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseParallelGC -XX:MaxGCPauseMillis=100
        -XX:MaxGCPauseMillis=100:设置每次年轻代垃圾回收的最长时间,如果无法满足此时间,JVM会自动调整年轻代大小,以满足此值。
      • java -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseParallelGC -XX:MaxGCPauseMillis=100 -XX:+UseAdaptiveSizePolicy
        -XX:+UseAdaptiveSizePolicy
        :设置此选项后,并行收集器会自动选择年轻代区大小和相应的Survivor区比例,以达到目标系统规定的最低相应时间或者收集频率等,此值建议使用并行收集器时,一直打开。
    2. 响应时间优先的并发收集器
      如上文所述,并发收集器主要是保证系统的响应时间,减少垃圾收集时的停顿时间。适用于应用服务器、电信领域等。
      典型配置
      • java -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:ParallelGCThreads=20 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC
        -XX:+UseConcMarkSweepGC:设置年老代为并发收集。测试中配置这个以后,-XX:NewRatio=4的配置失效了,原因不明。所以,此时年轻代大小最好用-Xmn设置。
        -XX:+UseParNewGC:设置年轻代为并行收集。可与CMS收集同时使用。JDK5.0以上,JVM会根据系统配置自行设置,所以无需再设置此值。
      • java -Xmx3550m -Xms3550m -Xmn2g -Xss128k -XX:+UseConcMarkSweepGC -XX:CMSFullGCsBeforeCompaction=5 -XX:+UseCMSCompactAtFullCollection
        -XX:CMSFullGCsBeforeCompaction:由于并发收集器不对内存空间进行压缩、整理,所以运行一段时间以后会产生“碎片”,使得运行效率降低。此值设置运行多少次GC以后对内存空间进行压缩、整理。
        -XX:+UseCMSCompactAtFullCollection:打开对年老代的压缩。可能会影响性能,但是可以消除碎片
  3. 辅助信息
    JVM提供了大量命令行参数,打印信息,供调试使用。主要有以下一些:
    • -XX:+PrintGC
      输出形式:[GC 118250K->113543K(130112K), 0.0094143 secs]

      [Full GC 121376K->10414K(130112K), 0.0650971 secs]

    • -XX:+PrintGCDetails
      输出形式:[GC [DefNew: 8614K->781K(9088K), 0.0123035 secs] 118250K->113543K(130112K), 0.0124633 secs]

      [GC [DefNew: 8614K->8614K(9088K), 0.0000665 secs][Tenured: 112761K->10414K(121024K), 0.0433488 secs] 121376K->10414K(130112K), 0.0436268 secs]

    • -XX:+PrintGCTimeStamps -XX:+PrintGC:PrintGCTimeStamps可与上面两个混合使用
      输出形式:11.851: [GC 98328K->93620K(130112K), 0.0082960 secs]
    • -XX:+PrintGCApplicationConcurrentTime:打印每次垃圾回收前,程序未中断的执行时间。可与上面混合使用
      输出形式:Application time: 0.5291524 seconds
    • -XX:+PrintGCApplicationStoppedTime:打印垃圾回收期间程序暂停的时间。可与上面混合使用
      输出形式:Total time for which application threads were stopped: 0.0468229 seconds
    • -XX:PrintHeapAtGC:打印GC前后的详细堆栈信息
      输出形式:
      34.702: [GC {Heap before gc invocations=7:
      def new generation total 55296K, used 52568K [0x1ebd0000, 0x227d0000, 0x227d0000)
      eden space 49152K, 99% used [0x1ebd0000, 0x21bce430, 0x21bd0000)
      from space 6144K, 55% used [0x221d0000, 0x22527e10, 0x227d0000)
      to space 6144K, 0% used [0x21bd0000, 0x21bd0000, 0x221d0000)
      tenured generation total 69632K, used 2696K [0x227d0000, 0x26bd0000, 0x26bd0000)
      the space 69632K, 3% used [0x227d0000, 0x22a720f8, 0x22a72200, 0x26bd0000)
      compacting perm gen total 8192K, used 2898K [0x26bd0000, 0x273d0000, 0x2abd0000)
      the space 8192K, 35% used [0x26bd0000, 0x26ea4ba8, 0x26ea4c00, 0x273d0000)
      ro space 8192K, 66% used [0x2abd0000, 0x2b12bcc0, 0x2b12be00, 0x2b3d0000)
      rw space 12288K, 46% used [0x2b3d0000, 0x2b972060, 0x2b972200, 0x2bfd0000)
      34.735: [DefNew: 52568K->3433K(55296K), 0.0072126 secs] 55264K->6615K(124928K)Heap after gc invocations=8:
      def new generation total 55296K, used 3433K [0x1ebd0000, 0x227d0000, 0x227d0000)
      eden space 49152K, 0% used [0x1ebd0000, 0x1ebd0000, 0x21bd0000)
      from space 6144K, 55% used [0x21bd0000, 0x21f2a5e8, 0x221d0000)
      to space 6144K, 0% used [0x221d0000, 0x221d0000, 0x227d0000)
      tenured generation total 69632K, used 3182K [0x227d0000, 0x26bd0000, 0x26bd0000)
      the space 69632K, 4% used [0x227d0000, 0x22aeb958, 0x22aeba00, 0x26bd0000)
      compacting perm gen total 8192K, used 2898K [0x26bd0000, 0x273d0000, 0x2abd0000)
      the space 8192K, 35% used [0x26bd0000, 0x26ea4ba8, 0x26ea4c00, 0x273d0000)
      ro space 8192K, 66% used [0x2abd0000, 0x2b12bcc0, 0x2b12be00, 0x2b3d0000)
      rw space 12288K, 46% used [0x2b3d0000, 0x2b972060, 0x2b972200, 0x2bfd0000)
      }
      , 0.0757599 secs]
    • -Xloggc:filename:与上面几个配合使用,把相关日志信息记录到文件以便分析。
  4. 常见配置汇总
    1. 堆设置
      • -Xms:初始堆大小
      • -Xmx:最大堆大小
      • -XX:NewSize=n:设置年轻代大小
      • -XX:NewRatio=n:设置年轻代和年老代的比值。如:为3,表示年轻代与年老代比值为1:3,年轻代占整个年轻代年老代和的1/4
      • -XX:SurvivorRatio=n:年轻代中Eden区与两个Survivor区的比值。注意Survivor区有两个。如:3,表示Eden:Survivor=3:2,一个Survivor区占整个年轻代的1/5
      • -XX:MaxPermSize=n:设置持久代大小
    2. 收集器设置
      • -XX:+UseSerialGC:设置串行收集器
      • -XX:+UseParallelGC:设置并行收集器
      • -XX:+UseParalledlOldGC:设置并行年老代收集器
      • -XX:+UseConcMarkSweepGC:设置并发收集器
    3. 垃圾回收统计信息
      • -XX:+PrintGC
      • -XX:+PrintGCDetails
      • -XX:+PrintGCTimeStamps
      • -Xloggc:filename
    4. 并行收集器设置
      • -XX:ParallelGCThreads=n:设置并行收集器收集时使用的CPU数。并行收集线程数。
      • -XX:MaxGCPauseMillis=n:设置并行收集最大暂停时间
      • -XX:GCTimeRatio=n:设置垃圾回收时间占程序运行时间的百分比。公式为1/(1+n)
    5. 并发收集器设置
      • -XX:+CMSIncrementalMode:设置为增量模式。适用于单CPU情况。
      • -XX:ParallelGCThreads=n:设置并发收集器年轻代收集方式为并行收集时,使用的CPU数。并行收集线程数。


调优总结

  1. 年轻代大小选择
    • 响应时间优先的应用尽可能设大,直到接近系统的最低响应时间限制(根据实际情况选择)。在此种情况下,年轻代收集发生的频率也是最小的。同时,减少到达年老代的对象。
    • 吞吐量优先的应用:尽可能的设置大,可能到达Gbit的程度。因为对响应时间没有要求,垃圾收集可以并行进行,一般适合8CPU以上的应用。
  2. 年老代大小选择
    • 响应时间优先的应用:年老代使用并发收集器,所以其大小需要小心设置,一般要考虑并发会话率会话持续时间等一些参数。如果堆设置小了,可以会造成内存碎片、高回收频率以及应用暂停而使用传统的标记清除方式;如果堆大了,则需要较长的收集时间。最优化的方案,一般需要参考以下数据获得:
      • 并发垃圾收集信息
      • 持久代并发收集次数
      • 传统GC信息
      • 花在年轻代和年老代回收上的时间比例
      减少年轻代和年老代花费的时间,一般会提高应用的效率
    • 吞吐量优先的应用:一般吞吐量优先的应用都有一个很大的年轻代和一个较小的年老代。原因是,这样可以尽可能回收掉大部分短期对象,减少中期的对象,而年老代尽存放长期存活对象。
  3. 较小堆引起的碎片问题
    因为年老代的并发收集器使用标记、清除算法,所以不会对堆进行压缩。当收集器回收时,他会把相邻的空间进行合并,这样可以分配给较大的对象。但是,当堆空间较小时,运行一段时间以后,就会出现“碎片”,如果并发收集器找不到足够的空间,那么并发收集器将会停止,然后使用传统的标记、清除方式进行回收。如果出现“碎片”,可能需要进行如下配置:
    • -XX:+UseCMSCompactAtFullCollection:使用并发收集器时,开启对年老代的压缩。
    • -XX:CMSFullGCsBeforeCompaction=0:上面配置开启的情况下,这里设置多少次Full GC后,对年老代进行压缩

linux下获取当前目录

[不指定 2010/01/11 23:44 | by ipaddr ]
1. 取得当前工作目录(相当于windows下的GetCurrentDirectory):
  #include "stdio.h"
  #include "stdlib.h"
  #include "string.h"
  #include "unistd.h"
  
  int main()
  {
   char buf[200];
  
   if(getcwd(buf, sizeof(buf)-1) != NULL)
   {
   printf(buf);
   printf("\n");
   }
   else
   {
   printf("error \n");
   }
  
   return 0;
  }

2. 取得实际文件目录(相当于windows下的GetModuleFileName())
每个进程在/proc下都有一个以进程号命名的目录.
在该目录下有exe文件,该文件是一个链接文件,它指向的路径就是该进程的全路径.
用readlink读exe文件返回该进程的全路径
如果不在意可能导致的安全隐患,可以使用procfs,然后readlink,把当前进程的pid对应的目录下面的file指向的位置读出来(注意需要先挂载procfs)
 
  pit_t mypid = getpid();
  sprintf(strsrc, "/proc/%d/file", mypid);
  readlink(strsrc, strdest, LEN);//LEN最好是你的_POSIX_PATH_MAX

所以,如果支持/proc文件系统,下面的代码可以解决你的问题:
 
  #include <stdlib.h>
  #include <unistd.h>
  #ifndef PATH_MAX
  #define PATH_MAX 1024
  #endif
 
  char * get_exe_name() {
  static char buf[PATH_MAX];
  int rslt = readlink("/proc/self/exe", buf, PATH_MAX);
  if ( rslt < 0 || rslt >= PATH_MAX ) {
  return NULL;
  }
  buf[rslt] = '\0';
  return buf;
  }
 
  int main( void)
  {
  char * exe_name = get_exe_name();
  puts( exe_name );
  return 0;
  }
 
 
  如果不支持/proc文件系统,我也没什么好办法了。

推荐十个最好的Java性能故障排除工具:

   1.jconsole是随着JDK 1.5而推出的。这是一个Java监测和管理控制台-JMX兼容的图形工具来监测Java虚拟机。它能够同时监测本地和远程的JVMs。详情可查看:jconsole工具介绍

   2.VisualVM 集成了几个现有的JDK软件工具,轻量级内存和CPU信息概要能力。这个工具被设计为同时在生产和开发时使用,进一步提高监视的能力和Java SE平台的性能分析能力。

   3.HeapAnalyzer  能够通过它采用启发式搜索引擎和分析Java堆栈存储信息发现可能的Java堆栈泄漏区域,它通过解析Java堆栈存储信息,创建定向图表,变换他们成定向树和执行启发式搜索引擎。   

   4.PerfAnal 是在Java 2平台上为了分析应用表现的一个基于GUI的工具。您能使用PerfAnal的辩认性来查找出您需要调整的代码。
  
    5.JAMon    是一个免费,简单,高性能,安全,允许开发者容易地监测生产应用程序的Java API。

    6.Eclipse Memory Analyzer      是帮助您发现内存泄漏和减少记忆消耗量的一台快速和功能丰富的Java堆分析仪。

    7.[url="http://www.eclipse.org/mat "]GCViewer[/url]   一个免费开源工具,使用Java VM属性-verbose:gc 和-Xloggc生成可视化数据。它也计算垃圾收集相关的性能指标(生产量、积累停留、最长的停留等等)。


如果您正在运行您的应用程序在HP - UX平台,看看下面:

    . HPjmeter
        1. 确定和诊断在HP-UX上运行的java 应用程序的问题;
        2. 监察正在运行的java应用程序和分析切面数据;
        3. 捕捉剖面数据与零制备时,使用JDK / JRE的5.0.04或更高;
        4. 在HP - UX , Linux和Windows 系统上运行HPjmeter控制台;
        5. 改善垃圾回收机制的表现。

     .HPjconfig         
是为调整您的HP-UX 11i HPIntegrity Itanium? 和HP 9000 PA-RISC系统核心参量的Java配置工具,匹配您的应用的特征。 HPjconfig为专门制作您的HP-UX硬件工作台提供核心参量推荐。他提供了保持和还原的功能,根据您的客户的需要提供适合的建议,考虑到具体的Java和HP - UX的版本问题,HPjconfig决定所有最新的HP - UX的修补程序所需的Java性能和功能在系统上安装,并提示出所有遗失或取代补丁。

     .Java Out-of-Box Tool
一个独立的捆绑安装时将安装启动( RC )的脚本,修改核心参量,重建核心和重新起动系统。 在启动期间,启动脚本将修改系统tunables,因而为Java提供更好的“Out of The Box”行为。

鱼漂个人用得比较多有的:jconsole, jprofiler, MAT.
此外,可以使用 -XX:+HeapDumpOnOutOfMemoryError这个参数启动Java应用程序(适用于JDK 1.6+) ,所以当出现Out of memory时,在TOMCAT_HOME%/bin/目录下才会出现java_pid3164.hprof这样的文件,文件名中的数字会根据当前JVM所占用的PID不同而不同。

为Openldap配置TLS(SSL)

[不指定 2010/01/04 23:01 | by ipaddr ]
最近在折腾openldap,以下是配置TLS(ssl)的摘要:

1. 首先,需要安装openssl (鱼漂提醒:rpm或deb安装的话,还需要openssl-devel包)
2. 修改/usr/lib/ssl/openssl.cnf设置默认的国家,省份,城市等信息
3. 复制/usr/lib/ssh/misc/CA.sh到工作目录,比如~/work/
4. 修改~/work/CA.sh的证书期限,比如根证书为15年,普通证书为3年
5. 进入工作目录 cd ~/work/
6. ./CA.sh -newca 按照提示输入一些信息,中间要输入三次密码,请记住你的密码,以后签署证书时需要用到。
7. 使用openssl生成证书,需要注意的是Common Name一定要输入ldap服务器的全称,比如ldap.systemadmin.cn, openssl命令如下:
    openssl req -new -nodes -keyout newreq.pem -out newreq.pem
8. 签署证书:
    ./CA.sh -sign
    需要输入刚才的密码。
9. 将生成的证书复制到openldap的目录:
    mkdir /usr/local/etc/openldap/ca
    mv newcert.pem /usr/local/etc/openldap/ca/servercrt.pem
    mv newreq.pem /usr/local/etc/openldap/ca/serverkey.pem
    cp demo/cacert.pem /usr/local/etc/openldap/ca/

10.修改Openldap服务端配置文件slapd.conf,增加证书配置:
    TLSCACertificateFile /usr/local/etc/openldap/ca/cacert.pem
    TLSCertificateFile /usr/local/etc/openldap/ca/servercrt.pem
    TLSCertificateKeyFile /usr/local/etc/openldap/ca/serverkey.pem

11.重启openldap服务器
    #kill -INT `cat /usr/local/var/run/slapd.pid`
    #/usr/local/libexec/slapd -h "ldap:/// ldaps:///"

12.客户端的配置
    首先,需要将根证书复制到每台客户端,并在客户端的ldap.conf文件中如下配置:
    TLS_CACERT /usr/local/etc/openldap/ca/cacert.pem
   
此外,鱼漂(http://www.eit.name), 特别提醒,需要在编译openldap时指定使用openssl:
(在ubuntu 9.10上测试时,只使用--with-tls,而没有指定openssl的话,好象是不成功的。)
#export CPPFLAGS="-I/usr/local/BerkeleyDB/include"
#export LDFLAGS="-L/usr/local/BerkeleyDB/lib"
(如果是编译安装BerkeleyDB,需要设置以上两个环境变量)
#./configure --with-tls=openssl --enable-modules
#make depend
#make
#make install

使用iptables来做tcp代理

[不指定 2010/01/04 16:12 | by ipaddr ]

可以使用iptables来做tcp代理, 原理就是NAT, 以下是一个简单的实现脚本:

===============================================

#!/bin/sh
# TCP Proxy using IPTables
# source: http://www.eit.name/

IPTABLES=/sbin/iptables

echo 1 > /proc/sys/net/ipv4/ip_forward

# Flush nat table
$IPTABLES -t nat -F

# tcpproxy LOCAL_IP LOCAL_PORT REMOTE_IP REMOTE_PORT
function tcpproxy {
$IPTABLES -t nat -A PREROUTING --dst $1 -p tcp --dport $2 -j DNAT --to-destination $3:$4
$IPTABLES -t nat -A POSTROUTING --dst $3 -p tcp --dport $4 -j SNAT --to-source $1
$IPTABLES -t nat -A OUTPUT --dst $1 -p tcp --dport $2 -j DNAT --to-destination $3:$4
}

# Example 1
tcpproxy 192.168.40.244 3200 10.10.10.2 3200

# Example 2
tcpproxy 192.168.40.245 3200 192.168.1.30 3200

===============================================

VI常用配置

[不指定 2009/12/30 22:21 | by ipaddr ]

1. 显示所有设置
:set all

2. 打开状态栏
:set ru|noru
3. 帮助
:help
:help 03
:help xxx

4. 显示行号
:set number|nu|nonumber|nonu

5. 语法高亮
:syntax on|enable

6. 自动缩进
:set ai|noai
:set sw=4 (自缩进4个空格)
:set expandtab|et (将Tab转为n个空格)
:set tabstop|ts=4 (设置tab位为4个空格)
:retab (将原有tab换成空格)

7. 是否区分大小写匹配
:set ic|noic

8. 括号匹配显示
:set showmatch|noshowmatch

9. 执行系统命令
:!date

10. 编辑多个文件
vi file1 file2 file3
:n 编辑下一个文件
:rew 编辑第一个文件

11. 搜索结果高亮
set hlsearch
(鱼漂整理,转载请注明)

12. 快速跳转
Shift + G =>最后一行
Shift + M =>页中
Shift + H =>页首
Shift + L =>页末
1G =>第一行
[[ 开头
]]结尾
[[^ 开头第一个字符
]]$ 结尾最后一个字符

13. 设置编码
:set encoding=utf-8
:set termencoding=utf-8
:set fileencoding=utf-8

14. 色彩选择
:set bg=dark|light
:colo|colorscheme desert

google-code-prettify introduction

[不指定 2009/12/29 09:42 | by ipaddr ]

Main page: http://code.google.com/p/google-code-prettify/

A Javascript module and CSS file that allows syntax highlighting of source code snippets in an html page.

For an example, see the README

Download

Change Log

Features

  • Works on HTML pages
  • Works even if code contains embedded links, line numbers, etc.
  • Simple API : include some JS&CSS and add an onload handler.
  • Lightweights : small download and does not block page from loading while running.
  • Customizable styles via CSS.
  • Supports all C-like, Bash-like, and XML-like languages. No need to specify the language
  • Extensible language handlers for other languages. You can specify the language.
  • Widely used with good cross-browser support. Powers code.google.com

Mysql动态修改参数

[不指定 2009/12/25 10:51 | by ipaddr ]
   mysql数据库也像ORACLE数据库一样,可以动态的修改参数,可以修改会话级变量只对当前会话产生影响;也可以修改全局变量,对所有新连接的会话都产生影响。

修改会话级变量

用show variables 命令查看当前参数的值,like 'pattern'用于模式匹配,查找指定的参数

mysql> show variables like '%sort_buffer_size%';
+---------------------------+------------+
| Variable_name             | Value      |
+---------------------------+------------+
| sort_buffer_size          | 6291448    |
+---------------------------+------------+
1 rows in set (0.00 sec)

用set SESSION命令设置会话级变量的新值

mysql> set SESSION sort_buffer_size=7000000;
Query OK, 0 rows affected (0.00 sec)

--修改会话级变量对当前会话来说立刻生效
mysql> show variables like '%sort_buffer_size%';       
+---------------------------+------------+
| Variable_name             | Value      |
+---------------------------+------------+
| sort_buffer_size          | 7000000    |
+---------------------------+------------+
1 rows in set (0.00 sec)

mysql> exit
Bye
退出重新连接后,此参数恢复原值
[root@devdbc_stb root]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 40 to server version: 5.0.37-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show variables like '%sort_buffer_size%';       
+---------------------------+------------+
| Variable_name             | Value      |
+---------------------------+------------+
| sort_buffer_size          | 6291448    |
+---------------------------+------------+
1 rows in set (0.00 sec)

修改全局变量
[root@devdbc_stb root]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 40 to server version: 5.0.37-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show variables like '%sort_buffer_size%';       
+---------------------------+------------+
| Variable_name             | Value      |
+---------------------------+------------+
| sort_buffer_size          | 6291448    |
+---------------------------+------------+
1 rows in set (0.00 sec)

用set GLOBAL 命令设置全局变量

mysql> set GLOBAL sort_buffer_size = 7000000;
Query OK, 0 rows affected (0.00 sec)

mysql> show variables like '%sort_buffer_size%';        
+---------------------------+------------+
| Variable_name             | Value      |
+---------------------------+------------+
| sort_buffer_size          | 6291448    |
+---------------------------+------------+
1 rows in set (0.00 sec)
当前此参数的值并不发生变化,先退出,然后重新连进去
mysql> exit
Bye
[root@devdbc_stb root]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 41 to server version: 5.0.37-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show variables like '%sort_buffer_size%';
+---------------------------+------------+
| Variable_name             | Value      |
+---------------------------+------------+
| sort_buffer_size          | 7000000    |
+---------------------------+------------+
1 rows in set (0.00 sec)
新的参数值生效

分页: 12/57 第一页 上页 7 8 9 10 11 12 13 14 15 16 下页 最后页 [ 显示模式: 摘要 | 列表 ]