LAMP server performance optimization tips: Linux host Optimization

Source: Internet
Author: User
Tags ide hard drive

LAMP (Linux + Apache + MySQL + PHP) has developed rapidly in recent years and has become a de facto standard for Web servers.

The term LAMP first came from the German Magazine "c't Magazine". In 1990, Michael Kunze first combined these projects to create the abbreviation of LAMP. Although these components are not designed for use at the beginning, these open-source software can be easily obtained at any time and free of charge. As a result, these components are often used together. Over the past few years, the compatibility of these components has been constantly improved, and the application situation has become very general. Some extension functions have been created to improve collaboration between different components. Currently, almost all Linux releases contain "LAMP stack" by default. These products form a powerful Web application platform. Every component in LAMP stack is a FOSS (Free or Open Source Software) instance.

There are three advantages of the FOSS method.

First, the nature of the FOSS software means that applications can be downloaded for free, so that more people can use the software without paying. This free method is especially attractive to users. If these users do not use free software, they need to pay for "professional" commercial software tools. This is usually an expensive step in website creation.

Second, the FOSS license is open, so there are very few use and restrictions on Application Software Based on the FOSS technology. You can develop and apply LAMP-based projects without having to pay any license fee for software release. Therefore, this is very attractive to amateurs and professionals. The main reason for the growth and use of FOSS technology (including LAMP) is that users can access their resources, fix faults, and improve the performance of their applications.

Combined with open-source software licenses, this approach simplifies the development process for many enterprises and provides them with the flexibility not limited by proprietary or commercial software.

This article describes the performance optimization techniques for LAMP-based servers:

LAMP optimization: CLEAR server disk fragments

No matter what file formats (ext3, JFS, XFS, and ReiserFS) and what types of Hard Disks (IDE and SCSI) are used by the Linux File System, the file system tends to be fragmented over time. Ext3, JFS, and other advanced file systems can reduce file system fragmentation, but they are not eliminated. In a busy database server, file fragmentation will reduce the hard disk performance over time, and the hard disk performance can be noticed only when data is read or written from the hard disk. After a long time, you will find that a lot of junk files are accumulated on each disk. Releasing disk space can help the system better work. In Linux, the best way to clear disk fragments is to make a full backup, reformat the partition, and restore the file from the backup. However, it is difficult for a 7 × 24 key task server.

Kleandisk is an efficient disk cleanup tool that divides files on disks into different "groups". For example, all "core" files are grouped into a Group ), in this way, you only need to delete this group when deleting all core files. A core file is a file generated when a software running error occurs. It is useful to software developers and does not make any sense to other users (such as email servers. Therefore, if you do not need software development, you can delete the core file.

LAMP optimization: Enable hard disk DMA

Currently, the IDE Hard Drive supports DMA66/100/133 (Direct Memory reading), but it is generally not enabled after the Linux release version is installed. It can be/etc/rc. d/rc. add a line at the end of local:/sbin/hdparm-d1-x66-c3-m16/dev/hda. In this way, the DMA of the hard disk will be enabled each time it is started, and you do not need to manually set it each time. You can use the command hdparm-Tt/dev/hda to test and compare before and after adding.

LAMP optimization: Adjust the buffer refresh Parameters

The Linux kernel contains configurable parameters for the system running state. You can adjust the buffer refresh parameters by adjusting the/proc/sys/vm/bdflush file. The format of this file is as follows:

 
 
  1. # cat /proc/sys/vm/bdflush
  2. 30 64 64 256 500 3000 60 0 0

Each column is a parameter, the most important of which is the previous parameters. The first number is to force the bdflush process to refresh the hard disk when the "dirty" buffer reaches, and the second number is the number of dirty blocks each time the bdflush process refreshes. The dirty block must be written to the cache block on the disk. The following parameter lists the number of memory blocks allowed to be flushed into idle buffer blocks each time. The above values are the default values in RHEL 4.0. You can modify it in two ways:

(1) Use commands

 
 
  1. # echo "100 128 128 512 5000 3000 60 0 0">/proc/sys/vm/bdflush

Add this command to the/etc/rc. d/rc. local file.

(2) Add the following lines to the/etc/sysctl. conf file:

 
 
  1. vm.bdflush = 100 128 128 512 5000 3000 60 0 0

The preceding settings increase the buffer size and reduce the frequency of bdflush startup. The buffer refresh mechanism of VFS is one of the reasons for Linux file system efficiency.

LAMP optimization: optimizes Input and Output

I/O programs are also very important to Linux system performance, and network hardware I/O is especially important to servers. Currently, most Linux servers use 10/100 Mb Ethernet. If there is a heavy network load, you can consider a Gigabit Ethernet Card. If you cannot buy a gigabit network card, you can use multiple network cards to create a virtual network card with the same IP address. In Linux, this technology is called Bonding. Bonding is included in the kernel above Linux2.4. You only need to select Bonding driver support in the network device option during compilation, as shown in figure 1. Of course, the prerequisite for using Bonding Technology to configure dual-nic binding is that the two NICs have the same chipset model and have independent BIOS chips.

Figure 1 Linux kernel Bonding driver support option

Then, recompile the core, restart the computer, and execute the following command:

 
 
  1. #ismod bonding
  2. #ifconfig eth0 down
  3. #ifconfig eth1 down
  4. #ifconfig bond0 ipaddress
  5. #ifenslave bond0 eth0
  6. #ifenslave bond0 eth1

Now the two NICs are working like one. This improves data transmission between cluster nodes. bonding is a good choice for Servers. When there is no Gigabit Nic, using two 100 m NICs as the bonding can greatly increase the bandwidth between the server and the switch. however, you need to set the two sub-ports connected to the bonding Nic on the vswitch to map to the same Virtual Interface. Edit the/etc/modules. conf file and add the following content so that the system can load the Bonding module at startup.

 
 
  1. alias bond0 bonding
  2. options bond0 mode=0

The value of "mode" indicates the working mode. There are four modes: 0, 1, 2, and 3. The value is set to 0. Bonding works in the Load Balancing (round-robin) mode, that is, two NICs work simultaneously. In this case, Bonding can theoretically provide twice the bandwidth. Bonding runs in Promisc mode and modifies the MAC addresses of the two NICs to the same. In hybrid mode, the NIC no longer only receives data frames whose destination hardware address is its MAC address, but can receive all frames on the network.

LAMP optimization: reduces the number of virtual terminals

After Linux is installed, the system defaults to 6 virtual terminals, that is, CTRL + ALT F1 ~ Six of F6, which can be used as servers, can be switched off, leaving only CTRL + ALT F1 ~ F2, which saves about 4 Mbytes of memory, but in this way, X-Window will change from CTRL + ALT F7 to CTRL + ALT F3. In the/etc/inittab, set mingetty 3 ~ 6. Add the # font size to all parts.

LAMP optimization: disable unnecessary services

When a Linux server is started, many system services need to be started. They provide Linux system function interfaces to local and network users and are directly oriented to applications and users. The programs that provide these services are executed by daemons running in the background. A daemon is a process with a long lifetime. They are independent of control terminals and periodically execute a task or wait for some events to be processed. They are often started during system boot loading and terminated when the system is shut down.

In linux, there are many daemon processes, and most servers use daemon. Such as Web Service http. At the same time, the daemon completes many system tasks, such as job planning process crond and printing process lqd. Some books and materials also refer to the daemon process as "services ". For how to disable the service, see the author's article: a deep understanding of the Linux daemon process. Link: http://www.ccw.com.cn/server/yyjq/htm2005/20050914_14ND5_1.htm.

LAMP optimization: use the tool software PowerTweak to optimize the system

Powertweak for linux0.99 can monitor your system and network connections, and set your system to the best.

Software installation:

 
 
  1. #wegt http://prdownloads.sourceforge.net/powertweak/powertweak-0.99.2-1.i386.rpm;
  2. #wegt http://prdownloads.sourceforge.net/powertweak/powertweak-gtk-0.99.2-1.i386.rpm
  3. #rpm –ivh powertweak-0.99.2-1.i386.rpm
  4. #rpm –ivh powertweak-gtk-0.99.2-1.i386.rpm

The powertweak-0.99.2-1.i386.rpm is the main program, and the powertweak-gtk-0.99.2-1.i386.rpm is the graphics front-end in the KDE environment. After the program is installed, it is automatically added to "System Tools" in the main menu. The running interface is shown in figure 2.

Figure-2 powertweak performance optimization program

Powertweak can be used to optimize X86 architecture processors, chipset, Voodoo, and other software. It supports most of the central processors and chipset, including Intel, AMD, and Cyrix. It has four built-in optimization settings, you can set the hardware (central processor, CD-ROM, PCI bus, hard disk, and disk array) and kernel (including logs, security, and resources) to be optimized), network (including ip, TCP, Core, ICMP, Unix domain Routing, Arp, Token Ring), virtual file system, performance memory management (page allocation, high-speed cache, swap partition ). Powertweak is a powerful system performance tuning software. However, the requirements for users are relatively high. Many options require you to have a better understanding of the Linux system to be accurate.

For installation of Apache, PHP, and Mysql software, we recommend that you install the latest version from the source code. Although many Linux distributions (RedHat, Suse, and TurboLinux) have the appropriate rpm packages, compiling and installing programs from the source code will suit your machine settings, it is usually installed in the/usr/local directory, which is easy to manage. The installation process is not described here.

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.