Blog

  • php-5.3.28安装ldap扩展

    racktables 用到了 ldap 认证,对已经编译好的 php-5.3.28,缺少这个模块

    现在需要加载 ldap.so

    首先准备依赖库

    yum安装依赖

    yum install -y cyrus-sasl-ldap.x86_64
    yum install -y openldap-devel.x86_64
    yum install -y openldap.x86_64
    yum install -y openldap-devel.i686

    下载源码 php-5.3.28.tar.gz

    cd ./ext/ldap
    /usr/local/php-5.3.28/bin/phpize
    ./configure --php-config=/usr/local/php-5.3.28/bin/php-config
    make
    make install

    最后在php.ini启用此扩展

    extension = "ldap.so"

    重启 php

  • python ip地址排序

    方法一:

    ip_list = ['192.168.1.100', '192.168.10.3', '192.168.8.1']
    ip_list.sort(lambda x,y: cmp(''.join( [ i.rjust(3, '0') for i in x.split('.')] ), ''.join( [ i.rjust(3, '0') for i in y.split('.')] ) ) )
    

    结果

    ['192.168.1.100', '192.168.8.1', '192.168.10.3']

    方法二:

    转换成 int 型,用 int 来比较

    import struct
    import socket
    
    def ip2int(addr):
        return struct.unpack("!I", socket.inet_aton(addr))[0]
    
    def int2ip(addr):
        return socket.inet_ntoa(struct.pack("!I", addr))
    
    ip_list = ['192.168.1.100', '192.168.10.3', '192.168.8.1']
    # 构建 int_ip:ip 形式的 key:value, 并对 key 排序
    
    ip_unsorted_dict = {}
    for ip in ip_list:
        int_ip = ip2int(ip)
        ip_unsorted_dict[int_ip] = ip
    
    keys = ip_unsorted_dict.keys()
    keys.sort()
    ip_sorted_list=[]
    for key in keys:
        ip_sorted_list.append(ip_unsorted_dict[key])
    
    print ip_sorted_list

    结果:

    ['192.168.1.100', '192.168.8.1', '192.168.10.3']

    参考:
    http://blog.csdn.net/hong201/article/details/3119519

  • nginx代理websocket

    map $http_upgrade $connection_upgrade {
     default upgrade;
     '' close;
    }
    
    upstream proxy_stomp {
     server 192.168.1.1:3000;
    }
    
    server {
     listen 3001;
     server_name proxy.abc.com;
     location / {
     proxy_pass http://proxy_stomp;
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "upgrade";
     }
    }

    upgrade 意思为升级为其他协议

    http://nginx.org/en/docs/http/websocket.html

  • rabbitmq3.3.1允许guest远程访问

    rabbitmq 默认允许 guest 本地访问
    为了方便需要允许远程访问

    把 /usr/share/doc/rabbitmq-server-3.3.1/rabbitmq.config.example 复制一份到 /etc/rabbitmq/rabbitmq.config,在 rabbit 段中,按如下格式

    [{rabbit, [{loopback_users, []}]}]

    参考:

    https://www.rabbitmq.com/access-control.html

  • 2015读书清单

    目标30本书

    开始时间 技术书 非技术书 教学视频
    2015-01-01 数学之美
    2015-01-19 乱时候,穷时候
    2015-05-17 图解HTTP
    2015-11-4 pro git
  • paste命令

    要把

    a
    b
    c
    d
    e

    变成

    a b c d e

    使用 paste 命令

    paste -s -d' ' filename

    paste 可以将多个文件整合,按列整合

    文件1  file1

    a

    b

    文件2 file2

    1

    2

      ~ paste file1 file2

    a 1

    b 2

      ~ paste -d’ ‘ file1 file2

    a 1

    b 2

    也可以变成

      ~ paste -s file1 file2

    a b

    1 2

    如果想把 奇偶行 拼接成一行,文件为

    1 foo
    2 bar
    3 foo
    4 bar
    5 foo
    6 bar
    7 foo
    8 bar
    

    命令为

    cat filename | paste -d, - -
    1 foo,2 bar
    3 foo,4 bar
    5 foo,6 bar
    7 foo,8 bar

    如果把三行并成一行

    cat filename | paste -d, - - -