lnmp
***************mysql***************
1)解压安装mysql
tar zxf mysql-boost-5.7.11.tar.gz
2)安装cmake(相当于configure),用来编译mysql
yum install -y cmake-2.8.12.2-4.el6.x86_64.rpm 同时解决依赖性
3)cd mysql-5.7.17/ (cmake相当于configure)
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql \
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data \
-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
4)根据提示解决依赖性问题
CMake Error at cmake/boost.cmake:81 (MESSAGE):
You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=
This CMake script will look for boost in . If it is not there,
it will download and unpack it (in that directory) for you.
If you are inside a firewall, you may need to use an http proxy:
缺少 -DWITH_BOOST= 参数 -DWITH_BOOST=boost/boost_1_59_0/ (可Tab补齐)
后面编译会有一个warning:
CMake Warning at cmake/bison.cmake:20 (MESSAGE):
Bison executable not found in PATH
Call Stack (most recent call first):
sql/CMakeLists.txt:514 (INCLUDE)
yum install -y bison
注意:每解决完一次错误,就应删除缓存 rm -fr CMakeCache.txt
5)make && make install (过程较长)
6)复制启动脚本到/etc/init.d/
[root@server5 support-files]# pwd
/root/mysql-5.7.17/support-files
[root@server5 support-files]# cp mysql.server /etc/init.d/mysqld
7)将原来的/etc/my.cnf备份,重新拷贝安装包里的过去
[root@server5 etc]# cp my.cnf my.cnf.bak
[root@server5 support-files]# cp my-default.cnf /etc/my.cnf
修改配置:
basedir = /usr/local/lnmp/mysql
datadir = /usr/local/lnmp/mysql/data
socket = /usr/local/lnmp/mysql/data/mysql.sock
8)添加用户和组:
groupadd -g 27 mysql
useradd -u 27 -g 27 mysql (id=27是因为rpm默认安装时mysql用户的id为27,并非强制)
chown mysql.mysql . -R (修改mysql目录的权限,使其对mysql用户可写)
9)将mysql命令添加到环境变量
vim ~/.bash_profile
添加:PATH= PATH: P A T H : HOME/bin:/usr/local/lnmp/mysql/bin
生效:source ~/.bash_profile
初始化mysql:
mysqld –user=mysql –initialize (以mysql用户身份初始化)
初始化会生成一个临时密码,用于登录mysql(要记住次密码)
10)为了安全,再将mysql目录的所有者改为root
chown root /usr/local/lnmp/mysql -R
11)启动mysql:/etc/init.d/mysqld start
12)进入mysql,执行:show databases; 会报错
需要执行:mysql_secure_installation,然后会提示是否启用密码检测插件,直接回车不启用,否则会要求密码有大小写和特殊字符等要求
剩余全部选 y
mysql安装配置完成
***************php***************
1)解压:tar jxf php-5.6.35.tar.bz2
2)进入解压后的目录,开始编译
./configure –prefix=/usr/local/lnmp/php –with-config-file-path=/usr/local/lnmp/php/etc –with-openssl –with-snmp –with-gd –with-zlib –with-curl –with-libxml-dir –with-png-dir –with-jpeg-dir –with-freetype-dir –with-gmp –with-gettext –with-pear –enable-mysqlnd –with-mysql=mysqlnd –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd –enable-inline-optimization –enable-soap –enable-ftp –enable-sockets –enable-mbstring –enable-fpm –with-fpm-user=nginx –with-fpm-group=nginx –with-mcrypt –with-mhash
以上为php需要编译的模块
3)编译报错,逐步解决依赖性
yum install -y re2c-0.13.5-1.el6.x86_64.rpm libmcrypt-2.5.8-9.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm (系统镜像没有的3个包)
4)make && make install
5)编译时添加了–with-fpm-user=nginx –with-fpm-group=nginx 参数
所以添加 nginx 用户:
useradd nginx
6)拷贝更改配置文件
[root@server5 etc]# cp php-fpm.conf.default php-fpm.conf
查看配置文件中以下几项是否开启:
user = nginx
group = nginx
pid = run/php-fpm.pid
7)拷贝更改php主配置文件
[root@server5 php-5.6.35]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini
修改时区:date.timezone = Asia/Shanghai
8)拷贝php启动脚本至/etc/init.d/
[root@server5 fpm]# pwd
/root/php-5.6.35/sapi/fpm
[root@server5 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
添加执行权限:chmod +x /etc/init.d/php-fpm
9)启动php:/etc/init.d/php-fpm start
***************nginx***************
1)解压nginx:tar zxf nginx-1.14.0.tar.gz
2)进入nginx解压包:
vim src/core/nginx.h
修改:#define NGINX_VER “nginx/”(将此行末尾显示nginx版本号的配置删除)
vim auto/cc/gcc
修改:
debug
CFLAGS=”$CFLAGS -g” (将这2行注释调,关闭debug)
3)编译安装nginx:
./configure –prefix=/usr/local/lnmp/nginx –with-http_ssl_module –with-http_stub_status_module –with-threads –with-file-aio –user=nginx –group=nginx
根据提示解决依赖性
4)make && make install
5)修改nginx配置文件,开启php模块
location / {
root html;
index index.php index.html index.htm; (添加php页面)
}
location ~ .php{
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts fastcgi_script_name;
include fastcgi.conf;
}
6)将nginx启动脚本链接到/usr/local/sbin/
ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/
7)在nginx默认发布目录添加 index.php
nginx安装配置完成
***************Discuz论坛搭建***************
1)解压 Discuz_X3.2_SC_UTF8.zip到nginx发布目录hml下:
unzip Discuz_X3.2_SC_UTF8.zip -d /usr/local/lnmp/nginx/html/
[root@server4 software]# cd /usr/local/lnmp/nginx/html/
[root@server4 html]# ls
50x.html index.php readme upload utility(新生成的三个)
2)将解压后的upload目录改名为bbs,便于访问
mv upload bbs
[root@server4 html]# mv upload bbs
[root@server4 html]# ls
50x.html bbs index.php readme utility
4)点击同意后会出现很多目录不存在和不可写的报错
chmod 777 config/ -R
chmod 777 data/ -R
chmod 777 uc_server/ uc_client/ -R
给以上目录增加权限
[root@server4 bbs]# ll
drwxrwxrwx 2 root root 4096 5月 31 10:03 config
drwxrwxrwx 13 root root 4096 5月 31 10:03 data
drwxrwxrwx 6 root root 4096 5月 31 2016 uc_client
drwxrwxrwx 13 root root 4096 5月 31 2016 uc_server
5)填写数据库名(任意) 数据库用户名:root 数据库密码:redhat
管理员帐号:admin 密码:redhat
6)接下来会报数据库连接错误: No such file or directory
编辑php主配置文件:vim / usr/local/lnmp/php/etc/php.ini
添加以下配置:以前为空
[Pdo_mysql]
; If mysqlnd is used: Number of cache slots for the internal result set cache
; http://php.net/pdo_mysql.cache_size
pdo_mysql.cache_size = 2000
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
; http://php.net/pdo_mysql.default-socket
pdo_mysql.default_socket=
添加:
pdo_mysql.default_socket= /usr/local/lnmp/mysql/data/mysql.sock
还要添加两行:
mysql.default_socket = /usr/local/lnmp/mysql/data/mysql.sock
mysqli.default_socket = /usr/local/lnmp/mysql/data/mysql.sock
以上路径为mysql安装的目录,根据自己的路径填写
重新加载php
/etc/init.d/php-fpm reload
7)再次刷新页面,还是报错:Permission denied
由于 nginx用户(程序) 对于 /usr/local/lnmp/mysql/data 目录没有权限
[root@server4 mysql]# pwd
/usr/local/lnmp/mysql
[root@server4 mysql]# ll
drwxr-x— 5 mysql mysql 4096 5月 31 08:40 data
[root@server4 mysql]# id nginx
uid=500(nginx) gid=500(nginx) groups=500(nginx)
所以:chmod 755 data/
再次刷新,成功安装
8)点击页面中“管理中心”,会出现报错:Please delete install/index.php via FTP!
[root@server5 bbs]# pwd
/usr/local/lnmp/nginx/html/bbs
[root@server5 bbs]# rm -fr index.php
再刷新页面,成功
***************php增加memcache模块***************
1)将php的bin目录路径增加到 ~/.bash_profile中,为了方便调用
PATH= PATH: P A T H : HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/bin
2)memcache目录中本来没有configure文件
先执行命令:phpize
会生成configure文件
3)编译安装memcache
./configure
make && make install
4)修改php主配置文件,增加memcache模块
extension=memcache.so
5)重新加载php
/etc/init.d/php-fpm reload
6)php -m | grep memcache 可以查看是否加载成功
7)安装memcached
yum install -y memcached
8)查看那memcached的配置文件
[root@server5 sbin]# cat /etc/sysconfig/memcached
PORT=”11211”
USER=”memcached”
MAXCONN=”1024”
CACHESIZE=”64”
OPTIONS=”” (如果写为OPTIONS=”-l 127.0.0.1” 即为只监听本机的11211端口)
9)启动memcached
/ect/init.d/memcached start
10)telnet测试
telnet localhost 11211
stats(查看状态)
set name 0 0 6 (0编号 0缓存时间(此处0代表不限制时间) 6限制字符数)
westosawd
CLIENT_ERROR bad data chunk
ERROR
westos
STORED
get name
VALUE name 0 6
11)拷贝php页面到nginx默认发布目录
[root@server5 memcache-2.2.5]# cp memcache.php example.php /usr/local/lnmp/nginx/html/
修改内容
define(‘ADMIN_USERNAME’,’memcache’); // Admin Username(自定义)
define(‘ADMIN_PASSWORD’,’redhat’); // Admin Password(自定义)
$MEMCACHE_SERVERS[] = ‘172.25.230.5:11211’; // add more as an array
$MEMCACHE_SERVERS[] = ‘mymemcache-server2:11211’; // add more as an array
只留一个主机,memcache没有转发或负载均衡机制,只能一个一个添加(因为本实验只有一个主机,其实可以添加多个)
观察时间和命中率
14)给nginx添加memc和sr cache模块,让nginx直接访问memcache来提高速度
先关闭原来的nginx,因为下面安装的openresty-1.13.6.1.tar.gz也是nginx
源码编译安装openresty-1.13.6.1.tar.gz(不需要加参数,使用默认)
./configure
gmake && gmake install
拷贝之前example.php和index.php到默认发布目录准备测试
[root@server5 html]# cp /usr/local/lnmp/nginx/html/index.php .
[root@server5 html]# cp /usr/local/lnmp/nginx/html/example.php .
修改nginx配置文件:vim /usr/local/openresty/nginx/conf/nginx.conf
添加:
upstream memcache {
server localhost:11211;
keepalive 512;
}
location /memc { internal; memc_connect_timeout 100ms; memc_send_timeout 100ms; memc_read_timeout 100ms; set $memc_key $query_string; set $memc_exptime 300; memc_pass memcache; } location ~ \.php$ { set $key $uri$args; srcache_fetch GET /memc $key;(这两个配置的作用是:请求php页面时,先会去memcache中找,如果没有,正常访问; srcache_store PUT /memc $key; 访问结束后将结果存到memcache,下次访问时直接从缓存中) root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi.conf; }
再次进行压测,速度会快很多
***************tomcat***************
1)安装jdk和tomcat
tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local/
tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/
2)做好软连接便于访问
ln -s jdk1.7.0_79/ java
ln -s apache-tomcat-7.0.37/ tomcat
3)配置环境变量
export JAVA_HOME=/usr/local/java
export CLASSPATH=.: JAVAHOME/lib: J A V A H O M E / l i b : JAVA_HOME/jre/lib
export PATH= PATH: P A T H : JAVA_HOME/bin
4)增加测试页面:vim /usr/local/apache-tomcat-7.0.37/webapps/ROOT/test.jsp
<%@ page contentType=”text/html; charset=GBK” %>
<%@ page import=”java.util.*” %>
Cluster App Test
Server Info:
<%
out.println(request.getLocalAddr() + ” : ” + request.getLocalPort()+”
”);%>
<%
out.println(“
ID ” + session.getId()+”
”);
String dataName = request.getParameter(“dataName”);
if (dataName != null && dataName.length() > 0) {
String dataValue = request.getParameter(“dataValue”);
session.setAttribute(dataName, dataValue);
}
out.print(“Session list“);
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = session.getAttribute(name).toString();
out.println( name + ” = ” + value+”
”);
System.out.println( name + ” = ” + value);
}
%>
name:
key:
5)在nginx配置文件中增加tomcat模块,为了实现session共享,需要支持sticky(粘滞)模块,nginx-1.14不支持sticky,所以使用nginx-1.10版本,重新编译nginx
添加–add-module=/root/nginx-sticky-module-ng 参数(提前解压nginx-sticky-module-ng.tar.gz),直接复制之前openresty里nginx配置文件,添加sticky选项,并
注释掉memcache和php选项
upstream memcache {
server localhost:11211;
keepalive 512;
location /memc {
internal;
memc_connect_timeout 100ms;
memc_send_timeout 100ms;
memc_read_timeout 100ms;
set memckey m e m c k e y query_string;
set $memc_exptime 300;
memc_pass memcache;
location ~ \.php$ { # set $key $uri$args; # srcache_fetch GET /memc $key; # srcache_store PUT /memc $key; root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi.conf; }
再次刷新页面,访问的ID号不会变,实现了sticky
接下来实现session共享:
1)进入/usr/local/tomcat/lib目录
将以下jar包拷贝到该目录:
asm-3.2.jar
kryo-1.04.jar
kryo-serializers-0.10.jar
memcached-session-manager-1.6.3.jar
memcached-session-manager-tc7-1.6.3.jar(最重要)
minlog-1.2.jar
msm-kryo-serializer-1.6.3.jar
reflectasm-1.01.jar
spymemcached-2.7.3.jar
2)编辑/usr/local/tomcat/conf/context.xml文件,加入session共享配置
原文链接:https://blog.csdn.net/weixin_40658000/article/details/80521819/