CentOS7安裝單機環境的es和Kibana

1.單機環境下es配置

[root@192 bin]# ./elasticsearch
future versions of Elasticsearch will require Java 11; your Java version from [/usr/java/jdk1.8.0_251-amd64/jre] does not meet this requirement
[2020-05-31T15:26:41,446][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [192.168.1.3] 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:163) ~[elasticsearch-7.3.2.jar:7.3.2]
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.3.2.jar:7.3.2]
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.3.2.jar:7.3.2]
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-7.3.2.jar:7.3.2]
	at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.3.2.jar:7.3.2]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.3.2.jar:7.3.2]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.3.2.jar:7.3.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-7.3.2.jar:7.3.2]
	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-7.3.2.jar:7.3.2]
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.3.2.jar:7.3.2]
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.3.2.jar:7.3.2]
	... 6 more

es 6.x之後就不能使用root用戶啓動了,所以需要新建用戶解決方案如下

# 創建用戶組
[root@192 bin]# groupadd huangfu
# 將用戶添加進用戶組
[root@192 bin]# useradd huangfu -g huangfu
#切換用戶
[root@192 bin]# su huangfu
[huangfu@192 bin]$ ./elasticsearch

創建用戶後依舊啓動報錯

[huangfu@192 bin]$ ./elasticsearch
future versions of Elasticsearch will require Java 11; your Java version from [/usr/java/jdk1.8.0_251-amd64/jre] does not meet this requirement
Exception in thread "main" java.nio.file.AccessDeniedException: /opt/elasticsearch/elasticsearch-7.3.2/config/jvm.options
	at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
	at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
	at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
	at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
	at java.nio.file.Files.newByteChannel(Files.java:361)
	at java.nio.file.Files.newByteChannel(Files.java:407)
	at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
	at java.nio.file.Files.newInputStream(Files.java:152)
	at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:61)

這是因爲沒有權限,所以需要將權限修改爲新創建的那個用戶

[root@192 elasticsearch]# chown -R huangfu:huangfu elasticsearch-7.3.2/

再次執行命令

#切換用戶
[root@192 bin]# su huangfu
[huangfu@192 bin]$ ./elasticsearch
future versions of Elasticsearch will require Java 11; your Java version from 
...
[2020-05-31T15:36:49,118][INFO ][o.e.c.m.MetaDataIndexTemplateService] [192.168.1.3] adding template [.monitoring-beats] for index patterns [.monitoring-beats-7-*]
[2020-05-31T15:36:49,244][INFO ][o.e.c.m.MetaDataIndexTemplateService] [192.168.1.3] adding template [.monitoring-alerts-7] for index patterns [.monitoring-alerts-7]
[2020-05-31T15:36:49,379][INFO ][o.e.c.m.MetaDataIndexTemplateService] [192.168.1.3] adding template [.monitoring-kibana] for index patterns [.monitoring-kibana-7-*]
[2020-05-31T15:36:49,554][INFO ][o.e.x.i.a.TransportPutLifecycleAction] [192.168.1.3] adding index lifecycle policy [watch-history-ilm-policy]
[2020-05-31T15:36:50,007][INFO ][o.e.l.LicenseService     ] [192.168.1.3] license [6533531c-753a-4134-ad95-be1bb3e19cc1] mode [basic] - valid
[2020-05-31T15:36:50,008][INFO ][o.e.x.s.s.SecurityStatusChangeListener] [192.168.1.3] Active license is now [BASIC]; Security is disabled

啓動成功了,但是此時外網是無法訪問的,所以我們需要進行配置

# 修改 /elasticsearch-7.3.2/config/elasticsearch.yml文件

# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------

再次啓動依舊會報錯

ERROR: [3] bootstrap checks failed
# 最大文件數太小了,需要增大最大文件數
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
# jvm的最大值也太小了,需要增加
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
# 沒有啓動引導
[3]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

一共是三個錯,一口氣改了

#--------------------------------------------------------
vim /etc/sysctl.conf
# 增加
vm.max_map_count = 655360
# 保存後執行刷新命令
[root@192 bin]# sysctl -p
vm.max_map_count = 655360
#--------------------------------------------------------
vim /etc/security/limits.conf
# 增加 注意不要寫在最後一行   在 End of file之前
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
#--------------------------------------------------------

修改保存後 再次啓動還會報錯

...
ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
...

修改 /elasticsearch-7.3.2/config/elasticsearch.yml文件

# 集羣名稱 這個很重要,集羣環境下,他會一個集羣的標識 
cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
# 節點名稱 集羣中每一個節點的名稱
node.name: node-1
# 集羣環境下有多少節點
cluster.initial_master_nodes: ["node-1"]

修改保存後,再次進入Bin目錄啓動,啓動成功,單機環境配置成功

[huangfu@192 elasticsearch-7.3.2]$ cd bin/
[huangfu@192 bin]$ ./elasticsearch

瀏覽器訪問 http://192.168.1.3:9200/

在這裏插入圖片描述

如上 啓動成功,es單機環境配置成功

# 守護線程啓動es
[huangfu@192 bin]$ ./elasticsearch -d

2. Kibana的安裝

他默認也是不能用root啓動的,我們修改下權限

[root@192 elasticsearch]# chown -R huangfu:huangfu kibana-7.3.2-linux-x86_64/
[root@192 elasticsearch]# cd kibana-7.3.2-linux-x86_64/
[root@192 kibana-7.3.2-linux-x86_64]# cd config/
[root@192 config]# vim kibana.yml
# ----------------------------------配置-------------------------------------------
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://192.168.1.3:9200"]
# ------將語言修改爲中文
i18n.locale: "zh-CN"

啓動

[root@192 config]# cd ../bin/
[root@192 bin]# su huangfu
[huangfu@192 bin]$ ./kibana
# 後臺啓動
[huangfu@192 bin]$ nohup ./kibana &

訪問http://192.168.1.3:5601/

在這裏插入圖片描述

啓動成功 9935

歡迎關注公衆號 關注公衆號,回覆架構師,提供各類技術的學習資料提供參閱!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章