专注业务连续性支持与数据保护
2009-08-27技术合集

Windows 7 下支付宝控件和证书安装已关闭评论

Windows 7 下支付宝控件和证书安装

对于在 Windows 7 上密码输入控件的安装,需要修改以下设置:

  • 1、先设置 IE8 浏览器。在 Tools – Internet Options – Advanced 里面,取消
    enable memory protection to help mitigate online attacks 前面的勾(这步对于解决无法输入密码很关键)。
  • 2、Tools – Internet Options – Security 里面,去掉 enable protected mod 前面的勾。
  • 3、帐户控制里面,设置提示等级为最低,控制面板里面的 user accounts, turn user account control on or off ,进去后设置 never notify。
  • 4、重启计算机,或者注销。
  • 5、登录支付宝网站,会提示安装证书。到这步,密码问题应该可以解决了

或者采用如下方式

直接关掉 DEP 数据保护,以管理员方式打开 CMD(命令提示符)并输入:

bcdedit.exe /set {current} nx Alwaysoff 

重启才会生效,注销不行。用过支付宝,如果想恢复原样,把 Alwaysoff 改为 OptIn (系统默认值)就可以了。之后你就可以进入支付宝账户了。

安装证书遇到的问题

Windows 7 上安装支付宝证书,一般会遇到 2 个错误提示。

错误一:800A138F 错误

这个错误是因为禁用 Microsoft Certificate Enrollment CAB 引起的,取消禁用即可。

解决方法:如果出现 “错误代码800A138F” 的错误,只需要安装上某些第三方工具,然后在插件管理里面把对 Microsoft Certificate Enrollment CAB的 屏蔽解除。当然过后就可以把第三方工具删除掉。

错误二: 80070057 错误

这个错误是由于 xenroll.dll 控件没有注册引起的。

解决方法:自己搜索下这个文件(文件名即为关键字)。 下载这个dll 文件后, 放到 C 盘 Windows/system32 目录下,然后点击”开始”菜单,“运行”,输入 regsvr32 xenroll.dll 即可解决。

注意

  • 1、取消禁用的 Microsoft Certificate Enrollment CAB 时候,也可以通过修改注册表解决,参见后面的附录。
  • 2、对于 xenroll.dll 这个 DLL 文件,版本有很多。下载的时候注意文件版本号 “5.131.3686.0″ ,其他版本不适用 Windows 7。

附录

Microsoft Certificate Enrollment CAB禁用.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\ActiveX Compatibility\{127698e4-e730-4e5c-a2b1-21490a70c8a1}]

“Compatibility Flags”=dword:00000400

“IeaDo”=-

Microsoft Certificate Enrollment CAB开锁 .reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\ActiveX Compatibility\{127698e4-e730-4e5c-a2b1-21490a70c8a1}]

“Compatibility Flags”=dword:00000000

“IeaDo”=dword:00000001

文件 xenroll.dll 下载:xenroll

2009-08-17技术合集

通过PXE网络安装OpenBSD 4.2已关闭评论

通过PXE网络安装OpenBSD 4.2

1. 准备PXE服务

我的PXE服务安装在Ubuntu 7.10 Desktop环境,配置过程如下:

1.1 配置tftp

确保安装了xinetd,因为tftp是借助xinetd监听端口的,/etc/xinetd.d/tftp的内容如下:

service tftp
{
        socket_type = dgram
        protocol = udp
        wait = yes
        user = root
        server = /usr/sbin/in.tftpd
        server_args = -s /tftpboot
        disable = no
}

参数 “-s /tftpboot” 指定tftp的根目录为/tftpboot,这个目录的文件结构如下:

yingyuan@yyresearch:~$ ls -Rl /tftpboot/
/tftpboot/:
总用量 5024
-rw-r--r-- 1 root root 5068775 2007-11-27 18:25 bsd.rd
drwxr-xr-x 2 root root    4096 2007-11-28 10:59 etc
-rw-r--r-- 1 root root   52928 2007-11-27 18:25 pxeboot

/tftpboot/etc:
总用量 4
-rw-r--r-- 1 root root 12 2007-11-28 10:59 boot.conf

bsd.rd是OpenBSD的ram disk文件系统,pxeboot是PXE请求时返回的启动加载文件,这两个文件都可以从安装光盘或者从ftp镜像网站提取。boot.conf是由pxeboot读取的启动配置文件,内容只有一行:

boot bsd.rd

启动tftp服务,

yingyuan@yyresearch:~$ sudo /etc/init.d/xinetd restart

1.2 配置DHCP服务

/etc/dhcp3/dhcpd.conf的配置内容如下,

ddns-update-style none;
option domain-name "example.com";
option domain-name-servers 10.0.0.1;
default-lease-time 600;
max-lease-time 7200;

class "openbsd-pxeboot-class" {
        match pick-first-value (option dhcp-client-identifier, hardware);
        filename "pxeboot";
        next-server 10.0.0.1;
}

subclass "openbsd-pxeboot-class" 1:8:0:27:3B:56:0;

subnet 10.0.0.0 netmask 255.255.255.0 {
        pool {
                allow members of "openbsd-pxeboot-class";
                option routers 10.0.0.1;
                range 10.0.0.200 10.0.0.240;
        }
}

需要安装OpenBSD机器的网卡MAC地址是08:00:27:3B:56:00,协议是以太网(协议号是1),我们把它分到openbsd-pxeboot-class这个类里。

启动dhcp服务,

yingyuan@yyresearch:~$ sudo /etc/init.d/dhcp3-server restart

2. 准备HTTP网络安装文件

我只从OpenBSD的镜像FTP站点拷贝了一些必要的文件,放在Apache的OpenBSD/i386目录下,

yingyuan@yyresearch:~$ ls -l /var/www/OpenBSD/i386
总用量 145976
-rw-r--r-- 1 yingyuan yingyuan 42603450 2007-11-27 17:21 base42.tgz
-rw-r--r-- 1 yingyuan yingyuan  6229740 2007-11-27 17:16 bsd
-rw-r--r-- 1 yingyuan yingyuan  5068775 2007-11-27 17:13 bsd.rd
-rw-r--r-- 1 yingyuan yingyuan  5185536 2007-11-27 17:08 cd42.iso
-rw-r--r-- 1 yingyuan yingyuan 78804092 2007-11-27 17:31 comp42.tgz
-rw-r--r-- 1 yingyuan yingyuan  1240720 2007-11-27 17:34 etc42.tgz
-rw-r--r-- 1 yingyuan yingyuan      266 2007-11-28 12:27 index.txt
-rw-r--r-- 1 yingyuan yingyuan   100845 2007-11-27 17:00 INSTALL.i386
-rw-r--r-- 1 yingyuan yingyuan    22354 2007-11-27 17:02 INSTALL.linux
-rw-r--r-- 1 yingyuan yingyuan  7656850 2007-11-27 17:35 man42.tgz
-rw-r--r-- 1 yingyuan yingyuan     1287 2007-11-27 17:14 MD5
-rw-r--r-- 1 yingyuan yingyuan  2292887 2007-11-27 17:38 misc42.tgz
-rw-r--r-- 1 yingyuan yingyuan    52928 2007-11-27 17:14 pxeboot

启动www服务,

yingyuan@yyresearch:~$ sudo /etc/init.d/apache2 restart

3. 安装OpenBSD 4.2

把机器设置为从网络启动,一按电源按照提示操作就OK了。

分区的时候我选择把整块硬盘分为一个OpenBSD分区,标签分配如下,

标签          容量                                  挂载点
----------------------------
a      512M            /
b      512M            swap
c      整个硬盘
d      1G              /var
e      剩下的空间                    /usr

指定大小的时候以磁盘扇区(512 bytes)为单位,所以需要计算一下。每个标签之间默认间隔一个磁道。

2009-08-16技术合集

Memcache的备忘已关闭评论

Memcache的备忘

  • 用memcache保存session的例子,非常简单
     
    CODE:

    1. <?php
    2. $session_save_path = "tcp://$host:$port?persistent=1&weight=2&timeout=2&retry_interval=10, ,tcp://$host:$port ";
    3. ini_set(‘session.save_handler’, ‘memcache’);
    4. ini_set(‘session.save_path’, $session_save_path);
    5. ?>

     

  • memcache每一个item上限是1M,注意不要超出上限
  • memcache本身并不支持namespace,但是可以通过一些手段模拟出namespace的效果来,见Memcache 中模拟 namespace
  • 刚接触memcache的时候,可能会写出这样的代码来
    CODE:

    1. $zhang = $memcache->get(‘key1’);
    2. $li = $memcache->get(‘key2’);
    3. $wang = $memcache->get(‘key3’);

    这种写法实际运行效果是

    • get(key1) – 客户端发出请求 – 服务器端查询 – 客户端获取
    • get(key2) – 客户端 – 服务器端 – 客户端
    • get(key3) – 客户端 – 服务器端 – 客户端

    如此一来,会有三次客户端和服务器端交互的过程。但是如果用批量查询的方法,就只有一次交互的过程。比如:

     
    CODE:

    1. $all = $memcache->get(array(‘key1’, ‘key2’, ‘key3’));

    这样性能会有一些提升。对于其它程序语言来说,也封装了类似get_multi这样的方法。

  • 从数据库从查询获得一个列表,放到memcache里面保存起来是一个不错的主意,但是不要忘记memcache有1m限制。如果列表太大,可以考虑把数据分割开来,然后用key序列来保存这个列表数据,比如event_0_500来保存前500行,用event_0_1000保存500-1000行,在获取的时候可以用前面说的批量get来一次性得到这个列表。
  • 经常观察memcached的大小和命中率,方便调整缓存策略
2009-08-16技术合集

最简便的清空memcache的方法已关闭评论

最简便的清空memcache的方法

This is easy right? Can’t you just restart the memcached server? Well yes, but you may cause errors in applications that are already connected to it. You can follow your memcached restart with an application restart, eg for a Ruby on Rails app:

# /etc/init.d/memcached restart && mongrel_rails cluster::restart

Of course if you have more than one application server you have to restart your app on every single one. This would work on an engineyard slice assuming you have the eycap gem installed:

$ cap production memcached:restart
$ cap production mongrel:restart

Restarting your application is not ideal however, you will lose anything cached in memory, cause delays to users trying to access your site, that sort of thing.

So what can be done? The answer is really simple. Assuming a memcached running on the local machine on the default port:

$ echo “flush_all” | nc localhost 11211

Easy!

2009-08-16技术合集

启用memcached压缩注意事项已关闭评论

启用memcached压缩注意事项

在php开发中,开启memcache的数据压缩存储是一件很简单的事情。在多数情况下,压缩数据不仅不会降低程序的执行效率,反倒会因为网络传输的开销降低,带来速度提升。看看最常用的Memcache::set方法:
bool Memcache::set ( string $key , mixed $var [, int $flag [, int $expire ]] )

在这个方法中,将$flag设置为MEMCACHE_COMPRESSED即可启用memcache压缩存储。

这样做有什么弊端?

如果没有做额外判断,每一次写入memcache都会启用压缩,不管数据的大小。对应的,每次获得数据都需要做一次解压缩的操作,这是典型的一刀切手法。实际上在数据很小的情况下,不需要压缩,在这个基础上压缩省不了多少空间。

更好的压缩策略?

好了,我的想法是在数据超过一定大小(比如2k)的情况下,才开启压缩。这个好办,捋起袖子就干,在调用Memcache::set方法之前,首先判断一下数据的大小,一个strlen就搞定了,再简单不过了。

PHP:

  1. $memcache = new Memcache;
  2. $memcache->connect(‘localhost’, 11211);
  3. $flag = strlen($data)> 2048 ? MEMCACHE_COMPRESSED : 0;
  4. $memcache->set(‘mykey’, $data, $flag);

有人可能会问了,array和object怎么办,这玩意可不能用strlen判断长度。

这还真能难住我一阵子,要知道把array/object写入memcache的时候,php会自动做serialize,再把它当作字符串插入memcache。

PHP:

  1. $flag = strlen(serialize($data))> 2048 ? MEMCACHE_COMPRESSED : 0;

谁会采用这段代码?看起来非常山寨,而且serialize也不快,赔本买卖。

更好的办法!

上面的文字都是废话,直接看这段就好。Memcache::setCompressThreshold方法可以包办之前所有的逻辑。

Memcache::setCompressThreshold – Enable automatic compression of large values

bool Memcache::setCompressThreshold ( int $threshold [, float $min_savings ] )

举个例子,下面这段会自动启用压缩策略,当数据大于2k时,以0.2的压缩比进行zlib。

PHP:

  1. $memcache->setCompressThreshold(2000, 0.2);

根据我的测试结果,setCompressThreshold方法会忽略Memcache::set的flag参数

2009-08-16技术合集

memcache.php stats like apc.php已关闭评论

memcache.php stats like apc.php

For a long time I was looking for a nice web interface like the apc.php (comes with the apc’s source) that displays whole nine yards of stats. The only good tool is memcache-tool from the danga guys. It’s quite complete but I guess I’m too lazy to go on the command line.

Anyways, I decided to rip write my own. Totally based on the original apc.php (I even recycled some functions) and apart from completeness, here is a memcache.php that you can get stats and dump from multiple memcache servers.
Here is a screenshot:


And here is the the source code.

As usual, this piece of software comes with the warnings:
– Don’t expect something complete, might have bugs and security problems etc.
– Do not install on a prod environment unless you’re sure!
– Feel free to add stuff to it, I’ll put it to google code or sf.net soon.
– Feel free to request features. (no I’m not planning a backup tool , there is memcache-tool for that)
– Enjoy!

2009-08-16技术合集

如何监控MemCached的状态已关闭评论

如何监控MemCached的状态

使用MemCached以后,肯定希望知道cache的效果,对于MemCached的一些运行状态进行监控是必要的。MemCached也提供了stats接口输出一些信息,最简单的方式,就是telnet上去输入stats查看:

telnet 127.0.0.1 11211
Trying 127.0.0.1 ...
Connected to memcache_test_host (127.0.0.1 ).
Escape character is '^]'.
stats
STAT pid 7186
STAT uptime 1695
STAT time 1238401344
STAT version 1.2.6
STAT pointer_size 64
STAT rusage_user 0.003999
STAT rusage_system 0.002999
STAT curr_items 1
STAT total_items 54
STAT bytes 135
STAT curr_connections 2
STAT total_connections 111
STAT connection_structures 4
STAT cmd_get 3
STAT cmd_set 54
STAT get_hits 0
STAT get_misses 3
STAT evictions 0
STAT bytes_read 5957
STAT bytes_written 50914
STAT limit_maxbytes 2147483648
STAT threads 1
END

这种方式相当的不方便,所以网上就有各种不同客户端接口写的工具,比如用perl写的这个memcache-tool

./memcached_tool
Usage: memcached-tool  [mode]

       memcached-tool 10.0.0.5:11211 display    # shows slabs
       memcached-tool 10.0.0.5:11211            # same.  (default is display)
       memcached-tool 10.0.0.5:11211 stats      # shows general stats
       memcached-tool 10.0.0.5:11211 move 7 9   # takes 1MB slab from class #7
                                                # to class #9.

You can only move slabs around once memory is totally allocated, and only
once the target class is full.  (So you can't move from #6 to #9 and #7
to #9 at the same itme, since you'd have to wait for #9 to fill from
the first reassigned page)

$ ./memcached_tool 127.0.0.1:11211 stats
  #127.0.0.1:11211 Field       Value
                   bytes         135
              bytes_read        5964
           bytes_written       51394
                 cmd_get           3
                 cmd_set          54
   connection_structures           4
        curr_connections           3
              curr_items           1
               evictions           0
                get_hits           0
              get_misses           3
          limit_maxbytes  2147483648
                     pid        7186
            pointer_size          64
           rusage_system    0.002999
             rusage_user    0.003999
                 threads           1
                    time  1238401521
       total_connections         112
             total_items          54
                  uptime        1872
                 version       1.2.6

命令行的方式,在批处理调用的时候比较方便。但是在展现方面还是web方式更加直观有效,所以就有了php写的memcache.php,是的,用一次就知道这是我想要的。