×
Community Blog Rose Bowl Games Scoreboard Powered by Redis & MySQL - Provisioning Resources with Terraform

Rose Bowl Games Scoreboard Powered by Redis & MySQL - Provisioning Resources with Terraform

This tutorial shows you how to to provision Redis and MySQL resources for a scoreboard using Terraform.

This tutorial shows you how to provision Redis and MySQL resources for a scoreboard using Terraform.

You can access all the tutorial resources, including deployment script (Terraform), related source code, sample data, and instruction guidance, from the GitHub project: https://github.com/alibabacloud-howto/opensource_with_apsaradb/tree/main/apache-superset

For more tutorials around Alibaba Cloud Database, please refer to: https://github.com/alibabacloud-howto/database

Project URL

https://github.com/alibabacloud-howto/solution-mysql-redis-cache-simple

Architecture Overview

1

Deployment

Terraform

Use Terraform to provision ECS, Redis and ApsaraDB RDS for MySQL instances that used in this solution against this .tf file: https://github.com/alibabacloud-howto/solution-mysql-redis-cache-simple/blob/master/deployment/terraform/main.tf

For more information about how to use Terraform, please refer to this tutorial:

For the video tutorial about how to use Redis and RDS MySQL, and cache retiring based on TTL in Redis, please refer to: https://www.youtube.com/watch?v=_JqcsKyDljw

Run Demo

Step 1: Log in to ECS and Set up Environment

In this tutorial, Alibaba Cloud Linux is used. When you check with the terraform script, you will see the image id is: aliyun_2_1903_x64_20G_alibase_20200904.vhd

  • Get the EIP of the ECS, and then logon to ECS via SSH. Please use the account root/N1cetest, the password has been predefined in Terraform script for this tutorial. If you changed the password, please use the correct password accordingly.

2
3

ssh root@<EIP_ECS>
  • Run the following command to install required utilities on the instance, including JDK, Maven and MySQL with MySQL Client:
yum install java-latest-openjdk.x86_64
yum install maven
yum install mysql

Step 2: Modify & Run Application

Execute the following commands one by one, which are to download the demo application code, then build the demo Java application.

wget https://github.com/alibabacloud-howto/solution-mysql-redis-cache-simple/raw/master/source.tar.gz
tar xvf source.tar.gz && cd source
mvn clean package assembly:single -DskipTests

Edit the env.sh file to set the Redis and RDS MySQL endpoints (you can get from Redis and RDS MySQL web console) accordingly.

  • Redis endpoint:

4

  • RDS MySQL endpoint:

5

  • Edit to apply the Redis and RDS MySQL endpoints

6
7

Use the mysql_client.sh to create a demo table and insert some records into the RDS MySQL.

sh mysql_client.sh < rosebowl.sql

8

You can also use mysql_client.sh to query the data in RDS MySQL. There should be 30 records now.

9
10

Run the Redis demo application to verify the cache and TTL logic. You can pick up a query from the file query.sql to run. The default TTL is set as 10 seconds in the demo application. It will tell you that the result is fetched from MySQL or Redis cache. Do remember that the life time of query result in Redis cache is only 10 seconds. If you want to make it longer, you can modify the code https://github.com/alibabacloud-howto/solution-mysql-redis-cache-simple/blob/master/source/src/main/java/demo/RedisCache.java and build to run again.

sh run_sample_app.sh

11

0 0 0
Share on

ApsaraDB

138 posts | 11 followers

You may also like

Comments

ApsaraDB

138 posts | 11 followers

Related Products