Lamp server performance optimization techniques Linux Host Optimization _linux

Source: Internet
Author: User
Tags gtk

At present, lamp (Linux + Apache + MySQL + PHP) has developed rapidly in recent years, has become the fact of the Web server standards.

The word lamp originated in the German magazine "C ' t Magazine", and Michael Kunze first assembled the items together in 1990 to create lamp abbreviations. These components are not designed to be used together, but they can be readily available and available free of charge. This leads to the common use of these components. In the past few years, the compatibility of these components has been perfected, and the application situation has become very universal. Some extension features have been created to improve collaboration between different components. Currently, the "LAMP stack" product is included by default in almost all Linux distributions. These products form a powerful Web application platform. Each component in LAMP stack is an instance of FOSS (free or open source software/free or open source Software).

The benefits of the FOSS approach are three.

First, the nature of FOSS means that applications can be downloaded for free, allowing a wider range of people to use the app without paying for it. This free way is particularly appealing to the vast majority of users. These users will need to pay for "professional" commercial software tools without using free software. This is usually an expensive step in making a website.

Second, FOSS licences are open, so there are very few uses and restrictions for FOSS based applications. You can develop and apply a lamp based project without paying any license fee for the release of the software. Therefore, this is very attractive to amateurs and professionals alike. The main reason for the growth and use of FOSS technology (including lamp) is that users are able to access their resources, and it is easy to fix failures and improve the performance of their applications.

Combined with open source software licenses, this approach simplifies the development process for many enterprises and provides the flexibility that is not available in proprietary software or business software restrictions for the enterprise.

In this article, we will describe the performance optimization techniques for a server based on lamp combination:

Lamp optimization: Cleaning up server disk fragmentation

Regardless of the file format (ext3, JFS, XFS, ReiserFS), what type of hard disk (IDE, SCSI) The Linux file system is using, the file system tends to be fragmented over time. Advanced file systems such as EXT3 and JFS can reduce the fragmentation of file systems, but not eliminate them. In a busy database server, over time, file fragmentation reduces hard disk performance, and hard disk performance can be noticed when you read or write data from your hard disk. A long time will find that each disk does accumulate a lot of junk files, freeing up disk space can help the system to work better. Linux's best way to defragment the disk is to do a full backup, reformat the partition, and then restore the file from backup. But it's more difficult for a 7x24-hour task-critical server.

Kleandisk is an efficient Disk Cleanup tool that divides the files on a disk into different groups, such as a group of all the core files, so that you delete all the core files as long as you remove the group. The core file is a file that is generated when the software runs wrong, and it is useful for software developers and has no meaning for other users, such as e-mail servers. Therefore, if there is no need for software development, see core files can be deleted.

Lamp optimization: Turn on Hard Drive DMA

The IDE hard disk that you are using now basically supports dma66/100/133 (direct memory read) but the Linux distribution is not normally open after installation, you can add a line to the/etc/rc.d/rc.local:/SBIN/HDPARM-D1–X66-C3-M16 /dev/hda after each boot, the DMA on the hard drive will be turned on without having to manually set each time. Before and after adding you can use the command: Hdparm-tt/dev/hda to test the contrast.

Lamp optimization: Adjusting buffer Refresh Parameters

The Linux kernel contains some configurable parameters for the running state of the system. The parameters for buffering refreshes can be done by adjusting the/proc/sys/vm/bdflush file, which is formatted like this:

 
  
  
  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 are the preceding parameters. The first number is to force the wake-up Bdflush process to refresh the hard drive when the "dirty" buffer is reached, and the second number is how many dirty blocks each time the Bdflush process is flushed. The so-called dirty block is a cache block that must be written to disk. The next argument is to allow the BD flush to put as many blocks of memory into the free buffer block list each time. The value above is the default value in Rhel 4.0. There are two methods you can use to modify:

(1) using the command

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

and add this command to the/etc/rc.d/rc.local file.

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

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

The above settings increase the buffer size, reducing the frequency at which the Bdflush is started, and the buffer refresh mechanism of the VFS is one of the reasons why the Linux file system is efficient.

Lamp optimization: optimizing Input and output

I/O programs are also very important for Linux system performance, and network hardware I/O is especially important to the server. Most Linux servers now use 10/100 MB Ethernet. If you have a heavier network load, you can consider Gigabit Ethernet cards. If you do not have the ability to buy a gigabit NIC: You can use multiple network cards to virtual become a network card, with the same IP address. This technology, in Linux, is called bonding. Bonding is already included in the Linux2.4 and above, just select the bonding driver support in the network device option at compile time see Figure 1. Of course, the use of bonding technology to configure the dual network adapter is the prerequisite for the two card chipset model is the same, and have a separate BIOS chip.

Figure 1 Bonding driver Support options for the Linux kernel

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 two cards have worked like a piece. This can improve the data transfer between cluster nodes. Bonding for the server to be a better choice, in the absence of Gigabit Nic, with two 100 gigabit NIC for bonding, Can greatly increase the bandwidth between the server and the switch. But you need to set up a connection on the switch the two bonding of the network card are mapped to the same virtual interface. Edit the/etc/modules.conf file and add the following to enable the system to load the bonding module at startup.

 
  
  
  1. Alias Bond0 Bonding
  2. Options Bond0 mode=0

The value of "mode" indicates the mode of operation, there are 0, 1, 2, and 34 modes, which are set to 0. Bonding work in a load-balancing (load Balancing (Round-robin)) mode, where two network cards work simultaneously, theoretically bonding can provide twice times the bandwidth. Bonding runs in the mixed (PROMISC) mode of the network card, and it modifies the MAC address of the two NIC to the same. Promiscuous mode is that the NIC no longer only receives the destination hardware address is the data frame of its own MAC address, but can receive all the frames on the network.

Lamp optimization: Reducing the number of virtual terminals

Linux installed after the system defaults to 6 virtual terminals, that is, the Ctrl+alt F1~f6 six, as a server can be used to turn off four of them, leaving only Ctrl+alt F1~f2, save about 4 Mbytes of memory, but in this way, X-window will be from the original Ctrl+alt F7 into Ctrl+alt F3. To modify the/etc/inittab, add the Mingetty 3 ~6 all with the # font size.

Lamp optimization: Turn off some unused services

Linux servers start with a number of system services, which provide local and network users with Linux system interface, directly to applications and users. The programs that provide these services are executed by the daemon (daemons) running in the background. A daemon is a process that has a long lifetime. They are independent of the control terminal and periodically perform certain tasks or wait to handle some of the events that occur. They are often started during system boot loading and terminate when the system shuts down.

Linux systems have many daemons, and most servers are implemented with daemons. such as Web services HTTP, and so on. At the same time, the daemon completes many system tasks, such as job planning process crond, printing process LQD, etc. Some books and materials also call the daemon the "service". Close the Service method check the author's article: Deep understanding of the Linux daemon. Chain knot: http://www.ccw.com.cn/server/yyjq/htm2005/20050914_14ND5_1.htm.

Lamp optimization: Using tool software Powertweak optimization system

Powertweak for linux0.99 can monitor your system and network connections and can 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

Where powertweak-0.99.2-1.i386.rpm is the main program, POWERTWEAK-GTK-0.99.2-1.I386.RPM is the graphical front-end of KDE environment. The program is automatically added to the "system tool" of the main menu, and the running interface is shown in Figure 2.

Figure-2 Powertweak Performance Optimization program

Powertweak software that optimizes settings for X86 architecture processors, chipsets, voodoo, and so on, supports most central processing units and chipsets, including INTEL,AMD, and Cyrix, with four built-in optimizations that allow you to configure the hardware you want to optimize (CPU , CD-ROM, PCI bus, hard disk, disk array, kernel (including logs, security, resources), network (including IP, TCP, Core, ICMP, Unix domain Routing, ARP, Token ring), virtual file system, performance memory management ( Page allocations, caching, swap partitions). Powertweak is a powerful system performance tuning software. But for users, many options require you to have a better understanding of the Linux system to fill in exactly.

About Apache, PHP, MySQL software installation, we recommend the installation of their latest version, and from the source installation program. Although many Linux distributions (RedHat, Suse, turbolinux) have the corresponding RPM package, but compiled from the source code installer, will be suitable for their own machine settings, we will normally be installed into the/usr/local directory, so easy to manage. The installation process here I will not introduce.

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.