日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Web服務(wù)之LNMMP架構(gòu)及動靜分離實現(xiàn)

一、LNMMP

LNMMP環(huán)境是Linux + Nginx + Memcached + MySQL + PhP,即LNMP + memcached。

Memcached 是一個高性能的分布式內(nèi)存對象緩存系統(tǒng),用于動態(tài)Web應(yīng)用以減輕數(shù)據(jù)庫負(fù)載。它通過在內(nèi)存中緩存數(shù)據(jù)和對象來減少讀取數(shù)據(jù)庫的次數(shù),從而提供動態(tài)、數(shù)據(jù)庫驅(qū)動網(wǎng)站的速度。Memcached基于一個存儲鍵/值對的hashmap。其守護進程(daemon )是用C寫的,但是客戶端可以用任何語言來編寫,并通過memcached協(xié)議與守護進程通信。

二、工程拓?fù)?/strong>

三、安裝nginx服務(wù)器

 
 
  1. 1)部署開發(fā)環(huán)境 
  2. # yum -y install "Development tools" "Server Platform Development" 
  3. 2)解決依賴 pcre-devel  openssl-devel 
  4. # yum -y install pcre-devel openssl-devel 
  5. 3) 設(shè)置用戶 
  6. # groupadd -r nginx 
  7. # useradd -r -g nginx nginx 
  8. 4)編譯安裝nginx-1.4.7 
  9. # tar xf nginx-1.4.7.tar.gz 
  10. # cd nginx-1.4.7 
  11. # ./configure --prefix=/usr --sbin-path=/usr/sbin/nginx \ 
  12. --conf-path=/etc/nginx/nginx.conf --error-log-path=\ /var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log \ 
  13. --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock \--user=nginx --group=nginx --with-http_ssl_module \ 
  14. --with-http_flv_module --with-http_stub_status_module \ 
  15. --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/ \ 
  16. --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=\ 
  17. /var/tmp/nginx/scgi --with-pcre 
  18. # make && make install 
  19. 5)檢測配置文件語法 
  20. # /usr/sbin/nginx -t 
  21. 6) 提供啟動腳本 
  22. # vim  /etc/rc.d/init.d/nginx 
  23.    內(nèi)容如下 
  24. # nginx - this script starts and stops the nginx daemon 
  25. # chkconfig:   - 85 15 
  26. # description:  Nginx is an HTTP(S) server, HTTP(S) reverse \ 
  27. #               proxy and IMAP/POP3 proxy server 
  28. # processname: nginx 
  29. # config:      /etc/nginx/nginx.conf 
  30. # config:      /etc/sysconfig/nginx 
  31. # pidfile:     /var/run/nginx.pid
  32. # Source function library. 
  33. . /etc/rc.d/init.d/functions
  34. # Source networking configuration. 
  35. . /etc/sysconfig/network
  36. # Check that networking is up. 
  37. [ "$NETWORKING" = "no" ] && exit 0
  38. nginx="/usr/sbin/nginx"
  39. prog=$(basename $nginx)
  40. NGINX_CONF_FILE="/etc/nginx/nginx.conf"
  41. [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
  42. lockfile=/var/lock/subsys/nginx
  43. make_dirs() { 
  44.    # make required directories 
  45.    user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` 
  46.    options=`$nginx -V 2>&1 | grep 'configure arguments:'` 
  47.    for opt in $options; do
  48.        if [ `echo $opt | grep '.*-temp-path'` ]; then
  49.            value=`echo $opt | cut -d "=" -f 2` 
  50.            if [ ! -d "$value" ]; then
  51.                # echo "creating" $value 
  52.                mkdir -p $value && chown -R $user $value 
  53.            fi
  54.        fi
  55.    done
  56. }
  57. start() { 
  58.     [ -x $nginx ] || exit 5 
  59.     [ -f $NGINX_CONF_FILE ] || exit 6 
  60.     make_dirs 
  61.     echo -n $"Starting $prog: "
  62.     daemon $nginx -c $NGINX_CONF_FILE 
  63.     retval=$? 
  64.     echo
  65.     [ $retval -eq 0 ] && touch $lockfile 
  66.     return $retval 
  67. }
  68. stop() { 
  69.     echo -n $"Stopping $prog: "
  70.     killproc $prog -QUIT 
  71.     retval=$? 
  72.     echo
  73.     [ $retval -eq 0 ] && rm -f $lockfile 
  74.     return $retval 
  75. }
  76. restart() { 
  77.     configtest || return $? 
  78.     stop 
  79.     sleep 1 
  80.     start 
  81. }
  82. reload() { 
  83.     configtest || return $? 
  84.     echo -n $"Reloading $prog: "
  85.     killproc $nginx -HUP 
  86.     RETVAL=$? 
  87.     echo
  88. }
  89. force_reload() { 
  90.     restart 
  91. }
  92. configtest() { 
  93.   $nginx -t -c $NGINX_CONF_FILE 
  94. }
  95. rh_status() { 
  96.     status $prog 
  97. }
  98. rh_status_q() { 
  99.     rh_status >/dev/null 2>&1 
  100. }
  101. case "$1" in
  102.     start) 
  103.         rh_status_q && exit 0 
  104.         $1 
  105.         ;; 
  106.     stop) 
  107.         rh_status_q || exit 0 
  108.         $1 
  109.         ;; 
  110.     restart|configtest) 
  111.         $1 
  112.         ;; 
  113.     reload) 
  114.         rh_status_q || exit 7 
  115.         $1 
  116.         ;; 
  117.     force-reload) 
  118.         force_reload 
  119.         ;; 
  120.     status) 
  121.         rh_status 
  122.         ;; 
  123.     condrestart|try-restart) 
  124.         rh_status_q || exit 0 
  125.             ;; 
  126.     *) 
  127.         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  128.         exit 2 
  129. esac
  130. 7)為服務(wù)腳本賦予執(zhí)行權(quán)限 
  131. # chmod +x /etc/rc.d/init.d/nginx 
  132. 8)添加到系統(tǒng)服務(wù)并開機啟動 
  133. # chkconfig --add nginx 
  134. # chkconfig nginx on 
  135. # chkconfig --list nigx 
  136. 9) 設(shè)置nginx配置文件的語法高亮 
  137. # mkdir ./vim/syntax -pv 
  138. # cd  .vim/syntax 
  139. # wget http://www.vim.org/scripts/download_script.php?src_id=19394 
  140. # cd .vim 
  141. # vim filetype.vim 內(nèi)容如下 
  142.  au BufRead,BufNewFile /etc/nginx/*,/usr/local/nginx/conf/* if &ft == '' | setfiletype nginx | endif 
  143. 10)啟動服務(wù) 
  144. # service nginx start 
  145. # ss -tnalp | grep nginx

四、安裝MySQL服務(wù)器

1.安裝
 

 
 
  1. # tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local
  2. # ln -sv /usr/local/mysql-5.5.33-linux2.6-x86_64 mysql 創(chuàng)建軟連接,易于操作

2.為數(shù)據(jù)庫創(chuàng)建數(shù)據(jù)目錄

 
 
  1. #mkdri -pv /mydata/data

3.新建用戶以安全方式運行進程

 
 
  1. #groupadd -r mysql      //創(chuàng)建系統(tǒng)組mysql
  2. #useradd -r -s /sbin/nologin -g mysql mysql -M -D /mydata/data mysql
  3. //創(chuàng)建系統(tǒng)用戶mysql
  4. #chown -R mysql:mysql /mydata/data
  5. //設(shè)置目錄屬主屬組

4.初始化mysql

 
 
  1. # cd /usr/local/mysql
  2. # scripts/mysql_install_db --datadir=/mydata/data --user=mysql
  3. //初始化數(shù)據(jù)庫
  4. # chown -R root .
  5. //設(shè)置當(dāng)前目錄所有文件屬主為root

5.提供腳本

 
 
  1. #cd /usr/local/mysql
  2. #cp support-files/mysql.server  /etc/rc.d/init.d/mysqld
  3. //設(shè)置腳本mysqld
  4. #chmod +x /etc/rc.d/init.d/mysqld
  5. //給腳本執(zhí)行權(quán)限
  6. # chkconfig --add mysqld
  7. //添加開機啟動
  8. # chkconfig  mysqld on

6.提供配文件

 
 
  1. #cd /usr/local/mysql
  2. #cp support-files/my-large.cnf  /etc/my.cnf
  3. #vim /etc/my.cnf
  4. thread_concurrency = 2
  5. //修改,并發(fā)線程數(shù),bithread_concurrency的值為CPU個數(shù)乘以2
  6. datadir = /mydata/data
  7. #添加,mysql數(shù)據(jù)文件的存放路徑:

7.其他配置

 
 
  1. # vim /etc/profile.d/mysqld.sh
  2. exportPATH=/usr/local/mysql/bin:$PATH
  3. # source /etc/profile.d/mysqld.sh
  4. #vim /etc/man.config
  5. MANPATH  /usr/local/mysql/man//添加此行
  6. # ln -sv /usr/local/mysql/include  /usr/include/mysql
  7. //輸出mysql的頭文件至系統(tǒng)頭文件路徑/usr/include
  8. # echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
  9. //輸出mysql的庫文件給系統(tǒng)庫
  10. #ldconfig   //重載系統(tǒng)庫:

8.啟動服務(wù)

 
 
  1. # service mysqld start 
  2. # ss  -tnl | grep 3306

9.用戶初始化

 
 
  1. #mysql
  2. mysql> use mysql
  3. mysql> selecthost,user,password from user;
  4. mysql> DELETE FROM user WHERE user = '';    //刪除空用戶
  5. mysql> DELETE FROM user WHERE user = '::1'; //刪除ipv6用戶
  6. mysql> UPDATE user SET password = PASSWORD('Hoolee') WHERE password = '';
  7. //為root用戶設(shè)置密碼
  8. mysql> FLUSH PRIVILEGES;

#p#

五、安裝php服務(wù)器

1.解決開發(fā)環(huán)境和依賴關(guān)系

 
 
  1. # yum -y install bzip2-devel
  2. # yum -y install libmcrypt-devel
  3. # yum -y groupinstall "Desktop Platform Development"

2.安裝php

 
 
  1. # tar xf php-5.4.26.tar.bz2 
  2. # cd /usr/src/php-5.4.26/ 
  3. # ./configure--prefix=/usr/local/php --with-openssl 
  4. --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd 
  5. --enable-mbstring --with-freetype-dir --with-jpeg-dir
  6. --with-png-dir --with-zlib--with-libxml-dir=/usr --enable-xml 
  7. --enable-sockets --with-apxs2=/usr/local/apache2/bin/apxs
  8. --with-mcrypt  --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d 
  9. --with-bz2  --enable-maintainer-zts 
  10. # make  && make install

3.提供配置文件

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

4.為php-fpm提供腳本,并將其添加到服務(wù)列表

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

5.為php-fpm提供配置文件

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

6.編輯php-fpm配置文件

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

7.啟動php-fpm

 
 
  1. # service php-fpm start 
  2. # ps -aux | grep php-fpm


六、安裝php加速器xcache

1.安裝xcache

 
 
  1. # tar xf xcache-3.0.3.tar.gz
  2. # cd xcache-3.0.3
  3. # /usr/local/php/bin/phpize
  4. //phpize是用來安裝php擴展模塊的,通過phpize可以建立php的
  5. 外掛模塊,若你想在原來編譯好的php中加入memcached或者
  6. ImageMagick等擴展模塊,就需要使用phpize
  7. # # ./configure --enable=xcache --with-php-config=/usr/local/php/bin/
  8. php-config
  9. # make && make install
  10. //顯示xcache模塊路徑:/usr/local/php/lib/php/extensions/no-debug-zts-20100525/

2.編輯配置文件,整合php + xcache

 
 
  1. # vim xcache.ini
  2. //添加模塊路徑
  3. extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
  4. # cp xcache.ini /etc/php.d/

3.重啟php-fpm

 
 
  1. # service php-fpm restart

七、配置nginx

1.編輯/etc/nginx/nginx.conf,實現(xiàn)動靜分離

 
 
  1. worker_processes  2; #worker進程的個數(shù) 
  2. error_log  /var/log/nginx/error.log  notice;    #錯誤日志路徑及級別 
  3. events { 
  4.     worker_connections  1024;    #每個worker能夠并發(fā)響應(yīng)的最大請求數(shù) 
  5. http { 
  6.     include       mime.types;    #支持多媒體類型 
  7.     default_type  application/octet-stream; 
  8.     sendfile        on;    #由內(nèi)核直接轉(zhuǎn)發(fā) 
  9.     #keepalive_timeout  0; 
  10.     keepalive_timeout  5;    #持久連接5s 
  11.     gzip  on;    #開啟壓縮功能 
  12.     server { 
  13.         listen       80; 
  14.         server_name  www.hoo.com; 
  15.         add_header X-via $server_addr;    #讓客戶端能夠看到代理服務(wù)器的IP 
  16.         location / { 
  17.             root   html; 
  18.             index  index.php index.html index.htm; 
  19.         } 
  20.         location ~* \.(jpg|jpeg|png|gif|js|css)$ {  #匹配靜態(tài)內(nèi)容 
  21.             root   html;    #默認(rèn)目錄在/usr/local/nginx/html 
  22.         } 
  23.         location ~ \.php$ {  #匹配動態(tài)php文件 
  24.             root                html; 
  25.             fastcgi_pass        172.16.7.11:9000;    #代理到的服務(wù)器 
  26.             fastcgi_index       index.php; 
  27.             fastcgi_param       SCRIPT_FILENAME scripts$fastcgi_script_name; 
  28.             include             fastcgi_params; 
  29.         } 
  30.    } 
  31. }

2.編輯/etc/nginx/fastcgi_params

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

3.重載nginx

 
 
  1. # service nginx reload 

八、安裝Memcached服務(wù)器

1.memcached特性  

Memcached是一款開發(fā)工具,它既不是一個代碼加速器,也不是數(shù)據(jù)庫中間件。其設(shè)計哲學(xué)思想主要反映在如下方面:

(1)簡單key/value存儲:服務(wù)器不關(guān)心數(shù)據(jù)本身的意義及結(jié)構(gòu),只要是可序列化數(shù)據(jù)即可。存儲項由“鍵、過期時間、可選的標(biāo)志及數(shù)據(jù)”四個部分組成;

(2)功能的實現(xiàn)一半依賴于客戶端,一半基于服務(wù)器端:客戶負(fù)責(zé)發(fā)送存儲項至服務(wù)器端、從服務(wù)端獲取數(shù)據(jù)以及無法連接至服務(wù)器時采用相應(yīng)的動作;服務(wù)端負(fù)責(zé)接收、存儲數(shù)據(jù),并負(fù)責(zé)數(shù)據(jù)項的超時過期;

(3)各服務(wù)器間彼此無視:不在服務(wù)器間進行數(shù)據(jù)同步;

(4)O(1)的執(zhí)行效率

(5)清理超期數(shù)據(jù):默認(rèn)情況下,Memcached是一個LRU緩存,同時,它按事先預(yù)訂的時長清理超期數(shù)據(jù);但事實上,memcached不會刪除任何已緩存數(shù)據(jù),只是在其過期之后不再為客戶所見;而且,memcached也不會真正按期限清理緩存,而僅是當(dāng)get命令到達時檢查其時長;

2.安裝memcached

   a).部署開發(fā)環(huán)境,解決依賴關(guān)系

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

   
b).編譯安裝memcached

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

   c).為memcached提供啟動腳本

 
 
  1. #!/bin/bash 
  2. # Init file for memcached 
  3. # chkconfig: - 86 14 
  4. # description: Distributed memory caching daemon 
  5. # processname: memcached 
  6. # config: /etc/sysconfig/memcached 
  7. . /etc/rc.d/init.d/functions
  8. ## Default variables 
  9. PORT="11211"
  10. USER="nobody"
  11. MAXCONN="1024"
  12. CACHESIZE="64"
  13. OPTIONS=""
  14. RETVAL=0 
  15. prog="/usr/local/memcached/bin/memcached"
  16. desc="Distributed memory caching"
  17. lockfile="/var/lock/subsys/memcached"
  18. start() { 
  19.         echo -n $"Starting $desc (memcached): "
  20.         daemon $prog -d -p $PORT -u $USER -c $MAXCONN -m $CACHESIZE -o "$OPTIONS"
  21.         RETVAL=$? 
  22.         [ $RETVAL -eq 0 ] && success && touch $lockfile || failure 
  23.         echo
  24.         return $RETVAL 
  25. stop() { 
  26.         echo -n $"Shutting down $desc (memcached): "
  27.         killproc $prog 
  28.         RETVAL=$? 
  29.         [ $RETVAL -eq 0 ] && success && rm -f $lockfile || failure 
  30.         echo
  31.         return $RETVAL 
  32. restart() { 
  33.         stop 
  34.         start 
  35. reload() { 
  36.         echo -n $"Reloading $desc ($prog): "
  37.         killproc $prog -HUP 
  38.         RETVAL=$? 
  39.         [ $RETVAL -eq 0 ] && success || failure 
  40.         echo
  41.         return $RETVAL 
  42. case "$1" in
  43.   start) 
  44.         start 
  45.         ;; 
  46.   stop) 
  47.         stop 
  48.         ;; 
  49.   restart) 
  50.         restart 
  51.         ;; 
  52.   condrestart) 
  53.         [ -e $lockfile ] && restart 
  54.         RETVAL=$? 
  55.         ;; 
  56.   reload) 
  57.         reload 
  58.         ;; 
  59.   status) 
  60.         status $prog 
  61.         RETVAL=$? 
  62.         ;; 
  63.    *) 
  64.         echo $"Usage: $0 {start|stop|restart|condrestart|status}"
  65.         RETVAL=1 
  66. esac
  67. exit $RETVAL

   d).添加memcached至服務(wù)列表

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

   
e).檢查是否運行

 
 
  1. # ss -tnlp | grep 11211

九、安裝php的memcached擴展

1.安裝memcached擴展

 
 
  1. # tar xf memcache-2.2.7.tgz 
  2. # cd memcache-2.2.7 
  3. # /usr/local/php/bin/phpize 
  4. # ./configure --with-php-config=/usr/local/php/bin/php-config --enable-memcache 
  5. # make && make install

2.編輯配置文件,整合php + memcached

 
 
  1. # vim xcache.ini 
  2. //添加模塊路徑 
  3. extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/memcache.so

3.重啟php-fpm

 
 
  1. # service php-fpm restart  

4.對memcached功能進行測試,在網(wǎng)站目錄中建立測試頁面test.php

 
 
  1. //php服務(wù)器 
  2. # vim test.php 
  3. $mem = new Memcache; 
  4. $mem->connect("172.16.1.13", 11211)  or die("Could not connect"); 
  5. $version = $mem->getVersion(); 
  6. echo "Server's version: ".$version."
    \n"; 
  7. $mem->set('hellokey', 'Hello World', 0, 600) or die("Failed to save data at the memcached server"); 
  8. echo "Store data in the cache (data will expire in 600 seconds)
    \n"; 
  9. $get_result = $mem->get('hellokey'); 
  10. echo "$get_result is from memcached server."; 
  11. ?> 
  12. ~

測試訪問即可。

5.安裝wordpress測試訪問即可

十、安裝memadmin-master查看memcached狀態(tài)信息

1.解壓即可使用

 
 
  1. //解壓至php服務(wù)器/usr/local/nginx/html/
  2. # unzip memadmin-master.zip

2.測試訪問

www.hoo.com/memadmin-master


網(wǎng)站題目:Web服務(wù)之LNMMP架構(gòu)及動靜分離實現(xiàn)
分享地址:http://m.5511xx.com/article/cdhochp.html