1.elasticsearch-6.7.1和kibana-oss-6.7.1的Linux安装
1.、安装JDK8(Elastic 需要 Java 8 环境)
1)下载jdk8文件:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html\
2)解压文件:tar -zxvf jdk-8u191-linux-x64.tar.gz
3)将JDK移动到/usr/local/jdk1.8.0_191目录之中:mv jdk1.8.0_191 /usr/local/jdk1.8.0_191
4)配置环境变量:
a)vi /etc/profile
b)在末尾添加
export JAVA_HOME=/usr/local/jdk1.8.0_191
export CLASSPATH=.:
J
A
V
A
H
O
M
E
/
l
i
b
/
d
t
.
j
a
r
:
JAVA_HOME/lib/dt.jar:
JAVAHOME/lib/dt.jar:JAVA_HOME/lib/tools.jar
export PATH=
J
A
V
A
H
O
M
E
/
b
i
n
:
JAVA_HOME/bin:
JAVAHOME/bin:PATH:$HOME/bin
c)source /etc/profile
5)验证是否安装成功:java -version
2.安装Elasticsearch
1)下载Elastic:wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.7.1.tar.gz
2)解压文件:tar -zxvf elasticsearch-6.7.1.tar.gz
3)安装:mv elasticsearch-6.7.1 /opt
3、创建Elasticsearch用户
es 规定 root 用户不能启动 es,所以需要新建一个其他用户来启动 es修改配置文件
1)添加用户:adduser esuser
2)设定密码:passwd esuser
3)添加权限:chown -R esuser /opt/elasticsearch-6.7.1
4、修改配置文件
1)进入/opt/elasticsearch-6.7.1/config目录,使用vi编辑器:vi elasticsearch.yml(注:冒号前面不能有空格,后面必须有一个空格)
2)取消如下注释,并修改为当前主机地址:
cluster.name: my-application
node.name: node-1
bootstrap.memory_lock: false
network.host: 192.168.223.137
http.port: 9200
discovery.zen.ping.unicast.hosts: [“192.168.223.137”]
discovery.zen.minimum_master_nodes: 1 #注意,因为本人目前是单节点,这里必须为1
3)新增如下配置:
transport.tcp.port: 9300
transport.tcp.compress: true
bootstrap.system_call_filter: false
注意这些修改前面加空格
4)使用vi编辑器,修改/etc/sysctl.conf文件,添加如下代码(若无将会出现下面常见问题2):
vm.max_map_count=262144
5)退出保存后执行如下命令:
sysctl -p
6)使用vi编辑器,修改/etc/security/limits.conf文件,在文件末尾添加如下代码(若无将会出现下面常见问题3):
# esuser为登录服务器的用户名
* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096
5、启动Elasticsearch
1)切换用户
su esuser
2)启动服务,切换到
elasticsearch-6.7.1/bin/elasticsearch
[esuser@localhost elasticsearch-6.7.1]$ elasticsearch-6.7.1/bin/elasticsearch
3)测试是否成功
curl -XGET ‘http://192.168.223.137:9200/’
kibana安装
1.下载地址:https://www.elastic.co/downloads/past-releases
解压
2.在config/kibana.yml中,有如下配置,意思是默认是localhost,外网是无法访问的,如果外网想访问,那需要修改一下server.host
server.port: 5601
server.host: "192.168.223.137"
elasticsearch.hosts: ["http://192.168.223.137:9200"]
注意也要加空格以防报错
启动 kibana
[root@localhost kibana-6.7.1-linux-x86_64]# ./bin/kibana
测试访问http://192.168.223.137:5601
elasticsearch6.7.1中文分词安装
1.GitHub下载地址https://github.com/medcl/elasticsearch-analysis-ik/releases
注意一定要安装对应的版本
unzip elasticsearch-analysis-ik-6.7.1.zip
2.如果没有unzip的使用 yum install zip unzip 命令安装
3.在plugins新建:analys-ik; 移动到es的plugins下的,并删除.zip文件
否则会报:
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: Could not load plugin descriptor for plugin directory [config]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-6.7.1.jar:6.7.1]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-6.7.1.jar:6.7.1]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.7.1.jar:6.7.1]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.7.1.jar:6.7.1]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.7.1.jar:6.7.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116) ~[elasticsearch-6.7.1.jar:6.7.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.7.1.jar:6.7.1]
Caused by: java.lang.IllegalStateException: Could not load plugin descriptor for plugin directory [config]
at org.elasticsearch.plugins.PluginsService.readPluginBundle(PluginsService.java:401) ~[elasticsearch-6.7.1.jar:6.7.1]
at org.elasticsearch.plugins.PluginsService.findBundles(PluginsService.java:386) ~[elasticsearch-6.7.1.jar:6.7.1]
at org.elasticsearch.plugins.PluginsService.getPluginBundles(PluginsService.java:379) ~[elasticsearch-6.7.1.jar:6.7.1]
at org.elasticsearch.plugins.PluginsService.<init>(PluginsService.java:151) ~[elasticsearch-6.7.1.jar:6.7.1]
at org.elasticsearch.node.Node.<init>(Node.java:339) ~[elasticsearch-6.7.1.jar:6.7.1]
at org.elasticsearch.node.Node.<init>(Node.java:266) ~[elasticsearch-6.7.1.jar:6.7.1]
at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:212) ~[elasticsearch-6.7.1.jar:6.7.1]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:212) ~[elasticsearch-6.7.1.jar:6.7.1]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.7.1.jar:6.7.1]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-6.7.1.jar:6.7.1]
... 6 more
4.不用配置config的elasticsearch.yml
5.启动,测试
curl -XGET http://92.168.223.137:9200/_analyze?pretty -H 'Content-Type:application/json' -d ' {
"analyzer": "ik_smart",
"text": "听说看这篇博客的哥们最帅、姑娘最美"
}
Springboot2.x整合ElasticSearch
6.报错(安装完中文分词)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemRepository': Invocation of init method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.elasticsearch.repository.support.NumberKeyedRepository]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: mapper [brand] of different type, current_type [text], merged_type [keyword]
7.解决
将
改为
问题解决
原因使用了中文分词,就不用再分了
启动报日志错误
解决:
启动es是非root用户启动,报错权限不够
这是只要在root用户下为普通用户授权就可以了
例如我的普通用户名是:esuser
chown esuser /opt/elasticsearch//elasticsearch-6.7.1 -R