You are on page 1of 33

Một số phương pháp debug

trên Linux
Cơ bản đến nâng cao
Giới thiệu
Nguyễn Quốc Bảo

● Kinh nghiệm làm việc


○ IoT (Arduino, Raspberry Pi,...)
○ Cloud infrastructure (Proxmox, OpenNebula, Openstack)
○ Backend Developer (Java, VoIP, E-commerce)
○ Security infrastructure (ElasticSearch)
○ Physical server: DL360/380 G8, DL360 G9
● Linux: 10 năm kinh nghiệm dùng nano làm text editor
Mục tiêu
● Giới thiệu một số công cụ thường dùng trên Linux để debug cho người mới
bắt đầu tiếp cận.
● Chia sẻ một số kinh nghiệm cá nhân trong quá trình sử dụng và giải đáp thắc
mắc trong phạm vi hiểu biết của bản thân.
● Giới thiệu một số keyword/phương pháp để nghiên cứu sâu hơn.
Monitor != Debug
Monitor

● Diễn ra liên tục trên số lượng lớn server, tốn ít tài nguyên
● Khó theo dõi được các sự kiện diễn ra tức thời.

Debug

● Thực hiện khi có sự cố hoặc bất thường cần kiểm tra


● Theo dõi được các sự kiện diễn ra trong thời gian rất ngắn (~ giây).
● Tốn nhiều tài nguyên server (dùng xong nhớ tắt :D)
Nhóm 1
Nhóm các tool về process tương tự Task Manager trên Windows

● top
● htop
● ps
● …
top
htop
ps
Nhóm 2
Nhóm các tool để theo dõi Disk activity

● iotop
● nmon (có thể theo dõi nhiều tài nguyên khác như network, CPU,...)
● vmstat
● iostat, sar (không chạy interactive tốt, ít dùng)
iotop

Sắp xếp bằng phím mũi tên qua phải/trái. Bấm r để đảo thứ tự lớn/nhỏ.
nmon
vmstat
Nhóm 3
Nhóm các tool về network

● netstat
● tcpdump
● nload
● iftop
● Wireshark
Nhóm 4
Nhóm các tool về OS level

● strace
strace
strace
Nhóm 5
Theo dõi về các system call trong Linux

● Falco (https://falco.org/)

Falco rule
This rule uses the ioctl syscall to retrieve the
teaming interface settings, and checks if the LACP
protocol is enabled (the value 0x8809 is used to
represent the LACP protocol in the if_team.h
header file). If LACP is enabled, the rule generates
a warning message indicating the interface name.

Note that this rule assumes that the teaming


interface is created using the teamd daemon and
that the appropriate kernel module is loaded. The
rule should be customized to match the specific
configuration of your system.
Nhóm 6
Linux perf và Flamechart

● http://www.brendangregg.com/linuxperf.html
● https://github.com/brendangregg/FlameGraph
● https://github.com/iovisor/bcc

FlameChart
https://transfer.sh/wQ7Qo9/mongo1.svg
bcctool -
Track ZFS latency
Write too many data ?
Block size - Write
Nhóm 7
Intel PCM (https://github.com/intel/pcm)

● pcm-memory
● pcm-sensor-server
● pcm-pcie
● pcm-iio
Memory bandwidth
pcm-sensor-server
Lack of memory bandwidth lead to CPU cycle stall
Detect miner
Tài liệu tham khảo
● https://www.booleanworld.com/guide-linux-top-command/
● https://codeahoy.com/2017/01/20/hhtop-explained-visually/
● https://www.tecmint.com/ps-command-examples-for-linux-process-monitoring/
● https://www.baeldung.com/linux/monitor-disk-io
● https://www.howtogeek.com/424334/how-to-use-the-vmstat-command-on-linux/
● https://blog.packagecloud.io/monitoring-tuning-linux-networking-stack-receiving-data/
● https://www.site24x7.com/learn/linux/traffic-monitor.html
● https://www.thegeekstuff.com/2011/11/strace-examples/
● https://hackertarget.com/tcpdump-examples/
● https://falco.org/docs/getting-started/installation/
● https://www.youtube.com/watch?v=b1EDVH6BuBM

VietOpenInfra Meetup
● Thời gian: 8:30-11:30 AM, ngày
11/03/2023 (sáng thứ Bảy)
● Địa điểm: VNG Data Center, Lô S,
39-40 Đường số 19, Tân Thuận
Đông, Quận 7, Thành phố Hồ Chí
Minh
● Nội dung:
a. Session 1: Open Policy Agent:
Policy Controller for Kubernetes
and Microservices
b. Session 2: How to manage
public cloud infrastructure with
GitOps
c. Session 3: Distributed tracing
for microservices in OpenStack

You might also like