Author: jpuyy

  • ansible sed替换

    使用 shell 模块时,有时为了偷懒 lineinfile,用 sed 替换,涉及到使用 sed 自己变量时,会报错

    例:将最后一行注释掉

    ansible all -i 172.28.128.3, -m shell -a "sed -e '$s/^/#/g' /etc/hosts" -u vagrant -s
    172.28.128.3 | FAILED | rc=1 >>
    sed: -e expression #1, char 4: comments don't accept any addresses

    由于 $s 代表最后一行,需要转义一下

    ansible all -i 172.28.128.3, -m shell -a "sed -i '\$s/#//g' /etc/hosts" -u vagrant -s
  • 开车时听的歌list

    1. linda(张学友 粤语)

  • 对日志每分钟数量进行统计

    日志格式

    2016-12-16 07:15:29.055
    

    统计每分钟的量

    uniq -w16 -c access.log
    
  • 客户端time_wait过多,调整服务端tcp_timestamps

    客户端发送大量 http 请求到服务端

    在客户端已经设置了

    net.ipv4.tcp_tw_recycle = 1
    net.ipv4.tcp_tw_reuse = 1

    发现客户端 time_wait 还是过多,后来在服务端设置

    sysctl -w net.ipv4.tcp_timestamps=1
  • ansible lineinfile 改文件某一行

    添加

    ansible all -i jpuyy-com-lan -m lineinfile -a "dest=/etc/hosts line='115.239.28.20 api.jpuyy.com'" -s

    删除

    ansible all -i jpuyy-com-lan -m lineinfile -a "dest=/etc/hosts line='115.239.28.20 api.jpuyy.com' state=absent" -s 

    更改某一行

    ansible all -i jpuyy-com-lan -m lineinfile -a "dest=/etc/env.yaml line='idc: sh' regexp='idc: qcloud'" -s
  • curl 测试时设置超时时间

    使用curl时,有两个超时时间:一个是连接超时时间,另一个是数据传输的最大允许时间。

    连接阶段超时时间用 –connect-timeout 参数
    整个过程的最大允许时间用 -m 参数

    例如:

    curl --connect-timeout 10 -m 20 http://jpuyy.com/

    连接超时的话,出错提示形如:

    curl: (28) connect() timed out!

    数据传输的最大允许时间超时的话,出错提示形如:

    curl: (28) Operation timed out after 2000 milliseconds with 0 bytes received