Content
Introductory
Running a web server may run out of space on the main partition on which you store your web pages. This can be very inconvenient, because in the best case, at least all the web pages have to be moved to another drive, which we have newly attached to the system. This is time consuming, so there are more downtime before we copy everything to the new partition. In the worst case, we can reinstall the entire system on the new hard drive.
In this description we can see a more practical solution, a bind mount a method that allows you to move even one website separately without downtime, leaving the rest intact. We also take advantage of the original partition as we do not copy everything over again. This way we can optimally manage all our storage space. The method can be used in several situations, for example:
- VirtualBox our machine we are adding another virtual hard drive
- We are adding a new hard drive to our live server
- We are not upgrading the machine with any new disks, we just want to use other partitions that already have more space on the machine
- We want to separate an existing web site from the rest, which needs more storage space
- We should upload a new website to our server, but it no longer has enough storage space in the basic structure
Whatever the situation, this solution will help you solve the problem. In this example, it is me ISPConfig in a perfect server environment I present with the third case when the system already contains the required larger partition and we want to move a web host to it. Regardless, it works with any web server configuration (e.g. LAMP servers), only this makes it more lifelike, as I’ve already separated a website on my server in the same way, so I’ll describe my own best practices for live use.
Move Web Hosting
Suppose that / var directory structure and / Home directory structure is on a separate partition. In the first are stored the ISPConfig , while the / home directory structure is on a separate partition with plenty of free space.
Let our website you want to migrate be named example.com, which has root access to the server:
/ Var / www / clients / client1 / web1 /
This directory is therefore the document directory of the website, which contains, among other things, the directory structure required for the chroot, as well as the "web /"subdirectory, which is the root directory of the web page.
In this example, we will move the webroot directory (/ Var / www / clients / client1 / web1 / web /) to / Home structure. The one root of the document itself is not moved because it is part of the server environment and does not take up much space, so only the root of the web page is redirected to the other partition.
Design of target area
Log in as root and create space for the web page under / home:
cd /home
mkdir example.com
Hand over the directory to the ISPConfig user:
chown web1:client1 /home/example.com
Copy content
We will then copy the website itself to this new directory. If you are creating a new web page and there is no content in the web root yet, still perform the copy because ISPConfig creates some subdirectories, such as stats /, cgi-bin /, etc., when you create the web host. so these must also be copied exactly for the system to work properly. However, if there is already content in the web root, so it is a working web page, its content will have to be deleted so that it does not take up space on the old partition.
Make the copy and then change the file structure to the web page user:
cp -r /var/www/clients/client1/web1/web /home/example.com/www
chown -R web1:client1 /home/example.com/www
So here we recursively copy everything from the web root, including the hidden files.
Configure Bind mount in the fstab file
Then open the / etc / fstab file for editing:
nano /etc/fstab
And add the following line and save it (it doesn't take effect yet):
/home/example.com/www /var/www/clients/client1/web1/web none bind,nobootwait,_netdev 0 0
(Mounting in the fstab file remains persistent, so the mount will be performed again after the system is restarted.)
- /home/example.com/www: Filesystem, where you specify the path to the new partition where the web page was copied
- / Var / www / clients / client1 / web1 / web: A mount point, which will be replaced by the original web root directory of the web page to which the physical content of the previous path will be mounted.
So the page remained available until we got here.
Delete original web content
After mounting, the contents of the original web root directory will no longer be accessible, as the specified directory will be mounted, so now the original content can be deleted (the web directory remains, only the content in it will be deleted):
rm -rf /var/www/clients/client1/web1/web/{*,.*}
It's a good idea to make sure everything has been deleted from the library, as it won't be revealed later that something's in place.
Mount execution
Then execute a mount command with the -a option:
mount -a
If we did everything right, then if you mount successfully, you can instantly access the page from your new (physical) location on the web, and even Apachedid not need to be restarted. This way, all other web pages were left running smoothly on the server, and the moved web page was dropped for only a few seconds while deleting and then mount.
Removal of Bind mount if necessary
If you want to unlink later for some reason (eg need to access the original web root or page relocation, etc.), you can do so with the following command as root without rebooting the system:
umount /var/www/clients/client1/web1/web
Then delete the added line from the / etc / fstab file.
Conclusion
Thus, the bind mount method allows you to move any web page individually on the server to another partition or to a new hard disk on the fly if there is not enough web space. As we have seen, the operation does not require a restart or shutdown, so it can be used in practice at any time on a live web server without disrupting other websites.
- To post registration and login required
- 238 views