3 steps to teach you to deploy personal application services to cloud server ECS

Every programmer should be familiar with Github, and may have encountered situations where applications deployed by code hosted by Github cannot be accessed properly, or where blogs and designed web pages that have been painstakingly prepared cannot be seen by users, resulting in an inevitable impact on their mindset.

"If you nod silently, congratulations on coming right and making money.". This article will teach you how to deploy the code hosted in Github into ECS, enabling users to access and use deployed applications on the Internet.

Here, Alibaba Cloud's ECS is selected. New customers can purchase it for 3 years for 180 yuan, with a high cost performance ratio. Especially, it can be used together with free DevOps, image services, as well as low-cost OSS, domain names, and other services. It is simply a "cloud family bucket.". It can be said to be a very low-cost deployment solution for open source small projects/personal blogs.

For rapid development and deployment, Alibaba Cloud DevOps tool "Cloud Effects" is used to automatically build and deploy uploaded code using Docker. The entire practice process is divided into three steps.

01 Basic environment configuration

To facilitate the subsequent deployment and integration of the DevOps environment, base environments such as nginx, docker, and mysql can be installed.

1. Nginx installation

The default service will come with the nginx service. You can use the 'rpm ql nginx' command to view the nginx configuration.

#Start and stop

/usr/sbin/nginx

#Configuration file

/etc/nginx/nginx.conf

2. Prepare the image warehouse provided by Alibaba Cloud

Create an image warehouse and configure access credentials to facilitate subsequent login to the warehouse and push images:

3. Mirror Acceleration

You can configure your own image acceleration service in Alibaba Cloud's container image service:

#Configuring the Image Accelerator Service

EOF

sudo systemctl daemon-reload

sudo systemctl restart docker

4. Docker installation

yum -y install docker-ce

systemctl start docker

5. Creating a Docker Network

The purpose of creating a new network is to achieve network interoperability between multiple containers on the same host, using the intranet, similar to software switching.

docker network create -d bridge --subnet 172.27.0.0/16 cloud-net

-The d parameter specifies the Docker network type, including bridge overlay. Where the overlay network type is used for Swarm mode.

-The subnet parameter indicates that a 172.27.0.0/255.255.0.0 network has been created with the name cloud net.

6. MySQL installation

#Search mysql

docker search mysql

#Pull Mirror Image

docker pull mysql:latest

#Run. Note that MySQL needs to be configured for persistence

#MySQL also needs to be added to the network, so that it can be accessed directly through the hostname in other Docker containers

docker container run --name mysql -p 3306:3306 --network=cloud-net --hostname=mysql -v

/home/mysql/data:/var/lib/mysql -e MYSQL_ ROOT_ PASSWORD=xxx mysql

02 Deployment Architecture

For daily management of code hosted on open platforms such as github, if you want to automatically build and deploy it, you can leverage Alibaba Cloud's cloud efficiency and ECS cloud server linkage to achieve rapid access to DevOps. Demonstrate the deployment of a Vue project and a Java project in Docker.

The Vue project and the Java project are both deployed in Docker. Vue adds a base to the http request for access through the attached configuration file_ url prefix。 Nginx in ECS is matched to base_ Url and forward to the java docker.

The deployment structure has been sorted out. Next, let's sort out the configuration items.

1. Vue Engineering

The vue project will add a base_ URL (plans), which can be configured by attaching and selecting base_ The content of the url.

Project configuration file:

Dockfile configuration:

FROM nginx:latest

#Copy to specified directory

COPY dist /usr/share/nginx/dist/

Built-in nginx configuration:

To run the Docker container:

Description of relevant parameters:

--Network: Set the network to join

--Hostname: where the container can access the service through hostname

-p: Set Port Mapping

-v: Mounted configuration file

Registry: Specify the image source

2. Java Engineering

Dockfile configuration:

#Environment

#Create a directory to store jar packages and configuration files

RUN mkdir -p /home/server

#Copy jar

#Set the exposed port number

#Set working directory

#Execute Command

Run the Docker container command:

Here, it is necessary to pay attention to the configuration of the time zone, otherwise there will be deviations when performing SQL queries.

3. Nginx forwarding configuration

03 Cloud Effect DevOps Integration

1. Vue Engineering Integration

New assembly line:

To speed up projects on github, you can add cnpmjs.org to the back of the website to avoid cloud based git clone operations that may time out. The following are the configuration items for the code warehouse:

The next step is to configure and build the node's basic environment:

Subsequently, the dist package of the construction output is used to build the Docker image:

After this step, the built image will be sent to the previously configured Alibaba Cloud image warehouse, and then the Docker image can be deployed. Select the deployed host and execution user, and fill in the executed deployment script to complete.

2. Java Engineering Integration

The Java project is similar to Vue's project, and you can select a Java construction template.

In the subsequent deployment of the Docker image, fill in the deployment script:

After saving the pipeline configuration, you can choose to execute it manually or use the webhook function to let cloud effects trigger the execution timing themselves.

The above is the complete process of deploying Github DevOps through ECS. Using ECS for code and application service deployment is still very convenient, and user access is very smooth and convenient, resulting in a better experience.

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00

phone Contact Us