Commit 5690e4e848b6100f1563779c47a643bcc4b393c6
Merge branch 'feature/kubernetes' into feature/docker-improve
Showing
18 changed files
with
823 additions
and
70 deletions
... | ... | @@ -19,12 +19,18 @@ server: |
19 | 19 | address: "${HTTP_BIND_ADDRESS:0.0.0.0}" |
20 | 20 | # Server bind port |
21 | 21 | port: "${HTTP_BIND_PORT:8080}" |
22 | -# Uncomment the following section to enable ssl | |
23 | -# ssl: | |
24 | -# key-store: classpath:keystore/keystore.p12 | |
25 | -# key-store-password: thingsboard | |
26 | -# keyStoreType: PKCS12 | |
27 | -# keyAlias: tomcat | |
22 | + # Server SSL configuration | |
23 | + ssl: | |
24 | + # Enable/disable SSL support | |
25 | + enabled: "${SSL_ENABLED:false}" | |
26 | + # Path to the key store that holds the SSL certificate | |
27 | + key-store: "${SSL_KEY_STORE:classpath:keystore/keystore.p12}" | |
28 | + # Password used to access the key store | |
29 | + key-store-password: "${SSL_KEY_STORE_PASSWORD:thingsboard}" | |
30 | + # Type of the key store | |
31 | + key-store-type: "${SSL_KEY_STORE_TYPE:PKCS12}" | |
32 | + # Alias that identifies the key in the key store | |
33 | + key-alias: "${SSL_KEY_ALIAS:tomcat}" | |
28 | 34 | |
29 | 35 | # Zookeeper connection parameters. Used for service discovery. |
30 | 36 | zk: |
... | ... | @@ -60,10 +66,10 @@ plugins: |
60 | 66 | |
61 | 67 | # JWT Token parameters |
62 | 68 | security.jwt: |
63 | - tokenExpirationTime: "${JWT_TOKEN_EXPIRATION_TIME:9000000}" # Number of seconds (15 mins) | |
64 | - refreshTokenExpTime: "${JWT_REFRESH_TOKEN_EXPIRATION_TIME:36000000}" # Seconds (1 hour) | |
65 | - tokenIssuer: "${JWT_TOKEN_ISSUER:thingsboard.io}" | |
66 | - tokenSigningKey: "${JWT_TOKEN_SIGNING_KEY:thingsboardDefaultSigningKey}" | |
69 | + token-expiration-time: "${JWT_TOKEN_EXPIRATION_TIME:9000000}" # Number of seconds (15 mins) | |
70 | + refresh-token-exp-time: "${JWT_REFRESH_TOKEN_EXPIRATION_TIME:36000000}" # Seconds (1 hour) | |
71 | + token-issuer: "${JWT_TOKEN_ISSUER:thingsboard.io}" | |
72 | + token-signing-key: "${JWT_TOKEN_SIGNING_KEY:thingsboardDefaultSigningKey}" | |
67 | 73 | |
68 | 74 | # Device communication protocol parameters |
69 | 75 | http: |
... | ... | @@ -79,12 +85,18 @@ mqtt: |
79 | 85 | leak_detector_level: "${NETTY_LEASK_DETECTOR_LVL:DISABLED}" |
80 | 86 | boss_group_thread_count: "${NETTY_BOSS_GROUP_THREADS:1}" |
81 | 87 | worker_group_thread_count: "${NETTY_WORKER_GROUP_THREADS:12}" |
82 | -# Uncomment the following lines to enable ssl for MQTT | |
83 | -# ssl: | |
84 | -# key_store: mqttserver.jks | |
85 | -# key_store_password: server_ks_password | |
86 | -# key_password: server_key_password | |
87 | -# key_store_type: JKS | |
88 | + # MQTT SSL configuration | |
89 | + ssl: | |
90 | + # Enable/disable SSL support | |
91 | + enabled: "${MQTT_SSL_ENABLED:false}" | |
92 | + # Path to the key store that holds the SSL certificate | |
93 | + key_store: "${MQTT_SSL_KEY_STORE:mqttserver.jks}" | |
94 | + # Password used to access the key store | |
95 | + key_store_password: "${MQTT_SSL_KEY_STORE_PASSWORD:server_ks_password}" | |
96 | + # Password used to access the key | |
97 | + key_password: "${MQTT_SSL_KEY_PASSWORD:server_key_password}" | |
98 | + # Type of the key store | |
99 | + key_store_type: "${MQTT_SSL_KEY_STORE_TYPE:JKS}" | |
88 | 100 | |
89 | 101 | # CoAP server parameters |
90 | 102 | coap: | ... | ... |
docker/cassandra/Dockerfile
renamed from
docker/thingsboard/build_and_deploy.sh
100755 → 100644
1 | -#!/bin/bash | |
2 | 1 | # |
3 | 2 | # Copyright © 2016-2017 The Thingsboard Authors |
4 | 3 | # |
... | ... | @@ -15,12 +14,8 @@ |
15 | 14 | # limitations under the License. |
16 | 15 | # |
17 | 16 | |
17 | +FROM cassandra:3.9 | |
18 | 18 | |
19 | -cp ../../application/target/thingsboard.deb thingsboard.deb | |
19 | +COPY ready-probe.sh / | |
20 | 20 | |
21 | -docker build -t thingsboard/application:1.2.3 -t thingsboard/application:latest . | |
22 | - | |
23 | -docker login | |
24 | - | |
25 | -docker push thingsboard/application:1.2.3 | |
26 | -docker push thingsboard/application:latest | |
\ No newline at end of file | ||
21 | +CMD ["cassandra", "-f"] | |
\ No newline at end of file | ... | ... |
docker/cassandra/Makefile
0 → 100644
docker/cassandra/cassandra.yaml
0 → 100644
1 | +# | |
2 | +# Copyright © 2016-2017 The Thingsboard Authors | |
3 | +# | |
4 | +# Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | +# you may not use this file except in compliance with the License. | |
6 | +# You may obtain a copy of the License at | |
7 | +# | |
8 | +# http://www.apache.org/licenses/LICENSE-2.0 | |
9 | +# | |
10 | +# Unless required by applicable law or agreed to in writing, software | |
11 | +# distributed under the License is distributed on an "AS IS" BASIS, | |
12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | +# See the License for the specific language governing permissions and | |
14 | +# limitations under the License. | |
15 | +# | |
16 | + | |
17 | +apiVersion: v1 | |
18 | +kind: Service | |
19 | +metadata: | |
20 | + name: cassandra-headless | |
21 | + labels: | |
22 | + app: cassandra-headless | |
23 | +spec: | |
24 | + ports: | |
25 | + - port: 9042 | |
26 | + name: cql | |
27 | + clusterIP: None | |
28 | + selector: | |
29 | + app: cassandra | |
30 | +--- | |
31 | +apiVersion: "apps/v1beta1" | |
32 | +kind: StatefulSet | |
33 | +metadata: | |
34 | + name: cassandra | |
35 | +spec: | |
36 | + serviceName: cassandra-headless | |
37 | + replicas: 2 | |
38 | + template: | |
39 | + metadata: | |
40 | + labels: | |
41 | + app: cassandra | |
42 | + spec: | |
43 | + nodeSelector: | |
44 | + machinetype: other | |
45 | + affinity: | |
46 | + podAntiAffinity: | |
47 | + requiredDuringSchedulingIgnoredDuringExecution: | |
48 | + - labelSelector: | |
49 | + matchExpressions: | |
50 | + - key: "app" | |
51 | + operator: In | |
52 | + values: | |
53 | + - cassandra-headless | |
54 | + topologyKey: "kubernetes.io/hostname" | |
55 | + containers: | |
56 | + - name: cassandra | |
57 | + image: thingsboard/cassandra:k8stest | |
58 | + imagePullPolicy: Always | |
59 | + ports: | |
60 | + - containerPort: 7000 | |
61 | + name: intra-node | |
62 | + - containerPort: 7001 | |
63 | + name: tls-intra-node | |
64 | + - containerPort: 7199 | |
65 | + name: jmx | |
66 | + - containerPort: 9042 | |
67 | + name: cql | |
68 | + - containerPort: 9160 | |
69 | + name: thrift | |
70 | + securityContext: | |
71 | + capabilities: | |
72 | + add: | |
73 | + - IPC_LOCK | |
74 | + lifecycle: | |
75 | + preStop: | |
76 | + exec: | |
77 | + command: ["/bin/sh", "-c", "PID=$(pidof java) && kill $PID && while ps -p $PID > /dev/null; do sleep 1; done"] | |
78 | + env: | |
79 | + - name: MAX_HEAP_SIZE | |
80 | + value: 2048M | |
81 | + - name: HEAP_NEWSIZE | |
82 | + value: 100M | |
83 | + - name: CASSANDRA_SEEDS | |
84 | + value: "cassandra-0.cassandra-headless.default.svc.cluster.local" | |
85 | + - name: CASSANDRA_CLUSTER_NAME | |
86 | + value: "K8Demo" | |
87 | + - name: CASSANDRA_DC | |
88 | + value: "DC1-K8Demo" | |
89 | + - name: CASSANDRA_RACK | |
90 | + value: "Rack1-K8Demo" | |
91 | + - name: CASSANDRA_AUTO_BOOTSTRAP | |
92 | + value: "false" | |
93 | + - name: POD_IP | |
94 | + valueFrom: | |
95 | + fieldRef: | |
96 | + fieldPath: status.podIP | |
97 | + - name: POD_NAMESPACE | |
98 | + valueFrom: | |
99 | + fieldRef: | |
100 | + fieldPath: metadata.namespace | |
101 | + readinessProbe: | |
102 | + exec: | |
103 | + command: | |
104 | + - /bin/bash | |
105 | + - -c | |
106 | + - /ready-probe.sh | |
107 | + initialDelaySeconds: 15 | |
108 | + timeoutSeconds: 5 | |
109 | + volumeMounts: | |
110 | + - name: cassandra-data | |
111 | + mountPath: /var/lib/cassandra/data | |
112 | + - name: cassandra-commitlog | |
113 | + mountPath: /var/lib/cassandra/commitlog | |
114 | + volumeClaimTemplates: | |
115 | + - metadata: | |
116 | + name: cassandra-data | |
117 | + annotations: | |
118 | + volume.beta.kubernetes.io/storage-class: fast | |
119 | + spec: | |
120 | + accessModes: [ "ReadWriteOnce" ] | |
121 | + resources: | |
122 | + requests: | |
123 | + storage: 3Gi | |
124 | + - metadata: | |
125 | + name: cassandra-commitlog | |
126 | + annotations: | |
127 | + volume.beta.kubernetes.io/storage-class: fast | |
128 | + spec: | |
129 | + accessModes: [ "ReadWriteOnce" ] | |
130 | + resources: | |
131 | + requests: | |
132 | + storage: 2Gi | |
\ No newline at end of file | ... | ... |
docker/cassandra/ready-probe.sh
renamed from
docker/thingsboard-db-schema/build_and_deploy.sh
... | ... | @@ -15,14 +15,14 @@ |
15 | 15 | # limitations under the License. |
16 | 16 | # |
17 | 17 | |
18 | - | |
19 | -cp ../../dao/src/main/resources/schema.cql schema.cql | |
20 | -cp ../../dao/src/main/resources/demo-data.cql demo-data.cql | |
21 | -cp ../../dao/src/main/resources/system-data.cql system-data.cql | |
22 | - | |
23 | -docker build -t thingsboard/thingsboard-db-schema:1.2.3 -t thingsboard/thingsboard-db-schema:latest . | |
24 | - | |
25 | -docker login | |
26 | - | |
27 | -docker push thingsboard/thingsboard-db-schema:1.2.3 | |
28 | -docker push thingsboard/thingsboard-db-schema:latest | |
\ No newline at end of file | ||
18 | +if [[ $(nodetool status | grep $POD_IP) == *"UN"* ]]; then | |
19 | + if [[ $DEBUG ]]; then | |
20 | + echo "UN"; | |
21 | + fi | |
22 | + exit 0; | |
23 | +else | |
24 | + if [[ $DEBUG ]]; then | |
25 | + echo "Not Up"; | |
26 | + fi | |
27 | + exit 1; | |
28 | +fi | |
\ No newline at end of file | ... | ... |
docker/common/common.yaml
renamed from
docker/deploy_cassandra_zookeeper.sh
100755 → 100644
1 | -#!/bin/bash | |
2 | 1 | # |
3 | 2 | # Copyright © 2016-2017 The Thingsboard Authors |
4 | 3 | # |
... | ... | @@ -15,17 +14,20 @@ |
15 | 14 | # limitations under the License. |
16 | 15 | # |
17 | 16 | |
18 | - | |
19 | -command='docker-compose -f docker-compose.yml -f docker-compose.static.yml' | |
20 | - | |
21 | -echo "stopping images.." | |
22 | -$command stop | |
23 | - | |
24 | -echo "removing stopped images.." | |
25 | -$command rm -f | |
26 | - | |
27 | -echo "building images.." | |
28 | -$command build | |
29 | - | |
30 | -echo "starting cassandra, zookeeper, thingsboard-db-schema images..." | |
31 | -$command up -d db zk thingsboard-db-schema | |
17 | +--- | |
18 | +apiVersion: storage.k8s.io/v1beta1 | |
19 | +kind: StorageClass | |
20 | +metadata: | |
21 | + name: slow | |
22 | +provisioner: kubernetes.io/gce-pd | |
23 | +parameters: | |
24 | + type: pd-standard | |
25 | +--- | |
26 | +apiVersion: storage.k8s.io/v1beta1 | |
27 | +kind: StorageClass | |
28 | +metadata: | |
29 | + name: fast | |
30 | +provisioner: kubernetes.io/gce-pd | |
31 | +parameters: | |
32 | + type: pd-ssd | |
33 | +--- | |
\ No newline at end of file | ... | ... |
docker/thingsboard-db-schema/Makefile
0 → 100644
1 | +VERSION=k8stest | |
2 | +PROJECT=thingsboard | |
3 | +APP=thingsboard-db-schema | |
4 | + | |
5 | +build: | |
6 | + cp ../../dao/src/main/resources/schema.cql . | |
7 | + cp ../../dao/src/main/resources/demo-data.cql . | |
8 | + cp ../../dao/src/main/resources/system-data.cql . | |
9 | + docker build --pull -t ${PROJECT}/${APP}:${VERSION} . | |
10 | + rm schema.cql demo-data.cql system-data.cql | |
11 | + | |
12 | +push: build | |
13 | + docker push ${PROJECT}/${APP}:${VERSION} | |
\ No newline at end of file | ... | ... |
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 | # |
17 | 17 | |
18 | 18 | |
19 | -until nmap db -p 9042 | grep "9042/tcp open" | |
19 | +until nmap $CASSANDRA_URL -p 9042 | grep "9042/tcp open" | |
20 | 20 | do |
21 | 21 | echo "Wait for Cassandra..." |
22 | 22 | sleep 10 |
... | ... | @@ -24,7 +24,7 @@ done |
24 | 24 | |
25 | 25 | if [ "$SKIP_SCHEMA_CREATION" == "false" ]; then |
26 | 26 | echo "Creating 'Thingsboard' keyspace..." |
27 | - cqlsh db -f /root/schema.cql | |
27 | + cqlsh $CASSANDRA_URL -f /root/schema.cql | |
28 | 28 | if [ "$?" -eq 0 ]; then |
29 | 29 | echo "'Thingsboard' keyspace was successfully created!" |
30 | 30 | else |
... | ... | @@ -34,7 +34,7 @@ fi |
34 | 34 | |
35 | 35 | if [ "$SKIP_SYSTEM_DATA" == "false" ]; then |
36 | 36 | echo "Adding system data..." |
37 | - cqlsh db -f /root/system-data.cql | |
37 | + cqlsh $CASSANDRA_URL -f /root/system-data.cql | |
38 | 38 | if [ "$?" -eq 0 ]; then |
39 | 39 | echo "System data was successfully added!" |
40 | 40 | else |
... | ... | @@ -44,7 +44,7 @@ fi |
44 | 44 | |
45 | 45 | if [ "$SKIP_DEMO_DATA" == "false" ]; then |
46 | 46 | echo "Adding demo data..." |
47 | - cqlsh db -f /root/demo-data.cql | |
47 | + cqlsh $CASSANDRA_URL -f /root/demo-data.cql | |
48 | 48 | if [ "$?" -eq 0 ]; then |
49 | 49 | echo "Demo data was successfully added!" |
50 | 50 | else | ... | ... |
1 | +# | |
2 | +# Copyright © 2016-2017 The Thingsboard Authors | |
3 | +# | |
4 | +# Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | +# you may not use this file except in compliance with the License. | |
6 | +# You may obtain a copy of the License at | |
7 | +# | |
8 | +# http://www.apache.org/licenses/LICENSE-2.0 | |
9 | +# | |
10 | +# Unless required by applicable law or agreed to in writing, software | |
11 | +# distributed under the License is distributed on an "AS IS" BASIS, | |
12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | +# See the License for the specific language governing permissions and | |
14 | +# limitations under the License. | |
15 | +# | |
16 | + | |
17 | +apiVersion: v1 | |
18 | +kind: Pod | |
19 | +metadata: | |
20 | + name: tb-db-schema | |
21 | +spec: | |
22 | + containers: | |
23 | + - name: tb-db-schema | |
24 | + imagePullPolicy: Always | |
25 | + image: thingsboard/thingsboard-db-schema:k8stest | |
26 | + env: | |
27 | + - name: SKIP_SCHEMA_CREATION | |
28 | + value: "false" | |
29 | + - name: SKIP_SYSTEM_DATA | |
30 | + value: "false" | |
31 | + - name : SKIP_DEMO_DATA | |
32 | + value: "false" | |
33 | + - name : CASSANDRA_URL | |
34 | + value: "cassandra-headless" | |
35 | + command: | |
36 | + - sh | |
37 | + - -c | |
38 | + - ./install_schema.sh | |
39 | + restartPolicy: Never | |
\ No newline at end of file | ... | ... |
docker/thingsboard/Makefile
0 → 100644
1 | +VERSION=k8stest | |
2 | +PROJECT=thingsboard | |
3 | +APP=application | |
4 | + | |
5 | +build: | |
6 | + cp ../../application/target/thingsboard.deb . | |
7 | + docker build --pull -t ${PROJECT}/${APP}:${VERSION} . | |
8 | + rm thingsboard.deb | |
9 | + | |
10 | +push: build | |
11 | + docker push ${PROJECT}/${APP}:${VERSION} | |
\ No newline at end of file | ... | ... |
docker/thingsboard/thingsboard.yaml
0 → 100644
1 | +# | |
2 | +# Copyright © 2016-2017 The Thingsboard Authors | |
3 | +# | |
4 | +# Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | +# you may not use this file except in compliance with the License. | |
6 | +# You may obtain a copy of the License at | |
7 | +# | |
8 | +# http://www.apache.org/licenses/LICENSE-2.0 | |
9 | +# | |
10 | +# Unless required by applicable law or agreed to in writing, software | |
11 | +# distributed under the License is distributed on an "AS IS" BASIS, | |
12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | +# See the License for the specific language governing permissions and | |
14 | +# limitations under the License. | |
15 | +# | |
16 | + | |
17 | +--- | |
18 | +apiVersion: v1 | |
19 | +kind: Service | |
20 | +metadata: | |
21 | + name: tb-service | |
22 | + labels: | |
23 | + app: tb-service | |
24 | +spec: | |
25 | + ports: | |
26 | + - port: 8080 | |
27 | + name: ui | |
28 | + - port: 1883 | |
29 | + name: mqtt | |
30 | + - port: 5683 | |
31 | + name: coap | |
32 | + selector: | |
33 | + app: tb | |
34 | + type: LoadBalancer | |
35 | +--- | |
36 | +apiVersion: policy/v1beta1 | |
37 | +kind: PodDisruptionBudget | |
38 | +metadata: | |
39 | + name: tb-budget | |
40 | +spec: | |
41 | + selector: | |
42 | + matchLabels: | |
43 | + app: tb | |
44 | + minAvailable: 3 | |
45 | +--- | |
46 | +apiVersion: v1 | |
47 | +kind: ConfigMap | |
48 | +metadata: | |
49 | + name: tb-config | |
50 | +data: | |
51 | + zookeeper.enabled: "true" | |
52 | + zookeeper.url: "zk-headless" | |
53 | + cassandra.url: "cassandra-headless:9042" | |
54 | +--- | |
55 | +apiVersion: apps/v1beta1 | |
56 | +kind: StatefulSet | |
57 | +metadata: | |
58 | + name: tb | |
59 | +spec: | |
60 | + serviceName: "tb-service" | |
61 | + replicas: 3 | |
62 | + template: | |
63 | + metadata: | |
64 | + labels: | |
65 | + app: tb | |
66 | + spec: | |
67 | + nodeSelector: | |
68 | + machinetype: tb | |
69 | + affinity: | |
70 | + podAntiAffinity: | |
71 | + requiredDuringSchedulingIgnoredDuringExecution: | |
72 | + - labelSelector: | |
73 | + matchExpressions: | |
74 | + - key: "app" | |
75 | + operator: In | |
76 | + values: | |
77 | + - tb-service | |
78 | + topologyKey: "kubernetes.io/hostname" | |
79 | + containers: | |
80 | + - name: tb | |
81 | + imagePullPolicy: Always | |
82 | + image: thingsboard/application:k8stest | |
83 | + ports: | |
84 | + - containerPort: 8080 | |
85 | + name: ui | |
86 | + - containerPort: 1883 | |
87 | + name: mqtt | |
88 | + - containerPort: 5683 | |
89 | + name: coap | |
90 | + - containerPort: 9001 | |
91 | + name: rpc | |
92 | + env: | |
93 | + - name: ZOOKEEPER_ENABLED | |
94 | + valueFrom: | |
95 | + configMapKeyRef: | |
96 | + name: tb-config | |
97 | + key: zookeeper.enabled | |
98 | + - name: ZOOKEEPER_URL | |
99 | + valueFrom: | |
100 | + configMapKeyRef: | |
101 | + name: tb-config | |
102 | + key: zookeeper.url | |
103 | + - name : CASSANDRA_URL | |
104 | + valueFrom: | |
105 | + configMapKeyRef: | |
106 | + name: tb-config | |
107 | + key: cassandra.url | |
108 | + - name : RPC_HOST | |
109 | + valueFrom: | |
110 | + fieldRef: | |
111 | + fieldPath: status.podIP | |
112 | + command: | |
113 | + - sh | |
114 | + - -c | |
115 | + - ./run_thingsboard.sh | |
116 | + livenessProbe: | |
117 | + httpGet: | |
118 | + path: /login | |
119 | + port: ui-port | |
120 | + initialDelaySeconds: 120 | |
121 | + timeoutSeconds: 10 | |
\ No newline at end of file | ... | ... |
docker/zookeeper/Dockerfile
0 → 100644
1 | +# | |
2 | +# Copyright © 2016-2017 The Thingsboard Authors | |
3 | +# | |
4 | +# Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | +# you may not use this file except in compliance with the License. | |
6 | +# You may obtain a copy of the License at | |
7 | +# | |
8 | +# http://www.apache.org/licenses/LICENSE-2.0 | |
9 | +# | |
10 | +# Unless required by applicable law or agreed to in writing, software | |
11 | +# distributed under the License is distributed on an "AS IS" BASIS, | |
12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | +# See the License for the specific language governing permissions and | |
14 | +# limitations under the License. | |
15 | +# | |
16 | + | |
17 | +FROM ubuntu:16.04 | |
18 | +ENV ZK_USER=zookeeper \ | |
19 | +ZK_DATA_DIR=/var/lib/zookeeper/data \ | |
20 | +ZK_DATA_LOG_DIR=/var/lib/zookeeper/log \ | |
21 | +ZK_LOG_DIR=/var/log/zookeeper \ | |
22 | +JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 | |
23 | + | |
24 | +ARG GPG_KEY=C823E3E5B12AF29C67F81976F5CECB3CB5E9BD2D | |
25 | +ARG ZK_DIST=zookeeper-3.4.9 | |
26 | +RUN set -x \ | |
27 | + && apt-get update \ | |
28 | + && apt-get install -y openjdk-8-jre-headless wget netcat-openbsd \ | |
29 | + && wget -q "http://www.apache.org/dist/zookeeper/$ZK_DIST/$ZK_DIST.tar.gz" \ | |
30 | + && wget -q "http://www.apache.org/dist/zookeeper/$ZK_DIST/$ZK_DIST.tar.gz.asc" \ | |
31 | + && export GNUPGHOME="$(mktemp -d)" \ | |
32 | + && gpg --keyserver ha.pool.sks-keyservers.net --recv-key "$GPG_KEY" \ | |
33 | + && gpg --batch --verify "$ZK_DIST.tar.gz.asc" "$ZK_DIST.tar.gz" \ | |
34 | + && tar -xzf "$ZK_DIST.tar.gz" -C /opt \ | |
35 | + && rm -r "$GNUPGHOME" "$ZK_DIST.tar.gz" "$ZK_DIST.tar.gz.asc" \ | |
36 | + && ln -s /opt/$ZK_DIST /opt/zookeeper \ | |
37 | + && rm -rf /opt/zookeeper/CHANGES.txt \ | |
38 | + /opt/zookeeper/README.txt \ | |
39 | + /opt/zookeeper/NOTICE.txt \ | |
40 | + /opt/zookeeper/CHANGES.txt \ | |
41 | + /opt/zookeeper/README_packaging.txt \ | |
42 | + /opt/zookeeper/build.xml \ | |
43 | + /opt/zookeeper/config \ | |
44 | + /opt/zookeeper/contrib \ | |
45 | + /opt/zookeeper/dist-maven \ | |
46 | + /opt/zookeeper/docs \ | |
47 | + /opt/zookeeper/ivy.xml \ | |
48 | + /opt/zookeeper/ivysettings.xml \ | |
49 | + /opt/zookeeper/recipes \ | |
50 | + /opt/zookeeper/src \ | |
51 | + /opt/zookeeper/$ZK_DIST.jar.asc \ | |
52 | + /opt/zookeeper/$ZK_DIST.jar.md5 \ | |
53 | + /opt/zookeeper/$ZK_DIST.jar.sha1 \ | |
54 | + && apt-get autoremove -y wget \ | |
55 | + && rm -rf /var/lib/apt/lists/* | |
56 | + | |
57 | +#Copy configuration generator script to bin | |
58 | +COPY zkGenConfig.sh zkOk.sh /opt/zookeeper/bin/ | |
59 | + | |
60 | +# Create a user for the zookeeper process and configure file system ownership | |
61 | +# for nessecary directories and symlink the distribution as a user executable | |
62 | +RUN set -x \ | |
63 | + && useradd $ZK_USER \ | |
64 | + && [ `id -u $ZK_USER` -eq 1000 ] \ | |
65 | + && [ `id -g $ZK_USER` -eq 1000 ] \ | |
66 | + && mkdir -p $ZK_DATA_DIR $ZK_DATA_LOG_DIR $ZK_LOG_DIR /usr/share/zookeeper /tmp/zookeeper /usr/etc/ \ | |
67 | + && chown -R "$ZK_USER:$ZK_USER" /opt/$ZK_DIST $ZK_DATA_DIR $ZK_LOG_DIR $ZK_DATA_LOG_DIR /tmp/zookeeper \ | |
68 | + && ln -s /opt/zookeeper/conf/ /usr/etc/zookeeper \ | |
69 | + && ln -s /opt/zookeeper/bin/* /usr/bin \ | |
70 | + && ln -s /opt/zookeeper/$ZK_DIST.jar /usr/share/zookeeper/ \ | |
71 | + && ln -s /opt/zookeeper/lib/* /usr/share/zookeeper | ... | ... |
docker/zookeeper/Makefile
0 → 100644
docker/zookeeper/zkGenConfig.sh
0 → 100755
1 | +#!/usr/bin/env bash | |
2 | +# | |
3 | +# Copyright © 2016-2017 The Thingsboard Authors | |
4 | +# | |
5 | +# Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | +# you may not use this file except in compliance with the License. | |
7 | +# You may obtain a copy of the License at | |
8 | +# | |
9 | +# http://www.apache.org/licenses/LICENSE-2.0 | |
10 | +# | |
11 | +# Unless required by applicable law or agreed to in writing, software | |
12 | +# distributed under the License is distributed on an "AS IS" BASIS, | |
13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | +# See the License for the specific language governing permissions and | |
15 | +# limitations under the License. | |
16 | +# | |
17 | + | |
18 | +ZK_USER=${ZK_USER:-"zookeeper"} | |
19 | +ZK_LOG_LEVEL=${ZK_LOG_LEVEL:-"INFO"} | |
20 | +ZK_DATA_DIR=${ZK_DATA_DIR:-"/var/lib/zookeeper/data"} | |
21 | +ZK_DATA_LOG_DIR=${ZK_DATA_LOG_DIR:-"/var/lib/zookeeper/log"} | |
22 | +ZK_LOG_DIR=${ZK_LOG_DIR:-"var/log/zookeeper"} | |
23 | +ZK_CONF_DIR=${ZK_CONF_DIR:-"/opt/zookeeper/conf"} | |
24 | +ZK_CLIENT_PORT=${ZK_CLIENT_PORT:-2181} | |
25 | +ZK_SERVER_PORT=${ZK_SERVER_PORT:-2888} | |
26 | +ZK_ELECTION_PORT=${ZK_ELECTION_PORT:-3888} | |
27 | +ZK_TICK_TIME=${ZK_TICK_TIME:-2000} | |
28 | +ZK_INIT_LIMIT=${ZK_INIT_LIMIT:-10} | |
29 | +ZK_SYNC_LIMIT=${ZK_SYNC_LIMIT:-5} | |
30 | +ZK_HEAP_SIZE=${ZK_HEAP_SIZE:-2G} | |
31 | +ZK_MAX_CLIENT_CNXNS=${ZK_MAX_CLIENT_CNXNS:-60} | |
32 | +ZK_MIN_SESSION_TIMEOUT=${ZK_MIN_SESSION_TIMEOUT:- $((ZK_TICK_TIME*2))} | |
33 | +ZK_MAX_SESSION_TIMEOUT=${ZK_MAX_SESSION_TIMEOUT:- $((ZK_TICK_TIME*20))} | |
34 | +ZK_SNAP_RETAIN_COUNT=${ZK_SNAP_RETAIN_COUNT:-3} | |
35 | +ZK_PURGE_INTERVAL=${ZK_PURGE_INTERVAL:-0} | |
36 | +ID_FILE="$ZK_DATA_DIR/myid" | |
37 | +ZK_CONFIG_FILE="$ZK_CONF_DIR/zoo.cfg" | |
38 | +LOGGER_PROPS_FILE="$ZK_CONF_DIR/log4j.properties" | |
39 | +JAVA_ENV_FILE="$ZK_CONF_DIR/java.env" | |
40 | +HOST=`hostname -s` | |
41 | +DOMAIN=`hostname -d` | |
42 | + | |
43 | +function print_servers() { | |
44 | + for (( i=1; i<=$ZK_REPLICAS; i++ )) | |
45 | + do | |
46 | + echo "server.$i=$NAME-$((i-1)).$DOMAIN:$ZK_SERVER_PORT:$ZK_ELECTION_PORT" | |
47 | + done | |
48 | +} | |
49 | + | |
50 | +function validate_env() { | |
51 | + echo "Validating environment" | |
52 | + if [ -z $ZK_REPLICAS ]; then | |
53 | + echo "ZK_REPLICAS is a mandatory environment variable" | |
54 | + exit 1 | |
55 | + fi | |
56 | + | |
57 | + if [[ $HOST =~ (.*)-([0-9]+)$ ]]; then | |
58 | + NAME=${BASH_REMATCH[1]} | |
59 | + ORD=${BASH_REMATCH[2]} | |
60 | + else | |
61 | + echo "Failed to extract ordinal from hostname $HOST" | |
62 | + exit 1 | |
63 | + fi | |
64 | + MY_ID=$((ORD+1)) | |
65 | + echo "ZK_REPLICAS=$ZK_REPLICAS" | |
66 | + echo "MY_ID=$MY_ID" | |
67 | + echo "ZK_LOG_LEVEL=$ZK_LOG_LEVEL" | |
68 | + echo "ZK_DATA_DIR=$ZK_DATA_DIR" | |
69 | + echo "ZK_DATA_LOG_DIR=$ZK_DATA_LOG_DIR" | |
70 | + echo "ZK_LOG_DIR=$ZK_LOG_DIR" | |
71 | + echo "ZK_CLIENT_PORT=$ZK_CLIENT_PORT" | |
72 | + echo "ZK_SERVER_PORT=$ZK_SERVER_PORT" | |
73 | + echo "ZK_ELECTION_PORT=$ZK_ELECTION_PORT" | |
74 | + echo "ZK_TICK_TIME=$ZK_TICK_TIME" | |
75 | + echo "ZK_INIT_LIMIT=$ZK_INIT_LIMIT" | |
76 | + echo "ZK_SYNC_LIMIT=$ZK_SYNC_LIMIT" | |
77 | + echo "ZK_MAX_CLIENT_CNXNS=$ZK_MAX_CLIENT_CNXNS" | |
78 | + echo "ZK_MIN_SESSION_TIMEOUT=$ZK_MIN_SESSION_TIMEOUT" | |
79 | + echo "ZK_MAX_SESSION_TIMEOUT=$ZK_MAX_SESSION_TIMEOUT" | |
80 | + echo "ZK_HEAP_SIZE=$ZK_HEAP_SIZE" | |
81 | + echo "ZK_SNAP_RETAIN_COUNT=$ZK_SNAP_RETAIN_COUNT" | |
82 | + echo "ZK_PURGE_INTERVAL=$ZK_PURGE_INTERVAL" | |
83 | + echo "ENSEMBLE" | |
84 | + print_servers | |
85 | + echo "Environment validation successful" | |
86 | +} | |
87 | + | |
88 | +function create_config() { | |
89 | + rm -f $ZK_CONFIG_FILE | |
90 | + echo "Creating ZooKeeper configuration" | |
91 | + echo "#This file was autogenerated by zk DO NOT EDIT" >> $ZK_CONFIG_FILE | |
92 | + echo "clientPort=$ZK_CLIENT_PORT" >> $ZK_CONFIG_FILE | |
93 | + echo "dataDir=$ZK_DATA_DIR" >> $ZK_CONFIG_FILE | |
94 | + echo "dataLogDir=$ZK_DATA_LOG_DIR" >> $ZK_CONFIG_FILE | |
95 | + echo "tickTime=$ZK_TICK_TIME" >> $ZK_CONFIG_FILE | |
96 | + echo "initLimit=$ZK_INIT_LIMIT" >> $ZK_CONFIG_FILE | |
97 | + echo "syncLimit=$ZK_SYNC_LIMIT" >> $ZK_CONFIG_FILE | |
98 | + echo "maxClientCnxns=$ZK_MAX_CLIENT_CNXNS" >> $ZK_CONFIG_FILE | |
99 | + echo "minSessionTimeout=$ZK_MIN_SESSION_TIMEOUT" >> $ZK_CONFIG_FILE | |
100 | + echo "maxSessionTimeout=$ZK_MAX_SESSION_TIMEOUT" >> $ZK_CONFIG_FILE | |
101 | + echo "autopurge.snapRetainCount=$ZK_SNAP_RETAIN_COUNT" >> $ZK_CONFIG_FILE | |
102 | + echo "autopurge.purgeInteval=$ZK_PURGE_INTERVAL" >> $ZK_CONFIG_FILE | |
103 | + | |
104 | + if [ $ZK_REPLICAS -gt 1 ]; then | |
105 | + print_servers >> $ZK_CONFIG_FILE | |
106 | + fi | |
107 | + echo "Wrote ZooKeeper configuration file to $ZK_CONFIG_FILE" | |
108 | +} | |
109 | + | |
110 | +function create_data_dirs() { | |
111 | + echo "Creating ZooKeeper data directories and setting permissions" | |
112 | + if [ ! -d $ZK_DATA_DIR ]; then | |
113 | + mkdir -p $ZK_DATA_DIR | |
114 | + chown -R $ZK_USER:$ZK_USER $ZK_DATA_DIR | |
115 | + fi | |
116 | + | |
117 | + if [ ! -d $ZK_DATA_LOG_DIR ]; then | |
118 | + mkdir -p $ZK_DATA_LOG_DIR | |
119 | + chown -R $ZK_USER:$ZK_USER $ZK_DATA_LOG_DIR | |
120 | + fi | |
121 | + | |
122 | + if [ ! -d $ZK_LOG_DIR ]; then | |
123 | + mkdir -p $ZK_LOG_DIR | |
124 | + chown -R $ZK_USER:$ZK_USER $ZK_LOG_DIR | |
125 | + fi | |
126 | + if [ ! -f $ID_FILE ]; then | |
127 | + echo $MY_ID >> $ID_FILE | |
128 | + fi | |
129 | + echo "Created ZooKeeper data directories and set permissions in $ZK_DATA_DIR" | |
130 | +} | |
131 | + | |
132 | +function create_log_props () { | |
133 | + rm -f $LOGGER_PROPS_FILE | |
134 | + echo "Creating ZooKeeper log4j configuration" | |
135 | + echo "zookeeper.root.logger=CONSOLE" >> $LOGGER_PROPS_FILE | |
136 | + echo "zookeeper.console.threshold="$ZK_LOG_LEVEL >> $LOGGER_PROPS_FILE | |
137 | + echo "log4j.rootLogger=\${zookeeper.root.logger}" >> $LOGGER_PROPS_FILE | |
138 | + echo "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender" >> $LOGGER_PROPS_FILE | |
139 | + echo "log4j.appender.CONSOLE.Threshold=\${zookeeper.console.threshold}" >> $LOGGER_PROPS_FILE | |
140 | + echo "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout" >> $LOGGER_PROPS_FILE | |
141 | + echo "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n" >> $LOGGER_PROPS_FILE | |
142 | + echo "Wrote log4j configuration to $LOGGER_PROPS_FILE" | |
143 | +} | |
144 | + | |
145 | +function create_java_env() { | |
146 | + rm -f $JAVA_ENV_FILE | |
147 | + echo "Creating JVM configuration file" | |
148 | + echo "ZOO_LOG_DIR=$ZK_LOG_DIR" >> $JAVA_ENV_FILE | |
149 | + echo "JVMFLAGS=\"-Xmx$ZK_HEAP_SIZE -Xms$ZK_HEAP_SIZE\"" >> $JAVA_ENV_FILE | |
150 | + echo "Wrote JVM configuration to $JAVA_ENV_FILE" | |
151 | +} | |
152 | + | |
153 | +validate_env && create_config && create_log_props && create_data_dirs && create_java_env | ... | ... |
docker/zookeeper/zkOk.sh
renamed from
docker/deploy.sh
1 | -#!/bin/bash | |
1 | +#!/usr/bin/env bash | |
2 | 2 | # |
3 | 3 | # Copyright © 2016-2017 The Thingsboard Authors |
4 | 4 | # |
... | ... | @@ -15,17 +15,14 @@ |
15 | 15 | # limitations under the License. |
16 | 16 | # |
17 | 17 | |
18 | +# zkOk.sh uses the ruok ZooKeeper four letter work to determine if the instance | |
19 | +# is health. The $? variable will be set to 0 if server responds that it is | |
20 | +# healthy, or 1 if the server fails to respond. | |
18 | 21 | |
19 | -command='docker-compose -f docker-compose.yml -f docker-compose.random.yml' | |
20 | - | |
21 | -echo "stopping images.." | |
22 | -$command stop | |
23 | - | |
24 | -echo "removing stopped images.." | |
25 | -$command rm -f | |
26 | - | |
27 | -echo "building images.." | |
28 | -$command build | |
29 | - | |
30 | -echo "starting images..." | |
31 | -$command up -d | |
22 | +ZK_CLIENT_PORT=${ZK_CLIENT_PORT:-2181} | |
23 | +OK=$(echo ruok | nc 127.0.0.1 $ZK_CLIENT_PORT) | |
24 | +if [ "$OK" == "imok" ]; then | |
25 | + exit 0 | |
26 | +else | |
27 | + exit 1 | |
28 | +fi | ... | ... |
docker/zookeeper/zookeeper.yaml
0 → 100644
1 | +# | |
2 | +# Copyright © 2016-2017 The Thingsboard Authors | |
3 | +# | |
4 | +# Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | +# you may not use this file except in compliance with the License. | |
6 | +# You may obtain a copy of the License at | |
7 | +# | |
8 | +# http://www.apache.org/licenses/LICENSE-2.0 | |
9 | +# | |
10 | +# Unless required by applicable law or agreed to in writing, software | |
11 | +# distributed under the License is distributed on an "AS IS" BASIS, | |
12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | +# See the License for the specific language governing permissions and | |
14 | +# limitations under the License. | |
15 | +# | |
16 | + | |
17 | +apiVersion: v1 | |
18 | +kind: Service | |
19 | +metadata: | |
20 | + name: zk-headless | |
21 | + labels: | |
22 | + app: zk-headless | |
23 | +spec: | |
24 | + ports: | |
25 | + - port: 2888 | |
26 | + name: server | |
27 | + - port: 3888 | |
28 | + name: leader-election | |
29 | + clusterIP: None | |
30 | + selector: | |
31 | + app: zk | |
32 | +--- | |
33 | +apiVersion: v1 | |
34 | +kind: ConfigMap | |
35 | +metadata: | |
36 | + name: zk-config | |
37 | +data: | |
38 | + ensemble: "zk-0;zk-1" | |
39 | + replicas: "3" | |
40 | + jvm.heap: "500m" | |
41 | + tick: "2000" | |
42 | + init: "10" | |
43 | + sync: "5" | |
44 | + client.cnxns: "60" | |
45 | + snap.retain: "3" | |
46 | + purge.interval: "1" | |
47 | + client.port: "2181" | |
48 | + server.port: "2888" | |
49 | + election.port: "3888" | |
50 | +--- | |
51 | +apiVersion: policy/v1beta1 | |
52 | +kind: PodDisruptionBudget | |
53 | +metadata: | |
54 | + name: zk-budget | |
55 | +spec: | |
56 | + selector: | |
57 | + matchLabels: | |
58 | + app: zk | |
59 | + minAvailable: 2 | |
60 | +--- | |
61 | +apiVersion: apps/v1beta1 | |
62 | +kind: StatefulSet | |
63 | +metadata: | |
64 | + name: zk | |
65 | +spec: | |
66 | + serviceName: zk-headless | |
67 | + replicas: 2 | |
68 | + template: | |
69 | + metadata: | |
70 | + labels: | |
71 | + app: zk | |
72 | + annotations: | |
73 | + pod.alpha.kubernetes.io/initialized: "true" | |
74 | + spec: | |
75 | + nodeSelector: | |
76 | + machinetype: other | |
77 | + affinity: | |
78 | + podAntiAffinity: | |
79 | + requiredDuringSchedulingIgnoredDuringExecution: | |
80 | + - labelSelector: | |
81 | + matchExpressions: | |
82 | + - key: "app" | |
83 | + operator: In | |
84 | + values: | |
85 | + - zk-headless | |
86 | + topologyKey: "kubernetes.io/hostname" | |
87 | + containers: | |
88 | + - name: zk | |
89 | + imagePullPolicy: Always | |
90 | + image: thingsboard/zk:k8stest | |
91 | + ports: | |
92 | + - containerPort: 2181 | |
93 | + name: client | |
94 | + - containerPort: 2888 | |
95 | + name: server | |
96 | + - containerPort: 3888 | |
97 | + name: leader-election | |
98 | + env: | |
99 | + - name : ZK_ENSEMBLE | |
100 | + valueFrom: | |
101 | + configMapKeyRef: | |
102 | + name: zk-config | |
103 | + key: ensemble | |
104 | + - name : ZK_REPLICAS | |
105 | + valueFrom: | |
106 | + configMapKeyRef: | |
107 | + name: zk-config | |
108 | + key: replicas | |
109 | + - name : ZK_HEAP_SIZE | |
110 | + valueFrom: | |
111 | + configMapKeyRef: | |
112 | + name: zk-config | |
113 | + key: jvm.heap | |
114 | + - name : ZK_TICK_TIME | |
115 | + valueFrom: | |
116 | + configMapKeyRef: | |
117 | + name: zk-config | |
118 | + key: tick | |
119 | + - name : ZK_INIT_LIMIT | |
120 | + valueFrom: | |
121 | + configMapKeyRef: | |
122 | + name: zk-config | |
123 | + key: init | |
124 | + - name : ZK_SYNC_LIMIT | |
125 | + valueFrom: | |
126 | + configMapKeyRef: | |
127 | + name: zk-config | |
128 | + key: tick | |
129 | + - name : ZK_MAX_CLIENT_CNXNS | |
130 | + valueFrom: | |
131 | + configMapKeyRef: | |
132 | + name: zk-config | |
133 | + key: client.cnxns | |
134 | + - name: ZK_SNAP_RETAIN_COUNT | |
135 | + valueFrom: | |
136 | + configMapKeyRef: | |
137 | + name: zk-config | |
138 | + key: snap.retain | |
139 | + - name: ZK_PURGE_INTERVAL | |
140 | + valueFrom: | |
141 | + configMapKeyRef: | |
142 | + name: zk-config | |
143 | + key: purge.interval | |
144 | + - name: ZK_CLIENT_PORT | |
145 | + valueFrom: | |
146 | + configMapKeyRef: | |
147 | + name: zk-config | |
148 | + key: client.port | |
149 | + - name: ZK_SERVER_PORT | |
150 | + valueFrom: | |
151 | + configMapKeyRef: | |
152 | + name: zk-config | |
153 | + key: server.port | |
154 | + - name: ZK_ELECTION_PORT | |
155 | + valueFrom: | |
156 | + configMapKeyRef: | |
157 | + name: zk-config | |
158 | + key: election.port | |
159 | + command: | |
160 | + - sh | |
161 | + - -c | |
162 | + - zkGenConfig.sh && zkServer.sh start-foreground | |
163 | + readinessProbe: | |
164 | + exec: | |
165 | + command: | |
166 | + - "zkOk.sh" | |
167 | + initialDelaySeconds: 15 | |
168 | + timeoutSeconds: 5 | |
169 | + livenessProbe: | |
170 | + exec: | |
171 | + command: | |
172 | + - "zkOk.sh" | |
173 | + initialDelaySeconds: 15 | |
174 | + timeoutSeconds: 5 | |
175 | + volumeMounts: | |
176 | + - name: zkdatadir | |
177 | + mountPath: /var/lib/zookeeper | |
178 | + securityContext: | |
179 | + runAsUser: 1000 | |
180 | + fsGroup: 1000 | |
181 | + volumeClaimTemplates: | |
182 | + - metadata: | |
183 | + name: zkdatadir | |
184 | + annotations: | |
185 | + volume.beta.kubernetes.io/storage-class: slow | |
186 | + spec: | |
187 | + accessModes: [ "ReadWriteOnce" ] | |
188 | + resources: | |
189 | + requests: | |
190 | + storage: 1Gi | |
\ No newline at end of file | ... | ... |
... | ... | @@ -41,7 +41,7 @@ import java.security.cert.X509Certificate; |
41 | 41 | */ |
42 | 42 | @Slf4j |
43 | 43 | @Component("MqttSslHandlerProvider") |
44 | -@ConditionalOnProperty(prefix = "mqtt.ssl", value = "key-store", havingValue = "", matchIfMissing = false) | |
44 | +@ConditionalOnProperty(prefix = "mqtt.ssl", value = "enabled", havingValue = "true", matchIfMissing = false) | |
45 | 45 | public class MqttSslHandlerProvider { |
46 | 46 | |
47 | 47 | public static final String TLS = "TLS"; | ... | ... |