实现动静分离的LNMMP网站架构

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介:

一、前提说明

1、实验目的

   实现动静分享的LNMMP网站

2、实现功能

(1)前端nginx服务器(172.16.7.10)处理静态内容并向后转发动态内容

(2)php服务器(172.16.7.100)处理动态内容

(3)数据库为MariaDB,版本为mariadb-10.0.10,IP:172.16.7.200

(4)在动态系统中,为了减小数据库的压力,提高性能,增加memcached服务器(172.16.7.201)

3、实验拓扑

   简单实验拓扑如下(因为都在一个网络内测试,所以前端nginx只给了一个IP):

wKioL1NcY8bDtMeFAABQWYDe_KU977.png

二、安装nginx服务器(172.16.7.10)

1、解决依赖关系

   在安装前,为了避免一些不必要的麻烦,首先装几个开发包组:"Development Tools"、"Server Platform Development"、并安装"pcre-devel包"

2、添加nginx用户,实现以nginx用户运行nginx服务进程

1
2
# groupadd -r nginx
# useradd -r -g nginx nginx

3、编译安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# ./configure \
   --prefix= /usr/local/nginx  \                    #指定安装路径
   --sbin-path= /usr/local/nginx/sbin/nginx  \      #指定nginx程序路径
   --conf-path= /etc/nginx/nginx .conf \            #指定配置文件路径
   --error-log-path= /var/log/nginx/error .log \    #指定错误日志路径
   --http-log-path= /var/log/nginx/access .log \    #指定访问日志路径
   --pid-path= /var/run/nginx/nginx .pid  \         #指定pid文件路径
   --lock-path= /var/lock/nginx .lock \             #指定锁文件路径
   --user=nginx \                                 #指定以nginx用户运行进程
   --group=nginx \
   --with-http_ssl_module \                       #添加ssl模块
   --with-http_flv_module \                       #添加流媒体模块
   --with-http_stub_status_module \               #添加服务器状态信息模块
   --with-http_gzip_static_module \               #添加gzip压缩模块
   --http-client-body-temp-path= /var/tmp/nginx/client/  \     #指定客户端请求时的主体临时目录
   --http-proxy-temp-path= /var/tmp/nginx/proxy/  \            #指定做代理服务器时的临时目录
   --http-fastcgi-temp-path= /var/tmp/nginx/fcgi/  \           #指定fcgi临时目录
   --http-uwsgi-temp-path= /var/tmp/nginx/uwsgi  \             #指定uwsgi临时目录(反向代理python开发的页面)
   --http-scgi-temp-path= /var/tmp/nginx/scgi  \               #另一种反向代理用户请求的协议
   --with-pcre                                               #指定pcre
# make && make install            #安装

4、为nginx提供SysV风格的脚本

   新建文件/etc/rc.d/init.d/nginx

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
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
# Source function library.
/etc/rc .d /init .d /functions
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
# Source networking configuration.
/etc/sysconfig/network
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
# Check that networking is up.
"$NETWORKING"  "no"  ] &&  exit  0
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
nginx= "/usr/local/nginx/sbin/nginx"
prog=$( basename  $nginx)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
NGINX_CONF_FILE= "/etc/nginx/nginx.conf"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
[ -f  /etc/sysconfig/nginx  ] && .  /etc/sysconfig/nginx
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
lockfile= /var/lock/subsys/nginx
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
make_dirs() {
    # make required directories
    user=`nginx -V 2>&1 |  grep  "configure arguments:"  sed  's/[^*]*--user=\([^ ]*\).*/\1/g'  -`
    options=`$nginx -V 2>&1 |  grep  'configure arguments:' `
    for  opt  in  $options;  do
        if  [ ` echo  $opt |  grep  '.*-temp-path' ` ];  then
            value=` echo  $opt |  cut  -d  "="  -f 2`
            if  [ ! -d  "$value"  ];  then
                # echo "creating" $value
                mkdir  -p $value &&  chown  -R $user $value
            fi
        fi
    done
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
start() {
     [ -x $nginx ] ||  exit  5
     [ -f $NGINX_CONF_FILE ] ||  exit  6
     make_dirs
     echo  -n $ "Starting $prog: "
     daemon $nginx -c $NGINX_CONF_FILE
     retval=$?
     echo
     [ $retval - eq  0 ] &&  touch  $lockfile
     return  $retval
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
stop() {
     echo  -n $ "Stopping $prog: "
     killproc $prog -QUIT
     retval=$?
     echo
     [ $retval - eq  0 ] &&  rm  -f $lockfile
     return  $retval
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
restart() {
     configtest ||  return  $?
     stop
     sleep  1
     start
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
reload() {
     configtest ||  return  $?
     echo  -n $ "Reloading $prog: "
     killproc $nginx -HUP
     RETVAL=$?
     echo
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
force_reload() {
     restart
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
configtest() {
   $nginx -t -c $NGINX_CONF_FILE
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
rh_status() {
     status $prog
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
rh_status_q() {
     rh_status > /dev/null  2>&1
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
case  "$1"  in
     start)
         rh_status_q &&  exit  0
         $1
         ;;
     stop)
         rh_status_q ||  exit  0
         $1
         ;;
     restart|configtest)
         $1
         ;;
     reload)
         rh_status_q ||  exit  7
         $1
         ;;
     force-reload)
         force_reload
         ;;
     status)
         rh_status
         ;;
     condrestart|try-restart)
         rh_status_q ||  exit  0
             ;;
     *)
         echo  $ "Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
         exit  2
esac

5、为服务脚本赋予执行权限

1
# chmod +x /etc/rc.d/init.d/nginx

6、把nginx服务添加至服务管理器,并让其开机自动启动

1
2
# chkconfig --add nginx
# chkconfig nginx on

7、启动服务并测试

1
2
3
# service nginx start
[root@nmshuishui ~] # ss -antlp | grep nginx
LISTEN     0      128                       *:80                       *:*       users :(( "nginx" ,4724,6),( "nginx" ,4726,6))

三、安装MariaDB(172.16.7.200)

1、二进制安装包

1
mariadb-10.0.10-linux-x86_64. tar .gz

2、安装步骤请参考我在LAMP博文中的链接

   http://nmshuishui.blog.51cto.com/1850554/1381822

四、安装php服务器(172.16.7.100)

1、安装nginx服务器

   同上第二步,安装完后测试一下

2、安装php服务器

(1)解决依赖关系

   事先已安装开发包组"Desktop Platform Development"

1
yum -y  install  libmcrypt libmcrypt-devel mhash mhash-devel mcrypt

(2)编译安装php-5.4.4

   安装完上面那几个还有报错,根据提示又安装了这几个

1
[root@shuishui php-5.4.4] # yum -y install libcurl-devel bzip2-devel libmcrypt-devel

   接下来再次编译安装

1
[root@shuishui php-5.4.4] #  ./configure --prefix=/usr/local/php --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml  --with-mhash --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd

(3)安装

1
[root@shuishui php-5.4.4] # make && make install

(4)为php提供配置文件

1
[root@shuishui php-5.4.4] # cp php.ini-production /etc/php.ini

(5)为php-fpm提供Sysv脚本,并将其添加到服务列表

1
2
3
4
[root@shuishui php-5.4.4] # cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@shuishui php-5.4.4] # chmod +x /etc/rc.d/init.d/php-fpm
[root@shuishui php-5.4.4] # chkconfig --add php-fpm
[root@shuishui php-5.4.4] # chkconfig php-fpm on

(6)为php-fpm提供配置文件

1
[root@shuishui php-5.4.4] # cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

(7)编辑php-fpm配置文件,配置fpm的相关选项,并启用pid

1
2
3
4
5
6
7
[root@shuishui ~] # vim /usr/local/php/etc/php-fpm.conf
pm.max_children = 150
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pid =  /usr/local/php/var/run/php-fpm .pid
listen = 172.16.7.100:9000

(8)启动php-fpm并验证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@shuishui ~] # service php-fpm start
Starting php-fpm .  done
[root@shuishui ~] # ps -aux | grep php-fpm
Warning: bad syntax, perhaps a bogus  '-' ? See  /usr/share/doc/procps-3 .2.8 /FAQ
root     60344  2.0  0.4  99684  4880 ?        Ss   01:28   0:00 php-fpm: master process ( /usr/local/php/etc/php-fpm .conf)        
nobody   60347  0.0  0.3  99684  3732 ?        S    01:28   0:00 php-fpm: pool www                                                
nobody   60348  0.0  0.3  99684  3732 ?        S    01:28   0:00 php-fpm: pool www                                                
nobody   60349  0.0  0.3  99684  3732 ?        S    01:28   0:00 php-fpm: pool www                                                
nobody   60350  0.0  0.3  99684  3732 ?        S    01:28   0:00 php-fpm: pool www                                                
nobody   60351  0.0  0.3  99684  3736 ?        S    01:28   0:00 php-fpm: pool www                                                
nobody   60352  0.0  0.3  99684  3736 ?        S    01:28   0:00 php-fpm: pool www                                                
nobody   60353  0.0  0.3  99684  3736 ?        S    01:28   0:00 php-fpm: pool www                                                
nobody   60354  0.0  0.3  99684  3736 ?        S    01:28   0:00 php-fpm: pool www                                                
root     60356  0.0  0.0 103244   856 pts /1     S+   01:28   0:00  grep  php-fpm

五、安装xcache,为php加速(172.16.7.100)

1、编译安装xcache

1
2
3
4
5
6
7
8
9
10
[root@shuishui ~] # tar xf xcache-3.0.1.tar.bz2
[root@shuishui ~] # cd xcache-3.0.1
[root@shuishui xcache-3.0.1] # /usr/local/php/bin/php
php         php-cgi     php-config  phpize
[root@shuishui xcache-3.0.1] # /usr/local/php/bin/phpize
Configuring  for :
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
[root@shuishui xcache-3.0.1] # ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config

结束后,会出现如下行

1
2
3
4
----------------------------------------------------------------------
Build complete.
Don 't forget to run ' make  test '.
Installing shared extensions:      /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/

2、编辑php.ini,整合php和xcache

(1)首先将xcache提供的样例配置导入php.ini

1
2
[root@shuishui xcache-3.0.1] # mkdir /etc/php.d
[root@shuishui xcache-3.0.1] # cp xcache.ini /etc/php.d/  #xcache.ini文件在xcache的源码目录中

(2)接下来修改/etc/php.d/xcache.ini,找到extension开头的行,修改为如下行:

1
extension =  /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache .so

3、重启php-fpm

1
2
3
[root@shuishui xcache-3.0.1] # service php-fpm restart
Gracefully shutting down php-fpm .  done
Starting php-fpm   done

六、整合nginx和php5

1、编辑/etc/nginx/nginx.conf(172.16.7.10)

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
worker_processes  2;  #worker进程的个数
error_log   /var/log/nginx/error .log  notice;     #错误日志路径及级别
events {
     worker_connections  1024;     #每个worker能够并发响应的最大请求数
}
http {
     include       mime.types;     #支持多媒体类型
     default_type  application /octet-stream ;
     sendfile        on;     #由内核直接转发
     #keepalive_timeout  0;
     keepalive_timeout  5;     #持久连接5s
     gzip   on;     #开启压缩功能
     server {
         listen       80;
         server_name  www.shuishui.com;
         add_header X-via $server_addr;     #让客户端能够看到代理服务器的IP
         location / {
             root   html;
             index  index.php index.html index.htm;
         }
         location ~* \.(jpg|jpeg|png|gif|js|css)$ {     #匹配以括号中结尾的格式
             root   html;     #默认目录在/usr/local/nginx/html
         }
         location ~ \.php$ {
             root                html;
             fastcgi_pass        172.16.7.100:9000;     #代理到的服务器
             fastcgi_index       index.php;
             fastcgi_param       SCRIPT_FILENAME scripts$fastcgi_script_name;
             include             fastcgi_params;
         }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
     }
}

2、编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容:(172.16.7.10)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fastcgi_param  GATEWAY_INTERFACE  CGI /1 .1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

3、重新载入nginx

1
2
3
4
[root@nmshuishui html] # service nginx reload
nginx: the configuration  file  /etc/nginx/nginx .conf syntax is ok
nginx: configuration  file  /etc/nginx/nginx .conf  test  is successful
Reloading nginx:                                           [  OK  ]

4、动、静分离测试

   前提:因为没有DNS服务器,所以事先要把www.shuishui.com所对应的IP:172.16.7.10写入到hosts文件中

(1)动态测试:在php服务器上的网页目录中创建index.php(172.16.7.100)

1
2
3
4
5
6
7
[root@shuishui html] # pwd
/usr/local/nginx/html
[root@shuishui html] # vim index.php
<h1>Welcome to php server(172.16.7.100)< /h1 >
<?php
         phpinfo();
?>

在windows主机上访问www.shuishui.com

wKioL1Ncv3_wOqAPAAECnEwqRXs864.png

(2)静态测试:在前端nginx服务器(172.16.7.10)的网页目录中放入1.png图片

1
2
3
4
[root@nmshuishui html] # pwd
/usr/local/nginx/html
[root@nmshuishui html] # ls
1.png  50x.html  index.html  index.html1  index.php

再到windows上去测试一下

wKiom1NcwFiCSuZLAAzGMWfm5SU285.png

由上面的动态、静态测试结果可看出,根据请求的资源类型的不同,即可实现动、静分离。因此,也知道了,网页目录需要准备两份,前端nginx服务器和后端的php服务器各需一份

七、安装Memcache服务器(172.16.7.201)

1、memcached简介

   Memcached是一款开源、高性能、分布式内存对象缓存系统,可应用各种需要缓存的场景,其主要目的是通过降低对Database的访问来加速web应用程序。它是一个基于内存的“键值对”存储,用于存储数据库调用、API调用或页面引用结果的直接数据,如字符串、对象等。

Memcached是一款开发工具,它既不是一个代码加速器,也不是数据库中间件。其设计哲学思想主要反映在如下方面:

(1)简单key/value存储:服务器不关心数据本身的意义及结构,只要是可序列化数据即可。存储项由“键、过期时间、可选的标志及数据”四个部分组成;

(2)功能的实现一半依赖于客户端,一半基于服务器端:客户负责发送存储项至服务器端、从服务端获取数据以及无法连接至服务器时采用相应的动作;服务端负责接收、存储数据,并负责数据项的超时过期;

(3)各服务器间彼此无视:不在服务器间进行数据同步;

(4)O(1)的执行效率


(5)清理超期数据:默认情况下,Memcached是一个LRU缓存,同时,它按事先预订的时长清理超期数据;但事实上,memcached不会删除任何已缓存数据,只是在其过期之后不再为客户所见;而且,memcached也不会真正按期限清理缓存,而仅是当get命令到达时检查其时长;

2、安装memcached服务器(172.16.7.201)

   也可以使用yum方式安装,这里使用编译安装

(1)安装libevent

   memcached依赖于libevent API,因此要事先安装

1
2
# yum groupinstall "Development Tools" "Server Platform Deveopment" -y
#yum install -y libevent-devel

(2)安装配置memcached

1
2
3
4
# tar xf memcached-1.4.15.tar.gz
# cd memcached-1.4.15
# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
# make && make install

(3)为memcached提供sysv脚本

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
#!/bin/bash
#
# Init file for memcached
#
# chkconfig: - 86 14
# description: Distributed memory caching daemon
#
# processname: memcached
# config: /etc/sysconfig/memcached
/etc/rc .d /init .d /functions
## Default variables
PORT= "11211"
USER= "nobody"
MAXCONN= "1024"
CACHESIZE= "64"
OPTIONS= ""
RETVAL=0
prog= "/usr/local/memcached/bin/memcached"
desc= "Distributed memory caching"
lockfile= "/var/lock/subsys/memcached"
start() {
         echo  -n $ "Starting $desc (memcached): "
         daemon $prog -d -p $PORT -u $USER -c $MAXCONN -m $CACHESIZE -o  "$OPTIONS"
         RETVAL=$?
         [ $RETVAL - eq  0 ] && success &&  touch  $lockfile || failure
         echo
         return  $RETVAL
}
stop() {
         echo  -n $ "Shutting down $desc (memcached): "
         killproc $prog
         RETVAL=$?
         [ $RETVAL - eq  0 ] && success &&  rm  -f $lockfile || failure
         echo
         return  $RETVAL
}
restart() {
         stop
         start
}
reload() {
         echo  -n $ "Reloading $desc ($prog): "
         killproc $prog -HUP
         RETVAL=$?
         [ $RETVAL - eq  0 ] && success || failure
         echo
         return  $RETVAL
}
case  "$1"  in
   start)
         start
         ;;
   stop)
         stop
         ;;
   restart)
         restart
         ;;
   condrestart)
         [ -e $lockfile ] && restart
         RETVAL=$?
         ;;
   reload)
         reload
         ;;
   status)
         status $prog
         RETVAL=$?
         ;;
    *)
         echo  $ "Usage: $0 {start|stop|restart|condrestart|status}"
         RETVAL=1
esac
exit  $RETVAL

(4)配置memcached成为系统服务

1
2
3
# chmod +x /etc/init.d/memcached
# chkconfig --add memcached
# service memcached start

(5)查看memcached监听端口是否成功

1
2
3
[root@shuishui ~] # ss -tnlp | grep 11211
LISTEN     0      128                      :::11211                   :::*       users :(( "memcached" ,3120,27))
LISTEN     0      128                       *:11211                    *:*       users :(( "memcached" ,3120,26))

八、安装php的memcache扩展(172.16.7.100)

1、安装php的memcache扩展

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@shuishui ~] # tar xf memcache-2.2.7.tgz
[root@shuishui ~] # cd memcache-2.2.7
[root@shuishui memcache-2.2.7] # /usr/local/php/bin/phpize
Configuring  for :
PHP Api Version:         20100412
Zend Module Api No:      20100525
Zend Extension Api No:   220100525
[root@shuishui memcache-2.2.7] # ./configure --with-php-config=/usr/local/php/bin/php-config --enable-memcache
     ……
     ……
[root@shuishui memcache-2.2.7] # make && make install
     ……
     ……
Build complete.
Don 't forget to run ' make  test '.
Installing shared extensions:      /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/

2、编辑/etc/php.ini,在“动态模块”相关的位置添加如下一行来载入memcache扩展:

1
extension= /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/memcache .so

3、重启php-fpm

1
2
3
[root@shuishui ~] # service php-fpm restart
Gracefully shutting down php-fpm .  done
Starting php-fpm   done

4、在windows客户端验证memcached是否安装成功

wKiom1Nc2PGQicAIAACKPpThYO0512.png

刚才的x-cache也安装成功了

5、对memcached功能进行测试,在网站目录中建立测试页面test.php,添加如下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@shuishui html] # pwd    #php服务器(172.16.7.100)
/usr/local/nginx/html
[root@shuishui html] # vim test.php
<?php
$mem = new Memcache;
$mem->connect( "172.16.7.201" , 11211)  or die( "Could not connect" );
$version = $mem->getVersion();
echo  "Server's version: " .$version. "<br/>\n" ;
$mem-> set ( 'hellokey' 'Hello World' , 0, 600) or die( "Failed to save data at the memcached server" );
echo  "Store data in the cache (data will expire in 600 seconds)<br/>\n" ;
$get_result = $mem->get( 'hellokey' );
echo  "$get_result is from memcached server." ;
?>
~

在windows服务器上测试,表明memcache已经能够正常工作

wKioL1Nc3-XAv81VAABW7likxFE673.png

由上图可以看出,memcached(172.16.7.201)已经可以正常工作了,到这里,基于动、静分离的LNMMP就已经实现了;下一步就是安装一个博客系统并监控其性能

九、安装wordpress和数据库授权前端nginx和后端的php都需要安装wordpress

1、在mysql数据库(172.16.7.200)中授权访问网段

1
2
3
4
5
MariaDB [(none)]> grant all on *.* to  'wordpress' @ '172.16.%.%'  identified by  'wordpress' ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]>
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

2、创建wordpress数据库,否则不让安装

1
MariaDB [(none)]> create database wordpress;

3、wordpress安装准备

1
2
3
4
5
6
7
[root@nmshuishui ~] # cd /usr/local/nginx/html/
[root@nmshuishui html] # unzip wordpress-3.2.1-zh_CN.zip
[root@nmshuishui html] # cd wordpress
[root@nmshuishui wordpress] # cp wp-config-sample.php wp-config.php
[root@nmshuishui wordpress] # vim wp-config.php  #需要在这里填入所需的数据库信息,这个还和Discuz不一样
[root@nmshuishui wordpress] # scp wp-config.php root@172.16.7.100:/usr/local/nginx/html/wordpress
#前端nginx和后端的php都需要安装wordpress,所以配置文件一保持一致

修改如下几项即可

wKiom1NdEmSQI4YIAABTBpVE_jo515.png

4、博客系统安装成功

wKioL1NdEmTRAG9xAAcTTN1NrVY336.png

十、安装memadmin-master查看memcached的状态信息

1、解压前端nginx和后端的php都需要解压安装memadmin-master

1
[root@shuishui html] # unzip memadmin-master.zip

2、连接memadmin-master

wKiom1NdEuSBYL_FAACdA2CHhlE638.png

3、查看memcached状态信息

wKiom1NdEv_jaz08AADXpXL1Sq8689.png










本文转自 nmshuishui 51CTO博客,原文链接:http://blog.51cto.com/nmshuishui/1403720,如需转载请自行联系原作者
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
11月前
|
存储 分布式计算 并行计算
计算存储分离架构
计算存储分离架构
|
存储 Java API
阿里高级技术专家谈开源DDD框架:COLA4.1,分离架构和组件(下)
阿里高级技术专家谈开源DDD框架:COLA4.1,分离架构和组件(下)
9450 2
阿里高级技术专家谈开源DDD框架:COLA4.1,分离架构和组件(下)
|
搜索推荐 前端开发 架构师
阿里高级技术专家谈开源DDD框架:COLA4.0,分离架构和组件(上)
阿里高级技术专家谈开源DDD框架:COLA4.0,分离架构和组件(上)
2530 0
阿里高级技术专家谈开源DDD框架:COLA4.0,分离架构和组件(上)
|
4月前
|
存储 关系型数据库 分布式数据库
【PolarDB开源】深入PolarDB内核:探究存储计算分离架构的设计哲学
【5月更文挑战第20天】PolarDB是阿里巴巴的云原生分布式数据库,以其存储计算分离架构为核心,解决了传统数据库的扩展性和资源灵活性问题。该架构将数据存储和计算处理分开,实现高性能(通过RDMA加速数据传输)、高可用性(多副本冗余保证数据可靠性)和灵活扩展(计算资源独立扩展)。通过动态添加计算节点以应对业务流量变化,PolarDB展示了其在云时代应对复杂业务场景的能力。随着开源项目的进展,PolarDB将持续推动数据库技术发展。
163 6
|
4月前
|
存储 Cloud Native 数据处理
Flink 2.0 状态管理存算分离架构演进
本文整理自阿里云智能 Flink 存储引擎团队负责人梅源在 Flink Forward Asia 2023 的分享,梅源结合阿里内部的实践,分享了状态管理的演进和 Flink 2.0 存算分离架构的选型。
1108 1
Flink 2.0 状态管理存算分离架构演进
|
2月前
|
存储 关系型数据库 分布式数据库
PolarDB,阿里云的云原生分布式数据库,以其存储计算分离架构为核心,解决传统数据库的扩展性问题
【7月更文挑战第3天】PolarDB,阿里云的云原生分布式数据库,以其存储计算分离架构为核心,解决传统数据库的扩展性问题。此架构让存储层专注数据可靠性,计算层专注处理SQL,提升性能并降低运维复杂度。通过RDMA加速通信,多副本确保高可用性。资源可独立扩展,便于成本控制。动态添加计算节点以应对流量高峰,展示了其灵活性。PolarDB的开源促进了数据库技术的持续创新和发展。
262 2
|
4月前
|
数据可视化 数据挖掘 数据管理
架构之争:数用一体VS数用分离,谁才是永远滴神
架构之争:数用一体VS数用分离,谁才是永远滴神
|
4月前
|
Linux API
Linux驱动的软件架构(三):主机驱动与外设驱动分离的设计思想
Linux驱动的软件架构(三):主机驱动与外设驱动分离的设计思想
80 0
|
存储 缓存 Apache
Apache Doris 巨大飞跃:存算分离新架构
Apache Doris 巨大飞跃:全新的存算分离架构正式推出,SeiectDB 未来将贡献至 Apache Doris 社区
Apache Doris 巨大飞跃:存算分离新架构
|
存储 固态存储 Cloud Native
【Paper Reading】PolarDB计算存储分离架构性能优化之路
本篇论文收录在 VLDB 2022,介绍了云原生数据库PolarDB在计算存储分离架构下遇到的性能挑战,分析了云存储相对于传统本地存储的工作特性差异及其根因,讨论了将各类存储引擎部署至云存储上时所会遇到的问题挑战,并提出了统一的优化框架 CloudJump。最后通过实验证明优化框架CloudJump适用于PolarDB,也适用于 RocksDB。
【Paper Reading】PolarDB计算存储分离架构性能优化之路

热门文章

最新文章