dongwei1263 2012-02-20 16:26
浏览 103
已采纳

多个服务器和Memcached

If Server 1 has both my database and Memcached as well as www.website1.co.uk - the site will work fine.

But What if I have the following scenario:

Server 1 - Database - Memcached - website1.co.uk 
Server 2 - website2.co.uk
Server 3 - website3.co.uk

How would I set this up so website2 and website3 can all connect, read and write to the memcached db on Server 1 (they can already connect to server 1 and read and write to the DB without memcache).

Would I need to install Memcache on server 2 and server 3 just to be able to connect?

I've never used memcache before so it's a learning experience.

  • 写回答

1条回答 默认 最新

  • douqiju2520 2012-02-21 05:30
    关注

    If Servers 1 to 3 are on the same network, you could install memcache on each of the application servers without worry because Memcache is designed for clustered architecture. This simply means that you can run as MANY instances as you want but your application 'sees' it as 1 giant memory cache.

    To paraphrase from the memcached's project wiki:

    //in your configuration file: 
    
    $MEMCACHE_SERVERS = array(
        "10.1.1.1", //web1
        "10.1.1.2", //web2
        "10.1.1.3", //web3
    );
    
    
    //at the 'bootstrapping' phase of your app somewhere:
    
    $memcache = new Memcache();
    foreach($MEMCACHE_SERVERS as $server){
        $memcache->addServer ( $server );
    }
    

    Is your question is related to scaling? If so:

    I've seen some people say to have your cache server on the DB server itself. IMHO, this is not very effective as you would want to give your DB server as much physical RAM as you can possibly afford (depending on how large your web app is in terms of traffic and load).

    I would allocate a portion of memory on each of the application servers (Server 2 and Server 3) for caching purposes. That way, if you want to scale out, you just provision one more application server, checkout your source code and add it to your network. This way the size of your memory cache would grow in a linear manner (more or less) as you add for application servers to your server pool.

    All of the above assumes all the servers are on 1 network obviously.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求码,CNN+LSTM实现单通道脑电信号EEG的睡眠分期评估
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路