This topic describes how to mount a Server Message Block (SMB) file system on a Linux Elastic Compute Service (ECS) instance. This topic also describes how to read data from and write data to the SMB file system.
Prerequisites
- An ECS instance is available in the region where you want to create a file system.
For more information, see Create an ECS instance.
One of the following Linux distributions is run on the ECS instance. Unless otherwise specified, this topic applies only to the following Linux distributions:
- CentOS 7.6 64-bit (3.10.0-957.5.1.el7.x86_64)
- Ubuntu 18.04 64-bit (4.15.0-48-generic)
- Debian 9.9 64-bit (4.9.0-9-amd64)
- SUSE Enterprise Server 12 SP2 64-bit (4.4.74-92.35-default)
- openSUSE 42.3 64-bit (4.4.90-28-default)
- Alibaba Cloud Linux (4.19.34-11.al7.x86_64)
- CoreOS (4.19.43-coreos VersionID=2079.4.0)
Note If you use a version of Linux that is not in this list, errors may occur on the SMB client. If you use an unsupported version, Alibaba Cloud does not guarantee the reliability of SMB file systems. - An SMB file system is created. For more information, see Create a General-purpose NAS file system in the NAS console.
- A mount target is created. For more information, see Create a mount target.
- The network is available.
- The Linux ECS instance and the SMB file system reside in the same virtual private cloud (VPC).
- The IP address of the Linux ECS instance is in the whitelist of the SMB file system and the ECS instance can access the SMB file system.
- TCP port 445 is enabled for the Linux ECS instance to access the SMB file system.
If port 445 is disabled, you must add a rule to a security group of the ECS instance for the port. For more information, see Add security group rules.
Install the cifs-utils package
Install the cifs-utils package on a Linux ECS instance.
- If you are using Ubuntu or Debian, use the apt-get package manager to install the
cifs-utils package.
sudo apt-get update
sudo apt-get install cifs-utils
- If you are using Red Hat Enterprise Linux (RHEL), CentOS, or Alibaba Cloud Linux,
use the Yellowdog Updater, Modified (YUM) package manager to install the cifs-utils
package.
sudo yum install cifs-utils
- If you are using openSUSE or SUSE Linux Enterprise Server 12 Service Pack 2 (SLES
12 SP2), use the Zypper or Yet another Setup Tool (YaST) package manager to install
the cifs-utils package.
sudo zypper install cifs-utils
Run the sudo yast2 command, choose Software > Software Management, and then install the cifs-utils package.
- If you are using CoreOS, install the cifs-utils package by performing the following
steps:
- Configure Security-Enhanced Linux (SELinux).
sed -i 's/SELINUXTYPE=mcs/SELINUXTYPE=targeted/' /etc/selinux/config
- Compile the cifs-utils package on a CoreOS ECS instance.
You can run the following command to create a Fedora container and compile the cifs-utils package. You can also download the cifs-utils package that Alibaba Cloud provides for CoreOS, and then copy the package to the /tmp or /bin directory.
$ docker run -t -i -v /tmp:/cifs fedora /bin/bash fedora # yum groupinstall -y "Development Tools" "Development Libraries" fedora # yum install -y bzip2 fedora # curl https://download.samba.org/pub/linux-cifs/cifs-utils/cifs-utils- 6.9.tar.bz2 --output cifs-utils-6.9.tar.bz2; fedora # bunzip cifs-utils-6.9.tar.bz2; && tar xvf cifs-utils-6.9.tar fedora # cd cifs-utils-6.9; ./configure && make fedora # cp mount.cifs /cifs/ fedora # exit
- Configure Security-Enhanced Linux (SELinux).
Mount a file system
Scenarios
To ensure optimal performance of the file system, you can specify mount options based on specific scenarios. This section lists scenarios and the mount options that are suitable for each scenario:
- Shared access to a file system from multiple Linux ECS instances
Multiple Linux ECS instances share access to a file system and no access control is required. In this scenario, you can use an authorized administrator of each ECS instance to mount the file system on the ECS instances. The following command shows an example:
mount -t cifs //smbfs.hangzhou-g.aliyun.com/myshare /mnt/sharepath -o vers=2.1,guest,mfsymlinks
- Shared access from multiple Linux ECS instances to a home directory
Multiple Linux ECS instances share access to a home directory and you need to control access to the home directory. You can set the uid, gid, dir_mode, and file_mode options in the mount command to manage permissions.
- Shared access to a file system from multiple Linux ECS instances that function as
web servers
You can install web server applications such as Apache HTTP Server on multiple Linux ECS instances and use an SMB file system as shared file storage.Note
- The SMB file system provides shared access, horizontal scalability, and high availability. When users access small files in the SMB file system, the performance of the SMB file system may be compromised. This occurs because the mechanism of SMB file systems is different from the mechanism of local disks. In this scenario, we recommend that you store shared files in the SMB file system and other files in local disks to ensure optimal performance.
- In most cases, web server applications have heavy workloads. You can enable the acceleration feature for the applications to process heavy workloads. You can contact NAS technical support to enable this feature.
- Shared access from both a Windows ECS instance and a Linux ECS instance to a file
system
A Windows ECS instance and a Linux ECS instance share access to an SMB file system. In this scenario, you must set the cache option to strict or use the default value of this option when you mount the file system on the Linux ECS instance.