本地mac安装没出现什么问题,直接安装都运行了,最近在阿里云服务器安装的时候各种坑不断的踩,平时也没有习惯写出来的习惯,但是每次安装都好费时间,而且还容易忘记,就自己写一写,留作以后备用.仅是个人安装遇到的问题.
什么是Elasticsearch-RTF
RTF是Ready To Fly的缩写,在航模里面,表示无需自己组装零件即可直接上手即飞的航空模型,Elasticsearch-RTF是针对中文的一个发行版,即使用最新稳定的elasticsearch版本,并且帮你下载测试好对应的插件,如中文分词插件等,目的是让你可以下载下来就可以直接的使用(虽然es已经很简单了,但是很多新手还是需要去花时间去找配置,中间的过程其实很痛苦),当然等你对这些都熟悉了之后,你完全可以自己去diy了,跟linux的众多发行版是一个意思。
一、Java环境安装。
因为Elasticsearch是Java环境编写的,所以要有Java环境来支持运行
检查是否有java(我直接输入java -version看的)
下载安装包并上传服务器
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
我这边放到了根目录scp jdk-8u162-linux-x64.rpm root@*:/root - *为ip
安装JDK
rpm -ivh jdk-8u162-linux-x64.rpm
查看是否安装正常
就是我们的常规配置环境变量了
1. vim /etc/profile 2. JAVA_HOME=/usr/java/jdk1.8.0_162 JRE_HOME=/usr/java/jdk1.8.0_162/jre PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib export JAVA_HOME JRE_HOME PATH CLASSPATH 3. source /etc/profile
手工,开始继续安装我们的主角
或者sudo apt-get install default-jd
二、安装Elasticsearch-rtf
下载(安装git)
home路径同级
git clone git://github.com/medcl/elasticsearch-rtf.git -b master --depth 1
![](http://upload-images.jianshu.io/upload_images/4063528-121d72d8ce707153.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/556)
运行
Mac/Linux:cd elasticsearch-rtf/bin ./elasticsearch
满怀惊喜,结果...
3.1.
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x000000008a660000, 1973026816, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 1973026816 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /home/wangyw/elasticsearch-rtf/bin/hs_err_pid28563.log
错误原因:由于elasticsearch5.0默认分配jvm空间大小为2g,修改jvm空间分配
解决方案:
elasticsearch-rtf路径下
vim config/jvm.options
![](http://upload-images.jianshu.io/upload_images/4063528-b5bc2780dc026cc2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/476)
3.2 继续运行
[WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:125) ~[elasticsearch-5.1.1.jar:5.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-5.1.1.jar:5.1.1]
at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) ~[elasticsearch-5.1.1.jar:5.1.1]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:96) ~[elasticsearch-5.1.1.jar:5.1.1]
at org.elasticsearch.cli.Command.main(Command.java:62) ~[elasticsearch-5.1.1.jar:5.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:89) ~[elasticsearch-5.1.1.jar:5.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:82) ~[elasticsearch-5.1.1.jar:5.1.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:100) ~[elasticsearch-5.1.1.jar:5.1.1]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:176) ~[elasticsearch-5.1.1.jar:5.1.1]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:306) ~[elasticsearch-5.1.1.jar:5.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-5.1.1.jar:5.1.1]
... 6 more
错误原因:因安全因素,不能在root用户下运行
解决方案:
groupadd es
useradd es -g es -p es
chown -R es:es es/elasticsearch-rtf
su es
然后再次启动
3.3 又出错了,快崩溃了
ERROR: bootstrap checks failed
max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决方法:切换到root用户,编辑limits.conf 添加类似如下内容
~ vim /etc/security/limits.conf
修改内容:* soft nofile 65536
然后重新登录一下用户输入
~ ulimit -Hn
65536
在切回root用户
~ vim /etc/sysctl.conf
vm.max_map_count=262144
~ sysctl -a|grep vm.max_map_count
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.eth0.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
vm.max_map_count = 262144
然后执行sysctl -p
,然后,重新启动elasticsearch,即可启动成功。
阿里云服务器访问外网修改了config/elasticsearch.yml 后还需要添加安全组
开启外网访问并且验证
~ vim config/elasticsearch.yml 翻到下面找到并修改 network.host: 0.0.0.0 http.cors.enabled: true http.cors.allow-origin: "*" http.cors.allow-methods: OPTIONS,HEAD,GET,POST,PUT,DELETE http.cors.allow-headers: "X-Requested-With,Content-Type,Content-Length, X-User"
然后保存退出,重新运行
~ ./elasticsearch
三、安装 elasticsearch-head
elasticsearch-head是集群管理工具、数据可视化、增删改查工具
git clone git://github.com/mobz/elasticsearch-head.git
elasticsearch-head的使用需要基于nodejs,所以需要安装nodejs
cd /usr/local/
wget https://npm.taobao.org/mirrors/node/v8.9.3/node-v8.9.3-linux-x64.tar.xz
不知道为什么我下载下来就是xz格式 一开始不能直接解压然后
xz -d node-v8.9.3-linux-x64.tar.xz
tar -xvf node-v8.9.3-linux-x64.tar
名字太长了重命名
mv node-v8.9.3-linux-x64 node
配置环境变量
vim /etc/profile
export NODE_HOME=/usr/local/node
export PATH=$NODE_HOME/bin:$PATH
保存退出,执行生效
source /etc/profile
然后使用命令查看版本
![](http://upload-images.jianshu.io/upload_images/4063528-deb1de4300b3b2d8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/201)
然后切回刚才下载的elasticsearch-head 目录执行
npm install
npm run start
正常执行 http://localhost:9100 就可以访问了
![](http://upload-images.jianshu.io/upload_images/4063528-ce30a60e7846b679.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700)