docker安装elasticsearch集群 - yxbook/notes GitHub Wiki

安装docker-compose

sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

docker-compose --version

安装node git

sudo su -
curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -
yum install -y nodejs
node -v


安装head插件

git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm run start

创建索引的方式postman或使用elasticsearch-head插件

PUT方式
http://127.0.0.1:9200/index_input_feed
Content-Type: application/json

{
    "settings":{
        "number_of_shards":5,
        "number_of_replicas":1
    },
    "mappings":{
        "properties":{
            "inputId":{
                "type":"keyword"
            },
            "upTime":{
                "type":"long"
            },
            "topicId":{
                "type":"keyword"
            },
            "calTime":{
                "type":"long"
            },
            "feedId":{
                "type":"keyword"
            },
            "prop":{
                "type":"keyword"
            },
            "upTimeStr":{
                "type":"date",
                "format":"yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || epoch_millis"
            },
            "express":{
                "type":"keyword"
            },
            "calTimeStr":{
                "type":"date",
                "format":"yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || epoch_millis"
            },
            "value":{
                "type":"double"
            }
        }
    }
}

set vm.max_map_count to 262144

grep vm.max_map_count /etc/sysctl.conf
vm.max_map_count=262144

sysctl -w vm.max_map_count=262144


新建docker-compose.yml文件

docker-compose up

docker exec -it elasticsearch


http.cors.enabled: true
http.cors.allow-origin: "*"

配置daemon.json

sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl status docker -l

免sudo

如果还没有 docker group 就添加一个:
sudo groupadd docker

将用户加入该 group 内。然后退出并重新登录就生效啦。
sudo gpasswd -a ${USER} docker

重启 docker 服务
sudo service docker restart

切换当前会话到新 group 或者重启 X 会话
newgrp - docker
Elasticsearch提供的API来检查一下集群和节点的健康状况
http://127.0.0.1:9200/_cluster/health
http://127.0.0.1:9200/_cat/health?v
http://127.0.0.1:9200/_cat/nodes?v&pretty
curl -X GET "localhost:9200/_cat/nodes?v&pretty"

防火墙

1.防火墙状态
sudo systemctl status firewalld

接着先是看centos7的防火墙的状态,查看的命令为。
查看后,看到active(running)就意味着防火墙打开了。

2.启动防火墙

sudo systemctl start firewalld

3.关闭防火墙
sudo systemctl stop firewalld
关闭后查看是否关闭成功,如果看到inactive(dead)就意味着防火墙关闭了。