首页自学基于文件的php跨机房session同步方案

基于文件的php跨机房session同步方案

adminadmin时间2024-06-28 19:24:10分类自学浏览36
场景:
公司网站接入CDN, CDN有两个回源后端做负载均衡以及故障转移,经过测试,CDN的回源是按权重比例轮询的。
要解决用户session状态在不同后端回源时不丢失,造成重复登录。

解决方案:
session文件的同步

实施步骤


1、设置php session保存目录session.save_path = "/php_session"
mkdir /php_session
chown www:www /php_session/


2、安装部署 inotify

3、编写同步脚本
#!/bin/bash
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format  '%T %w%f %e' --event modify,delete,create,attrib  /php_session | while read  date time file event
do
        rsync --chown=www:www --chmod=600 -a -e 'ssh -p 35389 -P ' $file  root@192.168.10.3:/php_session/ > /dev/null
done


技术要点

rsync --chown=www:www --chmod=600
将文件同步出去后,在目标机器上执行 同步文件的 所有者 与权限

4、定时任务增加守护脚本
#!/bin/sh
pid=(`ps -ef|grep moni|awk '{print $0}'`)
has=false
for info in ${pid[@]};
do
        if [ $info == '/shell/monitor_tmp.sh' ]; then
                has=true
        fi
done
if [ $has == false ];then
        /shell/monitor_tmp.sh &
        echo "run script!"
fi

本文《基于文件的php跨机房session同步方案》peizhi/40.html

与《基于文件的php跨机房session同步方案》

0
0
收藏0
德展健康:控股股东提议2亿元至3亿元回购股份

    未登录用户 回复需填写必要信息
    请先 登录 再评论,若不是会员请先 注册