1、安装
1)下载安装
到官网https://download.elastic.co找到对应版本,实用wget获取,并解压即可,如
wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.4.0/elasticsearch-2.4.0.tar.gz
2)yum 安装
编辑yum源
vi/etc/yum.repos.d/elasticsearch.repo
[elasticsearch-5.x]
name=Elasticsearch repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
保存,然后执行yum install
yum install elasticsearch |
2、启动
./elasticsearch
支持外网访问:
./config/elasticsearch.yml添加如下
network.host: “0.0.0.0"
network.publish_host: _nonloopback:ipv4
默认ES是不允许实用root账号启动,如果想root账号启动,需要:
./elasticsearch -d -Des.insecure.allow.root=true
3使用
1)将MYSQL的数据自动导入到ES
下载logtash
https://artifacts.elastic.co/downloads/logstash/logstash-6.2.0.tar.gz
执行命令
./bin/logstash-plugin installlogstash-input-jdbc
./bin/logstash-plugin install logstash-output-elasticsearch
需要安装mysql-connector-java
安装方式:
yum install mysql-connector-java –y
yum groupinstallJava Platform
yum -y install java-1.8.0-openjdk-devel.x86_64
都安装完之后,依旧可能出现找不到LIB文件的情况。
第一种办法:
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
将扩展的jar包拷贝到logstash-core的jars里面
input{
jdbc {
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string =>"jdbc:mysql://rm-***.mysql.rds.aliyuncs.com:3306/db_name"
jdbc_user=> "db_user"
jdbc_password => "db_password"
jdbc_paging_enabled => "true"
jdbc_page_size => "1000"
jdbc_default_timezone =>"Asia/Shanghai"
schedule=> "* * * * *"
statement=> "select * from jm_es_employee where updatetime >:sql_last_value"
use_column_value => true
tracking_column => "updatetime"
last_run_metadata_path => "./logstash_jdbc_last_run"
}
}
output{
elasticsearch{
hosts=> "es-cn-***.elasticsearch.aliyuncs.com:9200"
user =>"elastic"
password=> "es_password"
index=> "employee"
document_id => "%{id}"
}
stdout {
codec=> json_lines
}
}
启动logtash
参考文章:https://yq.aliyun.com/articles/276730
2)ES支持中文分词
ES默认使用的分词器是按空格分词,中文按字分词。对中文不友好。如果要支持中文分词,可以安装中文分词插件。
目前广泛使用的IK分词器,安装方式有两种:
1)进入elasticsearch的bin下面,使用plugin install命令
$ sudo bin/plugin install https://github.com/bosondata/elasticsearch-analysis-bosonnlp/releases/download/1.3.0-beta/elasticsearch-analysis-bosonnlp-1.3.0-beta.zip
2)一种下载源码使用mvn打包,不常用
不管使用哪种方式安装,一定注意版本号的匹配,根据elasticsearch的版本号选择对应的IK分词器版本号。