服务器_PHP实现多服务器session共享之NFS共享的方法,PHP实现多服务器session共享之NFS
# first, put the setting bellow in the php.ini file:
# of 3 levels of depth containing 32 directories in each directory,
#! /bin/sh
# mod_files.sh basedir depth [numberofsubdirs]
shell>#mkdir /tmp/php_sess
# NAME
fi
设置为可执行之后,运行以下命令来创建哈希目录:
hash_chars="0 1 2 3 4 5 6 7 8 9 a b c d e f"
然后重启 nfs 服务,即可对另外两台主机提供NFS共享了。
echo "usage: $0 basedir depth [numberofsubdirs]"
# SYNOPSIS
#
#
if [ ! -z $3 ] ; then
/tmp/php_sess/ svr*(rw,no_root_squash)
最后,在这两个主机上对 php.ini 增加/修改上面提到的内容,然后重启apache即可。
fi
# mod_files.sh - Update of the php-source/ext/session/mod_files.sh
if test "$2" = "0"; then
#
hash_chars="$hash_chars w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z - ,"
#
在 svr2、svr3 上执行以下命令来挂在NFS:
意为把session存放在 "/tmp/php_sess" 目录下,并且分成 2 级子目录,每级子目录又分别有 16 个子目录。
exit 1
for i in $hash_chars; do
#
接下来,假设php的主目录为 /usr/local/server/php/,则新建一个文件 /usr/local/server/php/include/php/ext/session/mod_files.sh,其内容如下:
fi
# DESCRIPTION
# this script creates the directories tree used by php to store the session files
if test "$3" -eq "64"; then
echo "numberofsubdirs: if unset, defaults to 16. if 32, 32 subdirs, if 64, 64 subdirs."
done
其中,有一种方法就是利用NFS来共享session,如果session量比较大并且所有的session文件都在同一个子目录下的话,那么可能会由此带来很严重的负载问题,甚至导致网站无法使用。本文就是对这个方案做一下详细的解说。
exit 0
#
shell>#./mod_files.sh /tmp/php_sess 2 16
前言,Nio大侠提出了session多服务器共享的问题,原文请见PHP 实现多服务器共享 SESSION 数据。
现在,就开始设置 NFS 共享了。假定有3台主机,ip分别为192.168.0.1(主机名svr1)、192.168.0.2(主机名svr2)、192.168.0.3(主机名svr3),现在让192.168.0.1来提供NFS共享服务,配置 /etc/exports,加入如下内容:
# Now create the basedir directory: 'mkdir /tmp/session'
首先,修改 php.ini的 session.save_path 选项,大致如下:
#
PHP实现多服务器session共享之NFS共享
#
Then, call this scrip with the following arguments:
#
(see php.ini - 'session.save_path' option)
shell>#cd /usr/local/server/php/include/php/ext/session/
sh $0 $newpath `expr $2 - 1` $3
if test "$2" = ""; then
shell>#mount svr1:/tmp/php_sess /tmp/php_sess
#
session.save_path = "3;/tmp/session"
#
./mod_files.sh ./mod_files.sh /tmp/session 3 32
mkdir $newpath || exit 1
if test "$3" -a "$3" -eq "32"; then
newpath="$1/$i"
#
Example: if you want php to store the session files in a directory tree
fi
hash_chars="$hash_chars g h i j k l m n o p q r s t u v"
fi
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/server/yun/6707.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
租用云服务器后的备案问
时间:2021-01-05
-
百度云服务器bcc有什么优
时间:2021-01-05
-
什么是云服务器cvm?怎么
时间:2021-01-05
-
云服务器怎么保证信息安
时间:2021-01-05
-
云服务器怎么预防被攻击
时间:2021-01-05
-
阿里云ECS实例设置用户r
时间:2020-12-29
-
阿里云ECS服务器入门使用
时间:2020-12-29
-
怎么配置云服务器
时间:2020-12-28
热门文章
-
租用云服务器后的备案问题你真的了解吗
时间:2021-01-05
-
选择美国云服务器需要关注什么?
时间:2020-12-27
-
阿里云服务器怎么买?阿里云服务器购买
时间:2020-12-25
-
运维必须知道的关于云服务器的十个问题
时间:2020-12-24
-
如何快速搭建一个阿里云服务器
时间:2020-12-24
-
什么是云?什么是云服务?什么是云主机
时间:2020-12-25
-
云服务器网站承载量一般有多大?一个云
时间:2020-12-28
-
浅谈云服务器和独立服务器的八大差异
时间:2020-12-24
-
SugarHosts云服务器如何开启访问端口和使用
时间:2020-12-24
-
云服务器是什么,云主机干什么用的?
时间:2020-12-28
