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

sudo nano /etc/security/limits.conf
<USERNAME> soft nofile 800000
<USERNAME> hard nofile 1048576
sudo swapon --show
free -h
df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           796M   79M  717M  10% /run
/dev/sda3       194G   12G  173G   7% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
/dev/sda2       2.0G  132M  1.7G   8% /boot
tmpfs           796M     0  796M   0% /run/user/1000
  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.
      sudo fallocate -l 8G /swapfile
    • Xác thực xem hệ thống đã để dành đúng 8G bộ nhớ chưa.
      ls -lh /swapfile
  2. Enable swap file
    • Chỉ cho phép user root truy cập swapfile bằng lệnh sau:
      sudo chmod 600 /swapfile
    • Xác thực thay đổi
      ls -lh /swapfile
    • Đánh dấu file làm dung lượng swap bằng lệnh.
      sudo mkswap /swapfile
  3. Đặt file swap thành vĩnh viễn
    • Backup file fstab.bak
      bsh sudo cp /etc/fstab /etc/fstab.bak
    • Thêm dòng sau vào cuối file fstab bằng lệnh
      echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
    • Verify
      free -h
 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
sudo sysctl -p /etc/sysctl.conf
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

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

Để lại một bình luận

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