Server Optimization-Sysctl, Apache, and MySQL

Source: Internet
Author: User
Server Optimization-Sysctl, Apache, and MySQL-Linux Enterprise Application-Linux server application information. For more information, see the following section. It is often said that the load capacity of the server depends largely on the configuration and optimization capabilities of the system administrator. This is correct. The same hardware and different software configurations will produce very different results. The following describes how to optimize sysctrl, Apache, and MySQL. Note that all configurations depend on individual users. Make adjustments based on your actual situation.

Configure Sysctl

Edit this file:

Nano-w/etc/sysctl. conf

If the file is empty, enter the following content; otherwise, adjust the file as needed:

# Controls source route verification
# Default shoshould work for all interfaces
Net. ipv4.conf. default. rp_filter = 1
# Net. ipv4.conf. all. rp_filter = 1
# Net. ipv4.conf. lo. rp_filter = 1
# Net. ipv4.conf. eth0.rp _ filter = 1

# Disables IP source routing
# Default shoshould work for all interfaces
Net. ipv4.conf. default. accept_source_route = 0
# Net. ipv4.conf. all. accept_source_route = 0
# Net. ipv4.conf. lo. accept_source_route = 0
# Net. ipv4.conf. eth0.accept _ source_route = 0

# Controls the System Request debugging functionality of the kernel
Kernel. sysrq = 0

# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
Kernel. core_uses_pid = 1

# Increase maximum amount of memory allocated to shm
# Only uncomment if needed!
# Kernel. shmmax = 67108864

# Disable ICMP Redirect Acceptance
# Default shoshould work for all interfaces
Net. ipv4.conf. default. accept_redirects = 0
# Net. ipv4.conf. all. accept_redirects = 0
# Net. ipv4.conf. lo. accept_redirects = 0
# Net. ipv4.conf. eth0.accept _ redirects = 0

# Enable Log Spoofed Packets, Source Routed Packets, Redirect Packets
# Default shoshould work for all interfaces
Net. ipv4.conf. default. log_martians = 1
# Net. ipv4.conf. all. log_martians = 1
# Net. ipv4.conf. lo. log_martians = 1
# Net. ipv4.conf. eth0.log _ martians = 1

# Decrease the time default value for tcp_fin_timeout connection
Net. ipv4.tcp _ fin_timeout = 25

# Decrease the time default value for tcp_keepalive_time connection
Net. ipv4.tcp _ keepalive_time = 1200

# Turn on the tcp_window_scaling
Net. ipv4.tcp _ window_scaling = 1

# Turn on the tcp_sack
Net. ipv4.tcp _ sack = 1

# Tcp_fack shoshould be on because of sack
Net. ipv4.tcp _ fack = 1

# Turn on the tcp_timestamps
Net. ipv4.tcp _ timestamps = 1

# Enable tcp syn Cookie Protection
Net. ipv4.tcp _ syncookies = 1

# Enable ignoring broadcasts request
Net. ipv4.icmp _ echo_ignore_broadcasts = 1

# Enable bad error message Protection
Net. ipv4.icmp _ ignore_bogus_error_responses = 1

# Make more local ports available
# Net. ipv4.ip _ local_port_range = 1024 65000

# Set TCP Re-Ordering value in kernel to '5 ′
Net. ipv4.tcp _ reordering = 5

# Lower syn retry rates
Net. ipv4.tcp _ synack_retries = 2
Net. ipv4.tcp _ syn_retries = 3

# Set Max SYN Backlog to '000000 ′
Net. ipv4.tcp _ max_syn_backlog = 2048

# Various Settings
Net. core. netdev_max_backlog = 1024

# Increase the maximum number of skb-heads to be cached
Net. core. hot_list_length = 256

# Increase the tcp-time-wait buckets pool size
Net. ipv4.tcp _ max_tw_buckets = 360000

# This will increase the amount of memory available for socket input/output queues
Net. core. rmem_default = 65535
Net. core. rmem_max = 8388608
Net. ipv4.tcp _ rmem = 4096 87380 8388608
Net. core. wmem_default = 65535
Net. core. wmem_max = 8388608
Net. ipv4.tcp _ wmem = 4096 65535 8388608
Net. ipv4.tcp _ mem = 8388608 8388608 8388608
Net. core. optmem_max = 40960


If you want to block others from pinging your host, add the following code:

# Disable ping requests
Net. ipv4.icmp _ echo_ignore_all = 1


After editing, run the following command to make the change take effect immediately:

/Sbin/sysctl-p
/Sbin/sysctl-w net. Route 4.route. flush = 1


MySQL Optimization

Edit the MySQL configuration file:

Nano/etc/my. cnf


Enter the following content:

[Mysqld]
Connect_timeout = 15
Interactive_timeout = 100
Join_buffer_size = 1 M
Key_buffer = 128 M
Max_allowed_packet = 16 M
Max_connections = 500
Max_connect_errors = 10
Myisam_sort_buffer_size = 64 M
Read_buffer_size = 1 M
Read_rnd_buffer_size = 768 K
Sort_buffer_size = 1 M
Table_cache = 1024
Thread _ cache_size = 100
Thread_concurrency = 4
Wait_timeout = 300
Query_cache_size = 32 M
Query_cache_limit = 1 M
Query_cache_type = 1
Skip-innodb


Note that the above configuration applies to MB ~ MB memory. If the memory size is larger, adjust the memory size by yourself. Adding memory to the project will speed up, but using too much memory will lead to swap enabling, which will greatly lead to a reduction in system efficiency. Among them, thread_concurrency is configured. Set single CPU to 2, and dual CPU to 4.

Apache Optimization

The following optimization applies to the Apache 1.3 series. If you are using the 2.0 series, make adjustments and judgments on your own.

Confirm the location of the Apache configuration file and start editing:

Locate httpd. conf
Nano-w/path/to/httpd. conf


The httpd. conf file has a lot of content, so the author will come up with what needs to be optimized:

KeepAlive On
MaxKeepAliveRequests 1000
KeepAliveTimeout 3

MinSpareServers 8
MaxSpareServers 13

MaxRequestsPerChild 50


Setting KeepAliveTimeout to a small number can reduce unnecessary waiting links on the server and increase server load to a certain extent.

In addition, the following is not optimized, but is related to Apache Security:

ServerSignature Off
ServerTokens ProductOnly

Disable ServerSignature and add ServerTokens ProductOnly to prevent normal users from detecting the actual version number of Apache, which helps Apache Security.

The above optimization will enhance the server load performance to some extent. However, please note that the best configuration is implemented.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.