Operations 6 min read

Master Linux Kernel, Nginx, MySQL & Tomcat Tuning for High‑Performance Servers

This guide compiles essential Linux kernel sysctl settings, Nginx performance tweaks, MySQL configuration for 8 GB RAM, Tomcat connector optimizations, and hardware load monitoring commands to help you fine‑tune a production server for maximum throughput and stability.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Linux Kernel, Nginx, MySQL & Tomcat Tuning for High‑Performance Servers

1. Linux kernel parameters

Common parameters for /etc/sysctl.conf:

net.core.netdev_max_backlog = 32768    # maximum packets queued
net.core.rmem_max = 8388608           # socket read buffer size
net.core.wmem_max = 8388608           # socket write buffer size
net.core.somaxconn = 32768            # max listen queue length per port
net.ipv4.ip_local_port_range = 1024 65000   # allowed port range
net.ipv4.tcp_fin_timeout = 30        # TIME_WAIT to CLOSED wait time
net.ipv4.tcp_keepalive_time = 1200   # keepalive interval
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_synack_retries = 1      # SYN+ACK retries before giving up
net.ipv4.tcp_syn_retries = 1          # SYN retries before giving up
net.ipv4.tcp_max_tw_buckets = 6000   # max TIME_WAIT sockets
net.ipv4.tcp_tw_recycle = 1          # fast recycle of TIME_WAIT sockets (default 0)
net.ipv4.tcp_tw_reuse = 1            # allow reuse of TIME_WAIT sockets (default 0)
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 65536 # SYN queue length
fs.file-max = 65535                  # max open files system-wide
fs.nr_open = 65535                   # must be >= fs.file-max

Apply changes: sysctl -p Adjust /etc/security/limits.conf to raise file descriptor limits:

* soft nofile 65535
* hard nofile 65535

Verify with:

ulimit -a

2. Nginx main tuning parameters

Worker and connection settings (place in nginx.conf):

worker_processes 8;                 # match CPU cores
worker_rlimit_nofile 65535;         # max file descriptors per worker
use epoll;                          # epoll event model
worker_connections 102400;         # max connections per worker

keepalive_timeout 60;               # keepalive timeout
client_body_buffer_size 64K;
client_header_buffer_size 8k;
large_client_header_buffers 4 128k;
client_max_body_size 8m;
open_file_cache max=204800 inactive=30s;
open_file_cache_valid 30s;
open_file_cache_min_uses 1;

3. MySQL configuration (example for an 8 GB server)

[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
user = mysql
default_storage_engine = InnoDB
skip_name_resolve
key_buffer_size = 32M
myisam_recover = FORCE,BACKUP
max_allowed_packet = 16M
max_connect_errors = 1000000
log_bin = /var/lib/mysql/mysql-bin
expire_logs_days = 7
sync_binlog = 0
tmp_table_size = 32M
max_heap_table_size = 32M
query_cache_type = 1
query_cache_size = 32M
max_connections = 500
thread_cache_size = 50
open_files_limit = 65535
table_definition_cache = 1024
table_open_cache = 2048
innodb_flush_method = O_DIRECT
innodb_log_files_in_group = 2
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 2
innodb_file_per_table = 1
innodb_buffer_pool_size = 4G
log_error = /var/log/mysql-error.log
log_queries_not_using_indexes = 1
slow_query_log = 1
slow_query_log_file = /var/log/mysql-slow.log

4. Tomcat connector tuning

In server.xml under the Connector for port 8080, add:

connectionTimeout="20000"
processorCache="1000"
acceptCount="5000"
acceptorThreadCount="8"   # match CPU cores
maxThreads="2000"
minSpareThreads="100"
socket.appReadBufSize="1024"
socket.appWriteBufSize="1024"
socket.bufferPool="1000"

Adjust JVM options in catalina.sh (example):

JAVA_OPTS="-server -Xms1048m -Xmx3072m -Xss1024K -XX:PermSize=64m -XX:MaxPermSize=128m -XX:NewRatio=4"

5. Hardware load monitoring commands

top               # CPU usage
free -m           # memory usage
iostat -kx 2      # disk I/O
sar -n DEV 2      # network traffic

Reference: Nginx optimization for over 100k concurrent connections.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxmysqlTomcatSystem Tuning
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.