mysql> create database discuz; --创建一个库,用于存放将要安装的discuz论坛的表
mysql> grant all on discuz.* to 'discuzuser'@'localhost' identified by '123'; --授权一个用户,用于discuz论坛程序连接mysql
mysql> flush privileges;
安装会出现下面的报错
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解决方法1:
把mysql的配置socket路径改成/tmp/mysql.sock
# vim /usr/local/mysql/etc/my.cnf
[mysqld]
port=3307
datadir=/mysqldata56
pid-file=/mysqldata56/mysql56.pid
socket=/tmp/mysql.sock
log-error=/mysqldata56/mysql56-err.log
[client]
socket=/tmp/mysql.sock
改完后,重启mysql
# vim /lnmp/web/memcachetest.php --在家目录下做一个测试页面,使用firefox访问这个页面,如果能显示This is a test!,则表示成功
<?php
$mem = new Memcache;
$mem->connect("127.0.0.1", 11211);
$mem->set('key', 'This is a test!', 0, 60);
$val = $mem->get('key');
echo $val;
?>
测试memcache方法一
(开memcache显示,关闭memcache不能显示)
# vim /usr/local/php/etc/php.ini
;extension = "memcache.so" --前面加;符号注释来模拟关闭
# pkill fpm
# /usr/local/php/sbin/php-fpm -D -y /usr/local/php/etc/php-fpm.conf
--再使用这两句把php的fastcgi重启,使之生效
测试memcache方法二
关闭memcache的11211,上面的This is a test!就无法显示.打开就OK
# cd /usr/src/lnmp/php-5.6.12/ext/mcrypt/
# /usr/local/php/bin/phpize --目录默认没有configure文件,需要使用你安装的对应版本phpize命令执行一下,才会出现configure
# ./configure --with-php-config=/usr/local/php/bin/php-config
# make
# make install
# ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/mcrypt.so
--产生了mcrpyt.so,表示安装成功
我们这里是内网做一些基本测试比较来说明lnmp的原理
测试工具
1,ab命令 apache自带
2,webbench
# tar xf 笔记目录/lnmp_soft/webbench-1.5.tar.gz -C /usr/src/lnmp/
# cd /usr/src/lnmp/webbench-1.5/
# make ;make install
测试一:测试opcache(php代码缓存加速软件,以前有叫apc,xcache,eaccelerator,zend opimizer等等很多)
有支持opcache的lnmp做如下测试
# ab -n 1000 -c 1000 http://172.16.2.35:8000/index.php
Concurrency Level: 1000
Time taken for tests: 0.122 seconds
Complete requests: 1000
Failed requests: 853
(Connect: 0, Receive: 0, Length: 853, Exceptions: 0)
Write errors: 0
Non-2xx responses: 1000
Total transferred: 646678 bytes
HTML transferred: 458061 bytes
Requests per second: 8226.05 [#/sec] (mean)
Time per request: 121.565 [ms] (mean)
Time per request: 0.122 [ms] (mean, across all concurrent requests)
Transfer rate: 5194.93 [Kbytes/sec] received
# webbench -c 1000 http://172.16.2.35:8000/index.php
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://172.16.2.35:8000/index.php
1000 clients, running 30 sec.
Speed=492092 pages/min, 2901688 bytes/sec.
Requests: 246001 susceed, 45 failed.
# vim /usr/local/php/etc/php.ini --把opcache相关配置注释掉然后重启php
# pkill fpm
# /usr/local/php/sbin/php-fpm -D -y /usr/local/php/etc/php-fpm.conf
没有支持opcache的lnmp做如下测试
# ab -n 1000 -c 1000 http://172.16.2.35:8000/index.php
Concurrency Level: 1000
Time taken for tests: 0.197 seconds
Complete requests: 1000
Failed requests: 158
(Connect: 0, Receive: 0, Length: 158, Exceptions: 0)
Write errors: 0
Non-2xx responses: 1000
Total transferred: 640892 bytes
HTML transferred: 452154 bytes
Requests per second: 5070.76 [#/sec] (mean)
Time per request: 197.209 [ms] (mean)
Time per request: 0.197 [ms] (mean, across all concurrent requests)
Transfer rate: 3173.64 [Kbytes/sec] received
# webbench -c 1000 http://172.16.2.35:8000/index.php
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://172.16.2.35:8000/index.php
1000 clients, running 30 sec.
Speed=309968 pages/min, 2615130 bytes/sec.
Requests: 154966 susceed, 18 failed.
补充三:
把单机lnmp分离成多机
你可以把nginx,mysql,php分成三台服务器都可以(或者把nginx和php做成一台)
跟单机lnmp的区别在于:
1,php的编译如果用下面的参数,那么编译没什么区别,远程一样可以让php支持mysql
--with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd
2,在安装论坛时,mysql授权时要写php的IP
# grant all on discuz.* to 'discuzuser'@'PHP服务器IP' identified by '123';
# flush privileges;
3,在安装论坛的web页面,写mysql在哪里,要写mysql的IP加端口,而不是localhost