Today I got a very strange problem when I using carrierwave, When I upload some pictures and the form validator told me some fields need to be filled, then I fill them and submit the form again, the uploaded file supposed to be cached, but it randomly told me some file supposed to be cached are missing.
After investigate a little bit I found I have 2 servers, and the cache file only stored on one of the server, so when request goes to another server which doesn’t has cache file, it will report no file uploaded.
For solving this, I just mount one directly to another server, make the cache directly the same.
On NFS server side:
sudo apt-get install nfs-server portmap nfs-common
On NFS client side:
sudo apt-get install nfs-client nfs-common
Add below line to
Mount the directory on another server:
sudo mount -o soft,intr,rsize=16384,wsize=16384 server_ip:/path_to_tmp_folder/tmp /local_path_to_empty_tmp_folder/tmp
Add below line to /etc/fstab, this is for auto mount when server reboot:
server_ip:/path_to_tmp/tmp /local_empty_folder/tmp nfs rsize=16384,wsize=16384,rw,auto,nolock