设为首页 收藏本站
查看: 1339|回复: 0

yum安装实现lamp分离及Xcache加速

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-4-25 09:56:33 | 显示全部楼层 |阅读模式
LAMP的搭建:
    准备前提:
       虚拟机:Centos7   172.18.250.77   安装httpd,通过Fcgi模块来跟php互动,只处理静态网页。
       虚拟机:Centos7   172.18.250.78   安装php-fpm程序,php-5.3.3的版本已经包含了php-fpm,不需要在打补丁,但CentOS6上官方源没有php-fpm包,所以用CentOS 7 实验。
       虚拟机:CentOS6  172.18.250.76    安装mysql,实现php跟mysql的互动。
   httpd提供两个虚拟主机,分别安装wordpress博客及discuz论坛。

一、yum安装httpd
1
[iyunv@localhost local]# yum -y install httpd



  1、编辑主配置文件,注释DocumentRoot

1
2
[iyunv@localhost httpd]# vim conf/httpd.conf
#DocumentRoot "/var/www/html"



  2、创建虚拟主机文件
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
[iyunv@localhost httpd]# cd /etc/httpd/conf.d/
[iyunv@localhost conf.d]# vim vhost.conf
<VirtualHost *:80>
   ServerName www.a.com
   DocumentRoot "/www/blog"
   <Directory "/www/blog">
      Options None
      Allowoverride None
      Require all granted
   <Directory>
   ProxyRequests Off
   ProxyPassMatch ^/(.*\.php)$ fcgi://172.18.250.78:9000/www/blog/$1
</VirtualHost>

<VirtualHost *:80>
   ServerName www.b.net
   DocumentRoot "/www/php"
   <Directory "/www/php">
      Options None
      Allowoverride None
      Require all granted
   <Directory>
   ProxyRequests Off
   ProxyPassMatch ^/(.*\.php)$ fcgi://172.18.250.78:9000/www/php/$1
</VirtualHost>



3、创建虚拟主机需要的目录
1
2
[iyunv@localhost conf.d]# mkdir -p /www/blog
[iyunv@localhost conf.d]# mkdir -p /www/php



4、启动httpd服务,查看监听端口
1
2
3
[iyunv@localhost conf.d]# systemctl start httpd.service
[iyunv@localhost conf.d]# ss -tan
LISTEN      0      128       :::80        :::*



5、在虚拟主机目录创建测试页,看httpd是否正常
1
2
[iyunv@localhost conf.d]# echo "www.a.com" >/www/blog/index.html
[iyunv@localhost conf.d]# echo "www.b.net" >/www/php/index.html



wKioL1caFAnDy3yKAAArof4-JHA953.jpg
wKiom1caE2XQEJouAAAp2PloYBM623.jpg
OK,虚拟主机正常

二、yum安装PHP
1
[iyunv@localhost ~]# yum -y install php-fpm



    PHP-FPM是一个PHPFastCGI管理器,是只用于PHP的,httpd通过Fcgi模块来把php的文件传送给php-fpm进行处理
1、编辑php-fpm文件
1
2
3
[iyunv@localhost ~]# vim /etc/php-fpm.d/www.conf
listen = 172.18.250.78:9000                //本机IP
listen.allowed_clients = 172.18.250.77     //httpd端IP



2、重启php-fpm程序,查看监听端口
1
2
3
[iyunv@localhost ~]# systemctl start php-fpm.service
[iyunv@localhost ~]# ss -tan
LISTEN      0      128              172.18.250.78:9000        *:*



3、在php端上创建和httpd上一样的目录
1
2
[iyunv@localhost ~]# mkdir -p /www/blog
[iyunv@localhost ~]# mkdir -p /www/php



4、创建测试页,验证看httpd能不能转发过来
1
2
3
4
5
6
7
[iyunv@localhost ~]# mkdir -p /www/blog
[iyunv@localhost ~]# mkdir -p /www/php
[iyunv@localhost ~]# vim /www/blog/index.php
[iyunv@localhost ~]# vim /www/php/index.php
<?php
   phpinfo();
?>



   wKioL1caGaKzPOEaAAI_Lh43rkg561.jpg
wKioL1caGeOBJuVtAAJk5uW6O3Y556.jpg
OK,httpd能读到.php结尾的文件并转发给php处理

三、yum安装mysql
1
[iyunv@localhost ~]# yum -y install mysql-server



1、启动mysql,并对数据库就行安全加固
1
2
3
4
5
6
7
8
[iyunv@localhost ~]# service mysqld start
[iyunv@localhost ~]# mysql_secure_installation
Enter current password for root (enter for none):    //默认数据库密码为空
Set root password? [Y/n] y                           //设置新密码
Remove anonymous users? [Y/n] y                      //移除匿名用户
Disallow root login remotely? [Y/n] n                //是否禁止用户远程登录
Remove test database and access to it? [Y/n] y       //是否移除test数据库
Reload privilege tables now? [Y/n] y                 //是否重启加载权限列表



2、创建用户和数据库,并授权php端能远程登录
1
2
3
4
5
6
7
8
mysql> grant all on *.* to 'admin'@'172.18.250.78' identified by "admin";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> create database mytest;
Query OK, 1 row affected (0.00 sec)
mysql> create database bbs;
Query OK, 1 row affected (0.01 sec)



3、测试php能不能登录数据库
1
2
3
4
5
6
7
8
9
10
11
[iyunv@localhost ~]# yum -y install php-mysql   //安装mysql驱动
[iyunv@localhost ~]# vim /www/blog/index.php
[iyunv@localhost ~]# vim /www/php/index.php
<?php
   $conn = mysql_connect ('172.18.250.76','admin','admin');
   if( $conn )
   echo "SUCCESS";
   else
        echo "Failure";
?>
[iyunv@localhost ~]# systemctl restart php-fpm.service



   wKioL1caH2GxEF83AAAtUDOWwHw226.jpg
wKiom1caHr-Rz56rAAApF14I6_c871.jpg
OK,测试正常,可以安装wordpress和Discuz论坛

  1、分别在php服务器上和httpd上解压wordpress包
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[iyunv@localhost blog]# unzip wordpress-4.3.1-zh_CN.zip
[iyunv@localhost blog]# unzip wordpress-4.3.1-zh_CN.zip  
[iyunv@localhost blog]# cd wordpress                  //只需在php上改动
[iyunv@localhost wordpress]# cp wp-config-sample.php wp-config.php
/** WordPress数据库的名称 */
define('DB_NAME', 'mytest');

/** MySQL数据库用户名 */
define('DB_USER', 'admin');

/** MySQL数据库密码 */
define('DB_PASSWORD', 'admin');

/** MySQL主机 */
define('DB_HOST', '172.18.250.76');



wKioL1caIrDhicl0AAA5iYbi1aI107.jpg
出现这个页面的话只需要修改httpd主配置文件,让httpd能识别php的文件代码
1
2
3
4
5
6
[iyunv@localhost blog]# vim /etc/httpd/conf/httpd.conf
AddType application/x-httpd-php .php              //添加下面的语句就行
AddType aaplication/x-httpd-source .phps
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>



重启httpd服务,再次测试下
wKioL1caJEejFmTkAAEj-23IHbo582.jpg
登录wordPress博客:

wKiom1caI7HBsoiqAABF8hDLK3Q073.jpg
OK,WordPress博客能正常加载

  1、分别在php服务器上和httpd上解压Discuz包
1
2
3
[iyunv@localhost php]# unzip Discuz_X3.2_SC_UTF8.zip
[iyunv@localhost php]# unzip Discuz_X3.2_SC_UTF8.zip
[iyunv@localhost php]# cd upload         //在php服务器上



wKiom1caKGHyNq70AAEsmi5_T2U997.jpg
修改目录的权限即可:
wKiom1caKJryEsZgAACvVGdfYps671.jpg
1
2
3
4
5
[iyunv@localhost upload]# chown -R apache config/
[iyunv@localhost upload]# chown -R apache uc_client/      //httpd和php上都需要改
[iyunv@localhost upload]# chown -R apache data
[iyunv@localhost upload]# chown -R apache template/
[iyunv@localhost upload]# chown -R apache uc_server/



根据步骤一步步执行就行:

wKiom1caKc2AA1A2AADCMoKnDhk761.jpg
注册完后登录论坛:
wKiom1caKiDjK-BOAACC0giGnY0298.jpg
。。。。。发现论坛只有文字,这是因为php安装了Discuz后修改了程序的文件导致的,这时httpd上的静态程序文件跟php上的动态程序文件不一致,所以只需要同步下就行。
1
[iyunv@localhost php]# scp -r upload/* root@172.18.250.77:/www/php/upload/



再次刷新:OK
wKioL1caLNnhJ4NuAAZ6p5vDafo923.jpg
如果想要实现自动同步的话,可以使用initory+rsync、sersync等工具。

四:安装Xcahe对php进行加速
1
2
3
4
5
6
7
8
9
10
11
12
13
[iyunv@localhost src]# tar -xf xcache-3.2.0.tar.bz2   //只需在PHP服务器上
[iyunv@localhost src]# ls
xcache-3.2.0  xcache-3.2.0.tar.bz2
[iyunv@localhost src]# cd xcache-3.2.0
[iyunv@localhost xcache-3.2.0]# yum -y install php-devel   //安装php开发工具包
[iyunv@localhost xcache-3.2.0]# phpize    //检查php的版本及api接口
Configuring for:
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
[iyunv@localhost xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/usr/bin/php-config
[iyunv@localhost xcache-3.2.0]# make && make install
[iyunv@localhost xcache-3.2.0]# cp xcache.ini /etc/php.d/



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
[iyunv@localhost upload]# ab -n100 -c10 http://172.18.250.77/wordpress/index.php
Benchmarking 172.18.250.77 (be patient).....done
Server Software:        Apache/2.4.6
Server Hostname:        172.18.250.77
Server Port:            80
Document Path:          /wordpress/index.php
Document Length:        0 bytes
Concurrency Level:      10
Time taken for tests:   3.908 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Non-2xx responses:      100
Total transferred:      34900 bytes
HTML transferred:       0 bytes
Requests per second:    25.59 [#/sec] (mean)  //ab压力测试每秒请求个数
Time per request:       390.849 [ms] (mean)
Time per request:       39.085 [ms] (mean, across all concurrent requests)
Transfer rate:          8.72 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       1
Processing:   104  369  95.7    368     589
Waiting:      104  367  94.8    367     589
Total:        105  369  95.7    368     589

Percentage of the requests served within a certain time (ms)
  50%    368
  66%    410
  75%    443
  80%    455
  90%    502
  95%    536
  98%    589
  99%    589
100%    589 (longest request)



重启php-fpm服务,看xcache有没有加载:
1
2
3
4
[iyunv@localhost blog]# php -m   
[Zend Modules]                  //表明xcache已经开启
XCache
XCache Cacher



wKioL1caNxqT9bwtAAB3RHKQNEM908.jpg
再一次做ab压力测试:
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
[iyunv@localhost upload]# ab -n100 -c10 http://172.18.250.77/wordpress/index.php
Benchmarking 172.18.250.77 (be patient).....done
Server Software:        Apache/2.4.6
Server Hostname:        172.18.250.77
Server Port:            80
Document Path:          /wordpress/index.php
Document Length:        0 bytes
Concurrency Level:      10
Time taken for tests:   1.489 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Non-2xx responses:      100
Total transferred:      34900 bytes
HTML transferred:       0 bytes
Requests per second:    67.18 [#/sec] (mean)   //加载xcache后有了提升
Time per request:       148.853 [ms] (mean)
Time per request:       14.885 [ms] (mean, across all concurrent requests)
Transfer rate:          22.90 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       1
Processing:    38  141  31.0    139     240
Waiting:       37  141  31.0    138     240
Total:         38  141  31.0    139     240

Percentage of the requests served within a certain time (ms)
  50%    139
  66%    152
  75%    160
  80%    168
  90%    179
  95%    194
  98%    216
  99%    240
100%    240 (longest request)



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-208555-1-1.html 上篇帖子: CentOS7搭建lamp(module)并实现Xcache、https访问 下篇帖子: Mantis安装过程中的各种坑(WAMP环境)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表