LAMP platform construction, acceleration and stress testing

Source: Internet
Author: User
Tags mcrypt zts

LAMP platform construction, acceleration and stress testing

Preparations
Environment:
RedHat 5.8)

Software:

  • Apr-1.4.6.
  • Apr-util-1.5.4
  • Httpd-2.4.12
  • Libmcrypt-2.5.8
  • Mcrypt-2.6.8
  • Mhash-0.9.9.9
  • Pcre-8.33
  • Php-5.4.38
  • Xcache-3.0.1
  • Mysql-5.5.41-linux2.6

1. Compile and install apache
1. Resolve Dependencies
(1) Compile and install apr
# Tar xf apr-1.4.6.tar.bz2
# Cd apr-1.4.6
#./Configure -- prefix =/usr/local/apr
# Make & make install

(2) Compile and install apr-util
# Tar xf apr-util-1.5.4.tar.bz2
# Cd apr-util-1.5.4
#./Configure -- prefix =/usr/local/apr-util -- with-apr =/usr/local/apr
# Make & make install

(3) Compile and install pcre
# Tar xf pcre-8.33.tar.gz
# Cd pcre-8.33
#./Configure -- prefix =/usr/local/pcre
# Make & make install

 

2. Compile and install the httpd-2.4.12
(1) first download the httpd-2.4.12 to the local, and then perform the following operations
# Tar xf httpd-2.4.12tar.bz2
# Cd httpd-2.4.12
#. /Configure -- prefix =/usr/local/apache -- sysconfdir =/etc/httpd -- enable-so -- enable-ssl -- enable-cgi -- enable-rewrite -- with-zlib -- -pcre =/usr/local/pcre -- with-apr =/usr/local/apr -- with-apr-util =/usr/local/apr-util -- enable-modules = most -- enable-mpms-shared = most -- with-mpm = event
# Make & make install

(2) modify the main configuration file of httpd and set the path of its Pid file.
Edit/etc/httpd. conf and add the following lines:
PidFile "/var/run/httpd. pid"

Note: If this step is missing, the following SysV-style script will not work properly!
(3) provide the SysV service script/etc/rc. d/init. d/httpd. The content is as follows:
#! /Bin/bash
#
# Httpd Startup script for the Apache HTTP Server
#
# Chkconfig:-85 15
# Description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# Processname: httpd
# Config:/etc/httpd/conf/httpd. conf
# Config:/etc/sysconfig/httpd
# Pidfile:/var/run/httpd. pid

# Source function library.
./Etc/rc. d/init. d/functions

If [-f/etc/sysconfig/httpd]; then
./Etc/sysconfig/httpd
Fi

# Start httpd in the C locale by default.
HTTPD_LANG =$ {HTTPD_LANG-"C "}

# This will prevent initlog from swallowing up a pass-phrase prompt if
# Mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS = ""

# Set HTTPD =/usr/sbin/httpd. worker in/etc/sysconfig/httpd to use a server
# With the thread-based "worker" MPM; be warned that some modules may not
# Work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.
Apachectl =/usr/local/apache/bin/apachectl
Httpd =$ {HTTPD-/usr/local/apache/bin/httpd}
Prog = httpd
Pidfile =$ {PIDFILE-/var/run/httpd. pid}
Lockfile =$ {LOCKFILE-/var/lock/subsys/httpd}
RETVAL = 0

Start (){
Echo-n $ "Starting $ prog :"
LANG = $ HTTPD_LANG daemon -- pidfile =$ {pidfile} $ httpd $ OPTIONS
RETVAL =$?
Echo
[$ RETVAL = 0] & touch $ {lockfile}
Return $ RETVAL
}

Stop (){
Echo-n $ "Stopping $ prog :"
Killproc-p $ {pidfile}-d 10 $ httpd
RETVAL =$?
Echo
[$ RETVAL = 0] & rm-f $ {lockfile }$ {pidfile}
}
Reload (){
Echo-n $ "Reloading $ prog :"
If! LANG = $ HTTPD_LANG $ httpd $ OPTIONS-t> &/dev/null; then
RETVAL =$?
Echo $ "not reloading due to configuration syntax error"
Failure $ "not reloading $ httpd due to configuration syntax error"
Else
Killproc-p $ {pidfile} $ httpd-HUP
RETVAL =$?
Fi
Echo
}

# See how we were called.
Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Status)
Status-p $ {pidfile} $ httpd
RETVAL =$?
;;
Restart)
Stop
Start
;;
Condrestart)
If [-f $ {pidfile}]; then
Stop
Start
Fi
;;
Reload)
Reload
;;
Graceful | help | configtest | fullstatus)
$ Apachectl $ @
RETVAL =$?
;;
*)
Echo $ "Usage: $ prog {start | stop | restart | condrestart | reload | status | fullstatus | graceful | help | configtest }"
Exit 1
Esac

Exit $ RETVAL

The main function of this script is to implement
# Service httpd {start | restart | stop | status | reload}

And other functions
 
Then grant the execution permission to the script:
# Chmod + x/etc/rc. d/init. d/httpd

Note: You must grant this script execution permission; otherwise, the service cannot be executed normally!
Add to service list:
# Chkconfig -- add httpd
# Chkconfig -- level 35 httpd on

Then you can start the service for testing.

2. Install mysql-5.5.41
Here we use the general binary format for installation. The specific installation method is similar to the compilation and installation method, which only saves the compilation process.
1. File System for data storage preparation
Create a new logical volume and mount it to a specific directory. For detailed procedures, refer to my previous blog posts.
Assume that the Mount directory of the logical volume is/mydata, and then create the/mydata/data directory as the directory for storing mysql data.
2. Create a New System User and system group and change the file attributes.
# Groupadd-r mysql
# Useradd-g mysql-r-s/sbin/nologin-M-d/mydata/data mysql
# Chown-R mysql: mysql/mydata/data

3. Install and initialize the mysql-5.5.41
Download MySQL from the corresponding platform to the local device. Here I download the 32-bit platform. You can download the required version from the official website.
# Tar xf mysql-5.5.41-linux2.6-i686.tar.gz-C/usr/local
# Cd/usr/local/
# Ln-sv mysql-5.5.41-linux2.6-i686 mysql
# Cd mysql

# Chown-R mysql: mysql.
# Scripts/mysql_install_db -- user = mysql -- datadir =/mydata/data
# Chown-R root

4. Provide the primary configuration file for mysql
# Cd/usr/local/mysql
# Cp support-files/my-large.cnf/etc/my. cnf

You also need to add the following lines to specify the storage location of mysql Data Files:
Datadir =/mydata/data

5. Provide sysv service scripts for mysql
Add to service list:
# Chkconfig -- add mysqld
# Chkconfig mysqld on

Then you can start the service test.
 
To use mysql installation to comply with the system usage specifications and export its development components to the system, perform the following steps, optional)
6. output the mysql man manual to the man command search path:
Edit/etc/man. config and add the following lines:
MANPATH/usr/local/mysql/man

7. output the mysql header file to the system header file path/usr/include:
This can be achieved through simple creation links:
# Ln-sv/usr/local/mysql/include/usr/include/mysql

8. output the mysql database file to the system database search path:
# Echo '/usr/local/mysql/lib'>/etc/ld. so. conf. d/mysql. conf

Then let the system reload the system database:
# Ldconfig-v

9. Modify the PATH environment variable so that the system can directly use mysql-related commands.
Create a file in/etc/profile. d/. you can name it as needed. I will name it mysql here and add it to the file:
Export PATH = $ PATH:/usr/local/mysql/bin

Log on to the system again.

3. Compile and install php-5.4.38
1. Resolve Dependencies
Configure the yum source (which can be a local system disk) and run the following command:
# Yum-y groupinstall "XSoftware Development"

Compile and install libcrypt and mhash. You can compile and install libcrypt and mhash normally.
2. Compile and install the php-5.4.38
# Tar xf php-5.4.38.tar.bz2
# Cd php-5.4.38
#. /Configure -- prefix =/usr/local/php -- with-mysql =/usr/local/mysql -- with-openssl -- with-mysqli =/usr/local/mysql/bin/ mysql_config -- enable-mbstring -- with-freetype-dir -- with-jpeg-dir -- with-png-dir -- with-zlib -- with-libxml-dir =/usr -- enable-xml -- enable-sockets -- with-apxs2 =/usr/local/apache/bin/apxs -- with-mcrypt -- with-config-file-path =/etc -- with-config-file-scan -dir =/etc/php. d -- with-bz2 -- enable-maintainer-zts
# Make
# Make test
# Make intall

Note:
1. The -- enable-maintainer-zts option is used during compilation to support the MPM of apache worker or event.
2. If PHP5.3 or later is used, you can specify mysqlnd to connect to the MySQL database, so that you do not need to install MySQL or MySQL development kit on the local machine. Mysqlnd is available from php 5.3 and can be bound to it during compilation (instead of binding to a specific MySQL client library), but it is set by default from PHP5.4.
#./Configure -- with-mysql = mysqlnd -- with-pdo-mysql = mysqlnd -- with-mysqli = mysqlnd

Provide a configuration file for php:
# Cp php. ini-production/etc/php. ini

3. Edit the apache configuration file httpd. conf to support php in apache.
# Vim/etc/httpd. conf

(1) Add the following two rows:
AddType application/x-httpd-php. php
AddType application/x-httpd-php-source. phps


(2) locate DirectoryIndex index.html
To:
DirectoryIndex index. php index.html

Then restart httpd or re-load the configuration file to test whether php can be used normally.
 
4. Install xcache to accelerate php
1. Installation
12345 # tar xf xcache-3.0.1.tar.gz
# Cd xcache-3.0.1
#/Usr/local/php/bin/phpize
#./Configure -- enable-xcache -- with-php-config =/usr/local/php/bin/php-config
# Make & make install

At the end of installation, the following lines will appear:
1 Installing shared extensions:/usr/local/php/lib/php/extensions/no-debug-zts-20100525/

2. Edit php. ini and integrate php and xcache.
First, import the sample configuration provided by xcache to php. ini.
# Mkdir/etc/php. d
# Cp xcache. ini/etc/php. d

Note: The xcache. ini file is in the xcache source code directory.
Next, edit/etc/php. d/xcache. ini, find the line starting with extension, and change it to the following line.
Extension =/usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache. so

Note: If the php. ini file contains multiple zend_extension command lines, make sure that the new lines are ranked first.

So far, the entire installation process is over. Next we will briefly introduce the use of the stress testing tool AB.


5. Conduct stress tests on websites
1. AB usage
 
Run the AB command to test the apache server performance:
 
-C concurrency: Number of requests initiated at a time. The default value is 1;
-I: The HEAD method is used for testing. The default value is GET;
-K: enables HTTP persistent connection requests;
-N requests: Number of simulated requests initiated. The default value is 1. The number of requests must be greater than or equal to the number of concurrent connections;
-Q: silent mode. When the number of requests is greater than 150, no percentage of requests completed is output;
 
Output result:
Time taken for tests: the duration from the first request connection establishment to the end of the response message received from the last request;
Complete requests: Number of successful requests;
Simple test:
AB-c 100-n 1000 http://www.a.com/index.php
This method can be used to evaluate the web server performance.

------------------------------------ Split line ------------------------------------

CentOS 6.5 system installation and configuration LAMP (Apache + PHP5 + MySQL) server environment

Configure the LAMP + phpMyAdmin PHP (5.5.9) development environment in Ubuntu 14.04

Ubuntu 14.10 text tutorial on hard drive installation in Windows 7

Install Ubuntu 14.10 on a USB flash drive

Official release and download of Ubuntu 14.10

How to upgrade Ubuntu 14.04 LTS to Ubuntu 14.10

Install LAMP in Ubuntu 14.10

------------------------------------ Split line ------------------------------------

This article permanently updates the link address:

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.