Because I like to look for cheap VPS and have to change servers frequently, website relocation has become a common thing. For large website data, it is best to transfer data directly between computer rooms. The three commonly used command tools Rsync, SCP, and Tar can help us quickly solve VPS remote website relocation and data synchronization.
However, thanks to the reminder from Xiao Z blog, in addition to using command tools to achieve data transfer, we can also use hard disk mounting to solve the problem of data migration. Using NFS, the Network File System distributed file system protocol, we can remotely mount the directories of different VPS hosts, making it much more convenient to copy files.
GlusterFS is the core of Gluster, the Scale-Out storage solution. It is an open source distributed file system with strong horizontal scalability, capable of supporting multi-PB storage capacity and processing thousands of clients through expansion. GlusterFS is generally used as an enterprise-level file storage solution, but we can also use GlusterFS to share storage between different VPS hosts.
The last one is samba. The main purpose of SAMBA's initial development was to communicate sharing between two different operating platforms, Windows and Unix Like. Samba is simple to configure and intuitive to operate. NFS remote mounting, GlusterFS shared storage and samba shared servers can also be used for file collaboration, server mirroring, etc. In short, the scalability is very strong.
This article will briefly share the operation methods of NFS remote mounting, GlusterFS shared storage and Samba shared server. For more information about cloud storage and webmaster tools, you can also learn:
- Nextcloud is an excellent choice for personal cloud storage: one-click automatic installation method and cloud disk usage experience
- Lsyncd builds synchronization mirror-use Lsyncd to achieve real-time synchronization between local and remote servers
- Linux VPS mounts Google Drive and Dropbox-realizes VPS host data synchronization and backup
1. NFS remote mounting
Demo environment, server A: 172.104.184.98, client B: 107.161.18.176. If you don’t have a VPS, you can take a look at the VPS host list I have used: VPS host list.
The relevant command operations are as follows:
#在两台VPS上安装执行安装
sudo apt-get install -y nfs-kernel-server
#在A上创建文件夹
mkdir -p /media/wzfou/asus
#在A上编辑并添加授权B读写
vim /etc/exports
/media/wzfou/asus 107.161.18.176(rw,no_root_squash,async)
#在A上重启
sudo systemctl restart nfs-server.service
#在B上创建文件夹
sudo mkdir -p /home/wzfou/share
#在B上将刚刚创建的文件夹挂载到A上共享文件夹
sudo mount -t nfs 172.104.184.98:/media/wzfou/asus /home/wzfou/share
If there is no prompt, it means the mount is successful.
Now the shared files on A and B have been mounted and synchronized in real time. You can see two-way synchronization by uploading or deleting files to the shared folder.
2. GlusterFS shared storage
2.1 GlusterFS Repository
Debian:
sudo apt-get install -y lsb-release sudo apt-get install -y apt-transport-https
Add the public key for GlusterFS repository.
wget -O - http://download.gluster.org/pub/gluster/glusterfs/LATEST/rsa.pub | sudo apt-key add - echo deb https://download.gluster.org/pub/gluster/glusterfs/LATEST/Debian/$(lsb_release -sc)/apt $(lsb_release -sc) main | sudo tee /etc/apt/sources.list.d/gluster.list
Ubuntu 16.04/14.04:
sudo apt-get install -y software-properties-common sudo add-apt-repository ppa:gluster/glusterfs-3.8
2.2 Install GlusterFS
Update repository cache.
sudo apt-get update
Install the GlusterFS package.
sudo apt-get install -y glusterfs-server
Start glusterfs-server service.
sudo service glusterfs-server start
Confirm whether glusterfs service is running.
sudo service glusterfs-server status
The following command is executed on the server to add the client node (107.161.18.176).
raj@gluster1:~$ sudo gluster peer probe 107.161.18.176 peer probe: success.
Confirm status.
sudo gluster peer status
List nodes.
sudo gluster pool list
Configure Firewall. Disable the firewall or add the client's IP to the allowed range.
sudo iptables -I INPUT -p all -s <ip-address> -j ACCEPT
The successful installation is as follows:
2.3 Create a shared storage volume
Now we need to create the shared storage volume. First, perform the following operations on the server:
#创建文件夹
sudo mkdir -p /data/gluster/gvol0
#创建共享卷volume,并分别挂载服务端(139.162.175.85)和客户端(107.161.18.176)
sudo gluster volume create gvol0 replica 2 139.162.175.85:/data/gluster/gvol0 107.161.18.176:/data/gluster/gvol0 force
#启用卷
sudo gluster volume start gvol0
#查看卷
sudo gluster volume info gvol0
Now go to the client (107.161.18.176) and mount the server (139.162.175.85). The command is as follows:
#安装客户端
apt-get install -y glusterfs-client
#创建文件夹
mkdir -p /mnt/glusterfs
#挂载服务端(139.162.175.85)
mount -t glusterfs 139.162.175.85:/gvol0 /mnt/glusterfs
#开机自动挂载
vim /etc/fstab
139.162.175.85:/gvol0 /mnt/glusterfs glusterfs defaults,_netdev 0 0
Execute the command: df -hP /mnt/glusterfs
, you can see that the mounting is successful.
You can also see this using the df command.
Now you can realize shared storage among different VPS hosts, and you can see the synchronization when adding or modifying files.
3. Samba realizes sharing between Linux and Windows
The two sharing methods mentioned above are suitable for Linux, so how do Windows and Linux share? The more popular method currently is through a cross-platform network file sharing protocol: SMB/CIFS. Windows natively supports SMB/CIFS, and Linux also implements the SMB/CIFS protocol through the open source software Samba.
3.1 Install samba
sudo apt-get install samba
3.2 Create shared directory
// 创建的目录即之后能够在Windows主机上直接访问的目录。
// 例如:在用户wzfou的主目录下新建share文件夹为共享目录
mkdir /home/wzfou/smbshare
// 由于Windows下的文件夹需可读可写可执行,需更改权限为777
sudo chmod 777 /home/wzfou/smbshare
3.3 Modify samba configuration file
// 修改 /etc/samba/smb.conf
sudo vim /etc/samba/smb.conf
// 在smb.conf文件最后加上以下内容
[share]
path = /home/wzfou/smbshare
public = yes
writable = yes
valid users = wzfou
create mask = 0644
force create mode = 0644
directory mask = 0755
force directory mode = 0755
available = yes
The description of smb.conf is as follows:
(1) [share] indicates the alias of the shared folder, and this alias will be used directly later.
(2) The settings of force create mode
and force directory mode
are caused by the different default permissions of files and folders under Windows and Linux. Newly created files under Windows are executable. , its file permissions must be set compulsorily.
(3) valid users is set to your current Linux user name, for example, mine is wzfou, because when you open a shared folder for the first time, you need to verify permissions.
3.4 Set login password
// 新建/etc/samba/smbpasswd文件
sudo touch /etc/samba/smbpasswd
// 根据3.3设置的valid users,设置用户密码
// wzfou 替换为你在3.3中设置的用户名
sudo smbpasswd -a wzfou
//输入两次密码后,会提示 Added user wzfou. 表示设置成功
// 若用户名非当前登录系统的用户名,可能会提示Failed
3.5 Start samba server
sudo /etc/init.d/samba restart
3.6 Test whether sharing is successful
sudo apt-get install smbclient
smbclient -L //xx.xx.xx.xx/share
//还记得吗?share为3.3中设置的共享文件夹的别名
//如果共享成功,将要求输入之前设置的密码
3.7 Using samba on Windows and Linux
Windows Explorer->Map Network Drive. The input format is: the name of the IP address configuration, then enter the account password and the connection is successful.
If you are using Windows 7 and may be unable to connect to Samba, you can take the following methods to solve the problem:
1. Modify the local security policy: Run secpol.msc to open the "Local Security Policy" form, click "Local Policy" - "Security Options", and modify the value of "Network Security: LAN Manager Authentication Level" to " Send LM and NTLM - Use NTLMv2 session security if negotiated", just OK all the way.
2. Modify the registry: Modify the value of LmCompatibilityLevel under HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlLsa to 1.
For Linux, access it through the address smb://<samba-server-IP-address>/share
in Thunar.
4. Summary
Among the Linux shared folder methods, the NFS remote mounting method is the most convenient, especially suitable for migrating website data between different VPS host servers. Once the remote mounting is successful, we can be as convenient as locally copying the data. This is better than Three command tools: Rsync, SCP, and Tar - quickly solve VPS remote website relocation and data synchronization and are more convenient.
The GlusterFS method of creating shared volumes is particularly suitable for cluster servers. The GlusterFS cluster file system can also be applied to enterprise-level Docker distributed storage. Samba realizes file sharing between Linux and Windows. Previously we shared the Raspberry Pi installation NextCloud tutorial - self-built home private cloud LAN sharing. In fact, we can also use samba to share the Raspberry Pi with other devices.