


Best Practices: Performance Tuning Guide for Building a Web Server on CentOS
Aug 04, 2023 pm 12:17 PMBest Practices: Performance Tuning Guide for Building Web Servers on CentOS
Abstract: This article aims to provide some performance tuning best practices for users building web servers on CentOS, aiming to improve the performance of the server. and response speed. Some key tuning parameters and commonly used optimization methods will be introduced, and some sample codes will be provided to help readers better understand and apply these methods.
1. Turn off unnecessary services
When building a web server on CentOS, some unnecessary services will be started by default. These services will occupy system resources and have no obvious impact on the performance of the web server. promote. Therefore, we should shut down these unnecessary services to free up resources.
Use the following command to list the running services:
systemctl list-units --type=service --state=running
Choose to close unnecessary services according to the actual situation, such as turning off the mail service:
systemctl stop postfix systemctl disable postfix
2. Adjust the kernel parameters
Optimizing kernel parameters is an important step in improving server performance. Kernel parameters can be adjusted by modifying the /etc/sysctl.conf
file. The following are some commonly used kernel parameter tuning solutions:
- Increase the limit on the number of file handles
# 增加系統(tǒng)最大文件句柄數(shù) fs.file-max = 65535 # 增加每個進程可以打開的文件句柄數(shù)限制 ulimit -n 65535
- Increase the limit on the number of TCP connections
# 增加系統(tǒng)的最大并發(fā)TCP連接數(shù) net.ipv4.ip_local_port_range = 1024 65535 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_max_tw_buckets = 5000 net.ipv4.tcp_max_syn_backlog = 1024 net.core.somaxconn = 65535
- Eliminate group chat fragmentation
# 消除群聊分片 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_sack = 0 net.ipv4.tcp_dsack = 0
- Increase the system TCP buffer size
# 提高TCP接收窗口緩沖區(qū)大?。▎挝唬鹤止?jié)) net.ipv4.tcp_rmem = 4096 87380 4194304 # 提高TCP發(fā)送窗口緩沖區(qū)大?。▎挝唬鹤止?jié)) net.ipv4.tcp_wmem = 4096 16384 4194304 # 提高系統(tǒng)的TCP連接跟蹤表的大小 net.netfilter.nf_conntrack_max = 65536
After modifying the above parameters, use the following command to enable It takes effect:
sysctl -p
3. Use a high-performance web server
Choosing an appropriate web server also has an important impact on performance. On CentOS, Nginx and Apache are commonly used web servers.
- Nginx
Nginx is a high-performance HTTP and reverse proxy server that uses an asynchronous non-blocking event-driven architecture to easily handle large traffic requests.
Install Nginx:
yum install nginx
Configure Nginx:
Edit /etc/nginx/nginx.conf
File:
user www-data; worker_processes auto; worker_cpu_affinity auto; events { worker_connections 1024; use epoll; multi_accept on; } http { # 配置HTTP服務器 ... }
- Apache
Apache is a feature-rich and widely used web server. Although its performance is slightly inferior to Nginx, it can still provide good performance in some specific scenarios.
Install Apache:
yum install httpd
Configure Apache:
Edit /etc/httpd/conf/httpd.conf
File:
ServerLimit 2048 MaxClients 2048
4. Use cache acceleration
Using caching technology can effectively improve the performance of the web server. The following two methods can be used for cache acceleration:
- HTTP Cache
By setting the appropriate Cache-Control
and Expires
Response header allows the client to cache static resources, reduce the load on the server, and improve the user's access experience. The sample code is as follows:
location /static { expires 7d; }
- Reverse proxy cache
Use reverse proxy cache to cache dynamic content and reduce requests to the backend server. You can use Nginx's proxy_cache
module to implement reverse proxy caching. The sample code is as follows:
proxy_cache_path /var/nginx/cache levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m; server { ... location / { proxy_cache my_cache; proxy_cache_valid 200 301 302 5m; proxy_pass http://backend; } }
Conclusion
By closing unnecessary services, adjusting kernel parameters, using high-performance web servers and using cache acceleration, the web server built on CentOS can be better Good performance and responsiveness. I hope the performance tuning guide provided in this article will be helpful to you.
Reference link:
- https://www.digitalocean.com/community/tutorials/5-tips-to-speed-up-your-nginx-web-server
- https://www.digitalocean.com/community/tutorials/how-to-optimize-nginx-configuration
The above is the detailed content of Best Practices: Performance Tuning Guide for Building a Web Server on CentOS. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

1. The Origin of .NETCore When talking about .NETCore, we must not mention its predecessor .NET. Java was in the limelight at that time, and Microsoft also favored Java. The Java virtual machine on the Windows platform was developed by Microsoft based on JVM standards. It is said to be the best performance Java virtual machine at that time. However, Microsoft has its own little abacus, trying to bundle Java with the Windows platform and add some Windows-specific features. Sun's dissatisfaction with this led to a breakdown of the relationship between the two parties, and Microsoft then launched .NET. .NET has borrowed many features of Java since its inception and gradually surpassed Java in language features and form development. Java in version 1.6

Software preparation I am using a virtual machine with CentOS-6.6, with the host name repo. Refer to the steps to install a Linux virtual machine in Windows, I installed JDK in that virtual machine, refer to the guide to installing JDK in Linux. In addition, the virtual machine is configured with a key-free login itself, and the settings for configuring key-free login between each virtual machine are referenced. The download address of Hadoop installation package is: https://mirrors.aliyun.com/apache/hadoop/common/. I am using hadoop 2.6.5 version. Upload the Hadoop installation package to the server and unzip [root@repo~]#tarzxv

Integrating Postman applications on CentOS can be achieved through a variety of methods. The following are the detailed steps and suggestions: Install Postman by downloading the installation package to download Postman's Linux version installation package: Visit Postman's official website and select the version suitable for Linux to download. Unzip the installation package: Use the following command to unzip the installation package to the specified directory, for example /opt: sudotar-xzfpostman-linux-x64-xx.xx.xx.tar.gz-C/opt Please note that "postman-linux-x64-xx.xx.xx.tar.gz" is replaced by the file name you actually downloaded. Create symbols

IIS is a web server software developed by Microsoft to host websites and applications. 1. Installing IIS can be done through the "Add Roles and Features" wizard in Windows. 2. Creating a website can be achieved through PowerShell scripts. 3. Configure URL rewrites can be implemented through web.config file to improve security and SEO. 4. Debugging can be done by checking IIS logs, permission settings and performance monitoring. 5. Optimizing IIS performance can be achieved by enabling compression, configuring caching and load balancing.

Reasons for IIS' popularity include its high performance, scalability, security and flexible management capabilities. 1) High performance and scalability With built-in performance monitoring tools and modular design, IIS can optimize and expand server capabilities in real time. 2) Security provides SSL/TLS support and URL authorization rules to protect website security. 3) Application pool ensures server stability by isolating different applications. 4) Management and monitoring simplifies server management through IISManager and PowerShell scripts.

RedHatendedsupportforCentOStoshifttowardsacommerciallyfocusedmodelwithCentOSStream.1)CentOStransitionedtoCentOSStreamforRHELdevelopment.2)ThisencourageduserstomovetoRHEL.3)AlternativeslikeAlmaLinux,RockyLinux,andOracleLinuxemergedasreplacements.

Optimizing the performance of Hadoop distributed file system (HDFS) on CentOS systems can be achieved through a variety of methods, including adjusting system kernel parameters, optimizing HDFS configuration files, and improving hardware resources. The following are detailed optimization steps and suggestions: Adjust the system kernel parameters to increase the limit on the number of files opened by a single process: Use the ulimit-n65535 command to temporarily adjust. If it needs to take effect permanently, please edit the /etc/security/limits.conf and /etc/pam.d/login files. Optimize TCP parameters: Edit /etc/sysctl.conf file, add or modify the following content: net.ipv4.tcp_tw

NGINXserveswebcontentandactsasareverseproxy,loadbalancer,andmore.1)ItefficientlyservesstaticcontentlikeHTMLandimages.2)Itfunctionsasareverseproxyandloadbalancer,distributingtrafficacrossservers.3)NGINXenhancesperformancethroughcaching.4)Itofferssecur
