By Alain Francois
When you host your application on the cloud, you need to store your data effectively on a secure and fast database management tool that can meet some interesting requirements. We recommend not deploying the database management tool and the application server on the same instance to ensure security and data availabilities. It will be more interesting if you have a fully managed solution for your database instance. Alibaba Cloud offers AsparaDB for RDS as a database management system. You can deploy your application server on the cloud and connect it to an AsparaDB for RDS to keep your data on a fully-managed database service that helps you manage and administer your relational databases on the cloud.
ApsaraDB for RDS is an online database service that handles some of the administrative tasks associated with managing a database. It is stable, reliable, scalable, and built on top of the Apsara Distributed File System and high-performance SSDs of Alibaba Cloud. AsparaDB for RDS supports many popular Relational Database Management System (RDBMS) engines, including MySQL, SQL Server, PostgreSQL, PPAS (highly compatible with Oracle), and MariaDB. The service allows you to quickly build a stable and reliable database system and provides a portfolio of solutions for disaster recovery, backup, restoration, monitoring, and migration to facilitate database operations and maintenance.
ApsaraDB for RDS can also protect against network attacks and intercept SQL injections, brute force attacks, and other types of database threats. It also offers some advantages compared with user-created databases and has significant advantages in cost-effectiveness, availability, reliability, ease of use, and performance:
You need an account to run an Alibaba Cloud AsparaDB for RDS instance. If you don’t have an account, you can get a coupon to start a new account during the Mega March Sale.
Log into your account and go to the AsparaDB service:
You can see the homepage:
Create a new instance:
You will need to choose the RDMS engine during the creation of the instance, and we will choose _PostgreSQL_. We will connect our RDS instance to an ECS instance, so we need to create our RDS instance in the same region and zone of the ECS instance the region:
Now, we need to configure the VPC setting of the instance. Make sure to take the good VPC configuration of the AsparaDB for RDS instance. We will select the same VPC as the ECS instance:
Complete the order:
Now, you can go back to the AsparaDB console and overview the new instance. After some time, you will be able to see the status updating from Creating to _Running_:
You can also rename the instance or click it to see the settings. You can have a detailed page of the new instance:
The new instance doesn't have any information yet by default. It means you need to create a user account for the database to log in to the instance. Go and create the user DB account. The account should have administrator privileges so it can be used to operate on the database:
Create the database on which you will connect:
Once created, you can connect to the database instance through an RDM:
You will be prompted to enter the information regarding the database user and the password:
You are connected to your AsparaDB for RDS instance. You can see some new information and which one can be used to connect to the database from an ECS instance:
Now that your AsparaDB for RDS instance is running, you need to connect your application server to the database instance to store all your data.
You need to go back to the AsparaDB console to connect your application server to your AsparaDB for RDS instance. In this guide, we will try to connect our SonarQube server to the PostgreSQL RDS instance instead of a local database service running on the same ECS.
Normally, since RDS and ECS instances are in the same VPC, they could be able to communicate. However, for some security, a RDS instance is only reachable from the servers whose IPs have been added on a whitelist. You need to add the IP address of your ECS instance to the RDS whitelist:
To connect your Sonarqube service to a remote database, you need to indicate the IP address of the database server. But you should have noticed that the information was not available. There is a notion of Internal Endpoint that can be considered as a virtual domain name (mapped to an IP address) to use for a remote connection. Its value can be long, so you can edit it to something easy to remember by default. If you want to connect to the RDS instance over an internal network, you need to use its internal endpoint:
Edit it if you want to make it simple. After you change an endpoint or port number of an RDS instance, the change immediately takes effect without restarting the RDS instance:
You can connect to the ECS instance and try a command-line connection to the PostgreSQL RDS database instance:
$ psql -U userdb -h pgm-demo-enpoint.pgsql.germany.rds.aliyuncs.com --d appsdb -W
After confirming that your ECS instance can communicate with your RDS instance, you can run your application server and indicate the necessary information to connect the database. In our case, we are running a SonarQube service with Docker. Then, we start our container with the following command:
$ docker run -d --name sonarqube-demo \ -e VIRTUAL_HOST=web-demo.com \ -e VIRTUAL_PORT=9000 \ -p 9000:9000 \ -e SONAR_JDBC_URL="jdbc:postgresql://pgm-demo-enpoint.pgsql.germany.rds.aliyuncs.com:5432/appsdb" \ -e SONAR_JDBC_USERNAME=userdb \ -e SONAR_JDBC_PASSWORD='34zvTKjis097BB' \ -v /opt/volume/sonarqube-demo/conf:/opt/sonarqube/conf \ -v /opt/volume/sonarqube-demo/extensions:/opt/sonarqube/extensions \ -v /opt/volume/sonarqube-demo/logs:/opt/sonarqube/logs \ -v /opt/volume/sonarqube-demo/data:/opt/sonarqube/data \ sonarqube:lts-community
If SonarQube can't communicate with the remote database, it will not start, and you will face some errors when checking the logs. We will check the logs and look at the line regarding the connection to the database:
$ docker logs -f sonarque-demo
You can see through the logs that sonar was able to connect to the RDS instance. You can access your application service through the browser
Our application is working and connected to our RDS instance. After changing an endpoint or port number of an RDS instance, you must change them on your application. If you do not change them on your application, your application cannot connect to the RDS instance.
You gain more benefits using AsparaDB for RDS to store the data of your application server. You have protection against DDoS attacks, SQL injections, etc. Since the service is managed, it means you will have less stress. You can also secure your RDS instance by adding it to a security group and creating more security rules.
● How to Set up Alibaba Cloud ApsaraDB for MongoDB for Your NoSQL Database Requirements
● Alibaba Cloud ApsaraDB for MongoDB is a secure and elastically scalable MongoDB database service. The service is relatively easy-to-set up.
● How to Install SonarQube and PostgreSQL with Docker on Alibaba Cloud ECS Instance
● SonarQube is a cross-platform and web-based tool used for continuous source code inspection that can be integrated into platforms, such as GitHub, GitLab, BitBucket, and more. This article explains how to install SonarQube and PostgreSQL using Docker on your ECS instance.
● How to Create a VPC and Configure a Security Group to Protect Your Alibaba Cloud Instances.
Alibaba Cloud offers a Virtual Private Network (VPC), which is a secure and isolated private cloud that contains your Elastic Compute Services (ECS) instances within a public cloud. You can access a VPC publicly from the Internet and secure traffic by configuring a security group.
How to Set up and Configure Alibaba Cloud Data Management Service to Manage all Your Cloud Databases
601 posts | 99 followersFollow
Alibaba Cloud Community - March 31, 2022
Alibaba Clouder - February 17, 2020
Alibaba Cloud Community - October 26, 2021
Alibaba Cloud Community - February 9, 2022
Alibaba Cloud Community - November 9, 2021
Alibaba Clouder - April 28, 2018
601 posts | 99 followersFollow
An on-demand database hosting service for MySQL, SQL Server and PostgreSQL with automated monitoring, backup and disaster recovery capabilitiesLearn More
An on-demand database hosting service for PostgreSQL with automated monitoring, backup and disaster recovery capabilitiesLearn More
An on-demand database hosting service for MySQL with automated monitoring, backup and disaster recovery capabilitiesLearn More
An on-demand database hosting service for SQL Server with automated monitoring, backup and disaster recovery capabilitiesLearn More
More Posts by Alibaba Cloud Community