Elasticsearch配置

配置文件位置

rpm和Debian安裝包默認放在/etc/elasticserach下面。
如果你自己下載java包到/data(注意elasticserach需要java se環境),那么之后根據官方文檔的也會放在/data下。

你也可以修配置文件的位置

./bin/elasticsearch -Epath.conf=/path/to/my/config/

配置文件格式:

下面修改數據和日志存放的目錄

path: data: /var/lib/elasticsearch 
logs: /var/log/elasticsearch

也可以這樣子寫

path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch

環境變量的替代

環境變量設置的格式為${...},
例如

node.name:  ${HOSTNAME}
network.host: ${ES_NETWORK_HOST}

第一個修改節點的名字,第二個修改可訪問到該節點的IP。

即時設置:(不會被寫進去配置文件中)

我們可以使用

${promp.text}
${promp.secret}

在前臺中開啟elasticsearch,使用prompt.secret時,在終端輸入的內容不會顯示出來,提高安全性。

例子:

node: name: ${prompt.text}

當我們開啟elasticsearch之后,會讓你輸入節點的名字

Enter value for [node.name]:
注意:Elasticsearch不會把${prompt.text}或者${prompt.secret}的設置用于service或者background的進程。

默認設置

在開啟elasticsearch時,可以在命令行中使用

default.

前綴使用默認設置,如下:

./bin/elasticsearch -Edefault.node.name=My_Node

節點的名字就是My_Node。當然我們也可以直接在config直接修改或者在命令行下重寫節點名字。(使用es.node.name)

日志輸出配置

Elasticseach使用

Log4j 2
http://logging.apache.org/log4j/2.x/

的格式來輸出日志。
我們可以使用Log4j 2屬性文件來配置Log4j 2 。Elasticsearch開放一個屬性

${sys:es.logs}

這個可以在配置文件中找到,它是用于設置日志文件存放的目錄。在runtime時這個路徑會成為Elasticsearch log目錄的前綴。

舉個例子:如果你的日志目錄(path.logs)是

/var/log/elasticsearch

然后你的cluster的名字是production,那么${sys:es.logs}將會是

/var/log/elasticsearch/production
appender.rolling.type = RollingFile  #1
appender.rolling.name = rolling
appender.rolling.fileName = ${sys:es.logs}.log  #2
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] 
%.10000m%n
appender.rolling.filePattern = ${sys:es.logs}-%d{yyyy-MM-dd}.log #3
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy #4
appender.rolling.policies.time.interval = 1 #5
appender.rolling.policies.time.modulate = true #6

1:Configure the RollingFile appender
2:日志輸出到 /var/log/elasticsearch/production.log
3:Roll logs to /var/log/elasticsearch/production-yyyy-MM-dd.log
4:Using a time-based roll policy
5:Roll logs on a daily basis
6:Align rolls on the day boundary (as opposed to rolling every twenty-four hours)

如果你添加.gz或者.zip到appender.roolling.filePattern,那么日志將會被壓縮

Multiple configuration files can be loaded (in which case they will get merged) as long as they are named log4j2.properties
and have the Elasticsearch config directory as an ancestor; this is useful for plugins that expose additional loggers. The logger section contains the java packages and their corresponding log level. The appender section contains the destinations for the logs. Extensive information on how to customize logging and all the supported appenders can be found on the Log4j documentation.

Deprecation logging

名詞解釋:"A deprecation log has been introduced to track calls to deprecated/outdated methods in the TYPO3 Core. Developers have to make sure to adjust their code to avoid using this old functionality since deprecated methods will be removed in future TYPO3 releases! The information can be found in /typo3conf/deprecation_[hash-value].log The install tool has a setting "enableDeprecationLog" that allows one to disable the logging of deprecation messages since the file might grow quite fast depending on the extensions installed."

為了能夠正常地進行日志輸出,Elasticsearch允許你使用廢棄的(過時的)
方法。默認地,deprecation logging 能夠在WRAN等級下使用:

logger.deprecation.level = warn

詳情參考:

https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html#logging

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • Spring Boot 參考指南 介紹 轉載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 46,925評論 6 342
  • 在應用程序中添加日志記錄總的來說基于三個目的:監視代碼中變量的變化情況,周期性的記錄到文件中供其他應用進行統計分析...
    時待吾閱讀 5,014評論 0 6
  • 一、Log4j簡介 Log4j有三個主要的組件:Loggers(記錄器),Appenders (輸出源)和Layo...
    默默守護閱讀 1,923評論 2 8
  • from:https://www.cnblogs.com/ITtangtang/p/3926665.html一、L...
    enshunyan閱讀 3,320評論 0 0
  • 這個世界百媚千紅,情有百種。 有兩種情感,可以稱之為真誠。一種是相濡以沫,另一種叫相忘于江湖。我們要做的,是與正在...
    我是李寨主閱讀 1,162評論 10 19