In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
First of all, we introduce several important concepts that appear in this article:
Function computing (Function Compute): function computing is an event-driven service. Through function calculation, users do not need to manage the operation of the server, but only need to write code and upload. The function calculation prepares the computing resources and runs the user code in an elastic way, while the user only needs to pay according to the resources consumed by the actual code. Function to calculate more information.
Fun: Fun is a tool for supporting Serverless application deployment, which can help you easily manage resources such as function computing, API gateways, log services, and so on. It assists you in developing, building, and deploying operations through a resource configuration file (template.yml). More documentation references for Fun.
Note: the techniques described in this article require a Fun version greater than or equal to 3.6.9.
What is Egg.js?
The official description of Egg.js is:
Egg.js is created for enterprise-level frameworks and applications, and we hope that more upper-level frameworks will be spawned by Egg.js to help development teams and developers reduce development and maintenance costs.
Egg pursues "convention is better than configuration" and develops applications according to a set of unified conventions. Using this approach within the team can reduce the learning cost of developers. Developers are no longer "nails" and can flow.
Egg's plug-in mechanism is highly extensible, and a plug-in only does one thing. Egg aggregates these plug-ins through the framework and customizes the configuration according to its own business scenario, so that the development cost of the application becomes very low.
Egg features:
Provide customized upper framework based on Egg, highly scalable plug-in mechanism, built-in multi-process management based on Koa development, excellent performance framework, stable framework, high test coverage, preview of progressive development example effect
For the link after the deployment of the application example involved in this article, click the preview effect:
Egg.js application example: http://mtime.functioncompute.com/hot
Environmental preparation
First install Fun on this machine as described in the Fun installation documentation.
PS: the method described in this article, you don't need to install Docker, just install Fun. The easiest way is to download executable binaries directly.
After the installation is complete, you can execute fun-version to check that the Fun installation is successful.
The first example: quickly initialize and deploy an Egg.js sample application
The steps described in the official Quick start documentation are as follows.
Initialize an egg.js example:
Mkdir egg-example & & cd egg-examplenpm init egg--type=simplenpm I
Run the test locally with the example:
Npm run dev
You can then visit http://127.0.0.1:7001 in the browser to see the effect.
After the local development is complete, you can directly use the following command for one-click deployment:
Fun deploy-y second example: rapid migration of an existing Egg.js application
Here we take an open source Egg.js web application as an example: https://github.com/OrangeXC/mtime
First, we need to clone the application:
Git clone https://github.com/OrangeXC/mtime
Go to the mtime directory and use npm to install dependencies:
Npm install
Launch the application locally:
Npm run dev
When launching the application locally, the config/config.default.js configuration will be used. You need to configure the username, password and other attributes of mysql in this configuration to the correct values to start the application.
After the startup is complete, open the URL http://127.0.0.1:7001 locally through the browser to preview the effect.
When the local test is complete, we need to think about how to deploy it online. When deployed online, Egg.js will give priority to the configuration of config/config.prod.js by default. We can configure the online database into this file, so that we can achieve the purpose of using different databases for local development and online deployment.
Of course, you can also verify whether the configuration is correct locally, use npm run start directly to run the application in production, and use npm run stop to stop the application.
Finally, we need to modify the cache and log directory of Egg.js. We add the following to config/config.prod.js:
Config.rundir ='/ tmp/run', config.logger = {dir:'/ tmp/log',}
The above configuration means that the Egg.js cache and logs are written to the writeable directory where the function is calculated (it is also possible for logs to be output to console).
Finally, we deploy with one click of Fun:
Fun deploy-y
After the deployment is completed, you can see the temporary domain name 13500180-1986114430573743.test.functioncompute.com in the terminal output. You can see the same effect as the local runtime by opening the temporary domain name through the browser.
Summary
This article mainly introduces how to deploy Egg.js applications to function computation. Compared with the traditional deployment method, it is not more complex, and the steps of purchasing machine, installing and configuring Node and Npm are omitted. It can be realized that after the traditional Egg.js application is developed locally, it can be deployed to the remote end directly for production, and has the characteristics of auto scaling, pay by quantity, free operation and maintenance, and so on.
If you encounter problems in the process of migrating your application, you are welcome to join our dingding group 11721331 feedback.
"Alibaba Cloud Native focus on micro-services, Serverless, containers, Service Mesh and other technology areas, focus on cloud native popular technology trends, cloud native large-scale landing practice, to be the best understanding of cloud native developers of the technology circle."
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.