How To Install Elasticsearch 7.x for Xenforo on CentOS

Sunka

Well-known member
How To Install Elasticsearch 7.x for Xenforo


This is tutorial for installing (not upgrading) elasticsearch 7 on centos.
If I am missing something, please post here.

Delete first old one if you have installed and install fresh new one elasticsearch v7
Code:
yum remove elasticsearch

Installing elasticsearch 7

Code:
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
Code:
nano /etc/yum.repos.d/elasticsearch.repo
insert this:
Code:
[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
If you do not have java installed, install it (elasticsearch itself includes a bundled version of OpenJDK, but, just to be sure).
Java v11 is what you want to install. You can have both version (v.8 and v.11) but I removed v8 and installed v11
Code:
yum remove java-1.8.0-openjdk
Code:
yum -y install java-11-openjdk

Code:
yum install --enablerepo=elasticsearch elasticsearch
Code:
nano /etc/elasticsearch/elasticsearch.yml
at the end of file add this:
Code:
cluster.name: CUSTOM NAME OF YOUR CLUSTER (same name "should" be inserted into your XenForo field in Admin Control Panel in field Elasticsearch Index Name)
network.host: localhost
http.port: 9200
node.name: ANOTHER CUSTOM NAME
cluster.initial_master_nodes: ANOTHER CUSTOM NAME (same as line above, and use all lowercase)

Also, in same above template change/modify the path -Djava.io.tmpdir=
Code:
-Djava.io.tmpdir=/home/elasticsearch

Then (thanks @rdan )
Code:
mkdir /home/elasticsearch

and

Code:
chown -R elasticsearch:elasticsearch /home/elasticsearch/


set how much ram you will add for elasticsearch - 512 megabytes is set in example (both Xms and Xmx must have same value)
Code:
nano /etc/elasticsearch/jvm.options
Code:
-Xms512m
-Xmx512m


Code:
service elasticsearch start
Code:
systemctl daemon-reload
Code:
systemctl enable elasticsearch.service
Code:
systemctl start elasticsearch.service

test if everything OK (give 1-2 minute after restarting elasticsearch)
Code:
curl -XGET 'localhost:9200'
If everything OK, you will see something like this in your CLI
Code:
# curl -XGET 'localhost:9200'
{
  "name" : "xxxx",
  "cluster_name" : "xxxxx",
  "cluster_uuid" : "4nAffvfpSGG-RE4ou1ttFA",
  "version" : {
    "number" : "7.6.0",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "7f634e9f44834fbc12724506cc1da681b0c3b1e3",
    "build_date" : "2020-02-06T00:09:00.449973Z",
    "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"
}

Also, just in case run command and choose Java 11 (if it will list more than 1 java version):
Code:
alternatives --config java

Also, it is better that you not use shard replica if Elasticsearch is on same server.
So for make by default no replica shards, run this command

Code:
curl -XPUT "localhost:9200/_template/all" -H'Content-Type: application/json' -d'
{
  "template": "*",
  "settings": {
    "number_of_replicas": 0,
    "number_of_shards": 1
  }
}
'

To see if you have unassigned replica shards run:

Code:
curl -s -XGET http://localhost:9200/_cat/shards | fgrep UNASSIGNED

To delete unassigned replica shards run:

Code:
curl -XGET http://localhost:9200/_cat/shards | grep UNASSIGNED | awk {'print $1'} | xargs -i curl -XDELETE "http://localhost:9200/{}"

Then deleted the index. After that go to ElasticSearch Setup in Xenforo ACP then rebuilt the index without deleting.

Minimum version of XenForo Enhanced Search you have installed for elasticsearch 7 is 2.0 I think!

After you installed elastic search, configure relevant options for enhanced search in your Xenforo ACP and rebuild index (all).
It is better and faster to rebuild index through cli. So:

Trunucate old index first (if you have it):
Code:
cd /PATH/TO/YOUR/XENFERO/INSTALL/public/

// SOMETHING LIKE: cd /home/nginx/domains/your_domain.com/public/
and then

Rebuild search with trunucating index before that
Code:
php cmd.php xf-rebuild:search --truncate
or just rebuild without trunucating index
Code:
php cmd.php xf-rebuild:search

And how it looks in elasticsearch setup page in xenforo ACP

setup.webp
 
At this stage Elasticsearch 8 isn't officially supported, but you can get it to work with some tweaks to disable new security features of ES8.. I'm using ES7 instead.

Add Elastic's GPG key to keyring to trust their packages.
Bash:
curl -fsSL https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elastic.gpg

Add the Elastic repository to the list of repositories
Bash:
echo "deb [signed-by=/usr/share/keyrings/elastic.gpg] https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list

Update apt's package list
Bash:
sudo apt update

Install Elasticsearch
Bash:
sudo apt install elasticsearch

At this stage you should have a working elasticsearch installation on port 9200 accessible via localhost only, usable in Xenforo Enhanced Search.

You can tweak other settings, but only if needed and you know what you are doing.

You can check ES status with

Bash:
curl -XGET 'http://localhost:9200/_cat/health?v'

Output should be something like this:

epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1685615762 10:36:02 elasticsearch green 1 1 44 44 0 0 0 0 - 100.0%


With a single node setup, you may well find the status is yellow not green. This is caused by the default configuration having shard replicas set to 1, but replicas can't run on a the same node as the original shard.

This used to fix this globally by setting replicas to 0 in the templates

Bash:
curl -XPUT "localhost:9200/_template/all" -H'Content-Type: application/json' -d'
{
  "template": "*",
  "settings": {
    "number_of_replicas": 0
    "number_of_shards": 1
  }
}
'

Then you could find existing unassigned shards like so:
Bash:
curl -s -XGET http://localhost:9200/_cat/shards | fgrep UNASSIGNED

Output will be something like this:
root@www:~# curl -XGET localhost:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason| grep UNASSIGNED
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3998 100 3998 0 0 75433 0 --:--:-- --:--:-- --:--:-- 75433
.ds-xxxxxxxxxxxxxxxxxxxx 2023.05.08-000036 0 r UNASSIGNED CLUSTER_RECOVERED



And delete them like so:
Bash:
curl -XGET http://localhost:9200/_cat/shards | grep UNASSIGNED | awk {'print $1'} | xargs -i curl -XDELETE "http://localhost:9200/{}"

However since version 7.16 a depreciation log is added which seemed to evade the above setting to 0 replicas. I'll see if I can figure out how to stop this, but note that yellow status here is not a problem, it will work just fine.
 
Last edited:
just for reference elasticsearch 8 on almalinux/centos

/etc/yum.repos.d/elasticsearch.repo
Code:
[elasticsearch]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md
run
Code:
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
yum install --enablerepo=elasticsearch elasticsearch
systemctl enable elasticsearch.service
yum install java-11-openjdk-devel
edit /etc/elasticsearch/elasticsearch.yml
Code:
cluster.name: forumsearch
node.name: node-forumsearch
http.port: 9200
xpack.security.enabled: false
run
Code:
service elasticsearch start
result
Code:
[root@localhost ~]# curl -XGET 'localhost:9200'
{
  "name" : "node-forumsearch",
  "cluster_name" : "forumsearch",
  "cluster_uuid" : "AJTUbKM-Ql2-7ELr8MMopQ",
  "version" : {
    "number" : "8.7.1",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "f229ed3f893a515d590d0f39b05f68913e2d9b53",
    "build_date" : "2023-04-27T04:33:42.127815583Z",
    "build_snapshot" : false,
    "lucene_version" : "9.5.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}
I just had an AlmaLinux 8 server provisioned as I have to migrate off my CentOS 7 server.

Are these all the steps you took to install Elasticserach 8? Did you follow other steps in the original guide? It's really hard to figure out how to start from scratch based on a thread that's 3 years old and any help to get started with a new server is helpful. I assume I still need to install Jave but what version now and how?
 
I just had an AlmaLinux 8 server provisioned as I have to migrate off my CentOS 7 server.

Are these all the steps you took to install Elasticserach 8? Did you follow other steps in the original guide? It's really hard to figure out how to start from scratch based on a thread that's 3 years old and any help to get started with a new server is helpful. I assume I still need to install Jave but what version now and how?

Late reply but there are quick tutorials online you can check out.

 
Top Bottom