Elasticsearch安装

Docker

Elasticsearch单节点

修改max_map_count值

sysctl -w vm.max_map_count=262144

创建持久化目录并配置权限

mkdir /opt/elasticsearch
setfacl -m u:1000:rwx -R /opt/elasticsearch/

创建配置文件

mkdir config
$ cat > elasticsearch.yml << EOF
cluster.name: "docker-cluster"
network.host: 0.0.0.0
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
EOF

运行容器

docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e "cluster.name=elasticsearch" \
-e "ES_JAVA_OPTS=-Xms512m -Xmx1024m" \
-v /opt/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-v /opt/elasticsearch/data:/usr/share/elasticsearch/data \
-v /opt/elasticsearch/logs:/usr/share/elasticsearch/logs \
-v /opt/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-d elasticsearch:7.17.5

初始化密码

$ docker exec -it elasticsearch bash
root@2001b18921ee:/usr/share/elasticsearch# /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y


Enter password for [elastic]: 
Reenter password for [elastic]: 
Enter password for [apm_system]: 
Reenter password for [apm_system]: 
Enter password for [kibana_system]: 
Reenter password for [kibana_system]: 
Enter password for [logstash_system]: 
Reenter password for [logstash_system]: 
Enter password for [beats_system]: 
Reenter password for [beats_system]: 
Enter password for [remote_monitoring_user]: 
Reenter password for [remote_monitoring_user]: 
Changed password for user [apm_system]
Changed password for user [kibana_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]

Curl登录测试

root@2001b18921ee:/usr/share/elasticsearch# curl -XGET -u elastic 'localhost:9200/_xpack/security/user?pretty'
Enter host password for user 'elastic':
{
  "elastic" : {
    "username" : "elastic",
    "roles" : [
      "superuser"
    ],
    "full_name" : null,
    "email" : null,
    "metadata" : {
      "_reserved" : true
    },
...

Kibana单节点

初始化配置文件

mkdir /opt/kibana/config
$ cat > /opt/kibana/config/kibana.yml << EOF
server.host: "0.0.0.0"
server.shutdownTimeout: "5s"
elasticsearch.hosts: [ "http://elasticsearch:9200" ]
monitoring.ui.container.elasticsearch.enabled: true
elasticsearch.username: "kibana"
elasticsearch.password: "kibana_passwd"
xpack.reporting.encryptionKey: "a_random_string"
xpack.security.encryptionKey: "something_at_least_32_characters"
EOF

运行容器

docker run  --name kibana -p 5601:5601 \
--link elasticsearch:es \
-e "elasticsearch.hosts=http://es:9200" \
-v /opt/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml \
-d kibana:7.17.5

ik分词器

cd /opt/
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.17.5/elasticsearch-analysis-ik-7.17.5.zip
unzip elasticsearch-analysis-ik-7.17.5.zip -d ik && rm -f elasticsearch-analysis-ik-7.17.5.zip

重启elasticsearch

参考文章:https://blog.csdn.net/qq_20143059/article/details/112992016

posted @ 2023-11-01 17:07  MegaloBox  阅读(2)  评论(0编辑  收藏  举报