## TMC�ǻ�������ƽ̨����˵��

### ���ݿ⻷��׼��
- mysql 5.7
- redis 5.0.0
- elasticsearch 6.5.4
- rabbitmq 3.6.9
ʹ�ø�Ŀ¼��maven �����ļ�
mysql���ݿ���Դ�����ú�ִ������sql������ʼ�����ݿ�
```
CREATE DATABASE `turing-admin` CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
CREATE DATABASE `turing-auth` CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
CREATE DATABASE `turing-datahandler` CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
CREATE DATABASE `turing-device` CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
```
������sqlĿ¼�µĸ���sql�ļ���������ʼ�����ͳ�ʼ������

### ��������׼��
SpringCloudʹ��gitee����Ϊ��������
[ʾ�������ļ���ַ](https://gitee.com/zkturing-tmc/fire_control_config_example)  

�޸�gitee�ϸ���΢���������µ����ݿ�������Ϣ������Ӧ�޸�΢�����������yml�����gitee������Ϣ

### ���������
1. �������΢������룬���ɶ�Ӧjar��
2. ִ�и��������ļ�����Dockerfile�ļ��������docker����


### ��������
��Ӧ�޸�docker-compose.yml�����ļ���ִ��`docker compose up -d` ������������

��������˳��Ϊ��CenterBootstrap -> ConfigServerBootstrap -> AuthBootstrap ->  AdminBootstrap -> GateBootstrap  ��

DeviceBootstrap��DataHandlerBootstrap ��DataCollectionBootstrap ����ǰ�������������ɺ�����������

### ǰ�˴�������
[https://gitee.com/zkturing-tmc/big_fire_data_vue](https://gitee.com/zkturing-tmc/big_fire_data_vue)

### Nginx����ʾ��
```
user www-data;
worker_processes auto;

worker_rlimit_nofile 51200;

events {

  use epoll;
  worker_connections 51200;
  multi_accept on;
}
http {
    include       mime.types;
    default_type  application/octet-stream;

    server_names_hash_bucket_size   128;

    client_header_buffer_size   32k;

    large_client_header_buffers 4 32k;
    log_format access '$remote_addr - $remote_user [$time_local] "$request" '
            '$status $body_bytes_sent "$http_referer" '
            '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log   access;
    sendfile    on;
    tcp_nopush  on;
    tcp_nodelay on;
    keepalive_timeout   65;
    server_tokens   off;
    client_body_buffer_size 1024k;
   
    proxy_connect_timeout   150s;
    proxy_send_timeout      150s;
    proxy_read_timeout      150s;

    proxy_buffer_size       512k;
    proxy_buffers           64 64k;
    proxy_busy_buffers_size 2048k;
    proxy_temp_file_write_size 2048k;


    gzip    on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary   on;    

    client_header_timeout 120s;     
    client_body_timeout 120s;  

    client_max_body_size 300M; 

    upstream mycluster{
        # ��Ӧ��˷����ַ
        server turing-gate.tmc-v1:8765 weight=1;
    }

    upstream websocket{
        # ��Ӧ��˷����ַ
        server turing-datahandler.tmc-v1:2345  weight=1;
    }

    server {
        listen 80;
        server_name _;
        #charset koi8-r;
        #access_log  /var/log/nginx/host.access.log  main;

        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }

        location /threed/ {
            root  /usr/share/nginx/threed;
        }

        location /api/ {
            #proxy_next_upstream http_502 http_504 error timeout invalid_header;
            proxy_set_header Connection "Keep-Alive";
            proxy_pass http://mycluster;
            proxy_set_header   X-Real-IP        $remote_addr:8765;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
        }

        location /alarm/websocket {
            proxy_pass http://websocket;
            proxy_redirect off;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

    }

}
```

### �����˺�

�˺ţ�admin

���룺Turing2018

### ��������

#### һ��jar��ȱʧ

����ʹ����Ŀ�е�settings�ļ���Ϊmaven���ã�settings�ļ���˽������Ŀ��������а���Ҳ������pom�ļ������ñ��ذ���Ŀǰȱʧjar�Ѿ����Ӷ�Ӧģ���lib�ļ����¡�pom�ļ���

```xml
<!--ʹ����������jar��-->
<dependency>
    <groupId>com.huawei</groupId>
    <artifactId>vms-util</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/src/main/resources/lib/vms-util-1.0.jar</systemPath>
</dependency>
<!--ʹ��˽��-->
<!--<dependency>
    <groupId>com.huawei</groupId>
    <artifactId>vms-util</artifactId>
    <version>1.0</version>
</dependency>-->
```



####  ����auth.serviceId �Ҳ���

�����Ŀ�������� auth.serviceId �Ҳ��� ��ȷ���������ķ����Ƿ���������Ŀ��ȡ��������auth-demo�Ƿ���ȷ��



#### ����elasticsearch ���ز�������

elasticsearch.yml �ļ�Ҫ�� application-demo.yml �е�����һ�¡��磺

application-demo.yml �ļ�

```
elasticsearch:
    cluster-name: fire-control
    cluster-nodes: 127.0.0.1:9300
```
elasticsearch.yml �ļ�
```java
cluster.name: fire-control
network.host: 127.0.0.1
```

**ע�⣺cluster-nodes ��Ҫ��http**

#### �ġ������ļ�����

**ע�⣺����ϸ�޸������ļ�����eureka��redis��rabbitMq��elasticsearch�����ݿ�������޸�Ϊ�Լ������ã�����������ģ���µ�bootstrap.yml�ļ�������ȷ�����磺**

###### turing-center �����µ� bootstrap.yml

```
spring:
    application:
        name: turing-center

server:
    port: 8761 #�����˿�

eureka:
    client:
        registerWithEureka: false  #false:����Ϊһ���ͻ���ע�ᵽע������
        fetchRegistry: false      #Ϊtrueʱ�����������������쳣��Cannot execute request on any known server
        defaultZone: http://127.0.0.1:8761/eureka/ # ��д���ػ��߷����� eureka �����ip��ַ
```

###### turing-auth �����µ� bootstrap.yml

```
spring:
  profiles:
    active: demo # ��git�������ļ�����һ��
  cloud:
    config:
      discovery:
        service-id: turing-config
        enabled: true
      label: master # git ��֧  # ��git�����÷�֧��һ��
      name: auth
      profile: ${spring.profiles.active}

management:
  security:
    enabled: false

---
spring:
  profiles: demo  # ��git�������ļ�����һ��
eureka:
  instance:
    statusPageUrlPath: /swagger-ui.html
    healthCheckUrlPath: /health
    # docker ������,�ǵý�IP�޸�Ϊ�������ڷ�����������IP
    leaseRenewalIntervalInSeconds: 5
  client:
    serviceUrl:
      defaultZone: http://host/eureka/  ## ע�� defaultZone Ҫ�� turing-center �����µ� bootstrap.yml�е� defaultZone һ�¡�
```

**��������ɻ����ٶȲ�ѯ��springcloud eureka �� config  ������õ���ϸ��Ϣ�Ͳ��裬�ڴ˲�����˵��**��



##### 1��AuthBootstrap ��������

```
java.lang.IllegalStateException: Service id not legal hostname (${jwt.user-service})
```

�˱���Ϊ��֤���ģ�AuthBootstrap��û���õ� application-demo.yml �����ļ�����ȷ�Ϸ����ע������ CenterBootstrap ��  ���������ļ����� ConfigServerBootstrap  ���������ˣ����ò��������ٶȲ�ѯ springcloud eureka �� config  ������õ���ϸ��Ϣ�Ͳ��裩��ȷ�� bootstrap.yml ���������е� defaultZone Ҫ�� turing-center �����µ� bootstrap.yml�е� defaultZone һ�¡�

##### 2��AdminBootstrap ��������

```
com.sun.jersey.api.client.ClientHandlerException: java.net.UnknownHostException: host

```

�˱���Ϊ�����ļ����ô�����ȷ�Ϸ����ע������ CenterBootstrap ��  ���������ļ����� ConfigServerBootstrap  ���������ˣ����ò��������ٶȲ�ѯ springcloud eureka �� config  ������õ���ϸ��Ϣ�Ͳ��裩���� admin-demo.yml �����ݿ������޸���ȷ��**��Ҫʹ��ʾ�����õ�ַ host ���������������ݿ��������hosts�ļ���ָ��hostΪ�˷�������ӳ�䡣**

```
spring:
  application:
    name: turing-admin
  datasource:                   
    url: jdbc:mysql://host:3306/turing-admin?useUnicode=true&characterEncoding=UTF8 ## ��������ȷ�����ݿ��ַ����Ҫʹ�� host ���������������ݿ��������hosts�ļ���ָ��hostΪ�˷�������ӳ�䡣
```

##### 3��GateBootstrap ��������

```
org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
```

�˱���Ϊ�����ļ���redis��ַ���ô�����ȷ�Ϸ����ע������ CenterBootstrap ��  ���������ļ����� ConfigServerBootstrap  ���������ˣ����ò��������ٶȲ�ѯ springcloud eureka �� config  ������õ���ϸ��Ϣ�Ͳ��裩���� application-demo.yml ��redis�����޸���ȷ��**��Ҫʹ��ʾ�����õ�ַ host ������������redis��������hosts�ļ���ָ��hostΪ�˷�������ӳ�䡣**

```
  redis:
    host: host     # ʹ����ȷ��redis���ڷ�������ַ
    password: Turing2018  # ʹ����ȷ��redis�����õ�����
    port: 6379
    database: 0
```

##### 4��DataCollectionBootstrap ��������

```
UnknownHostException: turing-center
com.sun.jersey.api.client.ClientHandlerException: java.net.UnknownHostException: turing-center

```

�˱���Ϊ�����ļ��������ȷ�Ϸ����ע������ CenterBootstrap ��  ���������ļ����� ConfigServerBootstrap  ���������ˣ����ò��������ٶȲ�ѯ springcloud eureka �� config  ������õ���ϸ��Ϣ�Ͳ��裩���뽫DataCollectionBootstrap�����е�bootstrap.yml�ķ���ע�����ĵ�ַ������ȷ��

```
eureka:
  instance:
    #    statusPageUrlPath: /swagger-ui.html
    healthCheckUrlPath: /health
    prefer-ip-address: true
    # ip-address:  ${spring.cloud.client.ipAddress}
    ip-address:  127.0.0.1    # ��д���ػ��߷�����ip��ַ
    leaseRenewalIntervalInSeconds: 5
  client:
    serviceUrl:
      #defaultZone: http://${CENTER_HOST:turing-center}:${CENTER_PORT:8761}/eureka/
      defaultZone: http://127.0.0.1:8761/eureka/ # ��д���ػ��߷����� eureka �����ip��ַ
```

#### �塢Command line is too long

idea���⣬��ο� https://blog.csdn.net/feitianlongfei/article/details/80976953