偶然間聽聞物聯網砰砰砰,狂戰幾天幾夜...因而乎就有了如今寫博客的我,本文是基於centos7.6系統環境搭建,旨爲與對開源的物聯網平臺(thingsboard)感興趣的同窗一塊兒研究,歡迎指正交流!html
話很少說,開碼→.→java
github地址:https://github.com/thingsboard/thingsboardnode
github docs網址:https://thingsboard.io/docs/getting-started-guides/helloworld/linux
github demo:https://demo.thingsboard.io/logingit
git(碼雲): https://gitee.com/mirrors/ThingsBoardgithub
CSDN大佬1: http://www.javashuo.com/article/p-znprxwty-z.htmlweb
博客園大佬1: https://www.cnblogs.com/danny-djy/p/9051714.htmlredis
segmentfault大佬: https://segmentfault.com/a/1190000019755315?utm_source=tag-newestspring
Xsheel: 連接:https://pan.baidu.com/s/1x8a66d1dwrUbaClRaJUMRw 提取碼:c7t9sql
Xftp: 連接:https://pan.baidu.com/s/1zAvh1Gupx-G1ZKhYOefcTw 提取碼:ox6g
VMware12: 連接:https://pan.baidu.com/s/1PQ4GiblqmWhDADjpGxwK-Q 提取碼:h1ku
CentOS-7-x86_64-DVD-1810.iso: 連接:https://pan.baidu.com/s/1Zp_gmfCk78nggrEIqxdoQA 提取碼:chmo
下載 : jdk-8u211-linux-x64.tar.gz(網上處處都是...),用Xftp傳到Linux端的 /usr/local/temp
解壓&配置環境變量 :
cd /usr/local/temp
tar vzxf jdk-8u211-linux-x64.tar.gz
mv jdk-8u211-linux-x64 /usr/local/jdk8
vi /etc/profile
添加
export JAVA_HOME=/usr/local/jdk-1.8.0
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
java -version
如圖爲安裝成功:
下載 : apache-maven-3.6.1-bin.tar.gz,用Xftp傳到Linux端的 /usr/local/temp
解壓&配置環境變量 :
cd /usr/local/temp
tar vzxf apache-maven-3.6.1-bin.tar.gz
mv apache-maven-3.6.1-bin /usr/local/apache-maven-3.6.1
vi /etc/profile
添加
export M2_HOME=/usr/local/apache-maven-3.6.1
export PATH=$PATH:${M2_HOME}/bin
source /etc/profile
mvn -version
如圖爲安裝成功:
注意修改配置文件:加粗字體部分
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- | This is the configuration file for Maven. It can be specified at two levels: | | 1. User Level. This settings.xml file provides configuration for a single user, | and is normally provided in ${user.home}/.m2/settings.xml. | | NOTE: This location can be overridden with the CLI option: | | -s /path/to/user/settings.xml | | 2. Global Level. This settings.xml file provides configuration for all Maven | users on a machine (assuming they're all using the same Maven | installation). It's normally provided in | ${maven.conf}/settings.xml. | | NOTE: This location can be overridden with the CLI option: | | -gs /path/to/global/settings.xml | | The sections in this sample file are intended to give you a running start at | getting the most out of your Maven installation. Where appropriate, the default | values (values used when the setting is not specified) are provided. | |--> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> --> <!--修改localRepository開始--!> <localRepository>/usr/local/.m2/repository</localRepository> <!--修改localRepository開始--!> <!-- interactiveMode | This will determine whether maven prompts you when it needs input. If set to false, | maven will use a sensible default value, perhaps based on some other setting, for | the parameter in question. | | Default: true <interactiveMode>true</interactiveMode> --> <!-- offline | Determines whether maven should attempt to connect to the network when executing a build. | This will have an effect on artifact downloads, artifact deployment, and others. | | Default: false <offline>false</offline> --> <!-- pluginGroups | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e. | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list. |--> <pluginGroups> <!-- pluginGroup | Specifies a further group identifier to use for plugin lookup. <pluginGroup>com.your.plugins</pluginGroup> --> </pluginGroups> <!-- proxies | This is a list of proxies which can be used on this machine to connect to the network. | Unless otherwise specified (by system property or command-line switch), the first proxy | specification in this list marked as active will be used. |--> <proxies> <!-- proxy | Specification for one proxy, to be used in connecting to the network. | <proxy> <id>optional</id> <active>true</active> <protocol>http</protocol> <username>proxyuser</username> <password>proxypass</password> <host>proxy.host.net</host> <port>80</port> <nonProxyHosts>local.net|some.host.com</nonProxyHosts> </proxy> --> </proxies> <!-- servers | This is a list of authentication profiles, keyed by the server-id used within the system. | Authentication profiles can be used whenever maven must make a connection to a remote server. |--> <servers> <!-- server | Specifies the authentication information to use when connecting to a particular server, identified by | a unique name within the system (referred to by the 'id' attribute below). | | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are | used together. | <server> <id>deploymentRepo</id> <username>repouser</username> <password>repopwd</password> </server> --> <!-- Another sample, using keys to authenticate. <server> <id>siteServer</id> <privateKey>/path/to/private/key</privateKey> <passphrase>optional; leave empty if not used.</passphrase> </server> --> </servers> <!-- mirrors | This is a list of mirrors to be used in downloading artifacts from remote repositories. | | It works like this: a POM may declare a repository to use in resolving certain artifacts. | However, this repository may have problems with heavy traffic at times, so people have mirrored | it to several places. | | That repository definition will have a unique id, so we can create a mirror reference for that | repository, to be used as an alternate download site. The mirror site will be the preferred | server for that repository. |--> <mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> <!--修改mirror開始--!> <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> </mirror> <!--修改mirror結束--!> </mirrors> <!-- profiles | This is a list of profiles which can be activated in a variety of ways, and which can modify | the build process. Profiles provided in the settings.xml are intended to provide local machine- | specific paths and repository locations which allow the build to work in the local environment. | | For example, if you have an integration testing plugin - like cactus - that needs to know where | your Tomcat instance is installed, you can provide a variable here such that the variable is | dereferenced during the build process to configure the cactus plugin. | | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles | section of this document (settings.xml) - will be discussed later. Another way essentially | relies on the detection of a system property, either matching a particular value for the property, | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'. | Finally, the list of active profiles can be specified directly from the command line. | | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact | repositories, plugin repositories, and free-form properties to be used as configuration | variables for plugins in the POM. | |--> <profiles> <!-- profile | Specifies a set of introductions to the build process, to be activated using one or more of the | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/> | or the command line, profiles have to have an ID that is unique. | | An encouraged best practice for profile identification is to use a consistent naming convention | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc. | This will make it more intuitive to understand what the set of introduced profiles is attempting | to accomplish, particularly when you only have a list of profile id's for debug. | | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo. <profile> <id>jdk-1.4</id> <activation> <jdk>1.4</jdk> </activation> <repositories> <repository> <id>jdk14</id> <name>Repository for JDK 1.4 builds</name> <url>http://www.myhost.com/maven/jdk14</url> <layout>default</layout> <snapshotPolicy>always</snapshotPolicy> </repository> </repositories> </profile> --> <!-- | Here is another profile, activated by the system property 'target-env' with a value of 'dev', | which provides a specific path to the Tomcat instance. To use this, your plugin configuration | might hypothetically look like: | | ... | <plugin> | <groupId>org.myco.myplugins</groupId> | <artifactId>myplugin</artifactId> | | <configuration> | <tomcatLocation>${tomcatPath}</tomcatLocation> | </configuration> | </plugin> | ... | | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to | anything, you could just leave off the <value/> inside the activation-property. | <profile> <id>env-dev</id> <activation> <property> <name>target-env</name> <value>dev</value> </property> </activation> <properties> <tomcatPath>/path/to/tomcat/instance</tomcatPath> </properties> </profile> --> </profiles> <!-- activeProfiles | List of profiles that are active for all builds. | <activeProfiles> <activeProfile>alwaysActiveProfile</activeProfile> <activeProfile>anotherAlwaysActiveProfile</activeProfile> </activeProfiles> --> </settings>
下載 : node-v10.15.1-linux-x64.tar.gz,用Xftp傳到Linux端的 /usr/local/temp
解壓&配置環境變量 :
cd /usr/local/temp
tar vzxf node-v10.15.1-linux-x64.tar.gz
mv node-v10.15.1-linux-x64 /usr/local/node-v10.15.1
vi /etc/profile
添加
export NODE_HOME=/opt/software/node-v10.15.1-linux-x64
export PATH=$PATH:${NODE_HOME}/bin
source /etc/profile
node -v
npm -v
如圖爲安裝成功:
下載 : git-2.8.6.tar.gz,用Xftp傳到Linux端的 /usr/local/temp
解壓 :
cd /usr/local/temp
tar vzxf git-2.8.6.tar.gz
mv git-2.8.6 /usr/local/git-2.8.6
編譯安裝 :
cd /usr/local/git-2.8.6
make configure
./configure --prefix=/usr/git ##配置目錄
make profix=/usr/git
make install
配置環境變量 :
vi /etc/profile
添加
export PATH="/usr/local/git/bin:$PATH"
source /etc/profile
git --version
如圖爲安裝成功:
推薦大佬安裝操做:https://www.cnblogs.com/netonline/p/7657810.html
萬事俱備只欠源碼~~~
cd ~
git clone git@github.com:thingsboard/thingsboard.git
或者
更加簡單粗暴將碼雲上的release-2.3以zip下載的方式下載下來,在用xftp傳到Linux安裝目錄(次例直接放置root下) <font color="red">[推薦此方法]</font>
強烈建議和我同樣的小白們利用Xftp和notpad++在Windows操做!
1. 修改thingsboard-release-2.3的pom.xml(繞過License選項)
註釋如下代碼:
<!-->約275行<--!> <plugin> <groupId>com.mycila</groupId> <artifactId>license-maven-plugin</artifactId> <version>3.0</version> <configuration> .... </plugin>
2. 修改thingsboard-release-2.3下的application/src/main/resources/thingsboard.yml文件
註釋HSQLDB,開啓PostgreSQL
# HSQLDB DAO Configuration #spring: # data: # jpa: # repositories: # enabled: "true" # jpa: # hibernate: # ddl-auto: "validate" # database-platform: "${SPRING_JPA_DATABASE_PLATFORM:org.hibernate.dialect.HSQLDialect}" # datasource: # driverClassName: "${SPRING_DRIVER_CLASS_NAME:org.hsqldb.jdbc.JDBCDriver}" # url: "${SPRING_DATASOURCE_URL:jdbc:hsqldb:file:${SQL_DATA_FOLDER:/tmp}/thingsboardDb;sql.enforce_si#ze=false;hsqldb.log_size=5}" # username: "${SPRING_DATASOURCE_USERNAME:sa}" # password: "${SPRING_DATASOURCE_PASSWORD:}" # PostgreSQL DAO Configuration spring: data: sql: repositories: enabled: "true" sql: hibernate: ddl-auto: "validate" database-platform: "${SPRING_JPA_DATABASE_PLATFORM:org.hibernate.dialect.PostgreSQLDialect}" datasource: driverClassName: "${SPRING_DRIVER_CLASS_NAME:org.postgresql.Driver}" url: "${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/thingsboard}" username: "${SPRING_DATASOURCE_USERNAME:postgres}"//只前安裝PostgreSQL時設置的 password: "${SPRING_DATASOURCE_PASSWORD:postgres}"//用戶名和密碼
註釋如下部分 :
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.0.0</version> <configuration> <finalName>${pkg.name}</finalName> <descriptors> <descriptor>src/main/assembly/windows.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>
進入源碼thingsboard-release-2.3
cd ~/thingsboard-release-2.3
mvn clean install -DskipTests -X
<font color="red">注意編譯時間較長,還可鞥須要屢次編譯,各類坑等着你呢...如下是我遇到的幾個坑:</font>
1. ui部分報錯 :
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.0.....................(沒截上圖...翻得百度搜索記錄)
解決:
百度半天沒啥luan用,仍是的本身看ERROR...分析到是npm install的時候出問題,結合報錯看出node_modules某個module沒有下載下來,而後在Xftp根據報錯提示查看modules的位置確實沒有報錯模塊文件夾及文件(高興地一批嘻嘻終於有點兒眉目),再而後手動在win環境npm install module名 -g (一次沒能行垃圾網絡,第二次成功下載),在到node全局modules文件夾中把下載的相關模塊文件夾copy到報錯模塊路徑中,在編譯
2. java報錯 :
編譯ui時報錯:Failed to create assembly: Error creating assembly archive windows: Problem.................(同上)
解決:
糟心半天,靈光一現以前不是刪過pom.xml中的maven-assembly-plugin配置嗎,抱着試試的心...,修改了ui/pom.xml文件,註釋瞭如下配置:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>3.0.0</version> <configuration> <finalName>${pkg.name}</finalName> <descriptors> <descriptor>src/main/assembly/windows.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>
再次編譯:OK 如圖:
找到編譯好的安裝文件
[root@localhost thingsboard-release-2.3]# cd application/target
運行安裝
[root@localhost thingsboard-release-2.3]# cd application/target
[root@localhost thingsboard-release-2.3]# sudo rpm -Uvh thingsboard.rpm
此時,出現一個問題:依賴檢測失敗
緣由:
咱們安裝的jdk問題!須要的是OpenJDK(JDK與OpenJDK的區別)
解決:卸載以前的jdk(記得註釋環境變量),安裝openjdk
[root@localhost thingsboard-release-2.3]# sudo yum install java-1.8.0-openjdk -y
[root@localhost thingsboard-release-2.3]# sudo yum install java-1.8.0-openjdk-devel -y
[root@localhost thingsboard-release-2.3]# java -version
[root[@localhost](https://my.oschina.net/u/570656) thingsboard-release-2.3]# openjdk version "1.8.0_181" OpenJDK Runtime Environment (build 1.8.0_181-b13) OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
再次運行安裝ok,繼續下一步
[root@localhost thingsboard-release-2.3]# cd /usr/share/thingsboard/bin/install
[root@localhost thingsboard-release-2.3]# ll
[root@localhost thingsboard-release-2.3]#./install.sh --loadDemo
啓動服務
[root@localhost thingsboard-release-2.3]#service thingsboard start
完成
可是在thingsboard-release-2.3出現個問題服務正常開啓!!!數據庫正常鏈接!!!各項配置ok!!!測試http:localhost:8080報出404
再次更換thingsboard v2.1版本進行前面第三步的編譯!!!
直接到:
鑑於上一次的失敗,此次我選擇江編譯好的項目導入IDEA進行run as:
前提:
1 . 數據庫:用navicat鏈接postgreSQL,導入數據(導入數據爲dao包下的sql):
方便測試這裏直接修改默認後臺的系統管理員帳號 用戶名:sysadmin@thingsboard.org 密碼:sysadmin爲:
用戶名:admin@thingsboard.org 密碼:sysadmin
2 . redis(windows端)
注意:鏈接測試(在redis目錄下在起一個cmd):
D:\soft\Redis-x64-3.2.100> redis-cli.exe -h 127.0.0.1 -p 6379
127.0.0.1:6379> set myKey abc
OK
127.0.0.1:6379> get myKey
"abc"
127.0.0.1:6379>
Run as "ThingsboardServerApplication"
瀏覽器打開"http://127.0.0.1:8080"
用戶名:admin@thingsboard.org 密碼:sysadmin登陸
完成!告辭~~~