Docker installation ElasticSearch
Get the image (elasticsearch:7.16.3)
# Pull the image docker pull elasticsearch:7.16.3
# View local mirror docker images
Start container
Startup parameters:
-d starts running in the background --name container name restart=always keeps docker running after it starts -p 9200:9200 http access port mapping -p 9300:9300 access port mapping between services -e ES_JAVA_OPTS="-Xms512m -Xmx512m" JVM memory size -e "discovery.type=single-node" Single node startup -v specifies the mounting directory. You need to prepare the mounting path: `/gonait/docker-mount/elastic-search`, and you need to specify the folder read and write permissions `chmod -R 777 elastic-search` elasticsearch:7.16.3 specifies the startup image
Do not specify the mounting directory for first startup
docker run -d \ --name=elastic-search \ --restart=always \ -e ES_JAVA_OPTS="-Xms512m -Xmx512m" \ -e "discovery.type=single-node" \ -p 9200:9200 \ -p 9300:9300 \ elasticsearch:7.16.3
# Check whether the container is started successfully docker ps | grep elastic-search
# Enter the container to view docker exec -it elastic-search /bin/bash
# Copy the configuration file in the container docker cp -a elastic-search:/usr/share/elasticsearch/config /gonait/docker-mount/elastic-search/config
# Modify the configuration file:/gonait/docker-mount/elastic-search/config/elasticsearch.yml vim elasticsearch.yml
# elasticsearch.yml configuration file cluster.name: "elastic-search" network.host: 0.0.0.0 #----------------------- BEGIN SECURITY AUTO CONFIGURATION ---------------------- - # # The following settings, TLS certificates, and keys have been automatically # generated to configure Elasticsearch security features on 16-10-2023 14:13:22 # #------------------------------------------------ ---------------------------------- # Enable security features # xpack.security.enabled: true Change to xpack.security.enabled: false, so that you can directly use http access, and does not require account and password authentication. This setting depends on your personal situation. If it is a production environment, it is recommended to start https and Account password authentication # xpack.security.enabled: true xpack.security.enabled: false xpack.security.enrollment.enabled: true # Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents xpack.security.http.ssl: enabled: true keystore.path: certs/http.p12 # Enable encryption and mutual authentication between cluster nodes xpack.security.transport.ssl: enabled: true verification_mode: certificate keystore.path: certs/transport.p12 truststore.path: certs/transport.p12 #----------------------- END SECURITY AUTO CONFIGURATION ---------------------- --- http.host: 0.0.0.0 path.repo: /usr/share/elasticsearch/data/elastic-backup
# Forced deletion of running containers docker rm -f elastic-search
Start the specified mounting directory again
docker run -d \ --name=elastic-search \ --restart=always \ -e ES_JAVA_OPTS="-Xms512m -Xmx512m" \ -e "discovery.type=single-node" \ -p 9200:9200 \ -p 9300:9300 \ -v /gonait/docker-mount/elastic-search/data:/usr/share/elasticsearch/data \ -v /gonait/docker-mount/elastic-search/plugins:/usr/share/elasticsearch/plugins \ -v /gonait/docker-mount/elastic-search/config:/usr/share/elasticsearch/config \ -v /gonait/docker-mount/elastic-search/logs:/usr/share/elasticsearch/logs \ elasticsearch:7.16.3
Check whether the container is started successfully
# Host browser access http://{linux_ip}:9200/
# Normal response result {<!-- --> "name": "df8caecf562d", "cluster_name": "docker-cluster", "cluster_uuid": "wiwctpzhTtu0F3LWsCyinA", "version": {<!-- --> "number": "7.16.3", "build_flavor": "default", "build_type": "docker", "build_hash": "4e6e4eab2297e949ec994e688dad46290d018022", "build_date": "2022-01-06T23:43:02.825887787Z", "build_snapshot": false, "lucene_version": "8.10.1", "minimum_wire_compatibility_version": "6.8.0", "minimum_index_compatibility_version": "6.0.0-beta1" }, "tagline": "You Know, for Search" }
Possible reasons for access failure:
- Check whether the docker container is started successfully,
docker logs elastic-search
, if the following error log appears, it means that the read and write permissions of the folderlogs
are not configured,chmod -R 777 elastic-search
[0.001s][error][logging] Error opening log file 'logs/gc.log': Permission denied [0.001s][error][logging] Initialization of output 'file=logs/gc.log' using options 'filecount=32,filesize=64m' failed. error: Invalid -Xlog option '-Xlog:gc*,gc + age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m', see error log for details. Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. at org.elasticsearch.tools.launchers.JvmOption.flagsFinal(JvmOption.java:119) at org.elasticsearch.tools.launchers.JvmOption.findFinalOptions(JvmOption.java:81) at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:38) at org.elasticsearch.tools.launchers.JvmOptionsParser.jvmOptions(JvmOptionsParser.java:135) at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:86)- Check whether the firewall is turned off:
systemctl status firewalld
, if it is not in the following status, you need to turn off the system firewall,systemctl stop firewalld
[root@easy-cloud-node-206 config]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1)- For other possible situations, you need to check the corresponding solutions based on the actual situation.
Install the elastic-search plug-in and other related components
- ik word segmentation plug-in:
- Download address: elasticsearch-analysis-ik-7.16.3
- Official website address of more versions: https://github.com/medcl/elasticsearch-analysis-ik/releases
- Unzip the zip package to the ik directory of plugins
# Switch to the specified directory cd /gonait/docker-mount/elastic-search/plugins/ik # unzip files unzip elasticsearch-analysis-ik-7.16.3.zip # Delete compressed package rm -f elasticsearch-analysis-ik-7.16.3.zip
- Visual operation tool: kibana
【Docker】docker installation kibana - Data import and export tool: elasticdump
【Docker】docker install elasticdump