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.
- 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:
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.
- 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)
- 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
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
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
- 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
- Log on to the Linux ECS instance as a root user or a sudo-enabled user.
- Run the following command to mount the file system:
mount -t cifs //xxx-crf23.eu-west-1.nas.aliyuncs.com/myshare /mnt -o vers=2.0,guest,uid=0,gid=0,dir_mode=0755,file_mode=0755,mfsymlinks,cache=strict,rsize=1048576,wsize=1048576
mount -t cifs //<Domain name of the mount target>/myshare <Path of the shared directory> -o <Mount options>
Parameter Description File system type Specify the
-t cifsparameter in the command for the SMB file system.
Domain name of the mount target Specify the domain name of the mount target in the command. The domain name is automatically generated when you create the mount target. For more information, see Manage mount targets. myshare The name of the shared directory for the SMB file system. You cannot change the name after you specify this parameter. Path of the shared directory The path of the directory on which the SMB file system is mounted. For example, you can specify /mnt/sharepath. Mount options
Specify the required mount options by adding the
-oargument in the mount command:
- vers: specifies the version of the SMB protocol. Specify 2.0 or 3.0 for the option.
- guest: specifies the identity that you want to use to mount the file system. You must use the guest identity that is authenticated based on the New Technology Lan Manager (NTLM) protocol.
- rsize: specifies the maximum size of a data packet that the SMB client can read from the SMB file system. In most cases, set this option to 1048576 (1 MB).
- wsize: specifies the maximum size of a data packet that the SMB client can write to the SMB file system. In most cases, set this option to 1048576 (1 MB).
Specify the following mount options by adding the
- uid: specifies the user to which the files in the file system belong after a successful mount. The default value of uid is 0.
- gid: specifies the user group to which the files in the file system belong after a successful mount. The default value of gid is 0.
- dir_mode: specifies the read, write, and execute permissions that you want to grant to the user on the specified directories. The value must start with 0, for example, 0755 and 0644. The default value of dir_mode is 0755.
- file_mode: specifies the read, write, and execute permissions that you want to grant to the user on files. The value must start with 0, for example, 0755 and 0644. The default value of file_mode is 0755.
- mfsymlinks: specifies whether symbol links are supported.
- If you set this option to strict, caching is enabled for the SMB client. The default value of cache is strict.
- If you set this option to none, caching is disabled for the SMB client.
- atime|relatime: If file access time does not affect your business, we recommend that you do not set this option to atime. The default value of this option is relatime.
- Run the
mount -lcommand to view the mount result.
The output in the following figure indicates that the file system is mounted.
- Read data from and write data to the file system.
You can access the file system the same way you access a local directory. The following figure shows an example.
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
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
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.