環(huán)境
- CentOS7
- 請確保已經(jīng)安裝了jdk1.8或更高的版本
下載
選擇要下載的独榴,我下載的是TAR
签孔。按需要下載照激。
解壓
我已經(jīng)將安裝包放在了usr/local/software
目錄下趋箩。
[root@localhost software]# pwd
/usr/local/software
[root@localhost software]# ls
elasticsearch-6.3.2.tar.gz
解壓安裝包着绊,得到 elasticsearch-6.3.2
畦娄。
tar -zxvf elasticsearch-6.3.2.tar.gz
我將elasticsearch-6.3.2
移動到了usr/local/dev-env
目錄下又沾。
[root@localhost dev-env]# pwd
/usr/local/dev-env
[root@localhost dev-env]# mv /usr/local/software/elasticsearch-6.3.2 elasticsearch-6.3.2
[root@localhost dev-env]# ls
elasticsearch-6.3.2 jdk1.8.0_181
啟動異常
當我在elastic下執(zhí)行./bin/elasticsearch
,啟動elastic的時候熙卡,報了一下錯誤:
[2018-08-09T18:11:32,675][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:140) ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.3.2.jar:6.3.2]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.3.2.jar:6.3.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.3.2.jar:6.3.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:326) ~[elasticsearch-6.3.2.jar:6.3.2]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.3.2.jar:6.3.2]
... 6 more
創(chuàng)建用戶
從上面可以看出杖刷,我們不能用root來啟動es,那么我們就新建一個用戶
# 添加用戶 elastic
adduser elastic
# 給用戶elastic設置密碼驳癌,按照提示輸入自己的密碼
passwd elastic
# 設置權(quán)限
chown -R elastic /usr/local/dev-env/elasticsearch-6.3.2
# 切換用戶
su elastic
# 查看權(quán)限
ll
啟動elasticsearch
./bin/elasticsearch
## 以守護進程在后臺運行
./bin/elasticsearch -d
測試啟動結(jié)果
執(zhí)行以下操作滑燃,查看輸出
curl 'http://localhost:9200'
當然在執(zhí)行時,可能會碰到下面問題
curl: (7) Failed connect to localhost:9200; Connection refused
我們只需要關閉防火墻
service firewalld stop
然后再運行颓鲜,我們可以看到輸出如下內(nèi)容:
{
"name" : "7KfHH2X",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "XihaCbM2Q9Sk3w6yJRhHEw",
"version" : {
"number" : "6.3.2",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "053779d",
"build_date" : "2018-07-20T05:20:23.451332Z",
"build_snapshot" : false,
"lucene_version" : "7.3.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
外部訪問
上面的設置只能在本地上能訪問表窘。我的linux是按照在虛擬機上的,現(xiàn)在我要在電腦的瀏覽器上訪問甜滨。我們發(fā)現(xiàn)是不行的乐严。那么我們需要新的設置
修改elasticsearch目錄下的config/elasticsearch.yml
文件
# 設置所有ip都能訪問
network.host: 0.0.0.0
http.port: 9200
其他問題
當我們設置好上面的配置是,又出現(xiàn)了其他的問題衣摩,下面一個個的處理
ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
上面出現(xiàn)了兩個問題昂验,我們一個個的處理。我們先切回到root
用戶艾扮。
- 問題 [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
修改文件/etc/security/limits.conf
既琴,在其后面追加如下內(nèi)容:
* soft nofile 65536
* hard nofile 65536
- 問題 [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
修改文件 /etc/sysctl.conf
, 在其后面追加如下內(nèi)容:
vm.max_map_count=655360
使用命令 sysctl -p
使剛才的設置生效。
最后泡嘴,我們切換到elastic
用戶甫恩,并啟動服務./bin/elasticsearch
,我們發(fā)現(xiàn)啟動成功磕诊,并且能在其他的機器上訪問到es了填物。