博客
关于我
memcache实现php会话保持
阅读量:796 次
发布时间:2023-02-08

本文共 2389 字,大约阅读时间需要 7 分钟。

Haproxy RR轮询调度与PHP会话管理优化配置实践

实验目标

通过配置Haproxy实现RR轮询调度,将用户会话ID保持不变,实现两台lamp服务器的负载均衡。

版本信息

  • Haproxy版本:haproxy-1.5.4-3.el6.x86_64(yum安装)
  • memcached版本:memcache-1.4.15-9.el7_2.1.x86_64(yum安装)
  • LAMP环境:httpd-2.4.9、mariadb-5.5.36、php-5.4.26(编译安装)
  • PHP memcache扩展:memcache-2.2.7(编译安装)

环境搭建

PHP安装(其他安装步骤可略)

  • 编译配置:
  • ./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
    1. memcache扩展安装:
    2. 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
      1. 修改php.ini:
      2. extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/memcache.so

        LAMP虚拟机配置

      3. httpd配置:
      4. VirtualHost 192.168.1.30:80  DocumentRoot "/www/test1.com"  ErrorLog "logs/dummy-test1.com-error_log"  CustomLog "logs/dummy-test1.com-access_log" common  
        Require all granted ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.1.30:9000/www/test1.com/$1
        1. 启用模块:
        2. LoadModule proxy_module modules/mod_proxy.soLoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
          1. 修改配置:
          2. 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

            PHP与Memcache连接测试

          3. 测试脚本:
          4. 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”则连接成功。

            会话存储到Memcache

            修改php.ini:

            session.save_handler = memcachesession.save_path="tcp://192.168.1.25:11211"

            Haproxy配置

          5. Main frontend配置:
          6. 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

            测试与验证

          7. 测试脚本:
          8. " . "192.168.1.13 web server";?>

            访问02.php,观察输出结果区分两台lamp服务器IP地址。

            通过以上配置和测试,验证haproxy RR轮询调度与PHP会话管理的正确性,确保用户会话ID保持不变。

    转载地址:http://qqyfk.baihongyu.com/

    你可能感兴趣的文章
    Memory Consistency Erros
    查看>>
    memory management before arc
    查看>>
    Memos-desktop:基于Electron框架的跨平台记事本应用
    查看>>
    memset,memcpy报错
    查看>>
    memset函数
    查看>>
    memset初始化高维数组为-1/0
    查看>>
    MEPS REAL-TIME推出Intelliguard可视化库存系统
    查看>>
    merge into 笔记
    查看>>
    Merge into的使用详解-你Merge了没有
    查看>>
    Merge Two Sorted Lists - LeetCode
    查看>>
    Merge 的小技巧
    查看>>
    Mesos 资源分配
    查看>>
    message.channel.id Discord PY
    查看>>
    Message: CLR 无法从 COM 上下文 0x219100 转换为 COM 上下文 0x219328,这种状态已持续 60 秒。
    查看>>
    MessageDigest
    查看>>
    Mes的理解
    查看>>
    MES系统如何实现远程访问?
    查看>>
    Metabase RCE漏洞复现(CVE-2023-38646)
    查看>>
    metaclass
    查看>>
    metaq杂记
    查看>>