Docker安裝請參考:http://www.reibang.com/p/64de448b637c
1帽揪、安裝Elasticsearch和Kibana
1.1山害、安裝Elasticsearch
docker pull elasticsearch:7.10.1
1.2裹纳、安裝kibana,kibana的版本一定要和elasticsearch的版本一樣弟翘。
docker pull kibana:7.10.1
1.3、創(chuàng)建Elasticsearch文件夾,以后會把配置文件放到config下新娜,數(shù)據(jù)文件放到data下
mkdir -p /usr/local/app/elasticsearch/config
mkdir -p /usr/local/app/elasticsearch/data
1.4桅滋、進入config文件夾慧耍,創(chuàng)建Elasticsearch配置文件
cd /usr/local/app/elasticsearch/config/
vi elasticsearch.yml
elasticsearch.yml中添加“http.host: 0.0.0.0”身辨,配置Elasticsearch可被任意主機連接
[root@localhost config]# cat elasticsearch.yml
http.host: 0.0.0.0
[root@localhost config]#
2、啟動Elasticsearch
啟動命令:
--name 為容器起名字芍碧;
-p 9200:9200 監(jiān)聽9200端口煌珊,接收http請求;
-p 9300:9300 監(jiān)聽9300端口泌豆,集群間通信端口定庵;
-e "discovery.type=single-node" 以單節(jié)點運行;
-e ES_JAVA_OPTS="-Xms64m -Xmx512m" 指定初始占用內(nèi)存64m踪危,最大占用512m蔬浙;
-v /usr/local/app/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml 將容器中的配置文件掛載到,剛才創(chuàng)建的config/elasticsearch.yml文件中贞远;
-v /usr/local/app/elasticsearch/data:/usr/share/elasticsearch/data 掛載data目錄畴博;
-v /usr/local/app/elasticsearch/plugins:/usr/share/elasticsearch/plugins 掛載插件目錄plugins;
-d elasticsearch:7.10.1 使用剛才下載的鏡像 蓝仲;
[root@localhost config]# docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
> -e "discovery.type=single-node" \
> -e ES_JAVA_OPTS="-Xms64m -Xmx512m" \
> -v /usr/local/app/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
> -v /usr/local/app/elasticsearch/data:/usr/share/elasticsearch/data \
> -v /usr/local/app/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
> -d elasticsearch:7.10.1
e4fba7b5ba08f4c5096f7e7b670138aed86ad0396bab150778a638a918967829
[root@localhost config]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e4fba7b5ba08 elasticsearch:7.10.1 "/tini -- /usr/local…" 3 seconds ago Up 3 seconds 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch
[root@localhost config]#
過一會俱病,elasticsearch會錯誤退出,查看docker中elasticsearch日志袱结,出現(xiàn)訪問拒絕報錯:
[root@localhost config]# docker logs elasticsearch
uncaught exception in thread [main]
ElasticsearchException[failed to bind service]; nested: AccessDeniedException[/usr/share/elasticsearch/data/nodes];
Likely root cause: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:388)
at java.base/java.nio.file.Files.createDirectory(Files.java:694)
at java.base/java.nio.file.Files.createAndCheckIsDirectory(Files.java:801)
at java.base/java.nio.file.Files.createDirectories(Files.java:787)
at org.elasticsearch.env.NodeEnvironment.lambda$new$0(NodeEnvironment.java:275)
at org.elasticsearch.env.NodeEnvironment$NodeLock.<init>(NodeEnvironment.java:212)
at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:272)
at org.elasticsearch.node.Node.<init>(Node.java:362)
at org.elasticsearch.node.Node.<init>(Node.java:289)
at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:227)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:227)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:393)
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170)
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:127)
at org.elasticsearch.cli.Command.main(Command.java:90)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)
For complete error details, refer to the log at /usr/share/elasticsearch/logs/elasticsearch.log
修改elasticsearch文件夾權(quán)限亮隙,-R遞歸修改所有子文件權(quán)限,777所有用戶垢夹、分組均可讀可寫
[root@localhost elasticsearch]# chmod -R 777 /usr/local/app/elasticsearch
[root@localhost elasticsearch]# ll
total 0
drwxrwxrwx. 2 root root 31 Jan 13 16:00 config
drwxrwxrwx. 2 root root 6 Jan 13 15:55 data
drwxrwxrwx. 2 root root 6 Jan 13 16:14 plugins
查看elasticsearch容器溢吻,并重啟elasticsearch,docker start后面跟上自己elasticsearch容器id就可以了棚饵。
[root@localhost elasticsearch]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e4fba7b5ba08 elasticsearch:7.10.1 "/tini -- /usr/local…" 23 hours ago Exited (1) 23 hours ago elasticsearch
[root@localhost elasticsearch]# docker start e4fba7b5ba08
e4fba7b5ba08
容器啟動成功
[root@localhost elasticsearch]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e4fba7b5ba08 elasticsearch:7.10.1 "/tini -- /usr/local…" 24 hours ago Up 2 minutes 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch
此時訪問虛擬機9200端口煤裙,返回成功
3、啟動kibana
--name kibana:給容器起名字kibana噪漾;
-e ELASTICSEARCH_HOSTS=http://{自己的虛擬機地址}:9200:指定elasticsearch的地址和端口硼砰;
-p 5601:5601:kibana的操作端口;
-d kibana:7.10.1:kibana的版本欣硼;
[root@localhost elasticsearch]# docker run --name kibana -e ELASTICSEARCH_HOSTS=http://192.168.43.129:9200 -p 5601:5601 -d kibana:7.10.1
b4f383036f1b14ea0a6d6a8cf38a8ed636360652a9811899c5a60c16a86d9563
[root@localhost elasticsearch]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b4f383036f1b kibana:7.10.1 "/usr/local/bin/dumb…" 4 seconds ago Up 4 seconds 0.0.0.0:5601->5601/tcp kibana
e4fba7b5ba08 elasticsearch:7.10.1 "/tini -- /usr/local…" 24 hours ago Up 15 minutes 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch
[root@localhost elasticsearch]#
訪問虛擬機5601端口题翰,kibana啟動成功