在elastic官网下载最新版本elasticsearch的zip包,我下载时的版本为:2.3.2.
将zip包上传到linux并解压,同时新建data和logs目录,用于存放数据和日志。
配置
修改elasticsearch-2.3.2/config下elasticsearch.yml配置文件,增加如下YAML的配置:
path: logs: /data/elasticsearch/logs data: /data/elasticsearch/data
相应的目录:
[ufo0818@web elasticsearch]$ pwd/data/elasticsearch //安装目录[ufo0818@web elasticsearch]$ lltotal 26956drwxr-xr-x 3 ufo0818 ufo0818 4096 May 4 17:44 data //数据目录drwxr-xr-x 7 ufo0818 ufo0818 4096 May 4 17:44 elasticsearch-2.3.2-rwxr-xr-x 1 ufo0818 ufo0818 27546579 May 4 17:15 elasticsearch-2.3.2.zipdrwxr-xr-x 2 ufo0818 ufo0818 4096 May 4 17:38 logs //日志目录-rw-rw-r-- 1 ufo0818 ufo0818 5 May 4 17:58 pid-rwxr-xr-x 1 ufo0818 ufo0818 239 May 4 17:58 start.sh
启动
用ufo0818去执行,报出如下错误:
[ufo0818@web elasticsearch-2.3.2]$ ./bin/elasticsearchlog4j:ERROR setFile(null,true) call failed.java.io.FileNotFoundException: /data/elasticsearch/logs/elasticsearch.log (Permission denied) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.(FileOutputStream.java:212) at java.io.FileOutputStream. (FileOutputStream.java:136) at org.apache.log4j.FileAppender.setFile(FileAppender.java:294) at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:165) at org.apache.log4j.DailyRollingFileAppender.activateOptions(DailyRollingFileAppender.java:223) at org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:307) at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:172) at org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:104) at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:842) at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:768) at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:648) at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:514) at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:440) at org.elasticsearch.common.logging.log4j.LogConfigurator.configure(LogConfigurator.java:128) at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:243) at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
切换成root用户启动,又报出如下错误:
[2016-05-04 17:38:20,623][ERROR][bootstrap ] Exceptionjava.lang.RuntimeException: don't run elasticsearch as root. at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93) at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144) at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:270) at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
根据elasticsearch的安全策略,不允许用root来启动。
所以得用普通用户启动,但是得具有elasticsearch目录的权限,所以需要执行如下命令来授权
chown - R ufo0818.ufo0818 elasticsearch/
到此,elasticsearch能愉快的启动了。
启动脚本
start.sh
kill `cat pid`echo 'elasticsearch stoped'elasticsearch-2.3.2/bin/elasticsearch -d -p pidecho 'elasticsearch started'
最后的测试结果如下:
[ufo0818@web elasticsearch]$ curl -XGxt http://localhost:9200/{ "name" : "Ardina", "cluster_name" : "elasticsearch", "version" : { "number" : "2.3.2", "build_hash" : "b9e4a6acad4008027e4038f6abed7f7dba346f94", "build_timestamp" : "2016-04-21T16:03:47Z", "build_snapshot" : false, "lucene_version" : "5.5.0" }, "tagline" : "You Know, for Search"}
远程访问
elasticsearch-2.3.2/config/elasticsearch.yml还需要增加如下配置:
network: host: 0.0.0.0
跨域调用
elasticsearch-2.3.2/config/elasticsearch.yml还需要增加如下配置
http.cors.enabled: true http.cors.allow-origin: "*"