17

I have multiple Linux web servers attached to a load balancer, and I like to share assets (such as pictures, videos, and other stuff) between these servers. What is the best way to do this?

Currently, I have mounted on a file server to all the web servers, but I am worried about it going down under a heavy traffic. How can I avoid this from happening?

Thanks in advance.

2

6 Answers 6

12

There are multiple ways to do this based on your needs.

  • Use a central file server mounted with fx NFS on the webservers
  • Same as above, but redundant, so if one goes down the other takes over
  • Use some sort of synchronization tool (rsync for example) and host the files locally on the webservers. Then setup a cronjob to sync the files between the servers at a specific interval.
  • Use a CDN such as Amazon S3, Akamai etc.

The first two are best if you have a lot of new files coming. The third would be the ideal solution if you don't add or change files that often since the users will get 404's on static content not yet synced..

The last option might be ideal in many ways, but might also turn out to be the most expensive of the 4. You would also need to rewrite your websites to support this.

3
  • The big problem with rsync is that you are likely to get a 404 if you upload new data and the rsync does not happen very quickly... Also a system like Cassandra (point 4) is free, although of course having 10 servers is not free... so, maybe I should say no extra charge (although it needs some programming to make it all work.) Feb 9, 2015 at 0:04
  • @AlexisWilke - You are right about rsync, and i did also sort of mention it in the answer. I have clarified it in the answer now.
    – Frederik
    Feb 9, 2015 at 8:30
  • Re: #3, the 'dead time' between new asset deployed and new asset synchronized can be minimized if you use a filesystem watcher (such as Facebook's watchman) and a fast sync tool (such as csync2). No, the delay will never go down to zero, but it's very minimal and might be easier to deploy than the other alternatives.
    – pepoluan
    Feb 11, 2015 at 2:38
2

Another great way to decrease load on webservers and perform load balancing is with squid (namely squid3) Set it up as a reverse proxy with caching. It will cache static content such as pictures etc to either the HDD (default) or to RAM (faster and the best) if you set it that way. It is capable of round robin to other squid servers as well if any one particular node is overloaded.

3
  • 1
    I think that kind of caching fails if you want a very dynamic website. Because with heavy dynamism, you still need to hit the one main backend server for a lot of the data. I think the user is looking into splitting the backend work instead. Feb 9, 2015 at 0:07
  • 1
    Your answer is correct about potentially reducing load, but doesn't answer the question about sharing asset files between multiple servers.
    – user186340
    Feb 9, 2015 at 9:33
  • @AlexisWilke it does (fail) if you don't have squid setup correctly. Adjust how it caches (or if it caches) in the settings, but you may find that no page is ever completely dynamic. There is always something you can cache. Also Andre, it helps a great deal in sharing assets as the title describes, but sharing files not so much. The question was how to keep the sites from going down under heavy load. Squid is excellent at doing this. Feb 21, 2015 at 19:41
2

One solution to this challenge I've employed is to have the main read/write copy of the files on a shared NFS drive, but also keep at read-only copy on each webserver so that a failure of the NFS host puts file-access in read-only mode rather than loosing them completely.

  • Files live on central host, shared with web-hosts via NFS mount
  • rsync runs ever 15 minutes to keep the read-only copy on each web host fresh.
  • A check_link bash script runs every minute to make sure the NFS mount is still there and if not swaps a symlink to the read-only copy.

More details are found in this article from when I first set up this system.

Upsides:

  • File reads are highly available
  • No race conditions for file writes
  • New files are instantly available to all web hosts.

Downsides:

  • a bit complex.
  • the number of read-only copies scales with the number of web hosts, which might be excessive if you have many more than two.
  • File writes are not highly available.
  • Potential for up to 1 minute of downtime before switching to the read-only copy.
1

Since usually the need for more servers comes from the resources needed to run dynamic websites/aps, consider hosting static assets at another subdomain/domain. (like static.yourdomain.com)

You can then use another server/servers to host them. Static file hosting doesn't use very much resources, so you will need considerably less servers for your static content. You will also free some resources on the servers for your dynamic content.

Depending on your load balancer you might also be able to do this on the same domain with the load balancer deciding which server to use for which request, but if you use a separate domain you can put your static assets onto a CDN quite easy, if the need should arise!

0

You might want to consider a NoSQL database. They are designed to work on clusters, provide eventual consistency. But be careful they are not ACID.

Here's an introduction that will help you decide what kind of NoSQL database you might want for your purpose.

Here is a list of resources related to available NoSQL.

5
  • 4
    How this answer helps in file sync problem?
    – titus
    Feb 9, 2015 at 8:36
  • @titus In NoSQL, when there is a write on one of the nodes, it will be replicated on other nodes in the cluster. Cassandra write consistency levels might help in making it clear
    – Azzy
    Feb 9, 2015 at 10:52
  • so the way to go is store all files in NoSQL db?
    – titus
    Feb 9, 2015 at 10:57
  • @titus you can, but NoSQL databases can do a lot more then store files, It all depends on your needs.
    – Azzy
    Feb 9, 2015 at 11:05
  • 2
    OP asked for a solution to a specific problem "multiple Linux web servers attached to a load balancer ... share assets (such as pictures, videos, and other stuff) between these servers." Your answer is very generic, can you suggest and explain specific tools (and preferably configurations thereof) to address the problem?
    – kdbanman
    Feb 12, 2015 at 5:48
0

Why don't you try a DFS solution , they provide high level of redundancy and the volume could be shared between as many as you'd like . Gluster is my favorite one and is very easy to install and configure in any famous Linux distro

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .