springboot框架,众多自动化的部署和约定配置,造成了springboot的着手麻烦,熟练后可以快速快捷进行开发,常用作快捷开发的java底层框架。各位看官都是大神,自行体会。
input {
jdbc {
jdbc_driver_library => "/usr/local/logstash-2.4.0/mysql-connector-java-5.1.39.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://******************:3306/******?characterEncoding=UTF-8&useSSL=false"
jdbc_user => "*******"
jdbc_password => "*******************"
statement => "SELECT n.pk,n.media_pk as mediapk,n.user_pk as userpk,n.access_source_pk as accesssourcepk,updated_at FROM tablename1 n LEFT JOIN v ON(n.pk=v.news_pk) LEFT JOIN tablename2 c ON(n.pk=c.news_pk) WHERE date_sub(n.updated_at,interval 8 hour) > :sql_last_value"
last_run_metadata_path => "/usr/local/logstash-2.4.0/conf/lastRun.news"
use_column_value => true
tracking_column => updated_at
jdbc_paging_enabled => "true"
jdbc_page_size => "50000"
schedule => "*/5 * * * *"
type => "news"
}
jdbc {
jdbc_driver_library => "/usr/local/logstash-2.4.0/mysql-connector-java-5.1.39.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://*************:3306/*******?characterEncoding=UTF-8&useSSL=false"
jdbc_user => "touchtv"
jdbc_password => "op@touchtv"
statement => "SELECT pk,name,avatar_url as avatarurl,`desc`,status,remark,identity_type as identitytype,updated_at FROM tablename WHERE status=1 AND date_sub(updated_at,interval 8 hour) > :sql_last_value"
last_run_metadata_path => "/usr/local/logstash-2.4.0/conf/lastRun.media"
use_column_value => true
tracking_column => updated_at
jdbc_paging_enabled => "true"
jdbc_page_size => "50000"
schedule => "*/20 * * * *"
type => "media"
}
}
filter {
json {
source => "message"
remove_field => ["message"]
}
}
output {
stdout {
codec => rubydebug
}
elasticsearch {
hosts => "192.168.*******"
index => "indexname"
document_id => "%{pk}"
}
use_column_value => true ,必须配置,开启字段跟踪
tracking_column => updated_at ,必须配置,指定跟踪的字段名,必须在返回的SQL结果集中存在的字段,要不然会有WARN。
basepath=$(cd `dirname $0`; pwd)
directory=${basepath%/*}
cd $directory
pidString=`ps -ef | grep rg.jruby.Main | grep "${confFile}" | grep -v grep | awk '{print $2}'`
if [ -n "$pidString" ]; then
kill -9 $pidString
echo -e "\nSTOP successfully! \n"
else
echo -e "\nNo need to be stoped because it had already been stoped\n"
fi
folder="${directory}/logs"
if [ ! -d "$folder" ]; then
mkdir "$folder"
fi
nohup bin/logstash -w 4 -f conf/"${confFile}" -l logs/logstash.log.news.`date -d today +"%Y-%m-%d"` > logs/nohup.log.news.`date -d today +"%Y-%m-%d"` 2>&1 &
echo -e "RESTARTING..."
sleep 3
pidString=`ps -ef | grep rg.jruby.Main | grep -v grep | awk '{print $2}'`
if [ -n "$pidString" ]; then
echo -e "\nRESTART SUCCESSFUL!\n"
else
echo -e "\nRESTART FAILED!\n"
fi
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
spring.data.elasticsearch.cluster-name: mycluster
spring.data.elasticsearch.cluster-nodes : 192.168.31.78:9300,192.168.31.79:9300
spring.data.elasticsearch.repositories.enabled : true
package cn.search.domain; import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.elasticsearch.annotations.Document;
import java.sql.Timestamp; /**
* Created by zhongshzh on 2016/10/17.
*/
@Document(indexName = "zsz", type = "news", shards = 10, replicas = 0, refreshInterval = "-1")
public class News {
@Id
private long pk;
@Version
private Long version; private int mediapk;
private int userpk;
......}
package cn.search.domain.repository; import cn.search.domain.Media;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; /**
* Created by zhongshzh on 2016/10/19.
*/
public interface MediaRepository extends ElasticsearchRepository<Media, String> { public Media findByPk(int pk); }
public Page<News> searchNews(String keyword, int pageSize, int pageNum) { QueryBuilder queryBuilder = QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("checkstatus", "0"))
.must(QueryBuilders.multiMatchQuery(keyword, "title", "summary", "content")); Pageable pageable = new PageRequest(pageNum, pageSize);
Page<News> pageNews = newsSearchRepository.search(queryBuilder, pageable);
if(pageNews==null || pageNews.getSize() < 1)
return null;
return pageNews;
}