Category: Linux

  • openssl shell 检验 ssl 证书过期时间

    语法如下

    site=www.youqiantu.com
    echo | openssl s_client -servername $site -connect $site:443 2>/dev/null | openssl x509 -noout -dates
    

    添加很多域名的 check

    #!/bin/bash
    
    domains='
    sentry.google.com
    console.google.com
    www.google.com
    m.google.com
    api.google.com
    '
    
    for domain in $domains
    do
      check_result=$(echo | openssl s_client -servername $domain -connect $domain:443 2>/dev/null | openssl x509 -noout -dates | grep After)
      echo "$domain\t $check_result" | awk -F"\t" '{sub(/^ /,"",$2);printf "%-40s%s\n",$1,$2}'
    done
    

    对于自己签发的证书

    openssl x509 -enddate -noout -in apiserver.pem 
    notAfter=Mar  5 13:23:40 2018 GMT
    

    或者通过第三方工具检查
    https://www.ssllabs.com/ssltest/analyze.html
    https://whatsmychaincert.com/?jpuyy.com

    证书信息 certificate/intermediate/root ca

    openssl x509 -in example.com.crt -text -noout
    

    key 信息

    openssl rsa -in example.com.key -check 
    

    检查 p12 证书过期时间
    https://stackoverflow.com/questions/28373771/how-to-determine-ssl-cert-expire-date-from-the-cert-file-itself-p12/28374749

    You can use openssl to extract the certificate from the .p12 file to a .pem file using the following command:
    
    openssl pkcs12 -in certificate.p12 -out certificate.pem -nodes
    Then, you can extract the expiration date from the certificate in the .pem file using the following command:
    
    cat certificate.pem | openssl x509 -noout -enddate
    
  • less 查找忽略大小写

    平时使用

    cat config.json | less

    如果有大小区分的时候搜索时不太方便

    现在只使用小写搜索

    cat config.json | less -i
  • 对日志每分钟数量进行统计

    日志格式

    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
  • 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

  • 打乱文件的行顺序

    命令

    shuf

    参考:http://x-wei.github.io/%E6%89%93%E4%B9%B1%E6%96%87%E6%9C%AC%E7%9A%84%E8%A1%8C.html