LEMP架构实现

本实验用到的架构图,如下所示:

简单介绍本次实验架构的数据流向:

首先client向A服务器发起网页请求,A接到请求,首先查看memcached是否有请求的内容,如果有就返回给client,如果memcached中没有,则A查询B服务器中client的请求响应缓存到memcached中一份,同时再响应给客户端,如果在一定时长内,client再次发起的同样的请求,A服务器直接将缓存响应给client,简单理解。

环境安装

A服务器安装memcached

yum install -y memcached

查看安装后的内容为:

[[email protected] ~]# rpm -ql memcached
/etc/rc.d/init.d/memcached  ##sysV风格服务启动脚本
/etc/sysconfig/memcached   ##软件默认配置文件
/usr/bin/memcached    ##可执行文件(后面简单介绍使用方法)
/usr/bin/memcached-tool ##可执行文件(后面简单介绍使用方法)
/usr/share/doc/memcached-1.4.4
/usr/share/doc/memcached-1.4.4/AUTHORS
/usr/share/doc/memcached-1.4.4/CONTRIBUTORS
/usr/share/doc/memcached-1.4.4/COPYING
/usr/share/doc/memcached-1.4.4/ChangeLog
/usr/share/doc/memcached-1.4.4/NEWS
/usr/share/doc/memcached-1.4.4/README
/usr/share/doc/memcached-1.4.4/protocol.txt
/usr/share/doc/memcached-1.4.4/readme.txt
/usr/share/doc/memcached-1.4.4/threads.txt
/usr/share/man/man1/memcached.1.gz
/var/run/memcached  #运行时信息存放目录,pid文件

查看/etc/sysconfig/memcached

[[email protected] ~]# cat /etc/sysconfig/memcached
PORT="11211" #memcache默认端口
USER="memcached" #默认用户
MAXCONN="1024" #最大缓存的链接数,通常要此参数修改
CACHESIZE="64" #缓存所占用的内存空间,单位为Mb,通常要修改
OPTIONS=""

B服务器的软件安装

nginx软件安装具体版本为nginx-1.4.7

# groupadd -r nginx
# useradd -r -g nginx nginx
# ./configure   --prefix=/usr/local/nginx   --sbin-path=/usr/local/nginx/sbin/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    --lock-path=/var/lock/nginx.lock   --user=nginx   --group=nginx   --with-http_ssl_module   --with-http_flv_module   --with-http_stub_status_module   --with-http_gzip_static_module   --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/   --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi   --http-scgi-temp-path=/var/tmp/nginx/scgi   --with-pcre
# make && make install

增加nginx启动脚本

#vim /etc/rc.d/init.d/nginx
#增加以下内容
#!/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/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

后续操作

# chmod +x /etc/rc.d/init.d/nginx  #加执行权限
# chkconfig --add nginx #加到服务列表
# chkconfig nginx on  #开机自启
# service nginx start 测试启动

安装php-fpm,让php工作于(简单)服务器模式,具体版本php-5.4.26

#yum groupinstall -y "Development Tools" "Server Platform Developments" "Server Platform Development"  #解决php安装过程中的包依赖
#tar -xf php-5.4.26.tar.bz2
#cd php-5.4.26
#./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sockets --enable-sysvshm  --with-mysqli=/usr/local/mysql/bin/mysql_config --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

提供php配置文件

# cp php.ini-production /etc/php.ini

增加php-fpm服务启动脚本,并添加至服务列表

# cp sapi/fpm/init.d.php-fpm  /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on

修改php-fpm提供的配置文件

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

调整php-fpm相关的参数,如下所示:

#cd /usr/local/php/etc
##############最修改的结果如下所示#################
[[email protected] etc]# grep -v ‘^$‘ php-fpm.conf |grep -v ‘^;‘|grep -v ‘^[[:space:]].*‘
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /var/log/php-fpm.log
[www]
user = nobody
group = nobody
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 128
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 5
pm.max_requests = 500
pm.status_path = /status
ping.path = /ping
ping.response = pong
rlimit_files = 10240

启动服务

# service php-fpm start

nginx与php5的整合

编辑/etc/nginx/nginx.conf,启用如下选项

只显示修改后的内容

方式

[[email protected] nginx]# grep -v ‘^[[:space:]].*#‘ nginx.conf |grep -v ‘^$‘
worker_processes  1;  #默认启动的进程线
events {
    worker_connections  1024;#连接并发数
}
http {
    include       mime.types; #支持的文件类型
    default_type  application/octet-stream;
    sendfile        on; #支持直接从内核空间返回响应给客户
    keepalive_timeout  65; #长连接时长
    fastcgi_cache_path /tmp levels=1:2 keys_zone=fcgi:50m max_size=1g inactive=12h;
    ##缓存文件存放路径,目录层次(目录结构),定义键值域名称 最大缓存空间1G,非活动时间12小时
    server {
        listen       80; #监听端口
        server_name  www.mytest.com; #虚拟主机
        location / {   URL上下言语
            root   /mydata/htdocshare; #htdoc在本地系统的路径
            index  index.php index.html index.htm; 默认首页索引文件
        }
        error_page   500 502 503 504  /50x.html; #不同出错代码所做出的网页跳转后显示的页面
        location = /50x.html { #定义具体的出错页面路径
            root   html;
        }
        location ~* /(status|ping) { #完全匹配字符
            root           /mydata/htdocshare; #匹配后跳转路径及处理方式
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_param  SCRIPT_FILENAME  /$fastcgi_script_name;
            auth_basic "admin area"; #认证提示框信息
            auth_basic_user_file /etc/nginx/.htpswd; #引用存放用户名称的文件
        include        fastcgi_params; #引用此文件中变量,此文件内容可以简单理解为nginx中的变量与fastcgi中的变量的一一对应关系(名称),从nginx传递过来的变量,fastcgi可以理解并认识
    }
        location ~ \.php$ { #用户访问php页面时所做出的处理方式,转给fastcgit程序处理
            root           /mydata/htdocshare;
            fastcgi_pass   127.0.0.1:9000; #php-fpm监听的路径与端口
            fastcgi_index  index.php; #索引页
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }

    }
}

编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容,此文件作用就是fastcgi中的变量与nginx中的变量能够相互转换。

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;

安装xcache为PH加速

# tar xf xcache-3.1.0.tar.bz2
# cd xcache-3.1.0
# /usr/local/php/bin/phpize
# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
# make && make install
安装完出现类似如下行:
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
首先将xcache提供的样例配置导入php.ini
#
# cp /software/xcache-3.1.0/xcache.ini /etc/php.d
接下来编辑xcache.ini 文件增加以下内容
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so

MariaDB安装

#useradd -r mysql
#mkdir /mydata/data -pv
#chown -R mysql.mysql /mydata/data
#tar -xf mariadb-10.0.10-linux-x86_64.tar.gz -C /usr/local
#cd /usr/local
#ln -sv mariadb-10.0.10-linux-x86_64 mysql
#cd mysql
#chown -R root.mysql ./*
#scripts/mysql_install_db --datadir=/mydata/data --user=mysql
# cd /usr/local/mysql
# cp support-files/my-large.cnf  /etc/my.cnf
##编辑my.cnf,增加以下内容
innodb_file_per_table=on
datadir = /mydata/data
为mysql增加服务启动脚本
# cd /usr/local/mysql
# cp support-files/mysql.server  /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
启动mysql
service mysqld start

新建测试页面来测试缓存服务器是否起作用

<?php
$mem = new Memcache;
$mem->connect("172.16.251.24", 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.";
?>

LEMP架构实现,布布扣,bubuko.com

时间: 2024-12-14 11:39:41

LEMP架构实现的相关文章

LEMP架构及应用部署

LEMP架构及应用部署 LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际流行的Web框架,该框架包括:Linux操作系统,Apache网络服务器,MySQL数据库,Perl.PHP或者Python编程语言,所有组成产品均是开源软件,是国际上成熟的架构框架,很多流行的商业应用都是采取这个架构,和 Java/J2EE架构相比,LAMP具有Web资源丰富.轻量.快速开发等特点,与微软的.NET架构相比,LAMP具有通用.跨平台.高性能.低价格的优势,因此LAMP无论是性能.质

Nginx网站服务器的安装及LEMP平台应用

1,  编译及安装Nginx1)       安装支持软件[[email protected] ~]# yum -y install pcre-devel zlib-devel注意:安装pcre是为了使nginx支持HTTP rewrite模块.2)创建程序用户和程序组[[email protected] ~]# useradd -M -s /sbin/nologin nginx3)编译安装Nginx[[email protected] ~]# cd /aaa/[[email protected

基于centos 7搭建LNMP架构

我们都知道的是LAMP平台时目前应用最为广泛的网站服务器架构,其中的"A"对应着web服务软件的Apache ,但是,现在随着时间的推移,越来越多的企业开始使用Nginx这匹黑马,LNMP或LEMP架构也收到越来越多的运维攻城狮的青睐.闲来无事,就写一下LNMP架构的搭建吧!一. 准备工作: ? centos7服务器一台及系统镜像: ? 安装mysql数据库,可参考博文:https://blog.51cto.com/14154700/2394026 : ? 部署Nginx网站服务器,参

CentOS 6.2 LNMP 环境搭建优化笔记

首先从centos 官方下载DVD镜像: 安装的时候才用文本安装模式: 文本安装模式的进入方法: 当出现选择菜单时:按ESC,输入 linux text 回车进入文本安装模式. 文本安装模式下centos为了弥补某些bug,所以不支持手动分区,默认就可以了.(以下介绍部分为转载) 系统安装教程:CentOS 6.2安装(超级详细图解教程): http://www.osyunwei.com/archives/1537.html 一.配置好IP.DNS .网关,确保使用远程连接工具能够连接服务器 C

快还要更快,让PHP 7 运行更加神速

导读 PHP 7 比5.x 快上很多,即使只有单纯的版本升级就已经很有感,不过大家还是希望它变得越来越快,这时再做些小调整就会更有fu,Let's try it! 事前准备 说到PHP 7,那一定跑不了LAMP 或是LEMP,请先准备好底层服务的安装. [CentOS 7] 整合Apache.MySQL.PHP 7 组成LAMP Server [CentOS 7] 整合Nginx.MariaDB.PHP 7 组成LEMP Server 以前我们要让PHP加快处理速度,通常会配合APC.eAcce

LNMP架构

1.1 1.1.1 LNMP介绍 大约在2010年以前,互联网公司最常用的经典Web服务环境组合就是LAMP(即 Linux.Apache.MySQL.PHP),近几年随着Nginx   Web服务的逐渐流行,又出现了 新的Web服务环境组合--LNMP或LEMP,其中LNMP为Linux.Nginx.MySQL. PHP等首字母的缩写,而LNMP中的E则表示Nginx,它取自Nginx名字的发音 (enginex).现在,LNMP已经逐渐成为国内大中型互联网公司网站的主流组合环境,因 此,我们

Centos 7 部署lnmp集群架构

前言介绍 lnmp的全程是 linux + nginx + mysql + php; lnmp就是上述系统及应用程序的简写组合: lnmp其实已经代表了一个用户正常对一个页面请求的流程,nginx接收请求,mysql进行数据存储,php进行后端处理:类似的架构还有lamp或者 linux + nginx + mysql + java等等: lnmp又叫lemp,外国人喜欢叫lemp,中国人喜欢叫lnmp: lnmp相比于lamp架构的优势在于轻便.操作相对简单:lamp优势相对于nginx而言模

Centos 7搭建LNMP架构及部署Discuz论坛

一.LNMP架构及应用部署 众所周知,LAMP平台时目前应用最为广泛的网站服务器架构,其中的"A"对应着web服务软件的Apache HTTP Server ,随着Nginx在工作环境中的使用越来越多,LNMP(或LEMP)架构也受到越来越多的Linux运维工程师的青睐. 就像构建LAMP平台一样,构建LNMP平台也需要Linux服务器.MySQL数据库.PHP解析环境,区别主义在于Nginx与PHP的协作配置上. 准备工作 Centos 7操作系统一台:Windows 客户端一台:案

下载-深入浅出Netty源码剖析、Netty实战高性能分布式RPC、NIO+Netty5各种RPC架构实战演练三部曲视频教程

下载-深入浅出Netty源码剖析.Netty实战高性能分布式RPC.NIO+Netty5各种RPC架构实战演练三部曲视频教程 第一部分:入浅出Netty源码剖析 第二部分:Netty实战高性能分布式RPC 第三部分:NIO+Netty5各种RPC架构实战演练