Thứ Tư, 10 tháng 9, 2025

Bài 2: Quản trị Linux cơ bản cho DevOps

1. Vì sao DevOps cần Linux?

  • Hầu hết server chạy Linux (Ubuntu, Debian, RHEL, CentOS, Oracle Linux, Fedora).

  • DevOps phải biết quản lý user, process, service, file log, monitoring cơ bản.

  • Đây là nền tảng để sau này deploy ứng dụng, quản lý container, cluster.


2. Quản lý User

Tạo user mới

sudo useradd devops sudo passwd devops

👉 Kết quả:

Changing password for user devops. New password: Retype new password: passwd: all authentication tokens updated successfully.

Xóa user

sudo userdel -r devops

3. Quản lý Service với systemctl

Bật / tắt service

# Start sudo systemctl start nginx # Stop sudo systemctl stop nginx # Restart sudo systemctl restart nginx # Kiểm tra trạng thái sudo systemctl status nginx

👉 Kết quả khi chạy status:

● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled) Active: active (running) since Mon 2025-09-09 10:00:00 +07; 5s ago

Bật service tự khởi động khi boot

sudo systemctl enable nginx

4. Quản lý Process

Liệt kê process

ps aux | head -5

👉 Kết quả mẫu:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 167692 1112 ? Ss 09:50 0:01 /sbin/init

Kill process theo PID

kill -9 <PID>

5. Monitoring cơ bản

Kiểm tra CPU, RAM

top

👉 Kết quả mẫu (rút gọn):

%Cpu(s): 5.6 us, 1.2 sy, 0.0 ni, 92.9 id, 0.2 wa MiB Mem : 7982.0 total, 1325.4 free, 4290.2 used, 2366.4 buff/cache

Kiểm tra Disk

df -h

👉 Kết quả:

Filesystem Size Used Avail Use% Mounted on /dev/sda1 50G 20G 28G 42% /

Kiểm tra RAM

free -m

👉 Kết quả:

total used free shared buff/cache available Mem: 7982 4290 1325 123 2366 3520

6. Quản lý Log

Xem log hệ thống

tail -n 20 /var/log/syslog # Ubuntu/Debian tail -n 20 /var/log/messages # RHEL/CentOS/Fedora/Oracle Linux

👉 Kết quả mẫu:

Sep 09 10:10:15 server1 systemd[1]: Started Session 42 of user devops. Sep 09 10:10:20 server1 sshd[2500]: Accepted password for devops from 192.168.1.100 port 50123 ssh2

7. Bài tập thực hành + Lời giải


🔹 Bài tập 1: Tạo user DevOps và kiểm tra

Yêu cầu: Tạo user devops, đặt mật khẩu, đăng nhập và kiểm tra bằng whoami.

Lời giải:

sudo useradd devops sudo passwd devops su - devops whoami

👉 Kết quả:

devops

🔹 Bài tập 2: Kiểm tra và restart service Apache/Nginx

Yêu cầu: Kiểm tra trạng thái web server, nếu đang inactive thì restart.

Lời giải:

sudo systemctl status nginx sudo systemctl restart nginx sudo systemctl status nginx

👉 Kết quả trước khi restart:

Active: inactive (dead)

👉 Kết quả sau restart:

Active: active (running)

🔹 Bài tập 3: Kiểm tra Disk, nếu > 80% thì in cảnh báo

Code script check_disk.sh:

#!/bin/bash usage=$(df / | grep / | awk '{print $5}' | sed 's/%//') echo "Disk usage: $usage%" if [ $usage -gt 80 ]; then echo "ALERT: Disk usage too high!" fi

Chạy:

bash check_disk.sh

👉 Kết quả khi còn nhiều chỗ trống:

Disk usage: 42%

👉 Kết quả khi đầy:

Disk usage: 85% ALERT: Disk usage too high!

✅ Sau Bài 2, bạn đã biết:

  • Quản lý user, service, process

  • Monitoring cơ bản CPU, RAM, Disk

  • Đọc log hệ thống

  • Viết shell script giám sát

=============================
Website không chứa bất kỳ quảng cáo nào, mọi đóng góp để duy trì phát triển cho website (donation) xin vui lòng gửi về STK 90.2142.8888 - Ngân hàng Vietcombank Thăng Long - TRAN VAN BINH
=============================
Nếu bạn không muốn bị AI thay thế và tiết kiệm 3-5 NĂM trên con đường trở thành DBA chuyên nghiệp hay làm chủ Database thì hãy đăng ký ngay KHOÁ HỌC ORACLE DATABASE A-Z ENTERPRISE, được Coaching trực tiếp từ tôi với toàn bộ bí kíp thực chiến, thủ tục, quy trình của gần 20 năm kinh nghiệm (mà bạn sẽ KHÔNG THỂ tìm kiếm trên Internet/Google) từ đó giúp bạn dễ dàng quản trị mọi hệ thống Core tại Việt Nam và trên thế giới, đỗ OCP.
- CÁCH ĐĂNG KÝ: Gõ (.) hoặc để lại số điện thoại hoặc inbox https://m.me/tranvanbinh.vn hoặc Hotline/Zalo 090.29.12.888
- Chi tiết tham khảo:
https://bit.ly/oaz_w
=============================
2 khóa học online qua video giúp bạn nhanh chóng có những kiến thức nền tảng về Linux, Oracle, học mọi nơi, chỉ cần có Internet/4G:
- Oracle cơ bản: https://bit.ly/admin_1200
- Linux: https://bit.ly/linux_1200
=============================
KẾT NỐI VỚI CHUYÊN GIA TRẦN VĂN BÌNH:
📧 Mail: binhoracle@gmail.com
☎️ Mobile/Zalo: 0902912888
👨 Facebook: https://www.facebook.com/BinhOracleMaster
👨 Inbox Messenger: https://m.me/101036604657441 (profile)
👨 Fanpage: https://www.facebook.com/tranvanbinh.vn
👨 Inbox Fanpage: https://m.me/tranvanbinh.vn
👨👩 Group FB: https://www.facebook.com/groups/DBAVietNam
👨 Website: https://www.tranvanbinh.vn
👨 Blogger: https://tranvanbinhmaster.blogspot.com
🎬 Youtube: https://www.youtube.com/@binhguru
👨 Tiktok: https://www.tiktok.com/@binhguru
👨 Linkin: https://www.linkedin.com/in/binhoracle
👨 Twitter: https://twitter.com/binhguru
👨 Podcast: https://www.podbean.com/pu/pbblog-eskre-5f82d6
👨 Địa chỉ: Tòa nhà Sun Square - 21 Lê Đức Thọ - Phường Mỹ Đình 1 - Quận Nam Từ Liêm - TP.Hà Nội

=============================
cơ sở dữ liệu, cơ sở dữ liệu quốc gia, database, AI, trí tuệ nhân tạo, artificial intelligence, machine learning, deep learning, LLM, ChatGPT, DeepSeek, Grok, oracle tutorial, học oracle database, Tự học Oracle, Tài liệu Oracle 12c tiếng Việt, Hướng dẫn sử dụng Oracle Database, Oracle SQL cơ bản, Oracle SQL là gì, Khóa học Oracle Hà Nội, Học chứng chỉ Oracle ở đầu, Khóa học Oracle online,sql tutorial, khóa học pl/sql tutorial, học dba, học dba ở việt nam, khóa học dba, khóa học dba sql, tài liệu học dba oracle, Khóa học Oracle online, học oracle sql, học oracle ở đâu tphcm, học oracle bắt đầu từ đâu, học oracle ở hà nội, oracle database tutorial, oracle database 12c, oracle database là gì, oracle database 11g, oracle download, oracle database 19c/21c/23c/23ai, oracle dba tutorial, oracle tunning, sql tunning , oracle 12c, oracle multitenant, Container Databases (CDB), Pluggable Databases (PDB), oracle cloud, oracle security, oracle fga, audit_trail,oracle RAC, ASM, oracle dataguard, oracle goldengate, mview, oracle exadata, oracle oca, oracle ocp, oracle ocm , oracle weblogic, postgresql tutorial, mysql tutorial, mariadb tutorial, ms sql server tutorial, nosql, mongodb tutorial, oci, cloud, middleware tutorial, docker, k8s, micro service, hoc solaris tutorial, hoc linux tutorial, hoc aix tutorial, unix tutorial, securecrt, xshell, mobaxterm, putty

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master