Introduction to High Availability Environment
Building a high-availability environment can eliminate the impact of single-point failures, enable the system to automatically switch to other nodes when a failure occurs, ensure the smooth operation of the system, improve system reliability and availability, and at the same time ensure data security, high-availability environment It is already a standard configuration for modern enterprise applications.
This article introduces how to quickly build a small high-availability environment. The products involved include: 2 cloud hosts (CenTOS 7.6 system), database and load balancing.
2. Preparation
Before officially starting the deployment, you need to complete the following preparations:
- To open a JD Cloud account, if you have not registered a JD Cloud account, you can register on the JD Cloud official website;
- After the account is opened, real-name authentication is required.
3. Build the first cloud host environment
To purchase 1 cloud host, this article chooses the CenTOS 7.6 system for operation demonstration
After the purchase is complete, visit the cloud hosting console
Click on the remote connection in the operation of a cloud host
Enter the password to log in. If you forget the password, you can return to the console to change the password
Install Java's JDK
yum install java-1.8.0-openjdk
install tomcat
yum install -y ca-certificates
wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.87/bin/apache-tomcat-8.5.87.tar.gz
Decompress tomcat, the war package of your Java application can be deployed to tomcat for release
tar -zxvf ./apache-tomcat-8.5.87.tar.gz
start tomcat
cd apache-tomcat-8.5.87/bin
./startup.sh
Access IP:8080 in the browser to check the startup effect. If the access fails, please check whether port 8080 is open in the security group
4. Build the second cloud host environment
Access the cloud host console, select the first cloud host with a built environment, and click Make Image in the operation
Enter the image name and description to make an image
After the image is created, you can click Create Cloud Host and use the image to purchase a new cloud host; if you already have a second cloud host, you can select the newly created image on the instance list page to reinstall the system
This article selects the second cloud host to reinstall the system for operation demonstration
After reinstalling the system, log in to the cloud host and check the Java environment
java -version
start tomcat
cd apache-tomcat-8.5.87/bin
./startup.sh
Access IP:8080 in the browser to check the startup effect. If the access fails, please check whether port 8080 is open in the security group
Five, configure the database
After purchasing the cloud database, visit the database console page
Click on the database name to enter the configuration page
Switch to the library management tab, click the Create library button to create a new database
Switch to the Account Management tab, create an account first, and then click Modify Permissions in Account Operations
Select the database you just created and authorize permissions
The Java application you deploy on the cloud host can link to the database through the intranet domain name in the figure below, and use the information just created in the above steps for the account and password
6. Configure load balancing
After purchasing the load balancer, visit the instance list page, click the name of the load balancer instance, and enter the configuration page
Switch to the virtual server group tab, create a new server group, and click Edit in the server group operation after creation
Select the host instance, click Add, and confirm
Switch to the listener tab and create a new listener with port 8080
Backend forwarding configuration, modify the port to 8080
The health detection port is 8080
Select the server group you just created and click OK
Enter the load-balanced IP in the browser to access