SIA-GATEWAY是基於SpringCloud微服務生態體系下開發的一個分佈式微服務網關係統。具有簡單易用、可視化、高可擴展、高可用性等特徵,提供雲原生、完整及成熟的接入服務解決方案。本文介紹API網關的安裝部署。html
git clone https://github.com/siaorg/sia-gateway.git
. ├── 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
1)MySQL的安裝和配置詳見MySQL官方文檔node
2)請下載項目源碼並解壓,獲取 "API網關數據庫初始化SQL腳本" 並執行便可。react
"API網關數據庫初始化SQL腳本" 位置爲:nginx
/sia-gateway/sia-gateway-admin/src/main/resources/db/gateway_admin.sql
# 網關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.ymlgit
2)gateway_service_test.ymlgithub
3)gateway_stream_test.yml redis
4)gateway_synchspeed_test.ymlspring
5)gateway_monitor_test.ymlsql
6)gateway_test.yml
說明:spring.application.name爲網關組名稱,開發者能夠修改此屬性,搭建新的網關組
<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>
1)若是已經正確進行上述配置,可將項目編譯打包部署。
2)操做步驟:
cd sia-gateway chmod +x *.sh sh build.sh
3)打包成功後,會出現如下標註文件。
注:前端打包須要用到nodeJs,如未安裝,可請參考 nodejs安裝文檔。
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)前端部署
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
說明:若是docker環境和編譯環境是在同一個操做系統上,可直接執行如下步驟;反之,須要先將如下文件按原目錄結構上傳docker環境所在服務器。
步驟:
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 <font color='red'>鏡像名 : 版本號</font>
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/
說明:
SIA相關開源產品連接
來源:宜信技術學院