Category: Life

  • 迁移 kvm

    domain=rskwliyu
    host1=10.31.216.10
    host2=10.31.216.20
    echo “in $host1”
    echo “ssh $host2 ok”
    echo “cd /”
    echo “tar c etc/libvirt/qemu/$domain.xml data/kvm/$domain.img | nc -l 3389”

    echo “in $host2”
    echo “cd /”
    echo “nc $host1 3389 | tar x”

    echo “in $host1”
    echo “virsh migrate –live $domain qemu+ssh://$host2/system”

    echo “in $host2”
    echo “virsh edit $domain”
    echo “in guest curl put”

    echo “curl http://etcd.hupu.io:4001/v2/keys/hostvars/$host1/domain/$domain?recursive=true -XDELETE”

  • jobs

    Why join the navy if you can be a pirate? 如果能当海盗,为什么要去参加海军? ——steve jobs

  • 常用数字

    86400 sec= 1d

    2592000 sec = 30d

    1440 min=1d

  • redis set使用

    统计集合 key 的 member 的数量

    SCARD hello:step:3000:obj_type0
  • logrotate

    添加配置文件

    cat /etc/logrotate.d/myservice
    
    /data/log/myservice/*.log
    {
        rotate 7
        daily
        dateext
        dateformat .%Y%m%d
        compress
        missingok
        notifempty
        sharedscripts
        postrotate
          /usr/bin/killall -HUP rsyslogd >/dev/null 2>&1 || true
        endscript
    }

    debug 配置文件是否正确,但不会真正动你的 log

    logrotate -d /etc/logrotate.d/myservice

    真实测试 logrotate 情况

    logrotate -f /etc/logrotate.d/myservice
  • python debug使用logging

    使用 logging 有很多好处:

    可以方便添加 timestamp
    可以为日志定级
    不会和业务的 print 混淆
    如果你忘了去掉 logging ,最多也只是有一个 log 文件

    如果要打印出来

    import logging
    logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
    logging.debug('This is a log message.')
    

    如果要放到文件里

    import logging
    logging.basicConfig(filename='log_filename.txt', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
    logging.debug('This is a log message.')
    

    报警级别

    logger.critical('This is a critical message.')
    logger.error('This is an error message.')
    logger.warning('This is a warning message.')
    logger.info('This is an informative message.')
    logger.debug('This is a low-level debug message.')
    

    http://inventwithpython.com/blog/2012/04/06/stop-using-print-for-debugging-a-5-minute-quickstart-guide-to-pythons-logging-module/