zoukankan      html  css  js  c++  java
  • 【Azure 应用服务】App Service For Linux 如何在 Web 应用实例上住抓取网络日志

    问题描述

    在App Service For Windows的环境中,我们可以通过ArmClient 工具发送POST请求在Web应用的实例中抓取网络日志,但是在App Service For Linux的环境中如何抓取网络包呢?

    抓取Windows的网络包可参考博文:【应用服务 App Service】App Service中抓取网络日志

    问题解决

    通过SSH方式登录到Linux实例,使用tcpdump的工具抓取网络包, 通过IP地址和端口443来进行过滤,生成的网络包写入到tmp目录下的 appnetworktrace.pcap  文件。 命令如下:

    tcpdump -i any host <your app service inbound ip address> and tcp port 443 -n -v -s 0 -w /tmp/appnetworktrace.pcap   

    • 如果在登录SSH的时候出现 SSH CONNECTION CLOSE - Error: Timed out while waiting for handshakeError: connect ECONNREFUSED 错误,则是因为使用自定义容器的方式发布的Docker镜像中没有启动SSH。只需要根据官方文档启动即可。

    启用 SSH

    SSH 实现容器和客户端之间的安全通信。 为了使自定义容器支持 SSH,你必须将其添加到 Docker 映像本身。

    1) 将 sshd_config 文件 添加到存储库,如以下示例中所示。

    Port            2222
    ListenAddress       0.0.0.0
    LoginGraceTime      180
    X11Forwarding       yes
    Ciphers aes128-cbc,3des-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr
    MACs hmac-sha1,hmac-sha1-96
    StrictModes         yes
    SyslogFacility      DAEMON
    PasswordAuthentication  yes
    PermitEmptyPasswords    no
    PermitRootLogin     yes
    Subsystem sftp internal-sftp

     备注: 此文件配置 OpenSSH 并且必须包括以下项:

    • Port 必须设置为 2222。
    • Ciphers 必须至少包含此列表中的一项:aes128-cbc,3des-cbc,aes256-cbc
    • MACs 必须至少包含此列表中的一项:hmac-sha1,hmac-sha1-96

    2) 向存储库添加 ssh_setup 脚本文件,以使用 ssh-keygen 创建 SSH 密钥。

    #!/bin/sh
    
    if [ ! -f "/etc/ssh/ssh_host_rsa_key" ]; then
        # generate fresh rsa key
        ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
    fi
    
    if [ ! -f "/etc/ssh/ssh_host_dsa_key" ]; then
        # generate fresh dsa key
        ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
    fi
    
    if [ ! -f "/etc/ssh/ssh_host_ecdsa_key" ]; then
        # generate fresh ecdsa key
        ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t dsa
    fi
    
    if [ ! -f "/etc/ssh/ssh_host_ed25519_key" ]; then
        # generate fresh ecdsa key
        ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t dsa
    fi
    
    #prepare run dir
        if [ ! -d "/var/run/sshd" ]; then
        mkdir -p /var/run/sshd
    fi

    3) 在 Dockerfile 中,添加以下命令:

    # Install OpenSSH and set the password for root to "Docker!". In this example, "apk add" is the install instruction for an Alpine Linux-based image.
    RUN apk add openssh 
         && echo "root:Docker!" | chpasswd 
    
    # Copy the sshd_config file to the /etc/ssh/ directory
    COPY sshd_config /etc/ssh/
    
    # Copy and configure the ssh_setup file
    RUN mkdir -p /tmp
    COPY ssh_setup.sh /tmp
    RUN chmod +x /tmp/ssh_setup.sh 
        && (sleep 1;/tmp/ssh_setup.sh 2>&1 > /dev/null)
    
    # Open port 2222 for SSH access
    EXPOSE 80 2222

    4) 在容器的启动脚本中启动 SSH 服务器。

    /usr/sbin/sshd

    参考资料

    为 Azure 应用服务配置自定义容器, 启动SSHhttps://docs.microsoft.com/zh-cn/azure/app-service/configure-custom-container?pivots=container-linux#enable-ssh

    当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

  • 相关阅读:
    leetcode 29-> Divide Two Integers without using multiplication, division and mod operator
    ros topic 发布一次可能会接收不到数据
    python中的print()、str()和repr()的区别
    python 部分函数
    uiautomatorviewer错误 unable toconnect to adb
    pyqt 不规则形状窗口显示
    appium 计算器demo
    Spring 3.0 注解注入详解
    Spring Autowire自动装配
    restful 学习地址
  • 原文地址:https://www.cnblogs.com/lulight/p/15457904.html
Copyright © 2011-2022 走看看