The short video AppServer is used to exchange data between the short video application and ApsaraVideo VOD, process business logic, and manage operations data. This topic describes how to build the short video AppServer.
Prerequisites
An Alibaba Cloud account is created and real-name verification is complete. To create an Alibaba Cloud account, visit the Alibaba Cloud official website. For more information about how to create an Alibaba Cloud account, see Create an Alibaba Cloud account.
- Elastic Compute Service (ECS) is activated. An ECS instance is configured. For more information, see Activate and configure ECS.
- Java Development Kit (JDK) 8 is installed on the ECS instance.
- MySQL 5.7 is installed on the ECS instance. For more information, see Install and configure a MySQL database. When you publish your short video service to the production environment, we recommend that you use ApsaraDB RDS. For more information, visit the buy page of ApsaraDB RDS.
- ApsaraVideo VOD is activated and transcoding templates are configured. For more information, see Configure settings in the ApsaraVideo VOD console.
Procedure
- Download the short video AppServer and the source code of the console. For more information, see SDK download.
- Run the following command on the server where the SDK package is saved to upload the source code package to the ECS instance: scp <Source code package> user@<IP address of the ECS instance>:<Path to which the the source code package is uploaded>scp ApsaraVideo_QuVideo_v1.4.0_Server_20191226.zip user@10.0.0.0:/home/user/workspace/
In this example, the source code package is ApsaraVideo_QuVideo_v1.4.0_Server_20191226.zip. The username that is used to log on to the ECS instance is user. The IP address of the ECS instance is 10.0.0.0. The upload path is /home/user/workspace/.
Note The preceding sample information, including the source code package, the username for logging on to the ECS instance, the IP address of the ECS instance, and the upload path, is used as examples in the following steps. Set these parameters based on your needs in actual use. - Log on to the ECS instance and decompress the source code package. cd /home/user/workspaceunzip ApsaraVideo_QuVideo_v1.4.0_Server_20191226.zipNote If the unzip tool is not installed, run the sudo apt install unzip command to install the unzip tool.
- Make sure that the query results that are returned by the database use the data structure defined by ApsaraVideo VOD. Otherwise, ApsaraVideo VOD cannot obtain music data from the database.
- If your database uses a custom data structure, modify the downloaded demo code so that ApsaraVideo VOD supports the data structure.
- Create a database named voddemo.
cd /home/user/workspace/ApsaraVideo_QuVideo_v1.4.0_Server_20191226/sql
mysqladmin -u root -p create voddemo
- Create a table and an administrator account. mysql -u root -p voddemo < ./appserver_create_table.sqlNote The appserver_create_table.sql script creates a table and uses an INSERT statement to create a console administrator account. The username of the account is admin, and the password is 123456. After you build the short video console, you can use the administrator account to log on to the short video console.
- Modify the case sensitivity check rule for the database.
- Configure the logon information of the database.
- Follow the procedure described in A RAM role is created. For more information, see Create a role and grant temporary access permissions to the role by using STS. to create a RAM role. After you select a policy for the RAM role, perform the following steps to configure the RAM role. You can set the name of the RAM role as needed. In this example, the name of the RAM role is alivc-demo-role.
- On the Roles page, click the name of the created RAM role alivc-demo-role to view the Alibaba Cloud Resource Name (ARN) of the RAM role. We recommend that you save the name and ARN of the RAM role in a file on your PC for subsequent use.
- On the Roles page, click the name of the created RAM role alivc-demo-role. On the details page of the RAM role, click the Trust Policy Management tab. On the Trust Policy Management tab, click Edit Trust Policy. In the Edit Trust Policy panel, modify the trust policy.
{ "Statement": [ { "Action": "sts:AssumeRole", "Effect": "Allow", "Principal": { "Service": [ "ecs.aliyuncs.com" ] } } ], "Version": "1" }
The trust policy indicates that the RAM role is a service-linked role, which can be assigned to the trusted Alibaba Cloud service ECS. If you do not modify the trust policy, you cannot assign the RAM role to the ECS instance.
The ID of the ECS instance must be specified in the
["Instance ID"]
format. - Assign the RAM role to the ECS instance.
Call the AttachInstanceRamRole operation that is provided by ECS in OpenAPI Explorer. For more information, see OpenAPI Explorer.
Note- RegionId: the ID of the region in which the ECS instance resides, such as China (Shanghai). You can go to the ECS console to obtain the region ID of the instance.
- RamRoleName: the name of the RAM role. In this example, the name of the RAM role is alivc-demo-role.
- InstanceIds: the ID of the ECS instance. You can go to the ECS console to view the ID of the instance. You must enter the instance ID in the format of an array. Example: ["i-bp135jrddxxf9tgo****"].
Click Initiate Call. After the call succeeds, a success response is displayed on the Response tab on the right part of the page.
- Run the following command on the ECS instance to check whether the RAM role is assigned to the ECS instance: curl http://100.100.100.200/latest/meta-data/ram/security-credentials/alivc-demo-roleIf the output contains the following Security Token Service (STS) authorization information, the RAM role is assigned to the ECS instance:
{ "AccessKeyId" : "STS.XXXXXXXXXXXX", "AccessKeySecret" : "XXXXXXXXXXXXXXXX", "Expiration" : "2020-11-20T14:33:31Z", "SecurityToken" : "XXXXXXXXXXXXXXXXXXXXXX", "LastUpdated" : "2020-11-20T08:33:31Z", "Code" : "Success" }
Note You can assign only one RAM role to an ECS instance. To change the RAM role, call the DetachInstanceRamRole operation in OpenAPI Explorer to remove the RAM role from the ECS instance. Then, call the AttachInstanceRamRole operation to assign another RAM role to the ECS instance. - Configure the information about RAM.
- Configure the information about ApsaraVideo VOD.
- Run the service.