1.Check JDK
Elasticsearch requires at least Java 8. Specifically as of this writing, it is recommended that you use the Oracle JDK version 1.8.0_131.
java -version
echo $JAVA_HOME
~ ➜ java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
~ ➜ echo $JAVA_HOME
/usr/local/java/jdk/jdk1.8.0_151/
2.Download
Let’s download the Elasticsearch 5.6.16 tar as follows:
curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.16.tar.gz
3.Install & Config
踩坑提醒 1:
因为 Elasticsearch 可以执行脚本文件,为了安全性,默认不允许通过 root 用户启动服务。我们需要新创建用户名和用户组启动服务
#增加 es 组
groupadd es
#增加 es 用户并附加到 es 组
useradd es -g es -p es
#给目录权限
chown -R es:es elasticsearch-5.6.16
#使用es用户
su es
#使用root用户初始化密码
passwd es
#使用es用户创建文件夹 拷贝elasticsearch-5.6.16.tar.gz,并解压当前文件夹
mv elasticsearch-5.6.16.tar.gz /home/es
tar -xvf elasticsearch-5.6.16.tar.gz
es ➜ pwd
/home/es
es ➜ ll
总用量 20
drwxr-xr-x 9 es es 4096 7月 29 19:33 elasticsearch-5.6.16
踩坑提醒 2:
默认情况下,Elasticsearch 只允许本机访问,如果需要远程访问,需要修改其配置文件
vim config/elasticsearch.yml
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#allow origin 允许插件访问
http.cors.enabled: true
http.cors.allow-origin: "*"
vim config/jvm.options
#两个值要一直,否则报错
-Xms128m
-Xmx128m
#定义临时文件路径,否则报错
-Djava.io.tmpdir=/home/es/tmp/elasticsearch
-Djna.tmpdir=/home/es/tmp/elasticsearch
踩坑提醒 3:
启动报错:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]命令行键入:
#root用户
ulimit -n 65536
踩坑提醒 4:
启动报错:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
#root用户
vim /etc/sysctl.conf
vm.max_map_count=262144
保存,并执行 sysctl -p
4.Run
#es用户
./elasticsearch
后台启动
#es用户
./elasticsearch -d
~ ➜ curl http://127.0.0.1:9200
{
"name" : "clJxFsP",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "5Z935z2lSymq4ltoXSNSJg",
"version" : {
"number" : "5.6.16",
"build_hash" : "3a740d1",
"build_date" : "2019-03-13T15:33:36.565Z",
"build_snapshot" : false,
"lucene_version" : "6.6.1"
},
"tagline" : "You Know, for Search"
}
5.elasticsearch-head
~ ➜wget https://github.com/mobz/elasticsearch-head/archive/master.zip
~ ➜unzip master.zip
~ ➜cd elasticsearch-head-master
~ ➜npm install
~ ➜npm run start
PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
npm install -g grunt-cli
es-head ➜ npm install -g grunt-cli
/usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt
+ grunt-cli@1.3.2
added 150 packages from 121 contributors in 25.955ss
修改vim Gruntfile.js文件:增加hostname属性,设置为全部,如图所示
修改_site/app.js 文件
启动服务grunt server &
es-head ➜ grunt server &
[1] 26724
es-head ➜ ps(node:26724) ExperimentalWarning: The http2 module is an experimental API.
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
nohup grunt server >/dev/null
es-head ➜ nohup grunt server >/dev/null
nohup: ignoring input and redirecting stderr to stdout
6.安装es-sql
运行: //此为一条命令
./bin/elasticsearch-plugi install https://github.com/NLPchina/elasticsearch-sql/releases/download/5.6.5.0/elasticsearch-sql-5.6.5.0.zip
下载sql安装包并解压缩后:
cd site-server
npm install express --save
node node-server.js &
7.view
https://www.wgg-net.cn/es/admin/
https://www.wgg-net.cn/es/