ElasticSearch(一)CentOs6.4下安裝ElasticSearch

一、準(zhǔn)備工作

Elastic 需要 Java 8 環(huán)境。如果你的機器還沒安裝 Java,先需要安裝java環(huán)境,同時還注意要保證環(huán)境變量JAVA_HOME正確設(shè)置。

下載地址:
https://pan.baidu.com/s/1kGHTtXbM1URHVz5dQQiwbg 
提取碼:ktxi 

習(xí)慣性下載到/usr/local/src目錄下,解壓并創(chuàng)建軟連接,方便配置環(huán)境變量

#tar zxf jdk-8u91-linux-x64.tar.gz -C /usr/local/  //解壓
#ln –s /usr/local/jdk1.8.0_91 /usr/local/jdk       //創(chuàng)建軟連接
# vim /etc/profile                    //把下面三行代碼放在底部
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
# source /etc/profile                    //編輯完成之后執(zhí)行命令生效

二、配置安裝ElasticSearch(這里是源碼包方式安裝版本elasticsearch-2.4.1,rpm包形式安裝)

下載

wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.4.1/elasticsearch-2.4.1.rpm 

安裝

# yum -y install elasticsearch-2.4.1.rpm  

修改配置文件

# vim /etc/elasticsearch/elasticsearch.yml

#集群名稱
cluster.name: my-application
#節(jié)點名稱
node.name: node-1
#數(shù)據(jù)存儲路徑
path.data: /var/lib/elasticsearch
#日志存儲路徑
path.logs: /var/log/elasticsearch
#將來訪問elastic的話,都是通過API訪問,在這我們要提供一個http主機地址,這里就是本機IP
network.host: 192.168.9.155  
#默認(rèn)端口
http.port: 9200

啟動ElasticSearch

#servicc elasticsearch start //啟動測試

這里遇到了幾個錯誤~

  • 錯誤一:不能root用戶啟動
[2018-01-11T09:48:34,177][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] 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.2.jar:5.1.2]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-5.1.2.jar:5.1.2]
    at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) ~[elasticsearch-5.1.2.jar:5.1.2]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.1.2.jar:5.1.2]
    at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.1.2.jar:5.1.2]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:89) ~[elasticsearch-5.1.2.jar:5.1.2]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:82) ~[elasticsearch-5.1.2.jar:5.1.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:100) ~[elasticsearch-5.1.2.jar:5.1.2]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:176) ~[elasticsearch-5.1.2.jar:5.1.2]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:306) ~[elasticsearch-5.1.2.jar:5.1.2]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-5.1.2.jar:5.1.2]
    ... 6 more

解決(創(chuàng)建新用戶)

#groupadd elasticsearch
#useradd elasticsearch -g elasticsearch -p elasticsearch
#cd /opt
#chown -R elasticsearch:elasticsearch /usr/local/elasticsearch
  • 錯誤二:啟動檢查沒有通過
[2018-01-11T09:55:14,892][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [transport-netty4]
[2018-01-11T09:55:14,894][INFO ][o.e.p.PluginsService     ] [node-1] no plugins loaded
[2018-01-11T09:55:35,673][INFO ][o.e.n.Node               ] [node-1] initialized
[2018-01-11T09:55:35,674][INFO ][o.e.n.Node               ] [node-1] starting ...
[2018-01-11T09:55:35,278][INFO ][o.e.t.TransportService   ] [node-1] publish_address {192.168.9.149:9300}, bound_addresses {192.168.9.149:9300}
[2018-01-11T09:55:35,288][INFO ][o.e.b.BootstrapCheck     ] [node-1] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
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]
[2018-01-11T09:55:35,336][INFO ][o.e.n.Node               ] [node-1] stopping ...
[2018-01-11T09:55:35,399][INFO ][o.e.n.Node               ] [node-1] stopped
[2018-01-11T09:55:35,399][INFO ][o.e.n.Node               ] [node-1] closing ...
[2018-01-11T09:55:35,461][INFO ][o.e.n.Node               ] [node-1] closed

①解決max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]。記住root用戶修改完文件,切換到elasticsearch用戶啟動服務(wù)時,還會報錯,記得一定再切換root,再切回elasticsearch用戶啟動方可成功

#vim  /etc/security/limits.conf //在底部添加兩行代碼,讓人需要切換到root用戶哦
* soft nofile 65536
* hard nofile 65536

②解決max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

# vim  /etc/security/limits.conf       //添加下面一行
vm.max_map_count=655360             //添加此行
#sysctl -p                                //添加完成執(zhí)行此命令

切換到elasticsearch用戶重新啟動服務(wù),返回下面提示即表示成功~

[2018-01-11T09:59:30,435][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [transport-netty3]
[2018-01-11T09:59:30,435][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [transport-netty4]
[2018-01-11T09:59:30,437][INFO ][o.e.p.PluginsService     ] [node-1] no plugins loaded
[2018-01-11T09:59:38,364][INFO ][o.e.n.Node               ] [node-1] initialized
[2018-01-11T09:59:38,364][INFO ][o.e.n.Node               ] [node-1] starting ...
[2018-01-11T09:13:38,903][INFO ][o.e.t.TransportService   ] [node-1] publish_address {192.168.9.149:9300}, bound_addresses {192.168.9.149:9300}
[2018-01-11T09:59:38,912][INFO ][o.e.b.BootstrapCheck     ] [node-1] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2018-01-11T09:59:45,164][INFO ][o.e.c.s.ClusterService   ] [node-1] new_master {node-1}{Tjz6HoyoR1KhuIuhE7A8FA}{CTQ4R5bjQ02yNoPlUwasQw}{192.168.9.149}{192.168.9.149:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2018-01-11T09:59:45,268][INFO ][o.e.h.HttpServer         ] [node-1] publish_address {192.168.9.149:9200}, bound_addresses {192.168.9.149:9200}
[2018-01-11T09:59:45,268][INFO ][o.e.n.Node               ] [node-1] started
[2018-01-11T09:59:45,301][INFO ][o.e.g.GatewayService     ] [node-1] recovered [0] indices into cluster_state
  • 錯誤三:java_path路徑
which: no java in (/sbin:/usr/sbin:/bin:/usr/bin)
Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME

解決辦法:

# vim /etc/sysconfig/elasticsearch  //添加下面一行到末尾
JAVA_HOME=/usr/local/jdk

OK~~啟動成功

# service elasticsearch start
Starting elasticsearch:                                    [  OK  ]

試著curl訪問


11.png

關(guān)掉防火墻瀏覽器訪問


12.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容