【引自每年的博客】项目完成了阶段性任务,这里有几点小技巧:1.授权研发人员越级(sudo)$catpublicUser_AliasA4=publicA4ALL=(ALL)NOPASSWD:/usr/bin/vim,/bin/cat,/usr/bin/tail#这里定义$ansibleall-mcopy-a'src=publicdest=/etc/sudoers.d'-s2。批量memcached清空缓存(flush_all)echo'flush_all'|nc-z-w1$IP$PORT如果有很多可以列下来分批清空。如果你觉得很low,可以使用数组declare-a,或者loopwhile,当然python写也是可以的,附上你自己的过程,请参考:$catclear_memcached.pyfrompymemcache.client.baseimportClientimportsysdefread_log(path):withopen(path)asf:yieldfromfdefHP(path):forlineinread_log(path):ret=line.strip().split()ret[1]=int(ret[1])ret=tuple(ret)print(ret)yieldretdefclear_mem(path):forhpinHP(path):c.flush_all()c.close()if__name__=="__main__":clear_mem(sys.argv[1])$catmall_mem.txt$IP1$PORT1$IP1$PORT2。..3.远程快速验证多台主机不同目录下文件内容的一致性(扩容大时很有用)$ssh-t$ip'find$dir1$dir2...-typef-execmd5sum{}\;'>$ip.md5#注意$dir1..等使用绝对路径$doc2unix$ip.md5#(这个很隐秘,多了一个windows回车)$ssh-tt$ip.other'md5sum-c--quiet'<$ip.md5#一致则不返回任何内容;如果不一致,它会告诉NOTMATCH的文件,不勉强自己用python写,自己实现了find+sha256sum,但是想保存在特定的文件中,没实现这个版本。我只想回顾一下“装饰器”,它在这里不起作用。#!/usr/bin/envpythonimportos,os.path,sysimporthashlibfromfunctoolsimportwrapsdefsearch(fn):@wraps(fn)defwrap(*args,**kwargs):paths=list(args)ret=fn(*args,**kwargs)#paths.pop()forpathinpaths:print(path)forpathnameinos.listdir(path):pathname=os.path.join(path,pathname)ifos.path.isfile(pathname):withopen(pathname,'rb')asf:m=hashlib.sha256(f.read())#hashfile=path+'.sha256'#print(hashfile)#withopen(hashfile,'a+')asf:#f.write('{}{}\n'.format(m.hexdigest(),pathname))print('%s%s'%(m.hexdigest(),pathname))#ret.write('aaa')#ret.write('%s%s'%(m.hexdigest(),pathname))#ret.close()ifos.path.isdir(pathname):wrap(pathname)returnwrap@searchdefwrite(*args,**kwargs):pass#hashfile=list(args).pop()#print(hashfile)#hashfile='10.255.201.10'#f=open(hashfile,'a+')#returnfif__name__=='__main__':write(*sys.argv[1:])4。配置Open-falconHostGroups时,根据主机名绑定模板,快速获取平台的主机名$ansible$group1-msetup-a'filter=ansible_hostname'-o|awk-F'[:|"{}]''{print$17}'5.关闭远程程序Nginx\Tomc在进程中,启动服务而不写入$catmarketapi_stop.sh#!/bin/bashkill-QUIT$(cat/home/aspire/config/nginx/nginx.pid)$ansible$group1-mscript-a'marketapi_stop.sh'-s--------$cattomcat_stop.sh#!/bin/bashkill-9$(psaux|awk'/tomat808[0]\/conf/{print$2}')$ansible$group1-mscript-a'tomcat_stop.sh'-s6。远程tail-f查看日志滚动$ssh-t$IP'tail-fxxxx.log'
