Docker安装elasticsearch :不用数据卷
0.注意事项
es暴露的端口很多
es很占内存,默认1g
es的数据需要放到安全目录,要做数据挂载
es集群,需要docker网络
1.官方启动es(不推荐,没设置es内存大小)
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.7.0
curl查看是否启动成功
[root@localhost haokai]# curl locallhost:9200
curl: (6) Could not resolve host: locallhost; Unknown error
[root@localhost haokai]# curl localhost:9200
{
"name" : "64353fa05644",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "Lg4AuNSISjC_E3ztBBZbTg",
"version" : {
"number" : "7.6.2",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
"build_date" : "2020-03-26T06:34:37.794943Z",
"build_snapshot" : false,
"lucene_version" : "8.4.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
[root@localhost haokai]#
2.docker stats查看容器占用状态
这个命令也比较耗费内存,因为是实施刷新的,所以不看了要ctrl + c关掉
docker stats
3.docker -e增加内存限制
-e ES_JAVA_OPS=“Xms64m Xmx=128”
内存指定:最小64M,最大128M,看自己需要,一般不超过物理内存的50%。
docker run --name elasticsearch -d -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -e "discovery.type=single-node" -p 9200:9200 -p 9300:9300 elasticsearch:7.7.0
[root@localhost jdk1.8.0_261]# docker stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
9bb52e7b7711 elasticsearch 0.38% 733.6MiB / 1.777GiB 40.32% 656B / 0B 370MB / 2.43MB 54
533124d2559a tomcat01 0.24% 62.11MiB / 1.777GiB 3.41% 17.8kB / 172kB 2.99GB / 49MB 36
aca793e8d0cc nginx01 0.00% 1.883MiB / 1.777GiB 0.10% 8.64kB / 6.78kB 22.4MB / 0B 5
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
9bb52e7b7711 elasticsearch 0.38% 733.6MiB / 1.777GiB 40.32% 656B / 0B 370MB / 2.43MB 54
533124d2559a tomcat01 0.24% 62.11MiB / 1.777GiB 3.41% 17.8kB / 172kB 2.99GB / 49MB 36
aca793e8d0cc nginx01 0.00% 1.883MiB / 1.777GiB 0.10% 8.64kB / 6.78kB 22.4MB / 0B 5
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
9bb52e7b7711 elasticsearch 0.43% 733.1MiB / 1.777GiB 40.29% 656B / 0B 370MB / 2.43MB 54
533124d2559a tomcat01 0.32% 61.75MiB / 1.777GiB 3.39% 17.8kB / 172kB 2.99GB / 49MB 36
aca793e8d0cc nginx01 0.00% 1.883MiB / 1.777GiB 0.10% 8.64kB / 6.78kB 22.4MB / 0B 5
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
9bb52e7b7711 elasticsearch 0.43% 733.1MiB / 1.777GiB 40.29% 656B / 0B 370MB / 2.43MB 54
533124d2559a tomcat01 0.32% 61.75MiB / 1.777GiB 3.39% 17.8kB / 172kB 2.99GB / 49MB 36
aca793e8d0cc nginx01 0.00% 1.883MiB / 1.777GiB 0.10% 8.64kB / 6.78kB 22.4MB / 0B 5
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
9bb52e7b7711 elasticsearch 8.27% 733.4MiB / 1.777GiB 40.31% 656B / 0B 381MB / 2.43MB 54
533124d2559a tomcat01 0.20% 61.75MiB / 1.777GiB 3.39% 17.8kB / 172kB 2.99GB / 49MB 36
aca793e8d0cc nginx01 0.00% 1.883MiB / 1.777GiB 0.10% 8.64kB / 6.78kB 22.4MB / 0B 5
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
9bb52e7b7711 elasticsearch 8.27% 733.4MiB / 1.777GiB 40.31% 656B / 0B 381MB / 2.43MB 54
533124d2559a tomcat01 0.20% 61.75MiB / 1.777GiB 3.39% 17.8kB / 172kB 2.99GB / 49MB 36
aca793e8d0cc nginx01 0.00% 1.883MiB / 1.777GiB 0.10% 8.64kB / 6.78kB 22.4MB / 0B 5
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
9bb52e7b7711 elasticsearch 0.31% 733.4MiB / 1.777GiB 40.31% 656B / 0B 381MB / 2.43MB 54
533124d2559a tomcat01 0.26% 61.75MiB / 1.777GiB 3.39% 17.8kB / 172kB 2.99GB / 49MB 36
aca793e8d0cc nginx01 0.00% 1.883MiB / 1.777GiB 0.10% 8.64kB / 6.78kB 22.4MB / 0B 5
^C
[root@localhost jdk1.8.0_261]#
4.WARNING: IPv4 forwarding is disabled. Networking will not work.
启动镜像,可能会遇到WARNING: IPv4 forwarding is disabled. Networking will not work,提示没有网络,因为没有开启转发,网桥配置完后,需要开启转发,不然容器启动后,就会没有网络,配置/etc/sysctl.conf,添加net.ipv4.ip_forward=1
命令含义:
vim /etc/sysctl.conf
#配置转发
net.ipv4.ip_forward=1
#重启服务,让配置生效
systemctl restart network
#查看是否成功,如果返回为“net.ipv4.ip_forward = 1”则表示成功
sysctl net.ipv4.ip_forward
[root@localhost haokai]# vim /etc/sysctl.conf
[root@localhost haokai]# systemctl restart network
[root@localhost haokai]# sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
5.curl测试
[root@localhost jdk1.8.0_261]# curl localhost:9200
{
"name" : "9bb52e7b7711",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "Y2vYqWaOSo68OT3Vaogc6g",
"version" : {
"number" : "7.7.0",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "81a1e9eda8e6183f5237786246f6dced26a10eaf",
"build_date" : "2020-05-12T02:01:37.602180Z",
"build_snapshot" : false,
"lucene_version" : "8.5.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
[root@localhost jdk1.8.0_261]#