Blog

  • 在ubuntu下安装phpredis

    翻译自:http://ricochen.wordpress.com/2012/03/25/install-phpredis-on-ubuntu/ 打不开不怪我。

    在12.04 TLS下测试可用。

    1) 准备工作

     sudo apt-get install php5-dev

    php5-dev 提供了开发库及编译必须的phpize工具

    2) 获取phpredis源代码

    git clone git://github.com/nicolasff/phpredis.git

    3) 编译安装

    cd phpredis
    phpize5
    ./configure
    make
    sudo -s make install

    4) 启用phpredis扩展

    sudo -s
    echo "extension=redis.so">/etc/php5/conf.d/redis.ini
    exit

    5) 写一段php代码进行测试 (在命令行下测试需要先安装好php5-cli)。以下是分别使用phpredis与Rediska(https://github.com/Shumkov/Rediska)进行测试。很明显使用c编写的phpredis插件性能高于php库Rediska。

    phpredis_set.php内容和测试结果:

    <?php
     // phpredis_set.php
     $redis=new Redis() or die("Can'f load redis module.");
     $redis->connect('127.0.0.1');
     $redis->set('set_testkey', 1);

    time for i in `seq 1 1000`; do php phpredis_set.php; done

    real 0m16.352s
    user 0m8.105s
    sys 0m5.784s

    rediska_set.php内容和测试结果:

    <?php
     require_once 'Rediska.php';
     $rediska=new Rediska();
     $rediska->set('set_testkey', 1);

    time for i in `seq 1 1000`; do php rediska_set.php; done

    real 0m21.075s
    user 0m12.657s
    sys 0m6.228s

  • ubuntu移动home目录

    有时候/home目录可能不够用,将现有的目录移动到新的分区需要如下六个步骤操作:

    1.设置目标分区

    2.将目标分区使用fstab挂载到/media/home并重启

    3.使用rsync将/home的数据移到/media/home

    4.将fstab中的新分区/media/home改为/home

    5.将/home改名为/old_home并重启

    6.将/old_home删掉

    具体操作参考:

    https://help.ubuntu.com/community/Partitioning/Home/Moving

    也可参考:

    http://www.ibm.com/developerworks/cn/linux/l-tip-prompt/tip05/

  • ubuntu本地回环

    安装uml-utilities

    apt-get install uml-utilities

    启用tun

    modprobe tun

    使用tunctl命令,这时会生成tap0的interface

    tunctl
    ifconfig tap0 172.16.1.110 netmask 255.255.0.0 up

    如果想再添加,则再运行tunctl命令

    tunctl
    ifconfig tap1 172.16.1.111 netmask 255.255.0.0 up
  • vim对文档进行排版

    1. 按v进入visual状态,选择多行,用>或<缩进或缩出

    2. 自动缩进排版,相当于code format

    当前行用== (连按=两次)
    对多行用n==(n是自然数)表示自动缩进从当前行起的下面n行。
    先使用gg使光标跳到第一行行首,再按=G可对整篇代码进行排版。

  • 思科路由器交换机使用ssh方式连接

    进入配置模式

    configure terminal

    一、设置enable密码

    enable secret password

    enable secret 5 $1$7W0A$UTAhixRjHMbE0kHPWZNMJ0

    二、给交换机命名

    hostname switch

    三、配置域名

    ip domain-name test.com

    四、启用AAA,并产生rsa密钥对

    aaa new-model
    crypto key generate rsa

    R1(config)#crypto key generate rsa
    The name for the keys will be: R1.router.jpuyy.com
    Choose the size of the key modulus in the range of 360 to 2048 for your
    General Purpose Keys. Choosing a key modulus greater than 512 may take
    a few minutes.

    How many bits in the modulus [512]: 1024
    % Generating 1024 bit RSA keys, keys will be non-exportable…[OK]

    注:rsa默认为512bits,建议采用768bits以上的长度,这样可开启对sshv2的支持

    五、配置用户名和口令

    username cisco password cisco

    六、配置登录方式为SSH。注意要将0-15全部配置为SSH方式,不然telnet仍可访问。

    line vty 0 4
     transport input ssh
    line vty 5 15
    transport input ssh

    最后可通过以下命令查看显示SSH配置信息

    R1#show ip ssh

    SSH Enabled – version 1.99
    Authentication timeout: 120 secs; Authentication retries: 3

  • 使用moto xt610作为modem的方法

    我这里使用的是上海电信的evdo rev.A网,3G。经过操过可以将电脑与手机通过usb连接,并使用3G流量上网。

    方法一:

    在ubuntu和windows下均可,在手机上

    设置->应用程序->开发,勾选USB调试;

    设置->无线和网络->绑定与便携式热点->勾选usb绑定;

    这里电脑已经多出来一个网卡可以上网了,分配的ip即是热点设置中dhcp分配的。

    方法二:

    只在windows下,安装motorola的驱动

    http://www.motorola.com/staticfiles/Support/Experiences/Global_Drivers/USB_Drivers_bit_4.7.1.zip

    连接好usb后,选择usb连接模式是“摩托罗拉手机门户”

    在网络设置处,新建拨号,默认会选中Motorola usb modem,拨号号码为#777,用户名密码均为card,连接后电脑即可上网。