一、準備工作
Elastic 需要 Java 8 環境。如果你的機器還沒安裝 Java,先需要安裝java環境,同時還注意要保證環境變數JAVA_HOME正確設定。
連結:https://pan.baidu.com/s/1X8IMOw9AWsZjQqu8KYX2ww 密碼:s1ov//百度雲分享連結/如果失效了可以找我要
習慣性下載到/usr/local/src目錄下,解壓並建立軟連線,方便配置環境變數
#tar zxf jdk-8u91-linux-x64.tar.gz -C /usr/local/ //解壓
#ln –s /usr/local/jdk1.8.0_91 /usr/local/jdk //建立軟連線
# 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 //編輯完成之後執行命令生效
# java -version //執行命令,出現下面三行程式碼表示成功
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
二、配置安裝ElasticSearch(這裡是原始碼包方式安裝版本elasticsearch-2.4.1,rpm包形式安裝)
下載安裝
連結:https://pan.baidu.com/s/1nQw03ONklUyYWRQ2hKaHUw 密碼:pmj5 //百度雲地址
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
#節點名稱
node.name: node-1
#資料儲存路徑
path.data: /var/lib/elasticsearch
#日誌儲存路徑
path.logs: /var/log/elasticsearch
#將來訪問elastic的話,都是通過API訪問,在這我們要提供一個http主機地址,這裡就是本機IP
network.host: 192.168.9.155
#預設埠
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
解決(建立新使用者)
#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使用者啟動服務時,還會報錯,記得一定再切換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 //新增完成執行此命令
切換到elasticsearch使用者重新啟動服務,返回下面提示即表示成功~
[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訪問
關掉防火牆瀏覽器訪問
OK~