Sia-gateway is a distributed microservice GATEWAY system developed under SpringCloud microservice ecosystem. With easy-to-use, visualization, high scalability, high availability and other features, to provide cloud native, complete and mature access service solutions. This article describes the installation and deployment of the API gateway.
Microservices and GateWay Technology (SIA-Gateway)
A, environmental
1.1 Compilation Environment
- Maven3+
- nodejs
- Jdk1.8 +
1.2 Third-party dependencies at runtime
- Mysql5.6 +
- Elasticsearch 5.5.2
- Kibana – 5.5.2
- 2.12 2.0.0 kafka
- Redis 3.2.11
- eureka-server
1.3 Operating Environment
- The 64 – bit OS, Linux/Mac/Windows/docker
- JDK1.8 +
Download the source code
git clone https://github.com/siaorg/sia-gateway.git
Copy the code
2.1 Source code structure is as follows:
.├ ─ Sia-gateway-BuildComponent │ ├─ Sia-gateway-BuildComponent │ ├─ Sia-gateway-BuildComponent │ ├─ Sia-gateway-BuildComponent │ ├─ Sia-gateway-BuildComponent │ ├─ Sia-gateway-BuildComponent │ ├─ Sia-gateway-BuildComponent │ ├─ Sia-gateway-BuildComponent │ ├─ Sia-gateway-BuildComponent │ ├─ ├─ Sia-gateway-Stream Log Component │ ├─ Sia-gateway-Service Log Component │ ├─ Sia-gateway-monitor Log component │ ├─ Sia-gateway-Monitor Log component │ ├─ Sia-gateway-Service Log Component │ ├─ Sia-gateway-Monitor ├ ─ ─ sia - gateway - reactive │ │ ├ ─ ─ sia - gateway - based rely on messaging │ │ ├ ─ ─ sia - gateway - sink │ │ ├ ─ ─ sia - gateway - esclient │ │ ├ ─ ─ sia - gateway - base ├ ─ ─ sia - gateway - admin - display gateway system front-end code ├ ─ ─ sia - gateway - buildcomponent gateway core - buildcomponent │ ├ ─ ─ Sia - gateway - core gateway core node │ │ ├ ─ ─ sia - gateway - base │ │ ├ ─ ─ sia - gateway - based rely on messaging │ │ ├ ─ ─ sia - gateway - reactive │ │ ├ ─ ─ sia - gateway - the templateCopy the code
Mysql > initialize API gateway database
1) See MySQL official documentation for installation and configuration
2) Please download and decompress the project source code, obtain the “API Gateway database initialization SQL script “and execute it.
The location of “API Gateway database initialization SQL script “is:
/sia-gateway/sia-gateway-admin/src/main/resources/db/gateway_admin.sql
Copy the code
4. Configuring the Gateway System
4.1 Gateway Configuration File Address
# gateway admin central conf
/sia-gateway/sia-gateway-admin-buildcomponent/config/gateway_admin_test.yml
Gateway monitoring service conf
/sia-gateway/sia-gateway-admin-buildcomponent/config/gateway_monitor_test.yml
Gateway auxiliary node conf
/sia-gateway/sia-gateway-admin-buildcomponent/config/gateway_service_test.yml
# gateway log service conf
/sia-gateway/sia-gateway-admin-buildcomponent/config/gateway_stream_test.yml
# Gateway Realtime Awareness service conf
/sia-gateway/sia-gateway-admin-buildcomponent/config/gateway_synchspeed_test.yml
Gateway core node conf
/sia-gateway/sia-gateway-buildcomponent/config/gateway_test.yml
Copy the code
1) gateway_admin_test. Yml
2) gateway_service_test. Yml
3) gateway_stream_test. Yml
4) gateway_synchspeed_test. Yml
5) gateway_monitor_test. Yml
6) gateway_test. Yml
Note: Spring.application. name indicates the gateway group name. Developers can modify this attribute to create a new gateway group
4.2 Configuring maven warehouse Addresses
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>JDK - 1.8 -</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
<profile>
<id>downloadSources</id>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</properties>
</profile>
<profile>
<id>spring plugins</id>
<activation>
<jdk>spring plugins</jdk>
</activation>
<pluginRepositories>
<pluginRepository>
<id>spring plugins</id>
<name>Spring plugins</name>
<url>https://maven.aliyun.com/repository/spring-plugin</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>downloadSources</activeProfile>
</activeProfiles>
Copy the code
Build deployment projects
5.1 Compiling a Project
1) If the above configuration has been correctly carried out, the project can be compiled and packaged for deployment.
2) Operation steps:
cd sia-gateway
chmod +x *.sh
sh build.sh
Copy the code
3) After successful packaging, the following annotation files will appear.
- / sia – gateway/sia – gateway – admin – buildcomponent/target/gateway_admin_1. 0. Zip
- Sia – gateway/sia – gateway – buildcomponent/target/gateway_1. 0. Zip
- /sia-gateway/sia-gateway-admin-display/dist/
Note: Front-end packaging requires nodeJs. If nodeJs is not installed, refer to the nodeJs installation documentation.
5.2 Deployment Items
- The API gateway system is deployed in distributed deployment and centralized management mode, that is, Core gateway nodes can be divided into different gateway groups according to service lines. The gateway management terminal serves as the gateway management center and provides a unified management interface. Users can set and maintain API, components, and basic system information on this interface. Collect monitoring logs, generate o&M management reports, and generate automatic alarms.
- Sia-gateway-admin-buildcomponent is a set of gateway management components, including admin, stream, service, SynchSpeed, and monitor. Deploy a single node on the management end (cluster is not supported at present).
- Sia-gateway-buildcomponent is a gateway Core component that can be grouped by service line and deployed in a single node or cluster within a group.
5.3 Vmware Deployment mode
1) Back-end deployment
Unzip gateway_admin_1. Zero. Zipcd /gatewayadmin/bin
chmod +x *.sh
Admin, stream, service, synchSpeed, monitorSh onekey_start. Sh -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- unzip gateway_1. 0. Zipcd /gateway/bin
chmod +x *.sh
Start the gateway Core service
sh start_gateway_test.sh
Copy the code
2) Front-end deployment
- Modify front-end site-map.js
-
Nginx proxy configuration, go to nginx directory nginx.conf, add the following configuration:
Upstream apigateway. Open. Location1 {# # # # sia - gateway - admin service IP server * * * * * * * : 8090; } server {# nginx listen 18086; server_name localhost; access_log logs/host.access.log main; #access_log "pipe:rollback logs/host.access_log interval=1d baknum=7 maxsize=2G" main; location / { #root html; #index index.html index.htm; root /app/jar/ROOT/dist; index index.html index.htm; } # back-end service location location ^ ~ / vv1 / {proxy_pass http://apigateway.open.location1/; proxy_set_header Host $host; proxy_set_header X-Real-IP $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; Proxy_http_version 1.1; } error_page 500 502 503 504 /50xcn.html; location = /50xcn.html { root html/error_page; index 50xcn.html; } location /check_status { vhost_traffic_status_display; vhost_traffic_status_display_format json; }}Copy the code
-
Restart the nginx
Verify that the configuration is correct ./nginx -t # restart ./nginx -s reload Copy the code
5.4 Docker Image Deployment mode
Note: If the Docker environment and compilation environment are on the same operating system, you can directly perform the following steps; Otherwise, you need to upload the following files to the server where the Docker environment resides according to the original directory structure.
- / sia – gateway/sia – gateway – admin – buildcomponent/target/gateway_admin_1. 0. Zip
- Sia – gateway/sia – gateway – buildcomponent/target/gateway_1. 0. Zip
- /sia-gateway/sia-gateway-admin-display/dist/
- /sia-gateway/third-libary
- /sia-gateway/build.sh
- /sia-gateway/docker-start.sh
- /sia-gateway/docker-run.sh
- /sia-gateway/Dockerfile
Steps:
Dist /static/site-map.js (dist/static/site-map.js
/** * vmware deployment: 127.0.0.1 ----> Nginx IP address * Docker image deployment: 127.0.0.1 ----> Host IP address of the Docker container */
'CESHI_API_HOST': '127.0.0.1:18086 / vv1'./** * 127.0.0.1 ----> Kibana IP address */
'CESHI_API_HOST_LOG': '127.0.0.1:5601'
Copy the code
2) Download the centos basic image file. If the basic image file has been downloaded, skip this step.
3) Modify Dockerfile FROM image name: version number
4) Configure the yum source. If the deployment machine can use Ali Yum source, skip this step.
Change the yum source file name to centos-base. repo and replace it with /sia-gateway/third-libary/
5) Build the image and start the container and services
# build mirror
cd /sia-gateway/
# authorization
chmod +x *.sh
# build mirror
sh docker-build.sh
Start containers and services
sh docker-run.sh
Check whether the container was started successfully
docker ps
Enter the container to see how the service is running
docker exec -it gateway-test:v1 bash
Copy the code
Access address: http://host IP address :18086/
Description:
- Docker image deployment mode is an all-in-one gateway deployment Demo that we provide to facilitate developers to build a gateway system based on Docker environment simply and quickly, that is, gateway monitoring service, early warning, gateway core node and so on are ALL built IN a Docker image. Developers can flexibly choose deployment schemes based on development environment conditions. Vmware + Docker image deployment is recommended, that is, the gateway management service is deployed on vmware and the gateway core node is deployed in the Docker environment.
Sia-related open source product links
- Microservices task scheduling Framework: SIa-Task: github.com/siaorg/sia-…
- Microservice routing gateway: sia-gateway: github.com/siaorg/sia-…
- Rabbitmq queue service PLUS: sia-rabbitmq-plus: github.com/siaorg/sia-…
Source: Creditease Institute of Technology