【IT168 报道】本文章主要讲解大型网站构建,全部采用开源软件和开源的操作系统,构架采用 LAMP (Linux+Apache+Mysql+Php)模式实现。
大型网站集群构建之: 需求分析篇
大型网站集群构建之:DNS配置篇
大型网站集群构建之:共享session讨论篇
大型网站集群构建之:负载均衡篇
大型网站集群构建之:共享session讨论篇
在集群中共享session是一个问题。
方案: 1、把session放到共享的设备上去,如nfs。
2、放到 memcache 中,这种方法被很多人推崇。
memcache install:
download http://www.danga.com/memcached
install memcache support modules:
download http://www.monkey.org/~provos/libevent/
./configure
make
make install
install memcache
./configure --prefix=/usr/local/memcached --enable-threads
make
make install
创建一个启动文件 /etc/init.d/memcached
#!/bin/sh
#
# memcached: MemCached Daemon
#
# chkconfig: - 90 25
# description: MemCached Daemon
#
# Source function library.
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
#[ ${NETWORKING} = "no" ] && exit 0
#[ -r /etc/sysconfig/dund ] || exit 0
#. /etc/sysconfig/dund
#[ -z "$DUNDARGS" ] && exit 0
start()
{
echo -n $"Starting memcached: "
daemon $MEMCACHED -u daemon -d -m 1024 -l 192.168.0.100 -p 11211
echo
}
stop()
{
echo -n $"Shutting down memcached: "
killproc memcached
echo
}
MEMCACHED="/usr/local/memcached/bin/memcached"
[ -f $MEMCACHED ] || exit 1
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0php memcahce modules install:
download http://pecl.php.net/package/memcache
phpize
./configure --enable-memcache
make
make install