博客
关于我
memcache实现php会话保持
阅读量:799 次
发布时间: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/

    你可能感兴趣的文章
    mysql 1264_关于mysql 出现 1264 Out of range value for column 错误的解决办法
    查看>>
    mysql 1593_Linux高可用(HA)之MySQL主从复制中出现1593错误码的低级错误
    查看>>
    mysql 5.6 修改端口_mysql5.6.24怎么修改端口号
    查看>>
    mui折叠面板点击事件跳转
    查看>>
    MySQL 8 公用表表达式(CTE)—— WITH关键字深入用法
    查看>>
    mysql 8 远程方位_mysql 8 远程连接注意事项
    查看>>
    MUI框架里的ajax的三种方法
    查看>>
    MySQL 8.0 恢复孤立文件每表ibd文件
    查看>>
    Mysql 8.0 新特性
    查看>>
    MultCloud – 支持数据互传的网盘管理
    查看>>
    MySQL 8.0.23中复制架构从节点自动故障转移
    查看>>
    MySQL 8.0开始Group by不再排序
    查看>>
    mysql ansi nulls_SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON 什么意思
    查看>>
    multi swiper bug solution
    查看>>
    MySQL Binlog 日志监听与 Spring 集成实战
    查看>>
    MySQL binlog三种模式
    查看>>
    multi-angle cosine and sines
    查看>>
    Mysql Can't connect to MySQL server
    查看>>
    mysql case when 乱码_Mysql CASE WHEN 用法
    查看>>
    Multicast1
    查看>>