vg安装使用

2016/7/6 posted in  GO

virtualenv 安装使用

2016/7/5 posted in  python

swoole项目service模板

2016/7/5 posted in  PHP OPS

查找redis中的大key

python find_bigkey.py host 6379 [password]
import sys
import redis
 
 
def find_big_key_normal(db_host, db_port, db_password, db_num):
  client = redis.StrictRedis(host=db_host, port=db_port, password=db_password, db=db_num)
  i=0
  temp = client.scan(cursor=i,count=1000)
  j =0
  while temp[0]>0 :
    i=temp[0]
    j=j+len(temp[1])
    try:
      r = client.pipeline(transaction=False)
      for k in temp[1]:
        r.debug_object(k)
      tempA = r.execute()
      x = 0
      for key in tempA:
        length = key.get("serializedlength")
        ##type = key.get("encoding")
        if length > 10240 :
          type = client.type(temp[1][x])
          print temp[1][x], type,length
        x=x+1
    except :
      print "a execption come"
    temp = client.scan(cursor=i,count=1000)
 
   
if __name__ == '__main__':
  if len(sys.argv) != 4:
     print 'Usage: python ', sys.argv[0], ' host port password '
     exit(1)
  db_host = sys.argv[1]
  db_port = sys.argv[2]
  db_password = sys.argv[3]
  r = redis.StrictRedis(host=db_host, port=int(db_port), password=db_password)
  nodecount = 1
  keyspace_info = r.info("keyspace")
  for db in keyspace_info:
    print 'check ', db, ' ', keyspace_info[db]
    find_big_key_normal(db_host, db_port, db_password, db.replace("db", ""))
删除缓存key: EVAL "return redis.call('del', unpack(redis.call('keys', ARGV[1])))" 0 cpx_sn_
EVAL "local keys = redis.call('keys', ARGV[1]) \n for i=1,#keys,5000 do \n redis.call('del', unpack(keys, i, math.min(i+4999, #keys))) \n end \n return keys" 0 prefix:*
2016/5/20 posted in  Redis

xhprof安装小记

xhprof安装步骤 https://github.com/longxinH/xhprof-apm/blob/php7/README_CN.md

1. 关闭opcache扩展
2. 增加php的内存限制到4GB

xgui安装步骤:https://github.com/perftools/xhgui

array {
    [函数名]=>
      array {
        ["ct"] => 调用次数 (int)
        ["wt"] => 函数方法执行的时间耗时 (int)
        ["cpu"] => 函数方法执行消耗的cpu时间 (int)
        ["mu"] => 函数方法所使用的内存 (int)
        ["pmu"] => 函数方法所使用的内存峰值 (int)
        ["files"] => array {
          [文件名] =>
            array {
              [行号] => 调用次数 (int)
            }
        }
    }
}
2016/5/20 posted in  PHP

xcode ide工具介绍

mac自带免费良心mac/ios开发工具,通过这个工具就可以赚钱了,了解下是很有必要的

设置字体

在设置->字体界面按command + a选择全部样式,然后单击字体按钮即可修改,参考如下:

自带的mac UI组件

xcode自带很多的ui组件,单击右上角的加号按钮即可展开,参考如下:

2015/3/27 posted in  mac&ios

gogs作为系统服务

[Unit]
Description=Gogs
After=syslog.target
After=network.target

[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
Type=simple
User=git
Group=git
WorkingDirectory=/home/git/gogs
ExecStart=/home/git/gogs/gogs web
Restart=always
Environment=USER=git HOME=/home/git

[Install]
WantedBy=multi-user.target

加载这个service和启动gogs

systemctl daemon-reload
systemctl start gogs
2014/7/12 posted in  OPS GIT

三分钟实现程序分库分表

2014/7/6 posted in  PHP SQL

三分钟上手shell语言

if语句

if [ "$arg1" = "$arg2" ] && [ "$arg1" != "$arg3" ]
then 
    echo "arg1和arg2相等,arg1和arg3不相等"
    exit 3
elif [ $arg1 = $arg2 ] && [ $arg1 = $arg3 ]
then
    echo "arg1, arg2, arg3均相等"
    exit 0
else
    echo "arg1, arg2, arg3都不相等"
    exit 4 
fi

for 循环语句

for i in $(seq 1 10);
do
    echo $i
done
arr=`seq 1 10`

for i in $arr
do
    echo $i
done

while语句

# 初始化变量值为0
a=0
while [ $a -lt 10 ]
do
    echo $a
    a=`expr $a + 1`
done

case语句

# 初始化变量a
a=4
case "$a" in
"1")
    echo "a等于1"
    ;;
"2" | "3")
    echo "a等于2或3"
    ;;
*)
    echo "a不等于1,2或3"
    ;;
esac

将一个命令的输出保存到变量

使用$(一个命令)就可以获取这个命令的输出了,然后可以把这个输出赋值给一个变量
比如把当前目录的文件保存到变量中

arr=$(ls)

操作效果如下

整数运算操作

使用双小括号的语法:$((运算内容)),返回运算后的结果,支持+, -, *, /, %, **, +=, -=, *=, /=, 自增,自减,进制转换等操作

i=1
b=$((i+1))
c=$((i=i+1))
d=$((i++))
e=$((++i))

echo $b # 2
echo $c # 2
echo $d # 2
echo $e # 4

处理换行

echo "aaa:bbb:ccc:ddd" | tr ":" "\n" | sed '/ccc/a\Chanpter 1'

一些注意的点

变量声明时不需要加$符号,但是使用时需要加,=左右不能存在空格

sed可做文件内容的字符串替换

awk可做文件内容输出的格式化

shell的操作符分数字和字符串,注意使用对应的操作符,文件也有对应的操作符,参考:http://www.tutorialspoint.com/unix/unix-basic-operators.htm

查看linux发行版: cat /etc/*release

查看进程树

pstree -p 进程的id
ps aft

参考资料

  1. https://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output/
  2. https://stackoverflow.com/questions/49110/how-do-i-write-a-for-loop-in-bash
  3. https://stackoverflow.com/questions/2359270/using-if-elif-fi-in-shell-scripts
  4. https://stackoverflow.com/questions/37985926/unix-shell-script-while-loop
  5. http://www.tutorialspoint.com/unix/unix-basic-operators.htm
  6. https://stackoverflow.com/questions/5562253/switch-case-with-fallthrough
2013/7/6 posted in  OPS 三分钟系列

brew安装使用

2013/4/9 posted in  mac