首页 文章 精选 留言 我的

精选列表

搜索[HTAP架构],共10000篇文章
优秀的个人博客,低调大师

在线抓娃娃的基本技术架构

线上视频抓娃娃风口正劲。用户可以通过手机遥控实体娃娃机,从正面与侧面两个视角判断爪子的位置,如果抓到了娃娃,可以选择寄送到家。短短几个月内,正式和即将上线的远程视频抓娃娃App和平台已有几十家,大有之前百团大战、百车大战、千播大战之势。 对于开发者来说,从日本红起来的抓娃娃由于其娱乐性、交互性,完全有可能成为下一个国民游戏,或成为泛娱乐产品的标配场景。然而,要抓住在线抓娃娃风口,尽快利用流量变现,需要一整套包含硬件和超低延迟的视频SDK的解决方案。 声网推出的视频抓娃娃全套解决方案,包括实时音视频SDK、娃娃机、控制板、摄像头、库房托管、娃娃采购、物流等服务,可以满足开发者的需求。声网抓娃娃整体解决方案已服务数十家主流抓娃娃厂商和平台,被市场验证。 接下来,就以声网的在线抓娃娃为例,为各位同学解读,在选择在线抓娃娃技术方案时,应该关注哪些要点。 一套完整的在线抓娃娃机解决方案包含以下部分: 必选: 娃娃机1台(为什么需要,不用解释了吧...) 摄像头2个以上(覆盖2个以上视角) PC机一台或工业主板一块,二选一 音视频传输软件方案 信令软件方案 在线抓娃娃App 可选: CDN云端 基本的业务流程 以声网的在线抓娃娃机解决方案为例,在线抓娃娃参与方有4个: 抓娃娃机 App操作端:操作抓娃娃 App高级观众端:低延时,可观看,可与操作端发起连麦,进行互动 App普通观众端:高延时,可观看 抓娃娃通过PC机或工业主板,连接摄像头,并集成实时音视频方案。在抓娃娃时: 抓娃娃机通过云端SD-RTN™,将视频流传输到操作端。 操作端通过信令,将操作指令,传输到抓娃娃机,进行操作。操作端可选择将自己的视频画面发送到云端。 抓娃娃机的画面,继续通过SD-RTN™,实时传输到操作端。 高级观众端,直接从SD-RTN™获取视频流。高级观众端可向操作端发起连麦,进行互动。 SD-RTN™可推一条rtmp的流至CDN云端,普通观众端可以获取这条高延时流进行观看,无法参与互动。 目前市场上,已经有一些线上抓娃娃整体解决方案,各自技术实现上有一些差异。线上抓娃娃解决方案,需要关注以下几个方面的差异: 一. 低延时 低延时是决定线上抓娃娃体验的核心关键点。线上抓娃娃的交互可概括为两类:信令传输操作指令和视频传输反馈图像。操纵者通过App通过信令来向抓娃娃机发送操作指令,由于数据包小,所以延时极低,可低达50ms,这一部分的开发较为简单。抓娃娃机向操纵端App传输视频流,操纵者通过观看视频,获得操作反馈结果。这部分视频实时传输的功能实现比较有技术难度,而且直接决定了延时高低。若视频传输延时过高,则用户的操作观感总有滞后感。 二.全平台支持 线上抓娃娃涉及到四方:娃娃机、娃娃机App操作端、娃娃机App高级观众端、娃娃机App普通观众端。 (一)娃娃机 目前市场上主要应用的方案有两种: 1)基于Windows平台 这种方案简易方法是,一台娃娃机配一台window电脑,连接两个摄像头,这两个摄像头安装在娃娃机的不同方位。通过Windows电脑来与App进行视频流传输。这种方案只涉及到软件开发和极少量的硬件改造,开发速度优势明显。 2)基于Android平台 在抓娃娃机上安装树莓派或工业主板,将安卓系统集成到主板上,摄像头也连接至主板。使用这种方案,成本较低,因为不需要配备电脑。但问题在于,首先,这种方案涉及到硬件改造,在硬件选配、集成上需要耗费一定时间。其次,安卓系统安装到工业主板上极不稳定,因此需要大量的调试、开发。 3)基于Linux平台 这种方案,相较Android平台的方案,区别在于,集成到主板上的操作系统是Linux,相对稳定。 在抓娃娃行业爆发的风口,速度就是一切。因此,一个新进入抓娃娃机市场的应用,应该首选Windows平台方案,占领市场。再通过Linux平台的方案,降低成本。 (二)娃娃机App操作端和观看端 声网的线上抓娃娃方案,操作端和观看端,均是全平台支持。尤其是用户量最大的Web端。通过Web端,既可以操作,也可以观看。这有助于抓娃娃新应用快速铺开市场。 三. 用户交互 用户与抓娃娃机的交互,主要有通过信令的的操作交互,和通过视频流的社交交互。操作交互的信令层开发,相对简单。视频流的社交交互是难点。 声网的抓娃娃机方案,是基于声网的视频SDK实现,支持操作者作为主播,发送自己的视频流。观看端可以看到操作者与娃娃机同屏的画面,甚至可以与操作者连麦进行音视频互动。这为线上抓娃娃扩展社交场景留下了空间。 目前,声网已与数十家抓娃娃机达成合作。可下载:乐抓、秒爪、哇叽哇叽体验声网在线抓娃娃技术方案。

优秀的个人博客,低调大师

通过ansible部署高可用LNAMMKP架构

主/备模式高可用keepalived+{nginx(proxy)|lvs} 两台主机:httpd+php+Discuz!+phpMyAdmin 一台主机:memcached用来缓存php的session; 一台主机:mysql-server或mariadb-server; 实验规划: 这里我规划用备用模式高可用两台keepalived+nginx(proxy)服务器作为前端代理,两台主机httpd+php+MariaDB+Discuz作为后端真实机,memcached放在第一台director上用来缓存php的session,最后用一台ansible主机实现对所有主机的部署调用。 ansible主机:172.16.1.7 director1(nginx+keepalived+memcached):172.16.1.10,虚拟ip:172.16.1.100 director2(nginx+keepalived):172.16.1.5 RS1(Apache+php+MariaDB):172.16.1.3 RS2(Apache+php+MariaDB):172.16.1.6 拓扑图如下: 注意: 1.把所有节点的防火墙和SElinux关闭,避免对实验干扰。 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 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 [root@zj07ansible] #tree . ├──ansible.cfg ├──files │└──nginx.conf ├──hosts ├──playbooks │├──amp.yml │├──first.retry │├──first.yml │├──ngx.retry │└──ngx.yml ├──roles │├──amp ││├──default ││├──files │││└──db.sh ││├──handlers ││├──tasks │││└──main.yml ││├──templates ││└──vars │├──keepalived ││├──default ││├──files ││├──handlers │││└──main.yml ││├──tasks │││└──main.yml ││├──templates │││└──keepalived.conf.j2 ││└──vars │├──memcached ││├──default ││├──files │││└──Discuz_X3.2_SC_UTF8.zip ││├──handlers │││└──main.yml ││├──tasks │││└──main.yml ││├──templates │││├──php.ini.j2 │││└──sessstore.php.j2 ││└──vars │├──memcached1 ││├──default ││├──files ││├──handlers ││├──tasks │││└──main.yml ││├──templates ││└──vars │└──nginx │├──default │├──files ││├──default.conf.j2 ││└──ip_forward.sh │├──handlers ││└──main.yml │├──tasks ││└──main.yml │├──templates ││├──nginx.conf.j2 ││└──nginx.repo.j2 │└──vars ├──zrs.retry └──zrs.yml 36directories,29files 下面开始部署 ------------------------------------------------------------------------------------------- 配置ansible主机 1.yum -y install ansible 2. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 vim /etc/ansible/hosts [knsrvs] 172.16.1.10STATE=MASTERPRI=100 172.16.1.5STATE=BACKUPPRI=98 [websrvs] 172.16.1.3 172.16.1.6 [memcached1] 172.16.1.10 [memcached] 172.16.1.3 172.16.1.6 3.建立免秘钥登陆,发给所以主机 ssh-keygen -t rsa -f .ssh/id_rsa -P '' ssh-copy-id -i .ssh/id_rsa.pub root@172.16.1.10 ssh-copy-id -i .ssh/id_rsa.pub root@172.16.1.5 ssh-copy-id -i .ssh/id_rsa.pub root@172.16.1.3 ssh-copy-id -i .ssh/id_rsa.pub root@172.16.1.6 ansible all -m ping测试连通性 4.在ansible主机上安装nginx和keepalived和php-fpm,以便ansible过程中需要使用其配置文件 ------------------------------------------------------------------------------------------- keepalived配置 1.mkdir /etc/ansible/roles/keepalived/{files,tasks,templates,handlers,vars,default} -pv 2.vim /etc/ansible/roles/keepalived/tasks/main.yml 3.vim /etc/ansible/roles/keepalived/handlers/main.yml 1 2 -name:restartkeepalivedserver service:name=keepalivedstate=restarted 4.复制刚才安装的keepalived主配置文件到指定目录,并修改如下 vim /etc/ansible/roles/keepalived/template/keepalived.conf.j2 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 !ConfigurationFile for keepalived global_defs{ notification_email{ root@localhost } notification_email_fromkeepalived@localhost smtp_server127.0.0.1 smtp_connect_timeout30 router_idnode1 vrrp_mcast_group4224.0.43.100 } vrrp_scriptngx_server{ script "killal-0nginx" interval1 weight-5 } vrrp_instanceVI_1{ state{{STATE}} interfaceeno16777736 virtual_router_id43 priority{{PRI}} advert_int1 track_scriptngx_server authentication{ auth_typePASS auth_passzrs66zrs } virtual_ipaddress{ 172.16.1.100 /32 brd172.16.1.100deveno16777736labeleno16777736:0 } } ------------------------------------------------------------------------------------------- nginx的配置: 1.mkdir /etc/ansible/roles/nginx/{files,tasks,templates,handlers,vars,default} -pv 2.vim /etc/ansible/roles/nginx/tasks/main.yml 3.vim /etc/ansible/roles/nginx/templates/nginx.repo.j2 1 2 3 4 5 [nginx] name=nginxrepo baseurl=http: //nginx .org /packages/centos/7/ $basearch/ gpgcheck=0 enabled=1 复制刚才安装的nginx主配置文件到指定目录,并修改如下 vim /etc/ansible/roles/nginx/templates/nginx.conf.j2 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 usernginx; worker_processes1; error_log /var/log/nginx/error .logwarn; pid /var/run/nginx .pid; events{ worker_connections1024; } http{ include /etc/nginx/mime .types; default_typeapplication /octet-stream ; log_formatmain '$remote_addr-$remote_user[$time_local]"$request"' '$status$body_bytes_sent"$http_referer"' '"$http_user_agent""$http_x_forwarded_for"' ; access_log /var/log/nginx/access .logmain; upstreamamp{ server172.16.1.3; server172.16.1.6; } server{ listen80; location/{ proxy_passhttp: //amp ; proxy_set_headerX-Real-IP$remote_addr; } } sendfileon; #tcp_nopushon; keepalive_timeout65; #gzipon; include /etc/nginx/conf .d/*.conf; } 4.复制刚才安装的nginx主配置文件到指定目录,并修改如下 vim /etc/ansible/roles/nginx/files/default.conf.j2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 server{ listen80default_server; server_namelocalhost; include /etc/nginx/default .d/*.conf; location/{ root /usr/share/nginx/html ; proxy_passhttp: //amp ; indexindex.htmlindex.htm; } error_page404 /404 .html; location= /404 .html{ root /usr/share/nginx/html ; } error_page500502503504 /50x .html; location= /50x .html{ root /usr/share/nginx/html ; } } 5.创建ip_forward脚本,开启前端代理服务器的核心转发功能 vim /etc/ansible/roles/nginx/files/ip_forward.sh 1 2 3 #!/bin/bash # echo >1 /proc/sys/net/ipv4/ip_forward ------------------------------------------------------------------------------------------- amp的配置: 1.mkdir /etc/ansible/roles/amp/{files,tasks,templates,handlers,vars,default} -pv 2.vim /etc/ansible/roles/amp/tasks/main.yml 3.创建testdb数据库,和授权用户访问 vim /etc/ansible/roles/amp/files/db.sh 1 2 3 4 5 6 #!/bin/bash # mysql-uroot-e" createdatabasetestdb; grantallontestdb.*TO 'testuser' @ 'localhost' IDENTIFIEDBY '123456' ; FLUSHPRIVILEGES;" ------------------------------------------------------------------------------------------- memcached配置 memcached缓存服务器为第一台调度器即172.16.1.10服务器,所以单独配置为memcached1 1.mkdir /etc/ansible/roles/memcached1/{files,tasks,templates,handlers,vars,default} -pv 2.vim /etc/ansible/roles/memcached1/tasks/main.yml 后端服务器上的配置 3.mkdir /etc/ansible/roles/memcached/{files,tasks,templates,handlers,vars,default} -pv 4.vim /etc/ansible/roles/memcached/tasks/main.yml 说明: 第二个任务:在本机安装php-fpm即可出现并修改/etc/php.ini该配置文件中的[Session]段中的缓存路径为如下, session.save_handler = memcache session.save_handler = "tcp://172.16.1.10:11211" 第四个任务:是建立一个缓存测试页面 vim /etc/ansible/roles/memcached/templates/sessstore.php 1 2 3 4 5 6 7 8 9 10 <?php $mem=newMemcache; $mem->connect( "172.16.1.10" ,11211)ordie( "Couldnotconnect" ); $version=$mem->getVersion(); echo "Server'sversion:" .$version. "<br/>\n" ; $mem-> set ( 'hellokey' , 'HelloWorld' ,0,600)ordie( "Failedtosavedataatthememcachedserver" ); echo "Storedatainthecache(datawillexpirein600seconds)<br/>\n" ; $get_result=$mem->get( 'hellokey' ); echo "$get_resultisfrommemcachedserver." ; ?> 第五个任务:将Discuz安装包放置在该目录下,传送到后端主机的指定目录。 第六个任务:解压该压缩包并赋予制定用户的权限 ------------------------------------------------------------------------------------------- 创建主配置文件,并且调用roles: vim /etc/ansible/zrs.yml 配置完成 先测试运行一下ansible-playbook --check zrs.yml,因为有的主机已经安装了某些软件,所以测试显示的是changed或者ok或者skipping 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 [root@zj07ansible] #ansible-playbook--checkzrs.yml PLAY[knsrvs]************************************************************************** TASK[GatheringFacts]***************************************************************** ok:[172.16.1.10] ok:[172.16.1.5] TASK[keepalived: install keepalived]************************************************* changed:[172.16.1.5] changed:[172.16.1.10] TASK[keepalived: install conf file ]************************************************** changed:[172.16.1.10] changed:[172.16.1.5] TASK[keepalived:startkeepalived]*************************************************** changed:[172.16.1.10] changed:[172.16.1.5] TASK[nginx:copynginxrepo]********************************************************* changed:[172.16.1.5] ok:[172.16.1.10] TASK[nginx: install nginx]*********************************************************** ok:[172.16.1.10] changed:[172.16.1.5] TASK[nginx:copyconf file ]********************************************************** changed:[172.16.1.10] changed:[172.16.1.5] TASK[nginx:reloadnginx]************************************************************ changed:[172.16.1.10] changed:[172.16.1.5] TASK[nginx:startnginx]************************************************************* changed:[172.16.1.5] ok:[172.16.1.10] TASK[nginx:ip_forward]************************************************************** changed:[172.16.1.5] changed:[172.16.1.10] RUNNINGHANDLER[keepalived:restartkeepalivedserver]******************************* changed:[172.16.1.5] changed:[172.16.1.10] PLAY[websrvs]************************************************************************* TASK[GatheringFacts]***************************************************************** ok:[172.16.1.6] ok:[172.16.1.3] TASK[amp: install apache-php-mysqlsomepackageonCentOS6]************************* skipping:[172.16.1.3]=>(item=[]) skipping:[172.16.1.6]=>(item=[]) TASK[amp: install apache-php-mysqlsomepackageonCentOS7]************************* ok:[172.16.1.6]=>(item=[u 'httpd' ,u 'mariadb-server' ,u 'php-fpm' ,u 'php-mysql' ]) changed:[172.16.1.3]=>(item=[u 'httpd' ,u 'mariadb-server' ,u 'php-fpm' ,u 'php-mysql' ]) TASK[amp:startapmserver]********************************************************** skipping:[172.16.1.3]=>(item=httpd) skipping:[172.16.1.3]=>(item=mysqld) skipping:[172.16.1.6]=>(item=httpd) skipping:[172.16.1.6]=>(item=mysqld) TASK[amp:startapmserver]********************************************************** changed:[172.16.1.6]=>(item=httpd) changed:[172.16.1.3]=>(item=httpd) changed:[172.16.1.6]=>(item=mariadb) changed:[172.16.1.3]=>(item=mariadb) PLAY[memcached1]********************************************************************** TASK[GatheringFacts]***************************************************************** ok:[172.16.1.10] TASK[memcached1: install memcached]************************************************** ok:[172.16.1.10] TASK[memcached1:startmemcached]**************************************************** changed:[172.16.1.10] PLAY[memcached]*********************************************************************** TASK[GatheringFacts]***************************************************************** ok:[172.16.1.6] ok:[172.16.1.3] TASK[memcached: install memcachedphpsession]*************************************** ok:[172.16.1.3] ok:[172.16.1.6] TASK[memcached:transferphpsessionconf]******************************************* changed:[172.16.1.3] changed:[172.16.1.6] TASK[memcached:reloadhttpd]******************************************************** changed:[172.16.1.6] changed:[172.16.1.3] TASK[memcached:copysessstore file ]************************************************* changed:[172.16.1.6] changed:[172.16.1.3] TASK[memcached:copydiscuz file ]**************************************************** changed:[172.16.1.6] changed:[172.16.1.3] TASK[memcached: tar discuz]********************************************************** changed:[172.16.1.6] changed:[172.16.1.3] PLAYRECAP***************************************************************************** 172.16.1.10:ok=14changed=8unreachable=0failed=0 172.16.1.3:ok=10changed=7unreachable=0failed=0 172.16.1.5:ok=11changed=10unreachable=0failed=0 172.16.1.6:ok=10changed=6unreachable=0failed=0 测试没问题,查看缓存页面是否成功,显示没问题。 开始运行 ansible-playbook zrs.yml 客户端查看,成功。 本文转自 Runs_ 51CTO博客,原文链接:http://blog.51cto.com/12667170/1981480,如需转载请自行联系原作者

优秀的个人博客,低调大师

消息提示的架构演进-理论篇

本文转自 virusswb 51CTO博客,原文链接:http://blog.51cto.com/virusswb/685995,如需转载请自行联系原作者项目是一个互联网应用。 假设项目有不同的用户群体,每个用户群体的前端都是一个独立的项目,交给不同的开发人员进行开发,前端和后端的交互方式选择 WebService 。 在前端和后端交互的过程中,主要有两类操作:一类是查询,包括返回单个记录和返回集合两种类型的查询;一类是命令,包括添加、删除、更新,当然,一次操作也可能是几个命令的组合请求。 第一类操作需要返回数据来显示,如果没有返回数据就会提示没有找到符合条件的数据。第二类操作,一般会影响后端的持久化数据,需要返回操作的结果,是成功还是失败,还是如何如何? 今天讨论的消息就是这种后端返回的操作结果,关于这种类型消息的设计,主要是这种消息在前段的处理、显示的相关设计。 刚开始,没有进行设计,每个项目的开发者自己设计自己的消息提示格式、提示内容和 UI 显示。有的人用浏览器的 alert ,有的人用前端框架的消息提示框,还有的在一个项目中两种提示都用了。提示的方式大都是在和后端交互,获得结果之后, new 一个消息框,然后直接 show 出来。提示的内容也都是硬编码(在 new 消息框的时候,使用构造函数初始化)。 当然了,刚开始大家都各自为战,加紧时间赶工期,也都没有在意这些事情。在第一个迭代周期的总结会上,大家提出了这个问题,做了个总结。发现上面的做法会带来以下一些问题。 消息提示内容的硬编码。多个相同类型是消息(例如提示操作成功),如果变更这个类型提示的内容,需要在很多地方修改,几乎苦不堪言。 消息框的初始化是散落在各个和后台交互的地方的,如果需要变更一下消息框的UI,也会造成需要多个地方的修改,已经苦不堪言了。 消息的逻辑代码和UI显示代码是混合在一起的,没有分离,导致无法单元测试。 对于上面的问题,大家讨论了一下,可以通过下面的重构进行改进。 首先,将消息分类,方便后面的处理。 对于硬编码的问题,根据类型,将相同类型的内容集中管理,达到复用和便于后期维护的作用。 集中管理消息框的初始化工作,也可以方便消息框UI的变更,可以通过引入工厂模式来解决。 分离消息的逻辑和UI显示代码,方便单元测试和UI的变更。 建立一个消息中心,集中管理消息框的初始化,以及消息的显示。 这么做的目的有以下几点: 消息处理的独立 消息处理的公用 分离消息处理的逻辑和消息内容的UI显示 消息管理的集中 经过整理,消息大概分为下面的几类 成功。正确完成一次请求。 提示。在完成请求的过程中,缺少必要条件,或者是某些条件发生变化,导致不能正确完成请求。 异常。在完成请求的过程中,发生了异常,包括:代码异常,网络异常等等。 在后面的实现中,准备引入面向接口的编程,将消息中心和消息的处理接口化,方便将来的替换。消息框的初始化引入工厂模式,实现初始化的集中管理,隔离消息框(标题,提示内容,按钮,按钮的操作)和消息框UI显示,为将来的UI变更预留空间。 今天先讨论到这里,关于实现以及代码会在后面几篇分开讲解。 大家如果有什么更好的建议,可以在后面留言给我,感谢大家的参与!!!

优秀的个人博客,低调大师

模拟WALMART网络架构-双栈冗余

SiteA and Site B 通信 SiteA: 192.168.1.X 192.168.3.X SiteB: 192.168.2.X 192.168.4.X =====MPLS Router Configuration===== R1 2 3 4 5 6 ====〉代表不同的MPLS 供应商 Step1:--MPLS域启用MPLS ip cef mpls ip mpls ldp router-id lo0 force mpls label protocol ldp int s0/0 mpls ip int s0/1 mpls ip Step2:---MPLS域 IGP通 router eigrp 80 no auto net 0.0.0.0 passive-interface f0/0 Step3:---MPLS域 PE接口启用VRF R1: ip vrf walmart rd 100:13 --->对方可以不一致,本地意义区分私网路由 route-target 100:79 -----〉对方必须一致 int f0/0 ip vrf forwarding walmart ip add R3: ip vrf walmart rd 100:31 route-target 100:79 int f0/0 ip vrf forwarding walmart ip add 验证show ip vrf detail [brief] R4:/R6: ip vrf walmart rd 200:46[200:64] route-target 200:81 int f0/0 ip vrf forwarding walmart ip add Step4:----MPLS域 MBGP R1: router bgp 100 bgp router-id 1.1.1.1 bgp log-neighbor-changes no bgp default ipv4-unicast \\起手配 neighbor 3.3.3.3 remote-as 100 neighbor 3.3.3.3 update-source Loopback0 ! ! address-family vpnv4------\\MP BGP neighbor 3.3.3.3 activate neighbor 3.3.3.3 send-community extended exit-address-family address-family ipv4 vrf walmart----- EBGP neighbor 17.1.1.7 remote-as 300 neighbor 17.1.1.7 activate exit-address-family R3: router bgp 100 bgp router-id 3.3.3.3 bgp log-neighbor-changes no bgp default ipv4-unicast neighbor 1.1.1.1 remote-as 100 neighbor 1.1.1.1 update-source Loopback0 ! ! address-family vpnv4 neighbor 1.1.1.1 activate neighbor 1.1.1.1 send-community extended exit-address-family address-family ipv4 vrf walmart----- EBGP neighbor 39.1.1.9 remote-as 300 neighbor 39.1.1.9 activate exit-address-family 验证: sh ip bgp vpnv4 vrf walmart summary R3#sh ip bgp vpnv4 all summary ============================================= R4: router bgp 200 bgp router-id 4.4.4.4 bgp log-neighbor-changes no bgp default ipv4-unicast neighbor 6.6.6.6 remote-as 200 neighbor 6.6.6.6 update-source Loopback0 ! ! address-family vpnv4 neighbor 6.6.6.6 activate neighbor 6.6.6.6 send-community extended address-family ipv4 vrf walmart neighbor 48.1.1.8 remote-as 300 neighbor 48.1.1.8 activate R6: router bgp 200 bgp router-id 6.6.6.6 bgp log-neighbor-changes no bgp default ipv4-unicast neighbor 4.4.4.4 remote-as 200 neighbor 4.4.4.4 update-source Loopback0 ! ! address-family vpnv4 neighbor 4.4.4.4 activate neighbor 4.4.4.4 send-community extended address-family ipv4 vrf walmart neighbor 61.1.1.1 remote-as 400 neighbor 61.1.1.1 activate =============================================== Step5:-CE BGP 300 /400 R7-CE#sh run | b r b router bgp 300 bgp router-id 7.7.7.7 bgp log-neighbor-changes neighbor 17.1.1.1 remote-as 100 no network 7.7.7.7 mask 255.255.255.255 R9-CE#sh run | b r b router bgp 400 bgp router-id 9.9.9.9 bgp log-neighbor-changes neighbor 39.1.1.3 remote-as 100 no network 9.9.9.9 mask 255.255.255.255 R7-CE#traceroute 9.9.9.9 source 7.7.7.7 Type escape sequence to abort. Tracing the route to 9.9.9.9 VRF info: (vrf in name/id, vrf out name/id) 1 17.1.1.1 60 msec 32 msec 52 msec 2 12.1.1.2 [MPLS: Labels 19/18 Exp 0] 44 msec 40 msec 52 msec 3 39.1.1.3 [MPLS: Label 18 Exp 0] 48 msec 52 msec 52 msec 4 39.1.1.9 48 msec 48 msec 52 msec 察看标签 R1#sh ip bgp vpnv4 vrf walmart 9.9.9.9 BGP routing table entry for 100:13:9.9.9.9/32, version 3 Paths: (1 available, best #1, table walmart) Advertised to update-groups: 2 400, imported path from 100:31:9.9.9.9/32 3.3.3.3 (metric 2809856) from 3.3.3.3 (3.3.3.3) Origin IGP, metric 0, localpref 100, valid, internal, best Extended Community: RT:100:79 mpls labels in/out nolabel/18 R1#sh ip bgp vpnv4 vrf walmart 7.7.7.7 BGP routing table entry for 100:13:7.7.7.7/32, version 4 Paths: (1 available, best #1, table walmart) Advertised to update-groups: 1 300 17.1.1.7 from 17.1.1.7 (7.7.7.7) Origin IGP, metric 0, localpref 100, valid, external, best Extended Community: RT:100:79 mpls labels in/out 18/nolabel R1#show mpls forwarding-table Local Outgoing Prefix Bytes tag Outgoing Next Hop tag tag or VC or Tunnel Id switched interface 16 Pop tag 23.1.1.0/24 0 Se0/0 point2point 17 Pop tag 2.2.2.2/32 0 Se0/0 point2point 18 Untagged 7.7.7.7/32[V] 2796 Fa0/0 17.1.1.7 19 19 3.3.3.3/32 0 Se0/0 point2point =================================内网HSRP====================== R7-CE#sh run int f1/0.1 Building configuration... Current configuration : 206 bytes ! interface FastEthernet1/0.1 encapsulation dot1Q 1 native ip address 192.168.1.251 255.255.255.0 standby 1 ip 192.168.1.1 standby 1 priority 120 standby 1 preempt standby 1 track 1 decrement 30 end R7-CE#sh run int f1/0.3 Building configuration... Current configuration : 199 bytes ! interface FastEthernet1/0.3 encapsulation dot1Q 3 ip address 192.168.3.251 255.255.255.0 standby 3 ip 192.168.3.1 standby 3 priority 120 standby 3 preempt //开启抢占 standby 3 track 1 decrement 30 \\如果接口down了优先级减30 end R8-CE#sh run int f1/0.1 Building configuration... Current configuration : 182 bytes ! interface FastEthernet1/0.1 encapsulation dot1Q 1 native ip address 192.168.1.252 255.255.255.0 standby 1 ip 192.168.1.1 standby 1 preempt //standby 1 track 1 decrement 30 R8-CE#sh run int f1/0.3 Building configuration... Current configuration : 175 bytes ! interface FastEthernet1/0.3 encapsulation dot1Q 3 ip address 192.168.3.253 255.255.255.0 standby 3 ip 192.168.3.1 standby 3 preempt //standby 3 track 1 decrement 30 end =================CE IBGP============================= R7-CE#sh run | b r r router rip version 2 network 7.0.0.0 network 78.0.0.0 no auto-summary ! router bgp 300 bgp router-id 7.7.7.7 bgp log-neighbor-changes network 192.168.1.0 network 192.168.3.0 neighbor 8.8.8.8 remote-as 300 neighbor 8.8.8.8 update-source Loopback0 neighbor 8.8.8.8 next-hop-self neighbor 17.1.1.1 remote-as 100 R8-CE#sh run | b r r router rip version 2 network 8.0.0.0 network 78.0.0.0 no auto-summary ! router bgp 300 bgp router-id 8.8.8.8 bgp log-neighbor-changes neighbor 7.7.7.7 remote-as 300 neighbor 7.7.7.7 update-source Loopback0 neighbor 7.7.7.7 next-hop-self neighbor 48.1.1.4 remote-as 200 R7-CE#sh ip bgp BGP table version is 5, local router ID is 7.7.7.7 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path * i 192.168.1.0 8.8.8.8 0 100 0 i *> 0.0.0.0 0 32768 i *> 192.168.2.0 17.1.1.1 0 100 400 i * i 8.8.8.8 0 100 0 200 400 i * i 192.168.3.0 8.8.8.8 0 100 0 i *> 0.0.0.0 0 32768 i *> 192.168.4.0 17.1.1.1 0 100 400 i * i 8.8.8.8 0 100 0 200 400 i 但R7-R8不希望学习到内部路由192.168.1.0 192.168.3.0,我们可以过滤掉 IBGP 过滤内网路由 R7-CE#sh run | be ip prefix-list ip prefix-list deny seq 5 permit 192.168.1.0/24 ip prefix-list deny seq 10 permit 192.168.3.0/24 R7-CE#sh run | be route-map route-map block deny 10 match ip address prefix-list deny ! route-map block permit 20 R7: router bgp 300 neighbor 8.8.8.8 route-map block in R8: router bgp 300 neighbor 7.7.7.7 route-map block in R7-CE#sh ip bgp BGP table version is 5, local router ID is 7.7.7.7 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter, x best-external, a additional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 192.168.1.0 0.0.0.0 0 32768 i * i 192.168.2.0 8.8.8.8 0 100 0 200 400 i *> 17.1.1.1 0 100 400 i *> 192.168.3.0 0.0.0.0 0 32768 i * i 192.168.4.0 8.8.8.8 0 100 0 200 400 i *> 17.1.1.1 0 100 400 i ======BUYTRIP场地 & internet========= R15: R15#sh run | b r e router eigrp 80 network 15.0.0.0 network 57.0.0.0 no auto-summary R7: ip route 0.0.0.0 0.0.0.0 61.1.1.6 R7-CE#sh run | b r b router bgp 300 redistribute eigrp 80 metric 400 network 0.0.0.0 mask 0.0.0.0 R7-CE#sh run | b r e router eigrp 80 network 57.0.0.0 redistribute bgp 300 metric 1000 100 255 1 1500 redistribute static R8: router bgp 300 bgp router-id 8.8.8.8 bgp log-neighbor-changes network 192.168.1.0 network 192.168.3.0 redistribute static metric 300 neighbor 7.7.7.7 remote-as 300 neighbor 7.7.7.7 update-source Loopback0 neighbor 7.7.7.7 next-hop-self neighbor 7.7.7.7 route-map block in neighbor 48.1.1.4 remote-as 200 EIGRP本地优化: access-list 10 permit 0.0.0.0 0.0.0.0 router ei 80 distribute-list 10 in fastEthernet 1/0 本文转自 bilinyee博客,原文链接: http://blog.51cto.com/ericfu/1963262 如需转载请自行联系原作者

优秀的个人博客,低调大师

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

一、前提说明 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): 二、安装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 (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上去测试一下 由上面的动态、静态测试结果可看出,根据请求的资源类型的不同,即可实现动、静分离。因此,也知道了,网页目录需要准备两份,前端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是否安装成功 刚才的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已经能够正常工作 由上图可以看出,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,所以配置文件一保持一致 修改如下几项即可 4、博客系统安装成功 十、安装memadmin-master查看memcached的状态信息 1、解压(前端nginx和后端的php都需要解压安装memadmin-master) 1 [root@shuishui html] # unzip memadmin-master.zip 2、连接memadmin-master 3、查看memcached状态信息 本文转自 nmshuishui 51CTO博客,原文链接:http://blog.51cto.com/nmshuishui/1403720,如需转载请自行联系原作者

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码