前提條件安裝java8,否則啟動的時候報錯誤
the minimum required Java version is 8; your Java version from [/opt/develop/jdk1.7.0_79/jre] does not meet this requirement
1.下載需要的安裝版本
我這里下載的是6.8.5,elasticsearch-6.8.5.tar.gz
下載地址:
https://www.elastic.co/cn/downloads/past-releases#elasticsearch
2.創建中間件安裝目錄和數據文件、日志文件目錄
[root@hadoop-slave1 soft]# mkdir -p /usr/local/services
[root@hadoop-slave1 soft]# mkdir -p /home/middle/elasticsearch/data
[root@hadoop-slave1 soft]# mkdir -p /home/middle/elasticsearch/logs
2.上傳到服務器
解壓縮並創建數據目錄
[root@hadoop-slave1 soft]# tar -xvf elasticsearch-6.8.5.tar.gz
[root@localhost soft]# mv elasticsearch-6.8.5 /usr/local/services/elasticsearch
[root@localhost soft]#cd /usr/local/services/elasticsearch
3.將elasticsearch目錄權限修改為yeemiao
[root@hadoop-slave1 config]# cd /usr/local/services
[root@hadoop-slave1 services]# chown -R yeemiao.yeemiao ./elasticsearch
同時修改數據文件和日志文件目錄給到yeemiao
[root@hadoop-slave1 services]# cd /home/middle
[root@hadoop-slave1 middle]# chown -R yeemiao.yeemiao ./elasticsearch
4.創建備份目錄
su - yeemiao
mkdir -p /home/yeemiao/esbak
5.修改配置文件
[root@hadoop-slave1 middle]# su - yeemiao
[yeemiao@hadoop-slave1 ~]$ cd /usr/local/services/elasticsearch/config
[yeemiao@hadoop-slave1 config]$ vi elasticsearch.yml
注意修改如下幾項:
path.data: /home/middle/elasticsearch/data
path.logs: /home/middle/elasticsearch/logs
network.host: 192.168.1.63
http.port: 19200
path.repo: /home/yeemiao/esbak
##安全認證
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
6.修改jvm參數(/usr/local/services/elasticsearch/config/jvm.options)
## JVM configuration
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms8g
-Xmx8g
7.修改/usr/local/services/elasticsearch/bin/elasticsearch
# ES_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/elasticsearch
export ES_HEAP_SIZE=8g
8.啟動
su - yeemiao
[yeemiao@hadoop-slave1 ~]$ cd /usr/local/services/elasticsearch/bin
./elasticsearch -d
9.驗證
這個時候登陸會報錯誤
[yeemiao@hadoop-slave1 bin]$ curl http://192.168.1.63:19200/?pretty
{
"error" : {
"root_cause" : [
{
"type" : "security_exception",
"reason" : "missing authentication token for REST request [/?pretty]",
"header" : {
"WWW-Authenticate" : "Basic realm=\"security\" charset=\"UTF-8\""
}
}
],
"type" : "security_exception",
"reason" : "missing authentication token for REST request [/?pretty]",
"header" : {
"WWW-Authenticate" : "Basic realm=\"security\" charset=\"UTF-8\""
}
},
"status" : 401
}
10.安裝安全認證(我這里密碼全部設置為 sdrdev123)
[yeemiao@hadoop-slave1 ~]$ cd /usr/local/services/elasticsearch/bin
[esuser@localhost bin]$ ./elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,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]:
Reenter password for [kibana]:
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]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]
11.再次驗證
curl -u elastic:sdrdev123 http://192.168.1.63:19200/?pretty
{
"name" : "Jzm_fbR",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "igZpEAg9T5uF1PGdit6dVQ",
"version" : {
"number" : "6.8.5",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "78990e9",
"build_date" : "2019-11-13T20:04:24.100411Z",
"build_snapshot" : false,
"lucene_version" : "7.7.2",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
12.設置開啟自啟動
14.設置開機自啟動
/etc/systemd/system/elasticsearch.service
在/etc/systemd/system目錄下創建 elasticsearch.service 文件
root下操作
vi /etc/systemd/system/elasticsearch.service
[Unit]
Description=elasticsearch
[Service]
User=yeemiao
LimitNOFILE=100000
LimitNPROC=100000
ExecStart=/usr/bin/su - yeemiao -c "/usr/local/services/elasticsearch/bin/elasticsearch -d -p pid"
[Install]
WantedBy=multi-user.target
設置開機自啟
systemctl enable elasticsearch