linux 安裝ElasticSearch 6.x
阿新 • • 發佈:2018-12-25
1. 安裝配置JDK 8
(1)下載並解壓縮
[root@node1 ~]# tar -zxvf jdk-8u112-linux-x64.tar.gz -C /opt
(2)編輯環境變數
vi /etc/profile.d/custom.sh
[[email protected] ~]# vi /etc/profile.d/custom.sh
[[email protected] ~]# cat /etc/profile.d/custom.sh
#!/bin/bash
#java path
export JAVA_HOME=/opt/jdk1.8.0_112
export PATH=$PATH:$JAVA_HOME /bin
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib
(3)生效
[root@node1 ~]# source /etc/profile.d/custom.sh
(4)檢視JDK版本
[root@node1 ~]# java -version
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
[root@node1 ~]#
2. 建立使用者
從5.0開始,ElasticSearch 安全級別提高了,不允許採用root帳號啟動,所以我們要新增一個使用者。
(1)建立bigdata 使用者組
[root@node1 ~]# groupadd bigdata
(2)建立使用者es
[root@node1 ~]# useradd es
[root@node1 ~]# passwd es
Changing password for user es.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@node1 ~]#
(3)將es使用者新增到bigdata組
[root@node1 ~]# usermod -G bigdata es
(4)設定sudo許可權
[root@node1 ~]# visudo
找到root ALL=(ALL) ALL
一行,新增es使用者,如下。
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
es ALL=(ALL) ALL
(5)切換使用者
[root@node1 ~]# su es
[es@node1 root]$ cd
[es@node1 ~]$
3. ElasticSearch 6.x 軟體包下載
[[email protected] ~]$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.1.tar.gz
--2018-01-06 08:24:06-- https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.1.tar.gz
Resolving artifacts.elastic.co (artifacts.elastic.co)... 54.225.188.6, 54.243.108.41, 184.72.218.26, ...
Connecting to artifacts.elastic.co (artifacts.elastic.co)|54.225.188.6|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 28462503 (27M) [application/x-gzip]
Saving to: ‘elasticsearch-6.1.1.tar.gz.1’
100%[===================================================================================================================================================>] 28,462,503 232KB/s in 3m 33s
2018-01-06 08:27:42 (130 KB/s) - ‘elasticsearch-6.1.1.tar.gz.1’ saved [28462503/28462503]
[[email protected] ~]$
(3)解壓縮 tar -zxvf elasticsearch-6.1.1.tar.gz
[es@node1 ~]$ tar -zxvf elasticsearch-6.1.1.tar.gz
[es@node1 ~]$ sudo mv elasticsearch-6.1.1 /opt
(4)修改目錄許可權
更改elasticsearch-6.1.1資料夾以及內部檔案的所屬使用者為es, 使用者組組為bigdata,-R表示逐級(N層目錄)
[[email protected] ~]$ sudo chown -R es:bigdata /opt/elasticsearch-6.1.1
[[email protected] ~]$ ll /opt/elasticsearch-6.1.1
total 220
drwxr-xr-x 2 es bigdata 4096 Jan 6 08:35 bin
drwxr-xr-x 2 es bigdata 75 Dec 17 15:24 config
drwxr-xr-x 2 es bigdata 4096 Dec 17 15:24 lib
-rw-r--r-- 1 es bigdata 11358 Dec 17 15:22 LICENSE.txt
drwxr-xr-x 15 es bigdata 272 Dec 17 15:24 modules
-rw-r--r-- 1 es bigdata 191887 Dec 17 15:24 NOTICE.txt
drwxr-xr-x 2 es bigdata 6 Dec 17 15:24 plugins
-rw-r--r-- 1 es bigdata 9326 Dec 17 15:22 README.textile
[[email protected] ~]$
4. ElasticSearch 配置
(1)修改elasticsearch.yml
[es@node1 elasticsearch-6.1.1]$ vi config/elasticsearch.yml
修改network.host和http.port
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 192.168.80.131
#
# Set a custom port for HTTP:
#
http.port: 9200
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
儲存退出。
修改執行緒數threads
vi /etc/security/limits.d/90-nproc.conf
* soft nproc 1024
#修改為
* soft nproc 2048
(2)修改/etc/sysctl.conf
切換到root使用者,
[root@node1 elasticsearch-6.1.1]# vi /etc/sysctl.conf
新增內容如下:
vm.max_map_count=262144
用命令sysctl -p 生效
[[email protected] ~]# sysctl -p
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
vm.max_map_count = 262144
[[email protected] ~]#
(3)修改檔案/etc/security/limits.conf
[root@node1 logs]# vi /etc/security/limits.conf
新增如下內容
* hard nofile 65536
* soft nofile 65536
* soft nproc 4096
* hard nproc 4096
# End of file
5.ElasticSearch啟動與停止
(1)直接啟動
[[email protected] elasticsearch-6.1.1]$ bin/elasticsearch
(2)停止
ctrl+c停止。
^C[2018-01-06T08:55:24,513][INFO ][o.e.n.Node ] [cNWkQjt] stopping ...
(3)後臺執行
可以通過引數-d後臺執行
[es@node1 elasticsearch-6.1.1]$ bin/elasticsearch -d
(4)查詢程序
[es@node1 elasticsearch-6.1.1]$ jps
3120 Elasticsearch
3135 Jps
[es@node1 elasticsearch-6.1.1]$
6. 驗證
(1)使用curl驗證
[es@node1 elasticsearch-6.1.1]$ curl http://192.168.80.131:9200
{
"name" : "cNWkQjt",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "Kd_e-tqxSx20dl_HjAt1ZQ",
"version" : {
"number" : "6.1.1",
"build_hash" : "bd92e7f",
"build_date" : "2017-12-17T20:23:25.338Z",
"build_snapshot" : false,
"lucene_version" : "7.1.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
[es@node1 elasticsearch-6.1.1]$
如果在Windows平臺通過瀏覽器開啟,需要配置hosts。編輯C:\Windows\System32\drivers\etc\hosts
新增
192.168.80.131 node1
6.問題解決
(1)jps看不到Java程序
[es@node1 elasticsearch-6.1.1]$ bin/elasticsearch -d
[es@node1 elasticsearch-6.1.1]$ jps
[es@node1 elasticsearch-6.1.1]$ jps
[es@node1 elasticsearch-6.1.1]$ ps -aux|grep elasticsearch
es 2930 125 65.2 3627480 1218920 pts/0 Sl 09:33 0:15 /opt/jdk1.8.0_112/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/opt/elasticsearch-6.1.1 -Des.path.conf=/opt/elasticsearch-6.1.1/config -cp /opt/elasticsearch-6.1.1/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
es 2998 0.0 0.0 112660 968 pts/0 S+ 09:33 0:00 grep --color=auto elasticsearch
[es@node1 elasticsearch-6.1.1]$
查詢原因
[es@node1 ~]$ ll /tmp
total 0
drwxr-xr-x 2 1000 1000 6 Jan 5 10:28 hsperfdata_es
drwxr-xr-x 2 root root 6 Jan 6 08:56 hsperfdata_root
drwxrwxr-x 2 1000 1000 6 Jan 5 10:21 jna-3246
drwxrwxr-x 3 1000 1000 32 Jan 5 09:40 npm-2339-f258bfea
drwxr-xr-x 3 root root 37 Jan 5 09:46 npm-2381-44b2a32e
drwxrwxr-x 3 es es 37 Jan 6 02:21 npm-2404-e0646f46
drwxrwxr-x 2 es es 6 Jan 6 02:24 npm-2416-56232d2b
drwxr-xr-x 3 root root 37 Jan 6 02:25 npm-2427-ac7dea5c
drwxrwxr-x 3 1000 1000 32 Jan 5 09:54 npm-2466-3358fd28
drwxrwxr-x 3 1000 1000 37 Jan 5 10:09 npm-2590-5ae8499b
drwxrwxrwx 5 1000 1000 202 Jan 6 02:27 phantomjs
drwx------ 3 root root 17 Jan 6 09:12 systemd-private-3333a83cac6947c59f5bb80f042de342-vmtoolsd.service-nRUgwa
[es@node1 ~]$
原因是當前es使用者沒有/tmp/hsperfdata_es目錄的寫許可權。
解決辦法:
[root@node1 ~]# chown -R es:es /tmp/hsperfdata_es
- 1