inux的环境是:
[root@localhost ~]# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.2.1511 (Core)
Release: 7.2.1511
Codename: Core
安装了Deveolpment Tools包
各软件版本:
apr-1.5.0
apr-util-1.5.3
httpd-2.4.10
mariadb-5.5.46-linux-x86_64
php-5.6.4
xcache-3.2.0
wordpress-4.3.1-zh_CN
编译安装apr
tar xf apr-1.5.0.tar.bz2
cd apr-1.5.0
./configure –prefix=/apps/apr
make -j 4 && make install
编译apr-util
tar xf apr-util-1.5.3.tar.bz2
cd apr-util-1.5.3
./configure –prefix=/apps/apr-util –with-apr=/apps/apr/
make -j 4 && make install
编译httpd
yum install -y pcre-devel
yum install -y openssl-devel
tar xf httpd-2.4.10.tar.bz2
cd httpd-2.4.10
./configure –prefix=/apps/http –with-apr=/apps/apr –with-apr-util=/apps/apr-util –enable-so –enable-ssl –enable-rewrite –with-zlib –with-pcre –enable-modules=most –enable-mpms-shared=all –with-mpm=prefork
make -j 4 && make install
注意:此处httpd编译的是prefork
配置:/apps/http/conf/httpd.conf
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
建立文件:
cat /etc/profile.d/http.conf
PATH=/apps/http/bin:$PATH
添加man配置
[root@localhost ~]# vim /etc/man_db.conf
MANDATORY_MANPATH /apps/http/man
添加头文件
[root@localhost ~]# ll /usr/include/http.h
lrwxrwxrwx. 1 root root 19 10月 12 04:33 /usr/include/http.h -> /apps/http/include/
使用httpd –k start命令启动httpd 查看80端口
安装mariadb:
此处的mariadb是通用二进制包安装:
tar xf mariadb-5.5.46-linux-x86_64.tar.gz –C /apps/
cd /apps
ln –sv mariadb-5.5.46-linux-x86_64 mysql
useradd -r -M -s /sbin/nologin mysql
mkdir -p /mysql/mydata
chown -R mysql.mysql /mysql/mydata/
cd /apps/mysql
chown -R root.mysql ./*
mkdir -p /etc/mysql/
cp support-files/my-large.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
在[mysqld]字段编辑如下语句:
datadir = /mysql/mydata
skip_name_resolve = ON
innodb_file_per_table = ON
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig –add mysqld
chkconfig –list mysqld
mv /etc/my.cnf /etc/my.cnf.bak
service mysqld start
查看端口3306是否启动
vim /etc/profile.d/mysql.conf如下:
PATH=/apps/mysql/bin:$PATH
. /etc/profile.d/mysql.conf
编译php
tar xf php-5.6.4.tar.xz
cd php-5.6.4
yum install libxml2-devel
yum install bzip2-devel
yum install libmcrypt
yum install libmcrypt-devel 注意:该软件是epel源里的,需要epel的yum源
./configure –prefix=/apps/php –with-mysql=/apps/mysql –with-openssl –with-mysqli=/apps/mysql/bin/mysql_config –enable-mbstring –with-png-dir –with-jpeg-dir –with-freetype-dir –with-zlib –with-libxml-dir=/usr –enable-xml –enable-sockets –with-apxs2=/apps/http/bin/apxs –with-mcrypt –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –with-bz2 –enable-fpm
make -j 4 && make install
注意:此处编译了php-fpm的属性,并且由于httpd编译的是prefork的,若果httpd编译为work或者event,则这里需要加以属性:–enable-maintainer-zts;
编辑vim /apps/http/conf/httpd.conf:去掉下面模块的注释符号#,
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
LoadModule dir_module modules/mod_dir.so
注释掉下面的模块:
#LoadModule php5_module modules/libphp5.so
在DocumentRoot下面添加一下语句:
DocumentRoot "/apps/http/htdocs"
ProxyRequests off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/apps/http/htdocs/$1
确保下面的没有被注释掉:
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>
cp php.ini-production /etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chkconfig –add php-fpm
chkconfig –list php-fpm
chmod +x /etc/init.d/php-fpm
mv /apps/php/etc/php-fpm.conf.default /apps/php/etc/php-fpm.conf
service php-fpm start
httpd -k restart
vim /apps/http/htdocs/index.php如下:
<?php
phpinfo();
?>
在浏览器中输入网址,是否是fastcgi模式:
在/apps/http/htdocs目录中:
unzip /root/wordpress-4.3.1-zh_CN.zip -d .
mysql
MariaDB [(none)]> create database wpdb;
MariaDB [(none)]> grant all privileges on wpdb.* to walker@'%' identified by "walker";
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> quit
[root@localhost ~]# vim /apps/http/htdocs/index.php
<?php
$conn = mysql_connect('172.16.251.187','walker','walker');
if($conn)
echo "OK";
else
echo "Failure";
phpinfo();
?>
访问网页,看是否连接成功:
如此可以使用wordpress。使用刚才创建的用户和数据可以初始化wordpress,在使用之前,需要更改wordpress目录的权限。否则无法写入数据:
chmod a+w wordpress
使用ab测试网站并发,ab工具是httpd-tools软件包里面的,如没有安装httpd-tools。在另外一台电脑使用命令:ab -c 20 -n 500 http://172.16.251.187/wordpress/wp-admin/
其中-c 20是并发量,-n 500是总的请求数。3次测试后,最后的数据是:
Requests per second: 11.43 [#/sec] (mean)
Time per request: 1749.168 [ms] (mean)
Time per request: 87.458 [ms] (mean, across all concurrent requests)
Transfer rate: 4.85 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 17 29.4 1 231
Processing: 196 1695 241.8 1697 2421
Waiting: 193 1695 241.2 1696 2353
Total: 199 1713 243.3 1719 2422
Percentage of the requests served within a certain time (ms)
50% 1719
66% 1799
75% 1847
80% 1875
90% 1941
95% 2006
98% 2176
99% 2236
100% 2422 (longest request) 最大的网页打开时间是2.422秒
编译安装xcashe提升并发:
tar xf xcache-3.2.0.tar.bz2
cd xcache-3.2.0
vim INSTALL
/apps/php/bin/phpize
./configure –enable-xcache –with-php-config=/apps/php/bin/php-config
make -j 4 && make install
mkdir /etc/php.d
mv /etc/xcache.ini /etc/php.d/
service php-fpm restart
httpd -k restart
在index.php网页里面查看是否有:
现在在用ab测试:
Requests per second: 31.13 [#/sec] (mean) 每秒处理请求,打开提升了3倍
Time per request: 642.426 [ms] (mean)
Time per request: 32.121 [ms] (mean, across all concurrent requests)
Transfer rate: 13.19 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 17 33.1 2 342
Processing: 101 610 114.4 605 1055
Waiting: 100 609 114.3 605 1055
Total: 102 627 113.8 622 1056
Percentage of the requests served within a certain time (ms)
50% 622
66% 653
75% 677
80% 690
90% 758
95% 811
98% 908
99% 985
100% 1056 (longest request) 打开网页的最长时间,提示你2倍多
原创文章,作者:王更生,如若转载,请注明出处:http://www.178linux.com/64415