Home  >  Article  >  Operation and Maintenance  >  Summary: 20 Linux server performance tuning tips

Summary: 20 Linux server performance tuning tips

Linux中文社区
Linux中文社区forward
2023-08-03 15:22:36954browse

Summary: 20 Linux server performance tuning tips

#Linux is an open source operating system that supports various hardware platforms. Linux servers are world-famous. The main difference between it and Windows is that Linux servers generally do not provide GUI (graphical user interface) by default, but commands Line interface, its main purpose is to efficiently handle non-interactive processes. Response time is not so important. On the contrary, being able to handle high loads for a long time is the most critical.


Linux high-availability server cluster solutions allow IT system administrators to cope with many common hardware and software failures, allowing multiple computers to work together , providing guarantee for the normal operation of key services, and system administrators can perform maintenance and upgrades without interrupting services.
Linux servers are used for various purposes such as web servers or internal branch servers, CMS or CRS servers, file servers (serving Windows and/or Linux users), VoIP phone servers, mail or domain name servers, databases Servers, infrastructure nodes, etc. in cloud computing configurations.

Linux is feature-rich, powerful, and flexible. You can use it to complete various tasks. In this article, we will discuss some tips for improving the performance of Linux servers.


01
Tuning the Linux kernel elevator algorithm for disk I/O

##After selecting the file system, there are some kernel and mount options that may affect its performance. One of the kernel settings is the elevator algorithm. By adjusting the elevator algorithm, the system can balance low performance. Latency requirements, collecting enough data to efficiently organize read and write requests to disk.


02
Disable unnecessary daemons


There are many daemons or services running on every server, and the irony is that there are many that are often not necessary and are not functioning but are consuming valuable memory and CPU time. . In addition, they may put the server at risk. Running one more service means opening more doors for hackers to get in. Therefore, you should remove them from the server. The biggest advantage of disabling them is that it can speed up the startup time and free up the server. Memory. Additionally, you can reduce the number of processes the CPU has to handle. Another benefit of disabling them is increased server security, as fewer daemons means fewer vulnerabilities that can be attacked and exploited.

The following are some Linux daemons that should be disabled. By default, they all run automatically:


Serial number Daemon process Description
1 Apmd Advanced power management daemon
2 Nfslock Used for NFS file locking
3 Isdn ISDN Moderm support
4 Autofs Automatically mount in the background File system (such as automatically mounting CD-ROM)
5 Sendmail Mail Transfer Agent
6 Xfs X Window's font server

##03
Turn off the GUI

## Generally speaking, Linux servers do not require a GUI. All management tasks can be completed from the command line, so it is best to turn off the GUI, redirect the X display or display it through a Web browser interface. In order to disable the GUI, the "init level" should be set to 3 (command line login), not 5 (graphical login). If a GUI is required, you can always run startx to enter the graphical user interface.


##0
4##Clean up unnecessary modules or functions
There are too many enabled functions or modules in the server software package that are actually unnecessary (such as many function modules in Apache), Check the Apache configuration file carefully to determine whether FrontPage support or other additional modules are really needed. If not, you should disable them from the server without hesitation. This will help increase the amount of system memory available and free up more resources. Make the software that really needs it run faster.


##05
Disable Control Panel

##In Linux, there are many popular control panels, such as Cpanel, Plesk, Webmin and phpMyAdmin, etc. I believe that every Linux junior user likes these control panels. However, disabling these software packages can release about 120MB Memory, therefore, I strongly recommend disabling these control panels unless they are really needed. They can be enabled through PHP scripts (although somewhat unsafe), or command line commands. After doing this, the memory usage can be reduced by about 30 -40%.


#06
Improvement Linux Exim Server Performance

##There are many ways to improve the performance of your server Exim performance, one way is to use the DNS caching daemon, which can reduce the bandwidth and CPU time required to parse DNS records. DNS caching improves network performance by eliminating the need to look up DNS records from the root node every time. Djbdns is A very powerful DNS server with DNS caching function, Djbdns is more secure and performs better than BIND DNS server. It can be downloaded directly from http://cr.yp.to/, or obtained through the software package provided by Red Hat.


##0
7##Use AES256 to enhance gpg file encryption security
In order to improve the security of backup files or sensitive information, many Linux system administrators will use gpg for encryption. When using gpg, it is best to specify gpg Use AES256 encryption algorithm. AES256 uses a 256-bit key. It is an open encryption algorithm. The National Security Agency (NSA) of the United States uses it to protect top-secret information. There is nothing more secure than it.


#08
Remote backup service security

Security is the most important factor when choosing a remote backup service. Most system administrators are afraid of two things: (hackers) can delete backup files and cannot restore the system from backup.

In order to ensure 100% security of backup files, backup service companies provide remote backup servers that use scp scripts or RSYNC to transfer data via SSH. In this way, no one can enter and access the remote system directly, and therefore, no one can directly enter and access the remote system. Data can be deleted from the backup service. When choosing a remote backup service provider, it is best to understand the robustness of its service from multiple aspects and, if possible, test it yourself.


##09
Update default kernel parameter settings

##In order to run enterprise applications smoothly and successfully, such as database servers, some default kernel parameter settings may need to be updated. For example, the 2.4.x series kernel message queue parameter msgmni has a default value (for example, shared memory, Or shmmax (default is only 33554432 bytes on Red Hat systems), which only allows limited concurrent connections to the database. The following provides some recommended values ​​for the database server to run better (from the IBM DB2 support website):


kernel.shmmax=268435456 (32-bit) kernel.shmmax=1073741824 (64-bit) kernel.msgmni=1024 fs.file-max=8192 kernel. sem=”250 32000 32 1024″


##10
##Optimization TCP
# Optimizing the TCP protocol helps improve network throughput , the greater the bandwidth used for cross-WAN communication and the longer the delay time, it is recommended to use a larger TCP Linux size to increase the data transmission rate. The TCP Linux size determines how much the sending host can send to the host when it does not receive the data transmission confirmation. How much data the receiving host sends.




#11
Choose the correct file system


##Use ext4 file system instead of ext3




  • ##Ext4 is an enhanced version of the ext3 file system, extending the storage limit

  • It has a logging function to ensure a high level of data integrity (in the event of abnormal shutdown)

  • In It does not need to check the disk during abnormal shutdown and restart (this is a very time-consuming action)

  • Faster writing speed, ext4 log optimization The hard disk head movement



##12
##Use noatime file system mount option
Use the noatime option in the file system startup configuration file fstab, if external storage is used, This mount option can effectively improve performance.



##13
Adjustment Linux file descriptor limits

Linux limits what any process can Number of open file descriptors. The default limit is 1024 per process. These limits may prevent optimal performance from benchmarking clients (such as httperf and apachebench) and the web server itself. Apache uses one process per connection and therefore is not affected by However, single-process web servers such as Zeus use one file descriptor per connection and are therefore easily affected by the default limit.

The open file limit is a limit that can be adjusted with the ulimit command. The ulimit -aS command displays the current limit, and the ulimit -aH command displays the hard limit (you cannot increase it before adjusting the kernel parameters in /proc limit).


Linux third-party application performance tips
There are also many performance optimization tips for third-party applications running on Linux, these Tips can help you improve the performance of your Linux server and reduce operating costs.


##14
##Correct Configure MySQL
##In order to allocate more memory to MySQL, You can set the MySQL cache size. If the MySQL server instance uses more memory, reduce the cache size. If MySQL becomes stagnant when requests increase, increase the MySQL cache.




#15
Configure Apache correctly
## Check how much memory Apache uses, and then adjust the StartServers and MinSpareServers parameters to free up more memory, which will help you save 30-40% of memory.
Here are some tips to improve Linux server monitoring and troubleshooting:



##16
Analysis Linux server performance

##The best way to improve system efficiency is Find the bottlenecks that are causing the overall slowdown and resolve them. Here are some basic tips for identifying critical bottlenecks in your system:
● When large applications like OpenOffice and Firefox are running at the same time, your computer may start to slow down. , the probability of insufficient memory is higher.

● If the startup is really slow, it may be that the application takes a long time to load for the first time. Once it starts, it will run normally. Otherwise, the hard disk may be too slow. In addition, search the public account programmer Xiaole's backend and reply "make money" to get a surprise gift package.

●The CPU load continues to be high and the memory is sufficient, but the CPU utilization is very low. You can use the CPU load analysis tool to monitor the load time.



##17
Learn 5 Linux Performance Commands

## Just use a few commands To manage the performance of Linux systems, the five most commonly used Linux performance commands are listed below, including top, vmstat, iostat, free and sar, which can help system administrators quickly solve performance problems.


01 topThe Top command not only displays the tasks of the current kernel service, but also displays many statistics about the host status. By default Under, it automatically updates the displayed data every 5 seconds (this time interval is configurable). Through the top command, we can know several results, such as: current uptime, system load, number of processes and memory usage rate, in addition, this command also displays those processes that use the most CPU time (including various information for each process, such as running user, executed commands, etc.).



02 vmstatThe Vmstat command provides a snapshot of the current CPU, IO, process and memory usage. It is similar to the top command and updates automatically. Data, such as:




#$ vmstat 10


03 iostat

Iostat command (included in the sysstat package on Ubuntu, Red Hat/Fedora) Three reports are provided: CPU utilization, device utilization and network file system utilization. When running without any parameters, iostat will display these three reports. Use the -c, -d and -h parameters to display these three reports independently. report.

04 free

#The Free command displays memory statistics of main memory and swap space. Specify the -t parameter to display the total memory amount. Specify The -b parameter can be displayed in bytes. Use -m to display in megabytes. By default, it is in kilobytes.

The Free command can also be run continuously using the -s parameter plus a delay time (unit: seconds), such as:



##$ free -s 5



##05 sarThe Sar command collects, views and records performance data. This command has a longer history than the previous commands. It Longer period data can be collected and displayed.



OtherHere are some performance tips categorized as Other:



##18
will Log files are moved to memory

##When a machine is When running, it is best to keep the system log in memory and copy it to the hard disk when the system is shut down. When you run a laptop or mobile device with the syslog function turned on, ramlog can help you improve the system battery. Or the life of a mobile device flash drive. One benefit of using ramlog is that you no longer have to worry about a daemon sending a message to syslog every 30 seconds. In the past, the hard disk had to keep running at all times, which was not good for the hard disk and the battery. .


#19
Pack first, then write
Divide a fixed-size space in the memory to save the log file. This means that the laptop hard drive does not have to keep running. It only runs when a daemon needs to write the log. Pay attention to the memory space used by ramlog. The size is fixed, otherwise the system memory will be used up quickly. If the notebook uses a solid-state drive, 50-80MB of memory can be allocated to ramlog. Ramlog can reduce many write cycles and greatly improve the service life of the solid-state drive.



##20
General Tuning Tips

##Use static content instead of dynamic content whenever possible , if you are generating weather forecasts, or other data that must be updated every hour, it is best to write a program to generate a static file every hour rather than letting the user run a CGI to dynamically generate the report.
Choose the fastest and most appropriate API for dynamic applications. CGI may be the easiest to program, but it will spawn a process for each request. Usually, this is a costly and unnecessary process. FastCGI is a better choice, and like Apache's mod_perl, can greatly improve application performance.

The above is the detailed content of Summary: 20 Linux server performance tuning tips. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:Linux中文社区. If there is any infringement, please contact admin@php.cn delete