五、安裝php服務器
1.解決開發環境和依賴關系
-
# yum -y install bzip2-devel
-
# yum -y install libmcrypt-devel
-
# yum -y groupinstall "Desktop Platform Development"
2.安裝php
-
# tar xf php-5.4.26.tar.bz2
-
# cd /usr/src/php-5.4.26/
-
# ./configure--prefix=/usr/local/php --with-openssl
-
--with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd
-
--enable-mbstring --with-freetype-dir --with-jpeg-dir
-
--with-png-dir --with-zlib--with-libxml-dir=/usr --enable-xml
-
--enable-sockets --with-apxs2=/usr/local/apache2/bin/apxs
-
--with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d
-
--with-bz2 --enable-maintainer-zts
-
# make && make install
3.提供配置文件
-
# cp php.ini-production /etc/php.ini
4.為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
5.為php-fpm提供配置文件
-
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
6.編輯php-fpm配置文件
-
# 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.1.11:9000
7.啟動php-fpm
-
# service php-fpm start
-
# ps -aux | grep php-fpm
六、安裝php加速器xcache
1.安裝xcache
-
# tar xf xcache-3.0.3.tar.gz
-
# cd xcache-3.0.3
-
# /usr/local/php/bin/phpize
-
//phpize是用來安裝php擴展模塊的,通過phpize可以建立php的
-
外掛模塊,若你想在原來編譯好的php中加入memcached或者
-
ImageMagick等擴展模塊,就需要使用phpize
-
# # ./configure --enable=xcache --with-php-config=/usr/local/php/bin/
-
php-config
-
# make && make install
-
//顯示xcache模塊路徑:/usr/local/php/lib/php/extensions/no-debug-zts-20100525/
2.編輯配置文件,整合php + xcache
-
# vim xcache.ini
-
//添加模塊路徑
-
extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
-
# cp xcache.ini /etc/php.d/
3.重啟php-fpm
-
# service php-fpm restart
七、配置nginx
1.編輯/etc/nginx/nginx.conf,實現動靜分離
-
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.hoo.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)___FCKpd___20nbsp;{ #匹配靜態內容
-
root html; #默認目錄在/usr/local/nginx/html
-
}
-
location ~ \.php___FCKpd___20nbsp;{ #匹配動態php文件
-
root html;
-
fastcgi_pass 172.16.7.11:9000; #代理到的服務器
-
fastcgi_index index.php;
-
fastcgi_param SCRIPT_FILENAME scripts$fastcgi_script_name;
-
include fastcgi_params;
-
}
-
}
-
}
2.編輯/etc/nginx/fastcgi_params
-
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
-
# service nginx reload
八、安裝Memcached服務器
1.memcached特性
Memcached是一款開發工具,它既不是一個代碼加速器,也不是數據庫中間件。其設計哲學思想主要反映在如下方面:
(1)簡單key/value存儲:服務器不關心數據本身的意義及結構,只要是可序列化數據即可。存儲項由“鍵、過期時間、可選的標志及數據”四個部分組成;
(2)功能的實現一半依賴於客戶端,一半基於服務器端:客戶負責發送存儲項至服務器端、從服務端獲取數據以及無法連接至服務器時采用相應的動作;服務端負責接收、存儲數據,並負責數據項的超時過期;
(3)各服務器間彼此無視:不在服務器間進行數據同步;
(4)O(1)的執行效率
(5)清理超期數據:默認情況下,Memcached是一個LRU緩存,同時,它按事先預訂的時長清理超期數據;但事實上,memcached不會刪除任何已緩存數據,只是在其過期之後不再為客戶所見;而且,memcached也不會真正按期限清理緩存,而僅是當get命令到達時檢查其時長;
2.安裝memcached
a).部署開發環境,解決依賴關系
-
# yum groupinstall "Development Tools" "Server Platform Deveopment" -y
-
# yum install -y libevent-devel
b).編譯安裝memcached
-
# 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
c).為memcached提供啟動腳本
-
#!/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: ___FCKpd___25 {start|stop|restart|condrestart|status}"
-
RETVAL=1
-
esac
-
exit $RETVAL
d).添加memcached至服務列表
-
# chmod +x /etc/init.d/memcached
-
# chkconfig --add memcached
-
# service memcached start
e).檢查是否運行
-
# ss -tnlp | grep 11211
九、安裝php的memcached擴展
1.安裝memcached擴展
-
# tar xf memcache-2.2.7.tgz
-
# cd memcache-2.2.7
-
# /usr/local/php/bin/phpize
-
# ./configure --with-php-config=/usr/local/php/bin/php-config --enable-memcache
-
# make && make install
2.編輯配置文件,整合php + memcached
-
# vim xcache.ini
-
//添加模塊路徑
-
extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/memcache.so
3.重啟php-fpm
-
# service php-fpm restart
4.對memcached功能進行測試,在網站目錄中建立測試頁面test.php
-
//php服務器
-
# vim test.php
-
<?php
-
$mem = new Memcache;
-
$mem->connect("172.16.1.13", 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.";
-
?>
-
~
測試訪問即可。
5.安裝wordpress測試訪問即可
十、安裝memadmin-master查看memcached狀態信息
1.解壓即可使用
-
//解壓至php服務器/usr/local/nginx/html/
-
# unzip memadmin-master.zip
2.測試訪問
www.hoo.com/memadmin-master
原文鏈接:http://hoolee.blog.51cto.com/7934938/1413346