类型 | 软件版本 | 地址分配 | 功能 |
前台 | httpd-2.4.9.tar.bz2 | 192.168.1.20(www.essun.com) | 处理静态页面请求 |
中间层处理器 | PHP-5.4.26.tar.bz2 |
192.168.1.10 | 解析脚本请求 |
后台业务数据 | mysql-5.5.33.tar.bz2 | 192.168.1.30 | 数据文件存储 |
一,安装httpd
先编译安装的httpd
httpd的版本是2.4.9
下载地址:
1
2
3
|
#wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.9.tar.bz2
#wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.0.tar.bz2
#wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.3.tar.bz2
|
依赖关系:
在2.4.9中在以安装apr与apr-util包,由于http-2.4.9采用了新的数据结构,所以要安装apr-1.5.0以后的版本与apr-util-1.5.3版本,本机在安装好要需要的环境,要安装两个包组
1
2
|
# yum groupinstall -y "Development tools" "Server Platform Development"
# yum install pcre-devel -y
|
2、图解编译过程
下载之后的包
安装APR-1.5.0.tar.bz2
进入APR-1.5.0目录编译安装
1
2
3
|
#cd apr-1.5.0
#./configure --prefix=/usr/local/apr
#make && make install
|
解压并安装apr-util-1.5.3.tar.bz
1
2
3
4
|
#tar xf apr-util-1.5.3.tar.bz2
#cd apr-util-1.5.3
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
|
解压并安装的httpd-2.4.9
1
2
3
4
|
# tar -xf httpd-2.4.9.tar.bz2
# cd httpd-2.4.9
#./configure --prefix=/usr/local/apache/ --sysconfdir=/etc/httpd24/ --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ -enable-modules=most --enable-mpms-shared=all --with-mpm=event
#make && make install
|
3、修改启动脚本(基于RPM安装的httpd所生成的服务脚本)
添加的PidFile文件路径
1
|
#vim /etc/httpd24/httpd.conf
|
此处为指定httpd服务创建的pid文件,优先读取配置文件中的参数。脚本本身的定义的参数将被忽略。在配置文件中变量是不区分大小写的,如若指定/var/run/directory/路径,运行应用程序的用户必须有对/var/run有创建权限。
修改脚本文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible \
# server implementing the current HTTP standards.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd/httpd.pid
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an extensible server
# implementing the current HTTP standards.
### END INIT INFO
# 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/httpd24
.pid}
lockfile=${LOCKFILE-
/var/lock/subsys/httpd24
}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure. So we just do it the way init scripts
# are expected to behave here.
start() {
echo
-n $
"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] &&
touch
${lockfile}
return
$RETVAL
}
# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
# httpd parent to SIGKILL any errant children.
stop() {
echo
-n $
"Stopping $prog: "
killproc -p ${pidfile} -d ${STOP_TIMEOUT} $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=6
echo
$
"not reloading due to configuration syntax error"
failure $
"not reloading $httpd due to configuration syntax error"
else
# Force LSB behaviour from killproc
LSB=1 killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
if
[ $RETVAL -
eq
7 ];
then
failure $
"httpd shutdown"
fi
fi
echo
}
# See how we were called.
case
"$1"
in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart|try-restart)
if
status -p ${pidfile} $httpd >&
/dev/null
;
then
stop
start
fi
;;
force-reload|reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo
$
"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
RETVAL=2
esac
exit
$RETVAL
|
4、添加到启动队列中
1
|
#chmod +x /etc/init.d/httpd24
|
7、在相应的虚拟主机中添加类似如下。
1
|
#vim /etc/httpd24/extra/httpd-vhosts.conf
|
8、编辑apache配置文件httpd.conf,让apache能识别php格式的页面,并支持php格式的主页
9、定位至DirectoryIndex index.html
#DirectoryIndex index.php index.html
=========================================到此httpd编译安装完成==========================
二、安装mysql
格式化、挂载到己经建立的目录上
查看挂载(mount)
1
2
3
|
# groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
# chown -R mysql:mysql /mydata/data
|
3、解压、编译
1
2
3
4
5
6
7
|
#tar -xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local/
#cd /usr/local/
# ln -s mysql-5.5.33-linux2.6-x86_64 mysql
#cd mysql
# chown -R mysql.mysql .
# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
#chown -R root .
|
1
2
|
# cd /usr/local/mysql
# cp support-files/my-large.cnf /etc/my.cnf
|
thread_concurrency = 4
5、为服务添加脚本
6、为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:
导出man帮助手册
1
|
#echo 'MANPATH /usr/local/mysql/man' >>/etc/man.config
|
链接头文件
1
|
#ln -s include /usr/include/mysql
|
指定库文件
1
2
|
#echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
#ldconfig
|
导入二进制文件
1
2
|
#echo 'export PATH=/usr/local/mysql/bin:$PATH' >/etc/profile.d/mysql.sh
# . /etc/profile.d/mysql.sh
|
============================================到此安装完成 mysql============================
三、安装php
1、下载地址:
1
|
#wget http:
//am1.php.net/distributions/php-5.4.26.tar.bz2
|
./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
注:
今天下午安装 php 5.4.26的时候出现了一个错误,是关于libxml2 configure: error: xml2-config not found. Please check your libxml2 installation.
1
2
3
|
..
/configure
--prefix=
/usr/local/php
--with-mysql=mysqlnd --with-openssl --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --
enable
-mbstring --with-freetype-
dir
--with-jpeg-
dir
--with-png-
dir
--with-zlib --with-libxml-
dir
=
/usr/local/libxml2/
--
enable
-xml --
enable
-sockets --
enable
-fpm --with-mcrypt --with-config-
file
-path=
/etc
--with-config-
file
-scan-
dir
=
/etc/php
.d --with-bz2
#make
#make install
|
1
|
# cp php.ini-production /etc/php.ini
|
1
2
3
4
5
|
cd
php-5.4.26
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
|
5、为php-fpm提供配置文件:
1
|
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
|
1
|
# vim /usr/local/php/etc/php-fpm.conf
|
本次实验用的到参数说明
1
|
# service php-fpm start
|
1
|
#ss -tunl |grep ":9000"
|
测试页面index.php示例如下
1
2
3
4
5
6
7
8
|
<?php
$link
= mysql_connect(
'192.168.1.30'
,
'root'
,
'mysql'
);
if
(
$link
)
echo
"Success..."
;
else
echo
"Failure..."
;
mysql_close();
?>
|
测试结果
1
2
3
4
|
#wget http://ncu.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.0.10/phpMyAdmin-4.0.10-all-languages.zip
# unzip phpMyAdmin-4.0.10-all-languages.zip
#cd phpMyAdmin-4.0.10-all-languages
#mv * /www/essun.com/
|
对其压力测试
1
|
#ab -c 100 -n 1000 http://essun.com/
|
四、安装xcache,为php加速
1、下载地址
1
|
#wget http://xcache.lighttpd.net/pub/Releases/3.1.0/xcache-3.1.0.tar.bz2
|
2、编译安装
1
2
3
4
5
|
# tar xf xcache-3.0.3.tar.gz
# cd xcache-3.0.3
# /usr/local/php/bin/phpize
# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
# make && make install
|
将编译生成的shared extensions后面的数据写入配置文件中,
找到zend_extension开头的行,修改为如下行:
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位
1
2
3
|
<?php
phpinfo();
?>
|
结果是
明显比上一次测试响应的要快的多