Build a private network disk (build with Alibaba Cloud oss)

1. Personal network disk scene description

Personal network disk architecture

Use ECS to install Cloudreve to provide network disk services, and OSS to provide storage services. When a user uses a personal network disk, accessing the public network IP address where Cloudreve ECS is deployed can complete file upload, download, delete, share and other services.

img

What is Cloudreve

Cloudreve can help you instantly build a network disk service for both personal use and public use, and realize a flexible file management experience through the support of multiple storage strategies, virtual file system and other features.

what is ossfs

ossfs allows you to mount the object storage OSS storage space (Bucket) to the local file system in the Linux system, and you can operate the OSS object (Object) like a local file to realize data sharing.

Information that needs to be collected in the personal network disk scenario

During the construction process, the following information needs to be collected to facilitate the configuration of subsequent construction steps. The cloudreve initial administrator password is a random value and needs to be recorded.

Please note: When entering URLs and command symbols, the input method needs to be switched to English mode, otherwise it will not work.

information type effect Remark
BucketName Used when configuring ossfs , mounting OSS , and configuring cloudreve storage policies . Obtain through OSS console>>Bucket list
AccessKeyId Use when configuring ossfs Click this link to get [Get AccessKeyId]
AccessKeySecret Use when configuring ossfs Click this link to get AccessKeySecret
Endpoint Used when configuring ossfs and mounting OSS Obtain through OSS console>>Bucket list>>Bucket overview>>Access port
ECS public address Use when cloudreve logs in Obtain the ECS cloud server-elastic IP through the Alibaba Cloud console
OSS mount point Used when mounting OSS Fixed value: /root/oss
cloudreve port Use when cloudreve logs in Fixed value: 5212
cloudreve initial administrator account Use when cloudreve logs in Fixed value: [email protected]
cloudreve initial admin password Use when cloudreve logs in Random value: need to record
cloudreve storage directory Cloudreve is used when configuring storage policies Fixed value: /root/oss/uploads/{uid}/{path}

2. Create an OSS Bucket

Log in to the OSS console

  1. Click the icon in the upper left corner of the Alibaba Cloud console home page in the browser img, enter " OSS " in the search box , and click Object Storage OSS in the search results to enter the OSS management console .

img

**Note: **As shown in the figure below, it means that you have entered the OSS management console.

img

Create an OSS Bucket

  1. You can use the OSS management console to select the Bucket list and click Create Bucket to create a Bucket.

img

2. When creating a Bucket, fill in the Bucket name , select the correct region , use the default values ​​for other parameters , and click OK to complete the creation of the Bucket.

illustrate:

  • **Bucket name:** is globally unique. If you encounter " This bucket already exists or is occupied by another user " when filling in the bucket, please change the bucket name.
  • Region: In the personal network disk scenario, it needs to be in the same region as the ECS instance . You can find the cloud ESC server and obtain ECS region information through the console .
  • ** Other parameters: ** Use the default value.

img

3. Install Cloudreve

Log in to the ECS instance

  1. Find the ECS instance where the network disk needs to be deployed, and switch to Terminal .

Install and run Cloudreve

  1. Installation package**.

Description : wget is a command-line tool for Linux systems to download files from the Web. Wget adds the link of the file to be downloaded to complete the download of the file.

wget https://labfileapp.oss-cn-hangzhou.aliyuncs.com/cloudreve_3.3.1_linux_amd64.tar.gz

**Description:** The return result is as follows, that is, the download of the cloudreve installation package is completed.img

3. After the download is complete, execute the following command to decompress the cloudreve installation package.

Explanation : tar is the decompression and compression command used by the Linux system. In the decompression parameters, z means to cooperate with the decompression**.gz type of compressed package , x means to decompress , v** means to display the detailed information of decompression, and f means to process the file.

tar -zxvf cloudreve_3.3.1_linux_amd64.tar.gz

**Description:** The return result is as follows, that is, the decompression of the cloudreve installation package is completed.

img

4. Execute the following command to grant permission to cloudreve.

Explanation **: chmod is used to change the access permission of a file or directory, +x** means to grant executable permission, and the next step is to run the cloudreve program, and you must give cloudreve executable permission.

chmod +x ./cloudreve

5. Execute the following command to run cloudreve.

./cloudreve

Note: The returned results are as follows, you can see the initial administrator account , initial administrator password and listening port . The initial password is randomly generated, you can record the initial administrator password , or return here for subsequent inquiries.

img

Verify Cloudreve

1. When accessing the network disk, you need to use the public network IP, and you need to obtain the public network address of the ECS instance.

2. In your local browser, open a new tab, visit http://< ECS public network address >:< cloudreve****listening port >, enter the initialization administrator account and initialization administrator password in sequence , Click Login . Note that the colon is an English format character.

Note: Assuming that the ECS public network address is 192.168.1.1, and the cloudreve**** listening port is a fixed value of 5212, then the access address of cloudreve is: http://192.168.1.1:5212. Please replace the public IP address of the actual ECS instance.img

3. The successful login interface is as follows.

img

Stop Cloudreve

4. Press Ctrl+C in the terminal to stop cloudreve from running.

4. Install ossfs

install ossfs

ossfs allows you to mount the object storage OSS storage space (Bucket) to the local file system in the Linux system, and you can operate the OSS object (Object) like a local file to realize data sharing. In this deployment, the OSS Bucket is mounted to the ECS instance through ossfs and used as the storage of the personal network disk.

  1. Run the following command to download the ossfs installation package.
wget https://gosspublic.alicdn.com/ossfs/ossfs_1.80.6_centos8.0_x86_64.rpm

Description : wget is a command-line tool for Linux systems to download files from the Web. Wget adds the link of the file to be downloaded to complete the download of the file.

ls 

**Note:** The return result is as follows, that is, the download of the ossfs installation package is completed.

img

2. Install ossfs.

yum (Yellow dog Updater, Modified) is a shell front-end package manager in Fedora and RedHat and SUSE. It can automatically download and install RPM packages from a specified server, automatically handle dependencies, and install all dependent software packages at one time without tedious downloading and installation again and again. In this scenario, we need to install the ossfs software. During the ossfs installation process, yum can automatically download and install the dependent software packages of the ossfs software.

  1. Run the following command to replace the yum source.

**Note: **The ECS system is Centos 8. Since the official Centos8 yum source is offline, it needs to be replaced with Alibaba Cloud yum source.

step1 : First delete the expired .repo file in the system

rm -f /etc/yum.repos.d/*

step2 : Download the new CentOS-Base.repo to /etc/yum.repos.d/

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

step3 : run yum makecache to generate cache

yum clean all && yum makecache

**Description:** The return result is as follows, that is, the replacement of the yum source is completed.

img

3. Execute the following command to install ossfs.

Note : When using the yum command to install ossfs, yum install xx.rpm means to install the xx.rpm package, and the -y parameter means to automatically select yes during the installation process

yum install -y ./ossfs_1.80.6_centos8.0_x86_64.rpm

Description: **** After executing the installation command, the returned result shows Complete! , as shown in the figure below, indicating that ossfs is installed successfully.

img

configure ossfs

  1. Obtain the OSS Bucket, AccessKey ID, and AccessKey Secret information.
  • BucketName : The name of the bucket you created in the OSS console , which can be viewed in the OSS console > Bucket list .
  • AccessKey ID and AccessKey Secret , AK ID is AccessKey ID, AK Secret is AccessKey Secret.
  • get ak method

2. Execute the following command to configure account access information, and store the Bucket name, AccessKey ID and AccessKey Secret information with the Bucket access permission in the /etc/passwd-ossfs file.

Note: You need to replace BucketName, yourAccessKeyId, and yourAccessKeySecret in the command with the Bucket name you created, the AccessKey ID of the primary account, and the AccessKey Secret of the primary account . Note the use of English formatting characters.

echo BucketName:yourAccessKeyId:yourAccessKeySecret > /etc/passwd-ossfs
示例:echo hhbtest:sdafsdfasdf12313:hjhsdjfhkjhkjhkjhkj > /etc/passwd-ossfs

20 Run the following command to grant permissions to the passwd-ossfs file.

Note: In the subsequent stage of mounting the OSS Bucket, you need to use the AccessKeyId and AccessKeySecret in passwd-ossfs to verify whether you have the permission of the Bucket in the passwd-ossfs file .

chmod 640 /etc/passwd-ossfs

5. Mount the OSS Bucket

create mount point

  1. On the ECS CLI, execute the following command to create a folder named oss.
mkdir oss

Manually mount the OSS Bucket

2. Execute the following command to mount the Bucket to the specified directory **/root/oss**. You need to replace the BucketName, mountfolder, and Endpoint in the command with the bucket name created before, the created oss ​​folder, and the contents of OSS Web Endpoint.

ossfs BucketName mountfolder -o url=Endpoint

illustrate:

  • BucketName : The name of the bucket you created in the OSS console , which can be viewed in the OSS console > Bucket list .
  • mountfolder : The mount folder created in the previous step (**/root/oss**).
  • Endpoint : The endpoint of the classic network access (intranet) of ECS of OSS, which can be viewed in Bucket List >> Bucket Overview >> Access Port .

img

  1. Check whether the mount is successful.
df -h

Note : The returned result is as follows, indicating that the mount is successful.

img

Set the OSS Bucket to be automatically mounted at startup

  1. Execute the following command to create the file ossfs in the /etc/init.d/ directory, and set the ECS startup script to automatically mount the OSS Bucket .

  2. Enter the Vim editor.

vim /etc/init.d/ossfs

3. Press the i key to enter the editing mode, and you will see the words **–INSERT–** at the bottom left of the vim editor, indicating that you have entered the editing mode.

img

4. Copy the content of the following sample script, right-click and paste, and the paste dialog box will pop up. At this time, you need to replace BucketName, mountfolder, and Endpoint in the last line of the command with the name of the Bucket you created, the folder path of the ossfs mount point you created, and Intranet Endpoint of OSS .

  • BucketName : The name of the bucket you created in the OSS console , which can be viewed in the OSS console > Bucket list .
  • ossfs mount point : /root/oss.
  • Endpoint : The endpoint of the classic network access (intranet) of ECS of OSS, which can be viewed in Bucket List >> Bucket Overview >> Access Port .
#! /bin/bash
#
# ossfs      Automount Aliyun OSS Bucket in the specified direcotry.
#
# chkconfig: 2345 90 10
# description: Activates/Deactivates ossfs configured to start at boot time.

ossfs BucketName mountfolder -o url=Endpoint -oallow_other

img

Note : It will be displayed as shown in the figure below, indicating that the pasting is completed.

img

5. Press the Esc key to exit the vim editing mode , that is, the word **–INSERT– disappears at the bottom left of the vim editor . **

img

6. Save the file, enter **:wq**, you will see **:wq** at the bottom left of the vim editor, **press the Enter key,** save and exit the Vim editor.

img

7. Execute the following command to grant executable permission to the newly created ossfs script.

Description : chmod is a command to add and change permissions, a refers to all user groups, and +x refers to adding execution permissions.

chmod a+x /etc/init.d/ossfs

8. Execute the following command to use the ossfs startup script as another service and start it automatically after booting.

chkconfig ossfs on

6. Configure personal network disk

run cloudreve

  1. Execute the following command to run cloudreve.
./cloudreve

Configure Cloudreve

Configuring cloudreve is mainly to configure storage policies and bind storage policies to user groups. Storage policies define storage platforms, uploads, and functional restrictions for files. A user group is bound to a storage policy, and users under this user group will share the same storage policy.

  1. Log in to cloudreve. Open a browser, visit http:// <ECS public network address>:****<cloudreve listening port> , enter the administrator account and password in turn, and click Login . Note that colons use English formatting characters.

Note: ****You can view the public network address of ECS through the cloud product resource list. Assume that the public network address of ECS is 192.168.1.1, the listening port of cloudreve**** is a fixed value of 5212, and the access address of cloudreve is: http: //192.168.1.1:5212.

2. In the upper right corner of the cloudreve main interface, click the management panel .

img

3. In the Determine Site URL Settings dialog box, click Change .

img

4. In the left navigation bar, click Storage Policies .

img

5. On the Storage Policies page, click Add Storage Policy .

img

6. In the Select Storage Method dialog box, select local storage .

img

7. On the upload path page of adding a local storage policy , change the storage directory to /root/oss/uploads/{uid}/{path}, and click Next .

img

Note: /root/oss is the mount point of the oss Bucket.

8. On the Direct Link Settings page for adding a local storage policy , click Next .

img

9. On the Add Native Storage Policy Upload Restriction page, click Next .

img

10. On the completion page of adding the local storage policy , enter the storage policy name OSS and click Finish .

img

Configure user groups

11. In the left navigation bar, click User Groups .

img

12. On the User Group page, click the Edit icon in Admin Actions.

img

13. In the Edit storage policy on the administrator page , select oss and click Save .

img

img

14. In the upper right corner of the user group, click Return to Home .

img

Upload files to personal network disk

  1. On the personal network disk page, drag and drop any file to the web page, and close the upload queue after the file is uploaded.

img

OSS Bucket verifies the upload result of the personal network disk

  1. Copy the address below, open a new tab in the Chromium web browser, paste it and access the OSS management console.
https://oss.console.aliyun.com/

2. In the left navigation bar, click Bucket List .

img

3. On the Bucket page, find the created Bucket and click the Bucket name .

img

4. On the file list page, click the corresponding folder name according to the Object path in the cloud product resource list to enter the Object path.

imgimg

5. On the file list page, click the folder named 1 .

img

6. In the 1 folder , you can see the files uploaded in the personal network disk.

img

So far, the personal network disk has been built and can be used as much as you like;

Guess you like

Origin blog.csdn.net/m0_55877125/article/details/132061641