日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

memcache

發布時間:2023/11/27 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 memcache 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

nginx+php+memcache緩存?

圖解:

?

?

[root@test5 ~]# /etc/init.d/iptables stop

[root@test5 ~]# nginx
[root@test5 ~]# /etc/init.d/php-fpm start
Starting php-fpm? done

[root@test5 ~]# tar zxf memcache-2.2.5.tgz

[root@test5 ~]# cd memcache-2.2.5

[root@test5 memcache-2.2.5]# ls

[root@test5 memcache-2.2.5]# cd ~

[root@test5 ~]# vim .bash_profile


[root@test5 ~]# source .bash_profile
[root@test5 ~]# cd memcache-2.2.5
[root@test5 memcache-2.2.5]# phpize

[root@test5 memcache-2.2.5]# ./configure?????????????????????? //編譯第一步

[root@test5 memcache-2.2.5]# make??????????????????????????????? //編譯第二步

[root@test5 memcache-2.2.5]# make install????????????????????? //編譯第三步

?

memcache配置:

[root@test5 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm? done
[root@test5 etc]# php -m |grep memcache
[root@test5 etc]# cd
[root@test5 ~]# yum install -y memcached

[root@test5 html ]# cat /etc/sysconfig/memcached

?[root@test5 ~]# /etc/init.d/memcached start
Starting memcached:??????????????????????????????????????? [? OK? ]
[root@test5 ~]# cd memcache-2.2.5

[root@test5 memcache-2.2.5]# cp memcache.php example.php /usr/local/lnmp/nginx/html/

[root@test5 memcache-2.2.5]# cd /usr/local/lnmp/nginx/html/
[root@test5 html]# ls

[root@test5 html ]# cat /etc/sysconfig/mecached

[root@test5 html ]# netstat -atunlp

[root@test5 html]# yum install telnet -y

[root@test5 html]# /usr/local/lnmp/nginx/html

[root@test5 html]# ls
50x.html? bbs? example.php? index.php? memcache.php? readme? utility

[root@test5 html]# vim memcache.php

[root@test5 ~]# /etc/init.d/memcached restart

瀏覽器上測試:

高并發壓力測試:

[root@test5 ~]# ab -c 10 -n 1000 http://172.25.1.5/index.php

[root@test5 ~]# ab -c 10 -n 1000 http://172.25.1.5/example.php

說明:

???????? example.php的頁面緩存中不存在,所以直接訪問了服務器,以至時間比較長;而index.php在memcache中有緩存,頁面是緩存,以至時間比較短。

?

nginx加緩存

OpenResty:

???????????????? 是一個基于 Nginx 與 Lua 的高性能 Web 平臺,其內部集成了大量精良的 Lua 庫、第三方模塊以及大多數的依賴項。用于方便地搭建能夠處理超高并發、擴展性極高的動態 Web 應用、Web 服務和動態網關。OpenResty的目標是讓你的Web服務直接跑在 Nginx 服務內部,充分利用 Nginx 的非阻塞 I/O 模型,不僅僅對 HTTP 客戶端請求,甚至于對遠程后端諸如 MySQL

PostgreSQL、Memcached 以及 Redis 等都進行一致的高性能響應。

?

[root@test5 ~]# tar zxf openresty-1.13.6.1.tar.gz
[root@test5 ~]# cd openresty-1.13.6.1
[root@test5 openresty-1.13.6.1]# ./configure --help????????????????? //用來查看需要編譯的內容

[root@test5 openresty-1.13.6.1]# ./configure --prefix=/opt/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio

[root@test5 openresty-1.13.6.1]# gmake && gmake install

[root@test5 openresty-1.13.6.1]# cd /opt/nginx/
[root@test5 nginx]# ls
bin? COPYRIGHT? luajit? lualib? nginx? pod? resty.index? site
[root@test5 nginx]# cd nginx/
[root@test5 nginx]# cd conf/
[root@test5 conf]# ls
fastcgi.conf??????????? koi-win???????????? scgi_params
fastcgi.conf.default??? mime.types????????? scgi_params.default
fastcgi_params????????? mime.types.default? uwsgi_params
fastcgi_params.default? nginx.conf????????? uwsgi_params.default
koi-utf???????????????? nginx.conf.default? win-utf

[root@test5 conf]# cp /usr/local/lnmp/nginx/conf/nginx.conf .
cp: overwrite `./nginx.conf'? y
[root@test5 conf]# /opt/nginx/nginx/sbin/nginx -t

[root@test5 conf]# /usr/local/lnmp/nginx/sbin/nginx

網頁訪問172.25.1.5:

[root@test5 conf]# cd ..
[root@test5 nginx]# cd html/
[root@test5 html]# ls
50x.html? index.html
[root@test5 html]# cp /usr/local/lnmp/nginx/html/example.php .
[root@test5 html]# cp /usr/local/lnmp/nginx/html/index.php .

#user? nobody;
worker_processes? 1;

#error_log? logs/error.log;
#error_log? logs/error.log? notice;
#error_log? logs/error.log? info;

#pid??????? logs/nginx.pid;


events {
??? worker_connections? 1024;
}


http {
?????? upstream memcache {
?????? server localhost:11211;
?????? keepalive 512;
?????? }
??? include?????? mime.types;
??? default_type? application/octet-stream;

#log_format? main? '$remote_addr - $remote_user [$time_local] "$request" '
??? #????????????????? '$status $body_bytes_sent "$http_referer" '
??? #????????????????? '"$http_user_agent" "$http_x_forwarded_for"';

??? #access_log? logs/access.log? main;

??? sendfile??????? on;
??? #tcp_nopush???? on;

??? #keepalive_timeout? 0;
??? keepalive_timeout? 65;

??? #gzip? on;

??? server {
??????? listen?????? 80;
??????? server_name? localhost;

??????? #charset koi8-r;

??????? #access_log? logs/host.access.log? main;

location / {
????????????? root?? html;
????????????? index? index.php index.html index.htm;
????????? }

?????????? location /memc {
?????????? internal;
?????????? memc_connect_timeout 100ms;
?????????? memc_send_timeout 100ms;
?????????? memc_read_timeout 100ms;
?????????? set $memc_key $query_string;
?????????? set $memc_exptime 300;
?????????? memc_pass memcache;
?????????? }
?????????? #error_page 404????????????????? /404.html;

?????????? # redirect server error pages to the static page /50x.html
?????????? #
?????????? error_page?? 500 502 503 504? /50x.html;
?????????? location = /50x.html {
?????????? root?? html;
?????????? }

?#location ~ \.jsp$ {
?????????? #???? proxy_pass http://127.0.0.1;?? ?
?????????? #}

?????????? location ~ \.php$ {
??????????????? set $key $uri$args;
??????????????? srcache_fetch GET /memc $key;
??????????????? srcache_store PUT /memc $key;

??????????????? root?????????? html;
??????????????? fastcgi_pass?? 127.0.0.1:9000;
??????????????? fastcgi_index? index.php;
??????????????? # fastcgi_param? SCRIPT_FILENAME? /scripts$fastcgi_script_name;
??????????????? include??????? fastcgi.conf;
??????????????? }
??????? # deny access to .htaccess files, if Apache's document root
??????? # concurs with nginx's one
??????? #
??????? #location ~ /\.ht {
??????? #??? deny? all;
??????? #}
??? }

?# another virtual host using mix of IP-, name-, and port-based configuration
??? #
??? #server {
??? #??? listen?????? 8000;
??? #??? listen?????? somename:8080;
??? #??? server_name? somename? alias? another.alias;

??? #??? location / {
??? #??????? root?? html;
??? #??????? index? index.html index.htm;
??? #??? }
??? #}


??? # HTTPS server
??? #
??? #server {
??? #??? listen?????? 443 ssl;
??? #??? server_name? localhost;

??? #??? ssl_certificate????? cert.pem;
??? #??? ssl_certificate_key? cert.key;

??? #??? ssl_session_cache??? shared:SSL:1m;
??? #??? ssl_session_timeout? 5m;

??? #??? ssl_ciphers? HIGH:!aNULL:!MD5;
??? #??? ssl_prefer_server_ciphers? on;

??? #??? location / {
??? #??????? root?? html;
??? #??????? index? index.html index.htm;
??? #??? }
??? #}

//配置文件的內容

?

客戶端測試:

[root@foundation1 dd]# ab -c 10 -n 1000 http://172.25.1.5/index.php

[root@foundation1 dd]# ab -c 10 -n 1000 http://172.25.1.5/example.php

?

nginx+tomcat+memcache緩存

圖解:

?

環境:

nginx:test5(172.25.1.5)????? tomcat1:test5(172.25.1.5)?????? tomcat2:test6(172.25.1.6)?????

memcache1:test5(172.25.1.5)???? memcache2:test6(172.25.1.6)

test5:搭建nginx、tomcat、memcache服務

test6:搭建tomcat、memcache服務

Tomcat簡介: ?

?????? Tomcat 服務器是一個免費的開放源代碼的Web 應用服務器,屬于輕量級應用服務器,在中小型系統和并發訪問用戶不是很多的場合下被普遍使用,是開發和調試JSP 程序的首選。可以這樣認為,當在一臺機器上配置好Apache 服務器,可利用它響應HTML頁面的訪問請求。實際上Tomcat是Apache 服務器的擴展,但運行時它是獨立運行的,所以當你運行tomcat 時,它實際上作為一個與Apache 獨立的進程單獨運行的。當配置正確時,Apache 為HTML頁面服務,而Tomcat 實際上運行JSP 頁面和Servlet。另外,Tomcat 服務器具有處理HTML頁面的功能,它還是一個Servlet和JSP容器,獨立的Servlet容器是Tomcat的默認模式。不過,Tomcat處理靜態HTML的能力不如Apache服務器。目前Tomcat最新版本為9.0。

jdk簡介:

?????????? 是 Java 語言的軟件開發工具包,主要用于移動設備、嵌入式設備上的java應用程序。JDK是整個java開發的核心,它包含了JAVA的運行環境(JVM+Java系統類庫)和JAVA工具。

工作原理:

?????? server端向nginx請求java動態頁面的時候,由于nginx只能處理靜態頁面,所以向后面傳送給jdk來處理java請求,處理之后通過nginx返回請求并交給server端。

圖形介紹:

[root@test5 ~]# tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local

[root@test5 local]# ln -s jdk1.7.0_79/ java

[root@test5 local]# ll -d /usr/local/java/
drwxr-xr-x 8 uucp 143 4096 Apr 11? 2015 /usr/local/java/
[root@test5 local]# ls
apache-tomcat-7.0.37? games??? jdk????????? lib64??? sbin?? test.class
bin?????????????????? include? jdk1.7.0_79? libexec? share? test.java
etc?????????????????? java???? lib????????? lnmp???? src??? tomcat
[root@test5 local]# cd java/
[root@test5 java]# vim /etc/profile

[root@test5 java]# source /etc/profile

[root@test5 java]# cd
[root@test5 ~]# vim test.java????????? //編寫一個簡單的java編程。

[root@test5 ~]# javac test.java

?

test5:

[root@test5 ~]# tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/????????????? //安裝包由官網進行下載:tomcat.apache.org

[root@test5 ~]# cd /usr/local/

[root@test5 local]# ln -s apache-tomcat-7.0.37/ tomcat???????????????? //做個軟連接

[root@test5 local]# cd tomcat/

[root@test5 tomcat]# bin/startup.sh

[root@test5 tomcat]# ls

[root@test5 tomcat]# bin/startup.sh

[root@test5 tomcat]# netstat -antlp | grep :8080?????????? //默認8080端口

[root@test5 tomcat]# cd /usr/local/lnmp/nginx/conf/
[root@test5 conf]# vim nginx.conf??????????????????? //修改配置文件使其訪問默認的80端口

[root@test5 conf]# nginx -t

[root@test5 conf]# nginx -s reload

[root@test5 conf]# cd /usr/local/tomcat/
[root@test5 tomcat]# ls
apache-tomcat-7.0.37? conf? LICENSE? NOTICE???????? RUNNING.txt? webapps
bin?????????????????? lib?? logs???? RELEASE-NOTES? temp???????? work
[root@test5 tomcat]# cd webapps/
[root@test5 webapps]# ls
docs? examples? host-manager? manager? ROOT
[root@test5 webapps]# cd ROOT/
[root@test5 ROOT]# vim test.jsp

?

test6:(與test5進行相同操作,事先搭好memcache服務,這里就不重復了)

[root@test6 ~]# tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local/
[root@test6 ~]# tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/
[root@test6 ~]# cd /usr/local/

[root@test6 local]# ls

[root@test6 local]# ln -s jdk1.7.0_79/ java
[root@test6 local]# ln -s apache-tomcat-7.0.37/ tomcat
[root@test6 local]# ll

[root@test6 local]# vim /etc/profile

[root@test6 local]# source /etc/profile

[root@test6 local]# cd tomcat/
[root@test6 tomcat]# bin/startup.sh

[root@test5 conf]# pwd
/usr/local/lnmp/nginx/conf
[root@test5 conf]# vim nginx.conf


[root@test5 conf]# nginx -t

nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@test5 conf]# nginx -s reload

[root@test5 conf]# /usr/local/tomcat/webapps/ROOT

[root@test5 ROOT]# scp test.jsp test6:/usr/local/tomcat/webapps/ROOT/????????????? //將test.jsp復制給test6

[root@test5 ROOT]# vim test.jsp

[root@test6 tomcat]# cd webapps/ROOT

[root@test6 ROOT]# vim test.jsp

?

主機進行靜態測試:

?

動態測試:

[root@test5 tomcat]# cd webapps/ROOT/
[root@test5 ROOT]# pwd
/usr/local/tomcat/webapps/ROOT

[root@test5 ROOT]# vim test.jsp

<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.util.*" %>
<html><head><title>Cluster App Test</title></head>
<body>
Server Info:
<%
out.println(request.getLocalAddr() + " : " + request.getLocalPort()+"<br>");%>
<%
out.println("<br> ID " + session.getId()+"<br>");
String dataName = request.getParameter("dataName");
if (dataName != null && dataName.length() > 0) {
String dataValue = request.getParameter("dataValue");
session.setAttribute(dataName, dataValue);
}
out.print("<b>Session list</b>");
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = session.getAttribute(name).toString();
out.println( name + " = " + value+"<br>");
System.out.println( name + " = " + value);
}
%>
<form action="test.jsp" method="POST">
name:<input type=text size=20 name="dataName">
<br>
key:<input type=text size=20 name="dataValue">
<br>
<input type=submit>
</form>
</body>
</html>

[root@test5 ROOT]# scp test.jsp test6:/usr/local/tomcat/webapps/ROOT/

[root@test5 ROOT]# cd -
/usr/local/tomcat
[root@test5 tomcat]# bin/shutdown.sh??????????????? //將test5的tomcat給down掉

?

真機進行訪問:

//關掉test5的tomcat,客戶端刷新可訪問到test6的session

?

[root@test5 tomcat]# /etc/init.d/memcached start

Starting memcached:??????????????????????????????????????? [? OK? ]
[root@test5 tomcat]# cd conf/
[root@test5 conf]# vim context.xml

[root@test5 conf]# /usr/local/tomcat/bin/startup.sh????????? //開啟tomcat服務

[root@test6 tomcat]# cd /usr/local/tomcat/conf
[root@test6 conf]# vim context.xml

[root@test6 conf]# /usr/local/tomcat/bin/startup.sh?????????????????????? //開啟tomcat服務

下載一個目錄jar,包含以下內容

將目錄分別發送給test5和test6

[root@test5 lib]# cd /usr/local/tomcat/lib

[root@test5 lib]# rm -rf memcached-session-manager-tc6-1.6.3.jar

[root@test6 lib]# cd /usr/local/tomcat/lib

[root@test6 lib]# rm -rf memcached-session-manager-tc6-1.6.3.jar

[root@test5 lib]# cd /usr/local/tomcat/
[root@test5 tomcat]# cat logs/catalina.out

[root@test6 lib]# cd /usr/local/tomcat/
[root@test6 tomcat]# cat logs/catalina.out

網頁測試:

其中test6的ID為:7368AD2B39FEF2C84F252EEA44BA9D2A-n2

[root@test6 tomcat]# yum install -y telnet????????????????????? //用來查看一些內容

[root@test6 tomcat]# telnet localhost 11211

[root@test6 tomcat]# cat logs/catalina.out

[root@test6 tomcat]# bin/shutdown.sh???????????? //若將test6的tomcat給down掉

?

總結

以上是生活随笔為你收集整理的memcache的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

歡迎分享!

轉載請說明來源于"生活随笔",并保留原作者的名字。

本文地址:memcache