本文共 2389 字,大约阅读时间需要 7 分钟。
通过配置Haproxy实现RR轮询调度,将用户会话ID保持不变,实现两台lamp服务器的负载均衡。
./configure --prefix=/usr/local/php-5.2.26 --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php-5.2.26 --with-bz2
tar xf memcache-2.2.7.tgzcd memcache-2.2.7./configure --with-php-config=/usr/local/php/bin/php-config --enable-memcache --make install
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/memcache.so
VirtualHost 192.168.1.30:80 DocumentRoot "/www/test1.com" ErrorLog "logs/dummy-test1.com-error_log" CustomLog "logs/dummy-test1.com-access_log" commonRequire all granted ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.1.30:9000/www/test1.com/$1
LoadModule proxy_module modules/mod_proxy.soLoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
DirectoryIndex index.php index.htmlInclude /etc/httpd-2.4.9/extra/httpd-vhosts.confAddType application/x-httpd-php-source .phpsAddType application/x-httpd-php .php
connect("192.168.1.25", 11211) or die("Could not connect");$version = $mem->getVersion();echo "Server's version: " . $version . "\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)\n";$get_result = $mem->get('hellokey');echo "$get_result is from memcached server.";?>
访问01.php,若显示“Hello World is from memcached server”则连接成功。
修改php.ini:
session.save_handler = memcachesession.save_path="tcp://192.168.1.25:11211"
frontend main *:80 default_backend app backend app balance roundrobin server app1 192.168.1.13:80 check server app2 192.168.1.30:80 check
" . "192.168.1.13 web server";?>
访问02.php,观察输出结果区分两台lamp服务器IP地址。
通过以上配置和测试,验证haproxy RR轮询调度与PHP会话管理的正确性,确保用户会话ID保持不变。
转载地址:http://qqyfk.baihongyu.com/