Build a Local File System with OSS
1. Experiment overview
This experiment is designed to attach an OSS bucket to a local file system through the OSSFS tool, allowing you to remotely manage the resources stored in the OSS bucket without the complex process of calling APIs. This experiment also deploys a WordPress environment in an ECS instance and completes specific configuration to directly synchronize the resources uploaded to WordPress to the OSS bucket.
1.1 Key points
- ECS simple operation
- Install and use OSSFS tools
- OSS Bucket resource management
- OSS Bucket mount local file system
- Start the lab environment
- Log in to the ECS instance remotely
- Install OSSFS tools application
- Mount OSS Bucket to ECS local file system
- OSS Bucket file management
1.3 Cloud resources
- ECS instance: Ubuntu 16.04.2 LTS
- Alibaba Cloud OSS console.
- ECS experience
- Learn about OSS Bucket file management operations
- The system has automatically assigned a username and password for logging on to the Alibaba Cloud console.
- The system automatically creates an ECS instance with a Ubuntu environment.
- The system automatically creates a bucket of the OSS container.
When you enter the ECS console, the default region area may be different because of the different network addresses of your logon location. If you find that the resource automatically created in the document does not exist at the console interface, please manually switch to the United States - Silicon Valley’s region, you will find them there.
If you encounter some differences between the real experimental environment and the captured pictures in the lab manual, it may be caused by cloud portal version difference, which does not have a great impact on your experimental experience. You can click comment to give feedback to us. We will update the document in time. Thank you for your cooperation.
2. Experiment instructions
2.1 Login Console
Click Start Lab in the upper right corner of the page to start the experiment.
After the experiment environment is successfully started, the system has deployed resources required by this experiment in the background, including the ECS instance, RDS instance, Server Load Balancer instance, and OSS bucket. An account consisting of the username and password for logging on to the Web console of Alibaba Cloud is also provided.
After the experiment environment is started and related resources are properly deployed, the experiment starts a countdown. You have two hours to perform experimental operations. After the countdown ends, the experiment stops, and related resources are released. During the experiment, pay attention to the remaining time and arrange your time wisely. Next, use the username and password provided by the system to log on to the Web console of Alibaba Cloud and view related resources:
Go to the logon page of Alibaba Cloud console.
Fill in the sub-user account and click Next.
Fill in the sub-user password and click Log on.
After you successfully log on to the console, the following page is displayed.
2.2 Shared Upload Folder
Alibaba Cloud Object Storage Service (OSS) is a massive, secure, cost-effective, and highly reliable cloud storage service from Alibaba Cloud. OSS has RESTful APIs that are independent from the platform and support 99.99999999% service persistence.
You can use the APIs or SDKs provided by Alibaba Cloud or the OSS migration tools to move massive data into or out of Alibaba Cloud OSS.
Managing the files stored in OSS instances through APIs or SDKs is complex and requires code compiling.
To simplify the management of resources stored in OSS instances, you can attach Alibaba Cloud OSS buckets to the local file system if you are using a Linux or Mac OS X operating system. Then, you can operate the objects in the OSS buckets through the local file system just like operating the resources in a local disk. You can also share data. This simplifies the process of operating OSS instances.
View an ECS instance
Enter the EIP of an ECS instance in the web browser:
The WordPress installation page appears. By default, the ECS instance is created using the system image of WordPress. This is equivalent to having installed a WordPress environment in the system. Perform subsequent operations later.
View an OSS bucket:
A default bucket has been created. Currently, the bucket is empty without any resources.
2.3 Connect to the ECS instance remotely
You can remotely connect to the ECS instance with the SSH protocol.
SSH is a network protocol for encrypted logon from one computer to another.
If you are using a <font size=4>Windows</font> computer, please download the SSH tool putty。
If you are using <font size=4>Linux</font> or <font size=4>Mac OS</font>, you can open the client application on your local computer and run the following command to log on to the ECS instance with the default account:
ssh root@(Elastic IP address of the instance)
The default account name and password of the ECS instance:
Account name: root
If you need to see the detailed login method, you can open the login link for further viewing.
After the ECS instance is connected, run the following command to install OSSFS, an application with an OSS instance attached.
apt-get install gdebi-core
Download the OSSFS installation package of the latest version:
2.4 Create an AccessKey
Refer back to the user’s home directory as shown below, click AccessKey Management.
Click Create AccessKey. After AccessKey has been created successfully, AccessKeyID and AccessKeySecret are displayed. AccessKeySecret is only displayed once. Click Save AccessKey Information to save the AccessKeySecret
2.5 Attach the OSS bucket to the local file system
Return to the terminal interface.
Set the bucket name, AccessKey, and AccessID, save the settings to the
/etc/passwd-ossfs file, and set the file permission correctly:
echo your-bucket-name:your-access-key-id:your-access-key-secret > /etc/passwd-ossfs
chmod 640 /etc/passwd-ossfs
Go to the website root directory of WordPress and the directory that stores the main content in sequence:
The wp-content directory contains the uploads subdirectory that stores the files uploaded to WordPress. After you attach the OSS bucket to the subdirectory, the files uploaded to WordPress are synchronized to the OSS bucket.
Attach the OSS bucket to the local file system:
ossfs your-bucket-name /data/wwwroot/default/wp-content/uploads -ourl=http://oss-us-west-1.aliyuncs.com
2.7 Manage the resources in the OSS bucket
Go to /data/wwwroot/default/wp-content/uploads to create a test file:
Return to the OSS console and refresh the current page. View the change in the number of files:
In the ECS instance, the files in the/data/wwwroot/default/wp-content/uploads directory are synchronized to the OSS bucket.
Delete the oss-test.txt file from the OSS bucket and check whether the file still exists in the /data/wwwroot/default/wp-content/uploads directory:
After the file is deleted from the OSS bucket, the same file is also deleted from the /data/wwwroot/default/wp-content/uploads directory in the ECS instance.
Data synchronization is enabled after the OSS bucket is attached to the local file system of the ECS instance. You can manage the files in the OSS bucket just like operating local files.
2.8 Synchronize the resources uploaded to WordPress to the OSS bucket
This section describes how to implement the function of synchronizing the files uploaded to WordPress to the OSS bucket Configuration is required to assign required permissions.
Detach the OSS bucket, complete the required modification, and attach the OSS bucket again:
Detach the OSS bucket:
Change the passwd-ossfs file owner:
chown www /etc/passwd-ossfs
Attach the OSS bucket again:
sudo -u www ossfs your-bucket-name /data/wwwroot/default/wp-content/uploads -ourl=http://oss-us-west-1.aliyuncs.com
Continue to install WordPress:
Log on to the WordPress site background:
Create a media file:
Upload the file:
After the file is uploaded to the WordPress background, go to the OSS console to check whether the file exists:
The current bucket has files. View the file details:
The image file uploaded to WordPress is stored in the OSS bucket. (Images with different resolutions)
Before you leave this lab, remember to log out your Alibaba RAM account before you click the ‘stop’ button of your lab. Otherwise you’ll encounter some issue when opening a new lab session in the same browser:
3. Experiment conclusion
This experiment implements two functions. The first is attaching an OSS bucket to the local file system through the OSSFS tool, allowing you to manage the resources stored in the OSS bucket without the complex process of calling APIs. The second is attaching an OSS bucket to the local file system through configuration to enable data synchronization, allowing you to synchronize the files uploaded to WordPress to the OSS bucket.