自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Linux系統(tǒng)管理之技巧

系統(tǒng) Linux 系統(tǒng)運維
項目完成了一個階段性的任務(wù),在這里小結(jié)一下幾個小技巧。

 [[186609]]

【引自年年歳歲的博客】項目完成了一個階段性的任務(wù),在這里小結(jié)一下幾個小技巧:

1. 授權(quán)研發(fā)人員權(quán)限越級(sudo)

  1. $ cat public 
  2. User_Alias A4 = public 
  3. A4       ALL=(ALL)       NOPASSWD: /usr/bin/vim,/bin/cat,/usr/bin/tail  #這里你自己定義 
  4. $ ansible all -m copy -a 'src=public dest=/etc/sudoers.d' -s  

2. 批量memcached清除緩存(flush_all)

  1. echo 'flush_all' | nc -z -w 1 $IP $PORT 

如果有很多,可以向下羅列,批量清除,如果你覺得很low,可以使用數(shù)組declare -a,或者循環(huán)while,

寫python當(dāng)然也行,附上自己的過程,請參考:

  1. $ cat clear_memcached.py  
  2. from pymemcache.client.base import Client 
  3. import sys 
  4.   
  5. def read_log(path): 
  6.     with open(path) as f: 
  7.         yield from f 
  8.   
  9. def HP(path): 
  10.     for line in read_log(path): 
  11.         ret = line.strip().split() 
  12.         ret[1] = int(ret[1]) 
  13.         ret = tuple(ret) 
  14.         print(ret) 
  15.         yield ret 
  16.           
  17. def clear_mem(path): 
  18.     for hp in HP(path): 
  19.         c.flush_all() 
  20.         c.close() 
  21.   
  22. if __name__ == "__main__"
  23.     clear_mem(sys.argv[1]) 
  24.    
  25. $ cat mall_mem.txt  
  26. $IP1 $PORT1 
  27. $IP1 $PORT2 
  28. ...  

3. 遠程快速校驗多臺主機不同目錄下的文件內(nèi)容一致性(擴容時發(fā)揮作用很大)

  1. $ ssh -t $ip 'find $dir1 $dir2 ... -type f -exec md5sum {} \;' > $ip.md5 # 注意$dir1..等使用絕對路徑 
  2. $ doc2unix $ip.md5  #(這個很隱秘,多了windows的回車符) 
  3. $ ssh -tt $ip.other 'md5sum -c --quiet' < $ip.md5  
  4. # 如果一致,什么也不反回;不一致的會告訴NOT MATCH的文件  

哎,非逼自己用python去寫,實現(xiàn)了find + sha256sum,但想將其保存到特定文件中,這一點卻沒實現(xiàn)。這一版,只是想回顧“裝飾器”,這里沒起到作用。

  1. #!/usr/bin/env python 
  2.   
  3. import os, os.path, sys 
  4. import hashlib 
  5. from functools import wraps 
  6.   
  7. def search(fn): 
  8.     @wraps(fn) 
  9.     def wrap(*args, **kwargs): 
  10.         paths = list(args) 
  11.         ret = fn(*args, **kwargs) 
  12.         #paths.pop() 
  13.         for path in paths: 
  14.             print(path) 
  15.             for pathname in os.listdir(path): 
  16.                 pathname = os.path.join(path, pathname) 
  17.                 if os.path.isfile(pathname): 
  18.                     with open(pathname, 'rb'as f: 
  19.                         m = hashlib.sha256(f.read()) 
  20.                         # hashfile = path + '.sha256' 
  21.                         # print(hashfile) 
  22.                         # with open(hashfile, 'a+'as f: 
  23.                         #     f.write('{}  {}\n'.format(m.hexdigest(), pathname)) 
  24.                         print('%s  %s' % (m.hexdigest(), pathname)) 
  25.                         #ret.write('aaa'
  26.                         #ret.write('%s  %s' % (m.hexdigest(), pathname)) 
  27.                         #ret.close() 
  28.                 if os.path.isdir(pathname): 
  29.                     wrap(pathname) 
  30.     return wrap 
  31.   
  32. @search 
  33. def write(*args, **kwargs): 
  34.     pass 
  35.     #hashfile = list(args).pop() 
  36.     #print(hashfile) 
  37.     #hashfile = '10.255.201.10' 
  38.     #f = open(hashfile, 'a+'
  39.     #return f 
  40.   
  41. if __name__ == '__main__'
  42.     write(*sys.argv[1:])  

4. 配置Open-falcon HostGroups時,根據(jù)hostname綁定template,快速獲取平臺的主機名

  1. $ ansible $group1 -m setup -a 'filter=ansible_hostname' -o | awk -F'[ :|"{}]' '{print $17}' 

5. 關(guān)閉遠程Nginx\Tomcat進程,啟動服務(wù)就不寫了

  1. $ cat marketapi_stop.sh  
  2. #!/bin/bash 
  3. kill -QUIT $(cat /home/aspire/config/nginx/nginx.pid) 
  4. $ ansible $group1 -m script -a 'marketapi_stop.sh' -s 
  5. ------- 
  6. $ cat tomcat_stop.sh  
  7. #!/bin/bash 
  8. kill -9 $(ps aux | awk '/tomat808[0]\/conf/{print $2}'
  9. $ ansible $group1 -m script -a 'tomcat_stop.sh' -s  

6. 遠程tail -f 查看日志滾動

  1. $ ssh -t $IP 'tail -f xxxx.log' 
責(zé)任編輯:龐桂玉 來源: 51CTO博客
相關(guān)推薦

2012-02-29 00:57:41

Linux系統(tǒng)

2011-04-02 10:13:36

Linux系統(tǒng)管理

2010-03-18 16:48:22

Linux命令

2010-03-18 16:51:32

2010-03-18 16:57:02

Linux命令

2009-10-22 13:23:34

linux系統(tǒng)管理

2012-11-01 11:33:11

IBMdw

2010-12-28 09:16:00

2010-03-04 14:44:05

Linux管理命令

2009-10-12 11:14:51

LinuxLinux磁盤文件系統(tǒng)管理

2010-05-05 15:56:37

Unix系統(tǒng)

2011-09-29 09:41:24

系統(tǒng)管理項目管理系統(tǒng)

2010-02-24 09:13:04

2023-08-28 10:49:13

Linux系統(tǒng)

2012-09-24 10:14:46

Linux系統(tǒng)管理

2013-04-17 14:37:39

Linux系統(tǒng)管理員susudo

2010-05-05 16:27:22

Unix系統(tǒng)

2010-05-04 15:22:25

Unix系統(tǒng)

2011-09-01 13:42:15

優(yōu)化布線系統(tǒng)管理布線系統(tǒng)

2011-10-20 15:32:07

系統(tǒng)管理訪問管理
點贊
收藏

51CTO技術(shù)棧公眾號