Linux系统管理之技巧—— 2017-03-23
2017-03-23 14:01
239 查看
项目完成了一个阶段性的任务,在这里小结一下几个小技巧:
授权研发人员权限越级(sudo)
写python当然也行,附上自己的过程,请参考:
5. 关闭远程Nginx\Tomcat进程,启动服务就不写了
授权研发人员权限越级(sudo)
$ cat public User_Alias A4 = public A4 ALL=(ALL) NOPASSWD: /usr/bin/vim,/bin/cat,/usr/bin/tail #这里你自己定义 $ ansible all -m copy -a 'src=public dest=/etc/sudoers.d' -s2. 批量memcached清除缓存(flush_all)
echo 'flush_all' | nc -z -w 1 $IP $PORT如果有很多,可以向下罗列,批量清除,如果你觉得很low,可以使用数组declare -a,或者循环while,
写python当然也行,附上自己的过程,请参考:
$ cat clear_memcached.py from pymemcache.client.base import Client import sys def read_log(path): with open(path) as f: yield from f def HP(path): for line in read_log(path): ret = line.strip().split() ret[1] = int(ret[1]) ret = tuple(ret) print(ret) yield ret def clear_mem(path): for hp in HP(path): c.flush_all() c.close() if __name__ == "__main__": clear_mem(sys.argv[1]) $ cat mall_mem.txt $IP1 $PORT1 $IP1 $PORT2 ...3. 远程快速校验多台主机不同目录下的文件内容一致性(扩容时发挥作用很大)
$ ssh -t $ip 'find $dir1 $dir2 ... -type f -exec md5sum {} \;' > $ip.md5 # 注意$dir1..等使用绝对路径 $ doc2unix $ip.md5 #(这个很隐秘,多了windows的回车符) $ ssh -tt $ip.other 'md5sum -c --quiet' < $ip.md5 # 如果一致,什么也不反回;不一致的会告诉NOT MATCH的文件哎,非逼自己用python去写,实现了find + sha256sum,但想将其保存到特定文件中,这一点却没实现。这一版,只是想回顾“装饰器”,这里没起到作用。
#!/usr/bin/env python import os, os.path, sys import hashlib from functools import wraps def search(fn): @wraps(fn) def wrap(*args, **kwargs): paths = list(args) ret = fn(*args, **kwargs) #paths.pop() for path in paths: print(path) for pathname in os.listdir(path): pathname = os.path.join(path, pathname) if os.path.isfile(pathname): with open(pathname, 'rb') as f: m = hashlib.sha256(f.read()) # hashfile = path + '.sha256' # print(hashfile) # with open(hashfile, 'a+') as f: # 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() if os.path.isdir(pathname): wrap(pathname) return wrap @search def write(*args, **kwargs): pass #hashfile = list(args).pop() #print(hashfile) #hashfile = '10.255.201.10' #f = open(hashfile, 'a+') #return f if __name__ == '__main__': write(*sys.argv[1:])4. 配置Open-falcon HostGroups时,根据hostname绑定template,快速获取平台的主机名
$ ansible $group1 -m setup -a 'filter=ansible_hostname' -o | awk -F'[ :|"{}]' '{print $17}'
5. 关闭远程Nginx\Tomcat进程,启动服务就不写了
$ cat marketapi_stop.sh #!/bin/bash kill -QUIT $(cat /home/aspire/config/nginx/nginx.pid) $ ansible $group1 -m script -a 'marketapi_stop.sh' -s ------- $ cat tomcat_stop.sh #!/bin/bash kill -9 $(ps aux | awk '/tomat808[0]\/conf/{print $2}') $ ansible $group1 -m script -a 'tomcat_stop.sh' -s6. 远程tail -f 查看日志滚动
$ ssh -t $IP 'tail -f xxxx.log'
相关文章推荐
- Linux系统管理技巧大荟萃
- linux系统管理技巧
- Linux日常运维管理技巧: w命令-查看系统负载、vmstat命令、top命令、sar命令
- linux系统安全管理的实用技巧
- Linux日常运维管理技巧--监控系统状态
- 26.Linux系统管理技巧2--io监控,free,ps,netstat,tcpdump
- Linux系统管理技巧的大荟萃
- Linux 系统管理 技巧
- RedHat / Centos Linux 系统运维与管理实践技巧荟萃,持续更新
- Linux系统中磁盘存储区管理原理与技巧
- Linux系统安全管理高级技巧
- 做一个好管家 Linux系统管理技巧大荟萃
- Linux系统管理技巧大荟萃
- Linux日常运维管理技巧: w命令-查看系统负载、vmstat命令、top命令、sar命令
- linux ,系统管理技巧
- 第13章 linux系统管理技巧(日常运维管理技巧)
- Linux系统管理技巧大荟萃
- Linux基础入门及系统管理01-shell三剑客之sed命令技巧讲解20
- linux系统安全管理的实用技巧