分类 Linux 相关 下的文章

草稿 用例驱动 讲明白 iptables 防火墙

涉及:
The iptables firewall works by interacting with the packet filtering hooks in the Linux kernel’s networking stack. These kernel hooks are known as the netfilter framework.

Every packet that enters networking system (incoming or outgoing) will trigger these hooks as it progresses through the stack, allowing programs that register with these hooks to interact with the traffic at key points. The kernel modules associated with iptables register at these hooks in order to ensure that the traffic conforms to the conditions laid out by the firewall rules.

Netfilter 的前身(Linux 2.2.x ipchains and Linux 2.0.x ipfwadm),后继 nftables iptables (table, chain, rule, policy)
network offload 到硬件

iptables 防火墙工具 基于 kernel 的netfilter 包过滤框架(package filter framework)
防火墙 policy 对应 iptables rule
iptables 语法:

参考: https://en.wikipedia.org/wiki/Netfilter
https://www.netfilter.org/
https://www.digitalocean.com/community/tutorials/a-deep-dive-into-iptables-and-netfilter-architecture
https://www.linode.com/docs/security/firewalls/control-network-traffic-with-iptables/

诊断由于 ulimit 设置 core file 为 unlimited 而引起的应用事故

一般情况下, 我们会设置 core file size 的 limit 为0, 通常出于性能(产生 core dump 消耗 CPU), 磁盘空间(core 文件通常特别大), 敏感数据( core dump 包含应用进程运行时很多数据)的原因, 把 core file size 设置为0, 也就是不允许产生 core dump. 有时候为了诊断某些特定的问题, 专门打开这个设置. 对于 Java 应用程序, 如果不涉及 native 代码, 通常 heap dump 就足够了, 所以不需要产生 core dump.

- 阅读剩余部分 -

linux 常见命令

文本处理类

  1. less
  2. more
  3. cat
  4. head
  5. tail
  6. awk
  7. cut
  8. grep, egrep, fgrep #print lines that match patterns, egrep & fgrep deprecated
    -- grep -v abc /var/log #打印不匹配的行
    -- grep -c abc -r /var/log #显示每个文件有多少匹配的数量
    -- grep -n abc /var/log #前面打印行号
    -- grep -n -C 3 abc /var/log #context 信息前后各3行, 或者 -B (Before), -A (After)
    -- grep -r abc /var/log #recursive
  9. sort
  10. uniq
  11. wc

- 阅读剩余部分 -

Linux 常见的系统日志文件

Linux 系统日志的配置文件在 /etc/rsyslog.conf.
默认常见的配置文件为:

authpriv.* /var/log/secure
auth user.* /var/log/messages
kern.* /var/log/kern.log
daemon.* /var/log/daemon.log
syslog.* /var/log/syslog
lpr,news,uucp.* /var/log/unused.log

对于应用程序来说, 可以通过以下方式找到日志文件

  1. 查看配置文件里面的配置项;
  2. 一般的日志文件在应用运行时都是在使用的, 通过 lsof 来查看
  3. google 以下

对于应用程序, 如何查找配置文件?

  1. 一般在 linux 的 /etc 目录, 人肉找, grep 找;
  2. 通过软件安装包管理软件, 如 rpm -c -q httpd
  3. 查看应用的日志文件, 在运行开头基本都回去读配置文件, 可能记到 log 里面;
  4. google 或 查看源代码