部署到服务器

前端部署

环境要求

  • nodeJs v12.xx
  • npm v6.xx
  1. 获取源代码
  1. $ git clone https://github.com/jetlinks/jetlinks-ui-antd.git
  1. 使用npm打包,并将打包后的文件复制到项目的docker目录下(命令在项目根目录下执行)
  1. npm install
  2. npm run-script build
  3. cp -r dist docker/

使用docker部署前端

  1. 构建docker镜像
  1. docker build -t registry.cn-shenzhen.aliyuncs.com/jetlinks/jetlinks-ui-antd:1.10.0 ./docker
  1. 运行docker镜像
  1. docker run -it --rm -p 9000:80 -e "API_BASE_PATH=http://xxx:8848/" registry.cn-shenzhen.aliyuncs.com/jetlinks/jetlinks-ui-antd:1.10.0

注意

环境变量API_BASE_PATH为后台API根地址. 由docker容器内进行自动代理. 请根据自己的系统环境配置环境变量: API_BASE_PATH

使用nginx部署

  1. 复制dist目录下到文件到/usr/share/nginx/html
  2. 添加nginx配置文件

nginx配置参考:

  1. server {
  2. listen 80;
  3. # gzip config
  4. gzip on;
  5. gzip_min_length 1k;
  6. gzip_comp_level 9;
  7. gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
  8. gzip_vary on;
  9. gzip_disable "MSIE [1-6]\.";
  10. root /usr/share/nginx/html;
  11. include /etc/nginx/mime.types;
  12. location / {
  13. index index.html;
  14. }
  15. location ^~/jetlinks/ {
  16. proxy_pass http://jetlinks:8844/; #修改此地址为后台服务地址
  17. proxy_set_header X-Forwarded-Proto $scheme;
  18. proxy_set_header Host $host:$server_port;
  19. proxy_set_header X-Real-IP $remote_addr;
  20. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  21. proxy_http_version 1.1;
  22. proxy_set_header Upgrade $http_upgrade;
  23. proxy_set_header Connection "upgrade";
  24. proxy_connect_timeout 1;
  25. proxy_buffering off;
  26. chunked_transfer_encoding off;
  27. proxy_cache off;
  28. proxy_send_timeout 30m;
  29. proxy_read_timeout 30m;
  30. client_max_body_size 100m;
  31. }
  32. }

后端部署

使用docker部署后端

  1. 使用maven命令将项目打包
    在代码根目录执行:
  1. mvn clean package -Dmaven.test.skip=true
  1. 使用docker构建镜像

注意

请自行准备docker镜像仓库,此处以registry.cn-shenzhen.aliyuncs.com阿里云私有仓库为例。

  1. $ cd ./jetlinks-standalone
  2. $ docker build -t registry.cn-shenzhen.aliyuncs.com/jetlinks/jetlinks-standalone:latest .
  1. 推送镜像
  1. $ docker push registry.cn-shenzhen.aliyuncs.com/jetlinks/jetlinks-standalone:latest
  1. 创建docker-compose文件
  1. version: '2'
  2. services:
  3. redis:
  4. image: redis:5.0.4
  5. container_name: jetlinks-ce-redis
  6. # ports:
  7. # - "6379:6379"
  8. volumes:
  9. - "redis-volume:/data"
  10. command: redis-server --appendonly yes --requirepass "redispassword"
  11. environment:
  12. - TZ=Asia/Shanghai
  13. elasticsearch:
  14. image: elasticsearch:6.8.11
  15. container_name: jetlinks-ce-elasticsearch
  16. environment:
  17. ES_JAVA_OPTS: -Djava.net.preferIPv4Stack=true -Xms1g -Xmx1g
  18. transport.host: 0.0.0.0
  19. discovery.type: single-node
  20. bootstrap.memory_lock: "true"
  21. discovery.zen.minimum_master_nodes: 1
  22. discovery.zen.ping.unicast.hosts: elasticsearch
  23. volumes:
  24. - elasticsearch-volume:/usr/share/elasticsearch/data
  25. # ports:
  26. # - "9200:9200"
  27. # - "9300:9300"
  28. kibana:
  29. image: kibana:6.8.11
  30. container_name: jetlinks-ce-kibana
  31. environment:
  32. ELASTICSEARCH_URL: http://elasticsearch:9200
  33. links:
  34. - elasticsearch:elasticsearch
  35. ports:
  36. - "5602:5601"
  37. depends_on:
  38. - elasticsearch
  39. postgres:
  40. image: postgres:11-alpine
  41. container_name: jetlinks-ce-postgres
  42. volumes:
  43. - "postgres-volume:/var/lib/postgresql/data"
  44. ports:
  45. - "5432:5432"
  46. environment:
  47. POSTGRES_PASSWORD: jetlinks
  48. POSTGRES_DB: jetlinks
  49. TZ: Asia/Shanghai
  50. ui:
  51. image: registry.cn-shenzhen.aliyuncs.com/jetlinks/jetlinks-ui-antd:latest
  52. container_name: jetlinks-ce-ui
  53. ports:
  54. - 9000:80
  55. environment:
  56. - "API_BASE_PATH=http://jetlinks:8848/" #API根路径
  57. volumes:
  58. - "jetlinks-volume:/usr/share/nginx/html/upload"
  59. links:
  60. - jetlinks:jetlinks
  61. jetlinks:
  62. image: registry.cn-shenzhen.aliyuncs.com/jetlinks/jetlinks-standalone:latest
  63. container_name: jetlinks-ce
  64. ports:
  65. - 8848:8848 # API端口
  66. - 1883-1890:1883-1890 # 预留
  67. - 8000-8010:8000-8010 # 预留
  68. volumes:
  69. - "jetlinks-volume:/application/static/upload" # 持久化上传的文件
  70. - "jetlinks-protocol-volume:/application/data/protocols"
  71. environment:
  72. # - "JAVA_OPTS=-Xms4g -Xmx18g -XX:+UseG1GC"
  73. - "TZ=Asia/Shanghai"
  74. - "hsweb.file.upload.static-location=http://127.0.0.1:8848/upload" #上传的静态文件访问根地址,为ui的地址.
  75. - "spring.r2dbc.url=r2dbc:postgresql://postgres:5432/jetlinks" #数据库连接地址
  76. - "spring.r2dbc.username=postgres"
  77. - "spring.r2dbc.password=jetlinks"
  78. - "spring.redis.host=redis"
  79. - "spring.redis.port=6379"
  80. - "spring.redis.password=redispassword"#生产环境请配置redis密码
  81. # 生产环境下请配置es的密码,或者关闭公网访问
  82. - "spring.data.elasticsearch.client.reactive.endpoints=elasticsearch:9200"
  83. # - "spring.data.elasticsearch.client.reactive.username=admin"
  84. # - "spring.data.elasticsearch.client.reactive.password=admin"
  85. # - "spring.reactor.debug-agent.enabled=false" #设置为false能提升性能
  86. # - "jetlinks.device.storage.enable-last-data-in-db=true" # 开启记录最新数据到数据库,但是会降低吞吐量
  87. - "logging.level.io.r2dbc=warn"
  88. - "logging.level.org.springframework.data=warn"
  89. - "logging.level.org.springframework=warn"
  90. - "logging.level.org.jetlinks=warn"
  91. - "logging.level.org.hswebframework=warn"
  92. - "logging.level.org.springframework.data.r2dbc.connectionfactory=warn"
  93. links:
  94. - redis:redis
  95. - postgres:postgres
  96. - elasticsearch:elasticsearch
  97. depends_on:
  98. - postgres
  99. - redis
  100. - elasticsearch
  101. volumes:
  102. postgres-volume:
  103. redis-volume:
  104. elasticsearch-volume:
  105. jetlinks-volume:
  106. jetlinks-protocol-volume:

注意:

jetlinks docker镜像版本更新和源代码根目录下文件pom.xml中的版本号同步。

6.运行docker-compose文件

  1. docker-compose up -d

jar包方式

1.使用maven命令将项目打包,在代码根目录执行:

  1. ./mvnw clean package -Dmaven.test.skip=true

2.将jar包上传到需要部署的服务器上。

jar包文件地址: jetlinks-standalone/target/jetlinks-standalone.jar

3.使用java命令运行jar包

  1. $ java -jar jetlinks-standalone.jar

注意

请根据情况调整jvm参数等信息.