Hướng dẫn Setup ElasticSearch with ElasticPress trên Docker
12th Mar 2022Elastic Search already has docker image available. So lets use that Docker image to setup elastic search with WordPress.
Step 1: Install docker
https://docs.docker.com/engine/installation/linux/ubuntulinux/
Step 2: Create an Elastic Search container
docker run -d -v "/var/esdata":/usr/share/elasticsearch/data elasticsearch
Repo url: https://hub.docker.com/_/elasticsearch/
Step 3: Note docker container ID
^_^[root@localhost:~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 763fd2ca5532 elasticsearch "/docker-entrypoint.s" About a minute ago Up About a minute 9200/tcp, 9300/tcp silly_bohr
Step 4: Note container’s Private IP
^_^[root@localhost:~]# docker inspect {container id}
You will get output something like below:
"Gateway": "172.17.0.1", "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", ...
Step 5: Start Elastic Search Service
First lets get a shell access to our docker container
docker exec -t -i 763fd2ca5532 /bin/bash
on second step check elastic search services status and start if not running.
root@763fd2ca5532:~# service elasticsearch status
elasticsearch is not running ... failed!
root@763fd2ca5532:~# service elasticsearch start
Starting Elasticsearch Server:sysctl: setting key "vm.max_map_count": Read-only file system.
root@763fd2ca5532:~# service elasticsearch status
elasticsearch is running.
Now lets get out of docker shell:
Check elastic search status from outside. ^_^[root@localhost:~]# curl http://{Container_IP}:9200 { "name" : "Bandit", "cluster_name" : "elasticsearch", "version" : { "number" : "2.3.3", "build_hash" : "218bdf10790eef486ff2c41a3df5cfa32dadcfde", "build_timestamp" : "2016-05-17T15:40:04Z", "build_snapshot" : false, "lucene_version" : "5.5.0" }, "tagline" : "You Know, for Search" }
Step 6 : Install ElasticPress plugin on wordpress
Install this plugin on your wordpress site – https://github.com/10up/ElasticPress
Add something like this on your wp-config.php. Replace {container_ip} with your docker ip.
define( 'EP_HOST', 'http://{container_ip}:9200' );
Run indexing for first time from web setting or use below wp-cli command :
wp elasticpress index
Check Elastic Search STATUS:
curl http://{container_ip}:9200/_stats
Add new comment