SIA-GateWay之API閘道器安裝部署指南

宜信技術學院發表於2019-09-11

SIA-GATEWAY是基於SpringCloud微服務生態體系下開發的一個分散式微服務閘道器係統。具備簡單易用、視覺化、高可擴充套件、高可用性等特徵,提供雲原生、完整及成熟的接入服務解決方案。本文介紹API閘道器的安裝部署。

一、環境

1.1 編譯環境

  • Maven3+
  • nodejs
  • Jdk1.8+

1.2 執行時第三方依賴

  • Mysql5.6+
  • elasticsearch 5.5.2
  • kibana-5.5.2
  • kafka 2.12-2.0.0
  • redis 3.2.11
  • eureka-server

1.3 執行環境

  • 64bit OS,Linux/Mac/Windows/docker
  • JDK1.8+

二、原始碼下載

git clone https://github.com/siaorg/sia-gateway.git

2.1 原始碼結構如下:

.
├── sia-gateway-admin-buildcomponent  閘道器admin元件集合
│   ├── sia-gateway-admin             閘道器admin監控系統元件
│   ├── sia-gateway-synchspeed        閘道器對下游服務實時感知元件
│   ├── sia-gateway-stream            閘道器日誌元件
│   ├── sia-gateway-service           閘道器係統輔助元件
│   ├── sia-gateway-monitor           閘道器監控、日誌元件
│   │    ├── sia-gateway-reactive    
│   │    ├── sia-gateway-messaging    基礎依賴 
│   │    ├── sia-gateway-sink
│   │    ├── sia-gateway-esclient
│   │    ├── sia-gateway-base
├── sia-gateway-admin-display         閘道器係統前端程式碼
├── sia-gateway-buildcomponent        閘道器core-buildcomponent
│   ├── sia-gateway-core              閘道器Core節點
│   │   ├── sia-gateway-base
│   │   ├── sia-gateway-messaging     基礎依賴
│   │   ├── sia-gateway-reactive
│   │   ├── sia-gateway-template

三、初始化“API閘道器資料庫”

1)MySQL的安裝和配置詳見MySQL官方文件

2)請下載專案原始碼並解壓,獲取 "API閘道器資料庫初始化SQL指令碼" 並執行即可。

"API閘道器資料庫初始化SQL指令碼" 位置為:

/sia-gateway/sia-gateway-admin/src/main/resources/db/gateway_admin.sql

四、配置“閘道器係統”

4.1 閘道器配置檔案地址

# 閘道器admin中心conf
/sia-gateway/sia-gateway-admin-buildcomponent/config/gateway_admin_test.yml
# 閘道器監控服務conf
/sia-gateway/sia-gateway-admin-buildcomponent/config/gateway_monitor_test.yml
# 閘道器輔助節點conf
/sia-gateway/sia-gateway-admin-buildcomponent/config/gateway_service_test.yml
# 閘道器日誌服務conf
/sia-gateway/sia-gateway-admin-buildcomponent/config/gateway_stream_test.yml
# 閘道器實時感知服務conf
/sia-gateway/sia-gateway-admin-buildcomponent/config/gateway_synchspeed_test.yml
# 閘道器核心節點conf
/sia-gateway/sia-gateway-buildcomponent/config/gateway_test.yml

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  

說明:spring.application.name為閘道器組名稱,開發者可以修改此屬性,搭建新的閘道器組

4.2 maven 倉庫地址配置

  <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>

五、構建部署專案

5.1 編譯專案

1)如果已經正確進行上述配置,可將專案編譯打包部署。

2)操作步驟:

    cd sia-gateway
    
    chmod +x *.sh
    
    sh build.sh

3)打包成功後,會出現以下標註檔案。

  • /sia-gateway/sia-gateway-admin-buildcomponent/target/gateway admin1.0.zip

  • /sia-gateway/sia-gateway-buildcomponent/target/gateway_1.0.zip

  • /sia-gateway/sia-gateway-admin-display/dist/

注:前端打包需要用到nodeJs,如未安裝,可請參考   nodejs安裝文件

5.2 部署專案

  • API閘道器係統的部署方式為分散式部署集中式管理模式,即閘道器Core節點可以按業務線劃分為不同的閘道器組,閘道器管理端作為閘道器的管理中心,供統一的管理介面,使用者可在此進行 API、元件、系統基礎資訊的設定和維護,收集監控日誌、生成各種運維管理報表、自動告警等。
  • sia-gateway-admin-buildcomponent是閘道器管理端元件集,包括:admin、stream、service、synchspeed、monitor;管理端部署單個節點即可(目前不支援叢集)。
  • sia-gateway-buildcomponent為閘道器Core元件,可以按業務線分組,組內以單節點或叢集方式部署。

5.3 Vmware方式部署

1)後端部署

unzip gateway_admin_1.0.zip
cd /gatewayadmin/bin
chmod +x *.sh 
#啟動閘道器管理服務,包括:admin、stream、service、synchspeed、monitor。
sh onekey_start.sh
---------------------------------------------------
unzip gateway_1.0.zip
cd /gateway/bin
chmod +x *.sh 
#啟動閘道器Core服務
sh start_gateway_test.sh

2)前端部署

  • 修改前端site-map.js

  • nginx的代理配置,進入nginx的目錄下nginx.conf,新增如下配置:

        upstream apigateway.open.location1 { 
           #### sia-gateway-admin服務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;
            }
            # 後端服務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;
            }
        }
  • 重啟nginx

    #校驗配置是否正確
    ./nginx -t
    # 重新啟動
    ./nginx -s reload

5.4 Docker 映象方式部署

說明:如果docker環境和編譯環境是在同一個作業系統上,可直接執行以下步驟;反之,需要先將以下檔案按原目錄結構上傳docker環境所在伺服器。

  • /sia-gateway/sia-gateway-admin-buildcomponent/target/gateway admin1.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

步驟:

1)配置:修改site-map.js,位置:/dist/static/site-map.js

        /**
         * vmware部署: 127.0.0.1 ----> nginx的ip地址
         * docker映象部署: 127.0.0.1 ----> docker容器的宿主機ip
         */
        'CESHI_API_HOST': '127.0.0.1:18086/vv1',
        
        /**
         * 127.0.0.1 ----> kibana的ip地址
         */
        'CESHI_API_HOST_LOG': '127.0.0.1:5601'

2)下載centos基礎映象,如果已經下載,此步忽略。

3)修改Dockerfile,FROM   映象名 : 版本號

4)配置yum源,如果部署機器能夠使用阿里yum源,此步忽略。

將yum原始檔名稱修改成 CentOS-Base.repo,並替換到/sia-gateway/third-libary/下

5)構建映象,並啟動容器和服務

    # 構建映象
    cd /sia-gateway/ 
    
    # 授權
    chmod +x *.sh
    
    # 構建映象
    sh docker-build.sh
    
    # 啟動容器和服務
    sh docker-run.sh
    
    # 檢視容器是否啟動成功
    docker ps 
    
    # 進入容器檢視服務執行情況
    docker exec -it gateway-test:v1 bash

訪問地址:   http://宿主機IP:18086/

說明:

  • Docker映象部署方式是我們為方便開發者簡單、快速地基於docker環境搭建閘道器係統而提供的一種ALL-IN-ONE形式的閘道器部署Demo,即閘道器監控服務、預警、閘道器核心節點等都構建在一個docker映象中;開發者可以根據開發環境條件來靈活選擇部署方案,推薦使用vmware+docker映象部署方式,即將閘道器管理端服務部署在vmware上,閘道器核心節點部署在docker環境中。

SIA相關開源產品連結

來源:宜信技術學院


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69918724/viewspace-2656746/,如需轉載,請註明出處,否則將追究法律責任。

相關文章