docker pull tdengine/tdengine:latest
mkdir -p /mydocker/tdengine/log /mydocker/tdengine/data
docker run --restart=always --name tdengine -p 6030:6030 -p 6041:6041 -p 6043-6049:6043-6049 -p 6043-6049:6043-6049/udp -v /mydocker/tdengine/log:/var/log/taos -v /mydocker/tdengine/data:/var/lib/taos -d tdengine/tdengine
客户端安装好后,firstEp和fqdn选择一个修改,测试都可以是ip或者域名,域名的话,记得配置本地hosts
firstEp gkrh_tdengine:6030
# The end point of the second dnode to be connected to if the firstEp is not available when `taosd` or `taos` is started
# secondEp
# The FQDN of the host where `taosd` will be started. It can be IP address
#fqdn gkrh_tdengine
192.168.2.25 gkrh_tdengine
spring:
datasource:
tdengine-server:
jdbc-url: jdbc:TAOS-RS://host:6041/iot?user=root&password=taosdata&timezone=Asia/Shanghai
username: root
password: taosdata
@Configuration
@MapperScan(basePackages = {"com.rh.energy.platformbackend.mapper.tdengine"}, sqlSessionTemplateRef = "tdengineSqlSessionTemplate")
public class TDengineServerConfig {
@Resource
private MybatisPlusInterceptor mybatisPlusInterceptor;
@Bean(name = "tdengineDataSource")
@ConfigurationProperties(prefix = "spring.datasource.tdengine-server")
public DataSource tdengineDataSource() {
return DataSourceBuilder.create().build();
}
@Bean("tdengineMybatisConfiguration")
@ConfigurationProperties(prefix = "mybatis-plus.configuration")
public MybatisConfiguration getCfg() {
return new MybatisConfiguration();
}
@Bean(name = "tdengineSqlSessionFactory")
public SqlSessionFactory tdengineSqlSessionFactory(@Qualifier("tdengineDataSource") DataSource dataSource) throws Exception {
MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
bean.setDataSource(dataSource);
bean.setPlugins(mybatisPlusInterceptor);
bean.setConfiguration(getCfg());
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/tdengine/*.xml"));
return bean.getObject();
}
@Bean(name = "tdengineTransactionManager")
public DataSourceTransactionManager tdengineTransactionManager(@Qualifier("tdengineDataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean(name = "tdengineSqlSessionTemplate")
public SqlSessionTemplate tdengineSqlSessionTemplate(@Qualifier("tdengineSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
<mapper namespace="com.rh.energy.platformbackend.mapper.tdengine.IotMeterMapper">
<resultMap id="BaseResultMap" type="com.rh.energy.platformbackend.entity.tdengine.IotMeter">
<id column="ts" jdbcType="VARCHAR" property="ts" />
<result column="current" jdbcType="FLOAT" property="current" />
<result column="voltage" jdbcType="FLOAT" property="voltage" />
<result column="phase" jdbcType="INTEGER" property="phase" />
<result column="location" jdbcType="VARCHAR" property="location" />
<result column="device_id" jdbcType="VARCHAR" property="deviceId" />
</resultMap>
<sql id="Base_Column_List">
ts, current, voltage,phase,location,device_id
</sql>
<select id="select" resultType="com.rh.energy.platformbackend.entity.tdengine.IotMeter">
select
<include refid="Base_Column_List" />
from iot_meter
where device_id=#{deviceId}
and ts <= #{endTime} and ts >= #{startTime}
order by ts desc
</select>
<select id="getLatestByDeviceId" resultType="com.rh.energy.platformbackend.entity.tdengine.IotMeter">
select
<include refid="Base_Column_List" />
from iot_meter
where device_id=#{deviceId}
order by ts desc
limit 1
</select>
<insert id="insert" parameterType="com.rh.energy.platformbackend.entity.tdengine.IotMeter" >
insert into #{deviceId} using iot_meter tags(#{location},#{deviceId}) values (#{ts}, #{current}, #{voltage}, #{phase})
</insert>
</mapper>
show create stable iot_meter \G;
该问题可以先用ntpdate cn.pool.ntp.org命令同步下时间,如果还报该错误,检查下客户端和服务端的版本,必须保持一致,
我当时是客户端是3.0.0.1,服务端是3.0.1.0就会报该错误