一信认、安裝elasticsearch
1其掂、拉取鏡像
docker pull elasticsearch:6.5.0
2喘漏、 啟動(dòng)容器
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 elasticsearch:6.5.0
3573e7af2aea8767415847b0c1214e3d08d11ce09ecf745eeb501f02d4530624
使用docker ps查看發(fā)現(xiàn)容器并沒(méi)有啟動(dòng)成功盔夜,查看日志
docker logs -f 3573
查看max_map_count的值
$ cat /proc/sys/vm/max_map_count
65530
重新設(shè)置max_map_count的值
$ sysctl -w vm.max_map_count=262144
vm.max_map_count = 262144
永久更改max_map_count值,
vm.max_map_count=200000直接寫到/etc/sysctl.conf中,然后執(zhí)行sysctl -p
重新啟動(dòng)容器
docker start elasticsearch
瀏覽器訪問(wèn)
http://ip:9200
{
"name" : "IK4_5lR",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "xw5vUFlqSu2G6lPOSq_8AQ",
"version" : {
"number" : "6.5.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "816e6f6",
"build_date" : "2018-11-09T18:58:36.352602Z",
"build_snapshot" : false,
"lucene_version" : "7.5.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
二本慕、安裝elasticsearch-head插件
1、拉取鏡像
docker pull mobz/elasticsearch-head:5
2牛欢、啟動(dòng)容器
docker run -d --name es-head -p 9100:9100 mobz/elasticsearch-head:5
訪問(wèn) http://ip:9100
提示未連接,修改elasticsarch-head的監(jiān)聽
進(jìn)入容器
docker exec -it es-head bash
使用vim會(huì)提示vim命令不存在,安裝vim命令,若是安裝時(shí)報(bào)錯(cuò)记靡,說(shuō)yum command not found ,使用apt-get update,然后使用apt-get install vim -y 進(jìn)行安裝下載即可
root@616029884dd4:/usr/src/app# vim Gruntfile.js
bash: vim: command not found
root@616029884dd4:/usr/src/app# yum install -y vim
bash: yum: command not found
root@616029884dd4:/usr/src/app# apt-get update
es-head使用的grunt-server作為服務(wù)器的,所以他的啟動(dòng)后監(jiān)聽的host默認(rèn)是localhost啼止, 所以我們要修改其中的配置文件趣些,增加一些配置,這樣可以使得能夠被外部訪問(wèn)的到舔庶,修改Gruntfile.js文件朦促,添加hostname
chon
重啟es-head
docker restart es-head
連接elasticsearch的地址油湖,查看控制臺(tái)會(huì)提示跨域錯(cuò)誤,修改elasticsearch.yml解決跨域問(wèn)題领跛,在文件最后添加
http.cors.enabled: true
http.cors.allow-origin: "*"
以掛載的方式啟動(dòng)es
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -v /home/elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml elasticsearch:6.5.0
elasticsearch.yml的內(nèi)容
cluster.name: "docker-cluster"
network.host: 0.0.0.0
# minimum_master_nodes need to be explicitly set when bound on a public IP
# # set to 1 to allow single node clusters
# # Details: https://github.com/elastic/elasticsearch/pull/17288
discovery.zen.minimum_master_nodes: 1
# head setting 解決跨域問(wèn)題
http.cors.enabled: true
http.cors.allow-origin: "*"
可能會(huì)啟動(dòng)失敗乏德,出現(xiàn)權(quán)限不足的問(wèn)題,這時(shí)候需要關(guān)閉selinux
[root@localhost home]# docker logs -f df99
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
2019-08-15 07:11:55,026 main ERROR No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2
Exception in thread "main" SettingsException[Failed to load settings from /usr/share/elasticsearch/config/elasticsearch.yml]; nested: AccessDeniedException[/usr/share/elasticsearch/config/elasticsearch.yml];
at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:102)
at org.elasticsearch.cli.EnvironmentAwareCommand.createEnv(EnvironmentAwareCommand.java:95)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124)
at org.elasticsearch.cli.Command.main(Command.java:90)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86)
Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/config/elasticsearch.yml
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:215)
at java.base/java.nio.file.Files.newByteChannel(Files.java:370)
at java.base/java.nio.file.Files.newByteChannel(Files.java:421)
at java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420)
at java.base/java.nio.file.Files.newInputStream(Files.java:155)
at org.elasticsearch.common.settings.Settings$Builder.loadFromPath(Settings.java:1189)
at org.elasticsearch.node.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:100)
... 6 more
啟動(dòng)之后再次連接就連接成功了
三吠昭、安裝ik分詞器
進(jìn)入到容器里
docker exec -it elasticsearch bash
cd bin
[root@d6bd6a5487ae bin]# elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.5.0/elasticsearch-analysis-ik-6.5.0.zip