当前位置:网站首页>Function calculation advanced IP query tool development
Function calculation advanced IP query tool development
2020-11-09 22:32:00 【Alicloud experience Lab】
Scenario introduction
The scenario describes how to develop a IP Query tools .
Background knowledge
What is? Serverless
since 2006 year 8 month 9 Japan ,Google Eric, CEO · schmidt (Eric Schmidt) At the search engine Conference (SESSanJose2006) First put forward “ Cloud computing ”(Cloud Computing) After the concept of , The development of cloud computing can be described by the word "changing with each passing day" . So what exactly is Serverless Well ?
Simply speaking ,Serverless It's an architecture , A product of the development of cloud computing , As for what is Serverless, Maybe no one can give him a clear concept , If you have to say a concept that is a little easier to understand , Maybe you can refer to Martin Fowler stay 《Serverless Architectures》 Chinese vs Serverless Such definition :Serverless=BaaS + FaaS
Serverless The difference between architecture and traditional projects
First , We take a common Web Service as an example :
In this picture , Routing rules may be involved in the server 、 Authentication logic and other complex business codes . meanwhile , The development team has to pay a lot of attention to the operation and maintenance of this server , For example, always pay attention to the following questions :
Whether the server needs to be expanded when the number of customers increases suddenly . Whether scripts and business code on the server are still running healthily . Are hackers constantly attacking the server . When we switch this thinking to Serverless After the logic of , It goes like this :
It can be said that , When the client and database have not changed , The server has changed a lot .
The routing module and authentication module that need to be maintained by the development team before will be accessed by the service provider API Gateway system and authentication system , The development team no longer needs to maintain these two parts of the business code , Just keep maintaining the rules . Under this structure , Business code is also broken down into function granularity , Different functions represent different functions . We can't see the server anymore , Because Serverless The goal is to let users only focus on their own business logic , So part of the security problem 、 Resource scheduling problem ( For example, the number of users has increased dramatically 、 How to realize automatic capacity expansion, etc ) All to the cloud manufacturer . Compared to traditional projects , Traditional projects whether or not there is user access , Services are running , There are costs , and Serverless for , Only when used to initiate a request , Function will be activated and executed , And will charge by volume , Relatively speaking, it can only be supported when there is traffic , There's no spending when there's no traffic , relatively speaking , The cost will be further reduced . Through the above analysis and description , It's not hard to see. Serverless The difference between architecture and traditional development model , And gradually found its advantages . But the problem is , A lot of work is left to cloud vendors , So what do we do ?
Use Serverless After the architecture :
Development teams no longer need to maintain their own servers , You don't need to worry about various performance indicators and resource utilization of the server , It allows the development team to devote more time and energy to the state and logic of the application itself . Serverless Application deployment will be very easy . We just upload the basic code , for example Python The program only needs to upload its logic and dependency package ,C/C++、Go And other languages just need to upload their binary files ,Java Just upload it Jar Just wait , At the same time, there is no need to use Puppet、Chef、Ansible or Docker For configuration management , Greatly reduced the operation and maintenance cost . Serverless The architecture no longer needs to monitor the underlying data , For example, you no longer need to monitor disk usage 、CPU Utilization rate, etc , You can focus more on monitoring the metrics of the application itself . At the same time Serverless Architecturally , The role of operation and maintenance personnel will be changed , Deployment will become more automated , Monitoring will be more application oriented . Use Serverless Advantages of Architecture
From the above we can see that , Compared to traditional projects ,Serverless Have the following advantages :
You don't have to purchase and manage infrastructure like servers , Low operation and maintenance cost . You just need to focus on the development of business logic , Design a development language supported by functional computing 、 Optimize 、 test 、 Review and upload your own application code . Trigger the application in an event driven way to respond to user requests . And Alibaba cloud object storage OSS、API gateway 、 Log service and form storage services are seamlessly connected , Help you build applications quickly . for example , adopt OSS Solve the storage problem of pictures and videos , When new data is written into your OSS Resource time , Automatic trigger function processing data . Provide log query 、 Performance monitoring and alarm and other functions quickly troubleshooting . Millisecond level elastic scaling , Quickly expand the bottom layer to cope with peak pressure . Pay as you go , Support 100 millisecond level charge . Just pay for the computing resources you actually use , It is suitable for user access scenarios with obvious peaks and troughs . To make a long story short ,Serverless It is developed on the traditional container technology and service grid , It refers to the combination of back-end services and function services . For developers , Be able to focus more on function services , More attention should be paid to the user's business logic .
meanwhile ,Serverless It is also the inevitable product of the development of cloud computing to a certain stage . As Pratt & Whitney , The goal of cloud computing development must be the products of green technology and mass technology —— and Serverless It's a good interpretation of these : Make the most of resources 、 Reduce waste of idle resources ; At the same time, reduce the cost of learning and use .
Serverless Architecture is called “ It really achieved the original goal of Cloud Computing ”, It's a little exaggerated , But on the other hand, it shows that everyone is right about Serverless Expectations and confidence in Architecture . since 2012 Since it was proposed in ,Serverless Architecture also went through 7 Year time , Is gradually moving towards maturity .
Step one : Connect ECS The server
Alibaba cloud product resource experience address :https://developer.aliyun.com/adc/scenario/d419eecaaf184013a45db0a5d613ad39
The scene will provide a configuration for CentOS 7.7 Of ECS example ( Cloud server ). Through the operation of this tutorial , You can develop a functional computing based IP Query tools .
Step two : Open function computing service
Before you use a function to calculate , Function calculation service needs to be opened .
explain : The alicloud sub account provided in this scenario has no function computing service operation permissions , Please use your own alicloud account to operate . You don't have to worry about the deduction , Because the function computing service has a certain amount of free , See billing method .
1. Log in to the alicloud console with your own alicloud account , Then enter Function to calculate product details page .
2. single click 【 Free to open 】.
3. read 《 Function computing service protocol 》 Check agree to service agreement , Finally, click 【 Open now 】 .
4. single click 【 Administrative console 】 Enter the function calculation console . 
Step three : install Funcraft Tools
Fun Is a support for Serverless Application deployment tools , Can help you easily manage function calculations 、API Gateway and log services and other resources . It uses a resource profile (template.yml), Help you develop 、 Build and deploy operations .
This step will be in ECS Installation on server Funcraft Tools .
1. Perform the following installation NodeJS.
curl -sL https://rpm.nodesource.com/setup_10.x | bash - && yum install -y nodejs
2. Perform the following installation Funcraft.
npm install request @alicloud/fun -g
3. perform fun config Command to configure locally .
fun config
Please refer to the following information to enter your alicloud account ID、AccessKeyID and AccessKey Key and other information . Aliyun Account ID: Please check your account on the account security settings page ID.
Aliyun Access Key ID and Aliyun Access Key Secret: Please be there. Security information management Page to see your account AK ID and AK Secret.
If you are using the main account of alicloud , Please click continue to use in the security prompt box on the security information management page AccessKey.
Default region name: Please select the region where the function calculation service is opened .
The correct settings are as follows :

Step four : Run template example
1. Execute the following command to create a new workspace .
mkdir search_ip && cd search_ip
2. perform fun init Order a new HTTP Function triggers .
fun init http-trigger-nodejs10
The results of the command execution are as follows :
among index.js The file is generated HelloWorld Function templates ,template.yml The file contains HelloWorld Functions and HTTP Default configuration information for triggers .
3. perform fun deploy -y Command deployment applies to function computing services .
fun deploy -y
The results of the command execution are as follows :
4. Use curl Command access HTTP trigger . Please send the following order to 11905929798***** Replace with your alicloud account ID.
curl https://11905929********.cn-shanghai.fc.aliyuncs.com/2016-08-15/proxy/search_ip/search_ip/
The results of the command execution are as follows :
You can see in the return result that , In the use of HTTP When you trigger , You can pass some parameters by default , Include Path,Queries as well as Headers,Method etc. , One of the parameters is clientIP, The value of this field is the client's IP Address , We can use this address to determine the client's IP Address . Next we're going to use clientIP Field development IP Query tools .
Step five : Development IP Query tools
1. Refer to the following steps to modify index.js The contents of the document . a. take index.js Empty file contents .
cat /dev/null > index.js
b. Use vim open index.js file .
vim index.js
c. Press down i Key in vim The editing mode of , Add the following to the document .
var getRawBody = require('raw-body')
module.exports.handler = function (request, response, context) {
getRawBody(request, function (err, data) {
var respBody = new Buffer.from(" Your IP yes :" + request.clientIP);
response.setStatusCode(200)
response.setHeader('content-type', 'text/html')
response.send(respBody)
})
};
d. Press down esc Key to enter command mode , Input :wq Save and exit vim.
2. perform fun deploy -y Command to redeploy to function computing service .
fun deploy -y
The results of the command execution are as follows :
3. Use curl Command access HTTP trigger . Please send the following order to 11905929798***** Replace with your alicloud account ID.
curl https://11905929798*****.cn-shanghai.fc.aliyuncs.com/2016-08-15/proxy/search_ip/search_ip/
The results of the command execution are as follows :

版权声明
本文为[Alicloud experience Lab]所创,转载请带上原文链接,感谢
边栏推荐
- PLSQL Developer常用设置
- PL/SQL Developer临时用户和新手的功能指南
- sql 筛选查询重复列
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
- Hot update scheme of Chrome extension program: 2. Based on double cache update function module
- CRM系统能帮助企业做哪些事?
- Functional guide for temporary users and novices of PL / SQL developer
- 剑指offer之打印二叉搜索树中第k小的结点
- 那么当下的行情投资者该怎么办呢? 现在新的投资风口来了!
- How SSL certificate and public IP address affect SEO
猜你喜欢

Postman (1) -- function introduction

SQL filter query duplicate columns

The movie theater booking system based on micro Service Framework

Prometheus安装配置

Open source project, private tool, rapid development

Software engineering in code -- source code analysis of menu project

How can financial management system help enterprises realize financial automation management?

在PHP7下怎么大幅度提升Laravel框架性能?安装Stone!
![[best practice] learn how eolinker helps Telecommuting](/img/3b/00bc81122d330c9d59909994e61027.jpg)
[best practice] learn how eolinker helps Telecommuting

Operation! Nested JSON second change dataframe!
随机推荐
sql 大小写转换,去掉前后空格
[QT] subclass QObject + movetothread to realize multithreading
Operation! Nested JSON second change dataframe!
JS deep copy
Analysis steps of commodity background management
How to implement LRU algorithm
Apache Hadoop的重要组成
How to carry out modular power operation efficiently
LeetCode 50 Pow(x,n)
CRM系统能帮助企业做哪些事?
面试官:缓存穿透、缓存雪崩和缓存击穿是什么?
eleven point nine
LeetCode 50 Pow(x,n)
CUDA常用概念及注意点
JT Jingtao project
商品后台系统实现
ES6, ES7, es8 Learning Guide
CUDA_存储器模型
没有磁盘空间 No space left on device
No space left on device