使用运行分布式服务的多个服务器(HAProxy、Apache、Ruby on Rails)时如何配置登录

发布于 2024-10-08 06:51:30 字数 466 浏览 0 评论 0原文

我有 3 台服务器运行一个网站。我现在需要实现登录系统,但我遇到了问题,因为用户根据所连接的服务器获得不同的行为(登录或注销)。

我在 Rails 中使用 Memcache 进行会话存储 - config.action_controller.session_store = :mem_cache_store

ActiveSupport::Cache::MemCacheStore.new("server1","server2","server3")

我认为第二行要么保持缓存同步,要么类似......

每个服务器有自己的数据库,有 1 个主数据库,2 个从数据库。我尝试过在 sql 存储中进行会话的路线,但这确实会损害 sql 服务器,并且复制负载变得非常重。

有没有一种简单的方法可以说,将此 Memcache 用于所有 3 台服务器上的所有会话存储?

这能解决我的问题吗?

我会非常感激的。

I have 3 servers running a website. I now need to implement login system and I am having problems with it as user gets a different behavior (logged in or logged out) depending on the server it gets connected to.

I am using Memcache for session store in Rails -
config.action_controller.session_store = :mem_cache_store

ActiveSupport::Cache::MemCacheStore.new("server1","server2","server3")

I thought the second line will either keep caches in sync or something like that ...

Each server has its own db with 1 master, 2 slaves. I have tried going the route of doing sessions in sql store but that really hurts sql servers and replication load becomes really heavy.

Is there an easy way to say, use this Memcache for all session store on all 3 servers?

Will that solve my problem?

I will really appreciate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏末染殇 2024-10-15 06:51:30

我之前没有使用过memcached来存储session(我觉得redis是一个更好的解决方案),但我认为只要你有
ActiveSupport::Cache::MemCacheStore.new("server1","server2","server3")
在每个应用程序服务器上,您的会话应该保持同步。

我仅使用您所描述的相同设置使用常规 cookie 会话就取得了很大的成功。

I haven't used memcached to store sessions before ( I feel like redis is a better solution ), but I think as long as you have the
ActiveSupport::Cache::MemCacheStore.new("server1","server2","server3")
line on each of your application servers, your sessions should stay synced up.

I've had a lot of success with just using regular cookie sessions using the same setup you've described.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文