2. Tối ưu hiệu suất máy chủ Ubuntu.

sudo swapon --show
  1. Tạo file swap
    • Chạy lệnh sau với bộ nhớ swap là 8G, bạn có thể tùy chỉnh theo nhu cầu.
      bash sudo fallocate -l 8G /swapfile
    • Xác thực xem hệ thống đã để dành đúng 8G bộ nhớ chưa.
      bash ls -lh /swapfile
  2. Enable swap file
    • Chỉ cho phép user root truy cập swapfile bằng lệnh sau:
      bash sudo chmod 600 /swapfile
    • Xác thực thay đổi
      bash ls -lh /swapfile
    • Đánh dấu file làm dung lượng swap bằng lệnh.
      bash sudo mkswap /swapfile
  3. Đặt file swap thành vĩnh viễn
    • Backup file fstab.bak
      bash sudo cp /etc/fstab /etc/fstab.bak
    • Thêm dòng sau vào cuối file fstab bằng lệnh
      bash echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
    • Verify
      bash free -h
  1. Tối ưu hóa hiệu suất bằng cách chỉnh sửa file sysctl.conf sudo nano /etc/sysctl.conf
    • Thêm phần sau vào cuối file sysctl.conf
    fs.file-max = 10000000 fs.nr_open = 10000000 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_max_syn_backlog = 2048 net.ipv4.tcp_keepalive_time = 240 net.ipv4.tcp_keepalive_intvl = 4 net.ipv4.tcp_keepalive_probes = 5 # Use Google's congestion control algorithm net.core.default_qdisc = fq net.ipv4.tcp_congestion_control = bbr
    • Reload /etc/sysctl.conf
    sudo sysctl -p /etc/sysctl.conf
  2. Tạo file bảo toàn hệ thống khi khởi động lại sudo nano /etc/rc.local
    • Dán đoạn mã sau vào file rc.local
    #!/bin/bash # Give CPU startup routines time to settle. sleep 120 sysctl -p /etc/sysctl.conf exit 0
  3. Đồng bộ thời gian với Chrony
    • Cài đặt Chrony
    sudo apt install chrony
    • Cấu hình chrony
    sudo nano /etc/chrony/chrony.conf
    • Copy đoạn mã sau vào file chrony.conf (xóa đoạn mã cũ nếu có)
pool time.google.com       iburst minpoll 2 maxpoll 2 maxsources 3 maxdelay 0.3
pool time.facebook.com     iburst minpoll 2 maxpoll 2 maxsources 3 maxdelay 0.3
pool time.euro.apple.com   iburst minpoll 2 maxpoll 2 maxsources 3 maxdelay 0.3
pool time.apple.com        iburst minpoll 2 maxpoll 2 maxsources 3 maxdelay 0.3
pool ntp.ubuntu.com        iburst minpoll 2 maxpoll 2 maxsources 3 maxdelay 0.3

# This directive specify the location of the file containing ID/key pairs for
# NTP authentication.
keyfile /etc/chrony/chrony.keys

# This directive specify the file into which chronyd will store the rate
# information.
driftfile /var/lib/chrony/chrony.drift

# Uncomment the following line to turn logging on.
#log tracking measurements statistics

# Log files location.
logdir /var/log/chrony

# Stop bad estimates upsetting machine clock.
maxupdateskew 5.0

# This directive enables kernel synchronisation (every 11 minutes) of the
# real-time clock. Note that it can’t be used along with the 'rtcfile' directive.
rtcsync

# Step the system clock instead of slewing it if the adjustment is larger than
# one second, but only in the first three clock updates.
makestep 0.1 -1

# Get TAI-UTC offset and leap seconds from the system tz database
leapsectz right/UTC

# Serve time even if not synchronized to a time source.
local stratum 10
sudo systemctl restart chrony

    Trả lời

    Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

    Nội dung