V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
fsckzy
V2EX  ›  Python

想用 python 获取几十台服务器日志中指定关键词内容

  •  
  •   fsckzy · Dec 8, 2016 · 4138 views
    This topic created in 3435 days ago, the information mentioned may be changed or developed.

    求给点思路

    几十台服务器,同样的路径,我需要看看 log 文件里面有没有出现 127.0.0.1 这个 ip

    20 replies    2016-12-09 13:09:19 +08:00
    clino
        1
    clino  
       Dec 8, 2016
    ansible
    erevus
        2
    erevus  
       Dec 8, 2016
    elk
    wyntergreg
        3
    wyntergreg  
       Dec 8, 2016
    不建议用 python 搜索关键词,可以用 python 把文件拿过来用文本工具进行搜索
    izoabr
        4
    izoabr  
       Dec 8, 2016
    还不如脚本 ssh 挨个上去 grep '127.0.0.1'然后回传或者写入新文件呢
    knightdf
        5
    knightdf  
       Dec 8, 2016   ❤️ 1
    for ssh grep 不久完了
    vus520
        6
    vus520  
       Dec 8, 2016
    salt(salt-ssh)、 ansible 不好么, grep 出来,然后放到共享目录里
    czheo
        7
    czheo  
       Dec 8, 2016
    加上 xargs -P 可以并发哦。
    est
        8
    est  
       Dec 8, 2016
    ansible
    ywgx
        9
    ywgx  
       Dec 8, 2016 via iPhone
    楼主,我给你总结一下你的需求?

    “如何管理大量服务器集群?”
    ywgx
        10
    ywgx  
       Dec 8, 2016 via iPhone
    kinghs
        11
    kinghs  
       Dec 8, 2016
    paramiko 可破
    SlipStupig
        12
    SlipStupig  
       Dec 8, 2016
    @erevus 这么点小需求,用 elk 学习成本太高了
    cat /your/dir/*.log | sort | uniq | xargs -n 10 | grep -e ".*127.0.0.1.*",如果是远程的话可以用 rsync 同步一下就行了
    iyaozhen
        13
    iyaozhen  
       Dec 8, 2016 via Android
    简单的需要。找一台跳板机,添加信任。然后登录到各个机器上去执行 grep
    skydiver
        14
    skydiver  
       Dec 8, 2016
    polysh
    RealLiuSha
        15
    RealLiuSha  
       Dec 8, 2016
    ansible playbook or command module
    ty89
        16
    ty89  
       Dec 8, 2016
    pssh
    v2014
        17
    v2014  
       Dec 8, 2016
    fabric
    Livid
        18
    Livid  
    MOD
    PRO
       Dec 8, 2016   ❤️ 1
    1. 如果是一次性需求,用 Ansible
    2. 如果是持续需求,把日志推到 papertrailapp.com 然后为 127.0.0.1 这个关键词设定一个 alert
    cxmtime
        19
    cxmtime  
       Dec 9, 2016
    和楼主有类似德需求,用 ruby 写了一个工具,自己用的顺手。
    hanbaobao2005
        20
    hanbaobao2005  
       Dec 9, 2016
    嗯 同 15 楼, 建议 Ansible + log 分析
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2733 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 89ms · UTC 08:34 · PVG 16:34 · LAX 01:34 · JFK 04:34
    ♥ Do have faith in what you're doing.