How to configure log rotation for Embedded Elasticsearch in Bitbucket server
プラットフォームについて: Server および Data Center のみ。この記事は、Server および Data Center プラットフォームのアトラシアン製品にのみ適用されます。
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Fisheye および Crucible は除く
要約
This article describes how to configure log rotation for an embedded Elasticsearch instance that is installed alongside Bitbucket Server. The configuration below configures rotation in such a way that the bitbucket-search.log
file will be rotated every time it exceeds 25MB in size. The maximum number of log files retained for a single day is set to 10. Both parameters (size and number of files) can be configured as needed. This approach has been tested with Elasticsearch instances that are bundled with Bitbucket Server, however this should also work with a standalone Elasticsearch instance, such as when using Bitbucket Data Center.
環境
Elasticsearch version 5 and newer
Bitbucket Server version 7.x
ソリューション
Here are the steps to implement size-based log rotation for ES
- Navigate to
<Bitbucket_Home>/shared/search
. You should see a file namedlog4j2.properties.
Edit the
log4j2.properties
file and remove or comment out (by prefixing them with#)
the following lines:log4j2.propertiesappender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}.log appender.rolling.policies.time.type = TimeBasedTriggeringPolicy appender.rolling.policies.time.interval = 1 appender.rolling.policies.time.modulate = true
Then add the following lines:
log4j2.propertiesappender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.log appender.rolling.policies.size.type = SizeBasedTriggeringPolicy appender.rolling.policies.size.size = 25MB appender.rolling.strategy.type = DefaultRolloverStrategy appender.rolling.strategy.max = 10
Restart Bitbucket Server, which will restart the bundled Elasticsearch instance. If you are attempting to apply this configuration to a standalone Elasticsearch instance, you do not need to restart Bitbucket Server, but will need to restart Elasticsearch manually. Once the restart is complete, Elasticsearch will be rotating files as configured, and once the log file has reached the configured threshold, you should be seeing multiple log files in the log directory, such as the ones below.
Bitbucket_Home/log/searchbitbucket_search-2022-02-08-10.log bitbucket_search-2022-02-08-1.log bitbucket_search-2022-02-08-2.log bitbucket_search-2022-02-08-3.log bitbucket_search-2022-02-08-4.log bitbucket_search-2022-02-08-5.log bitbucket_search-2022-02-08-6.log bitbucket_search-2022-02-08-7.log bitbucket_search-2022-02-08-8.log bitbucket_search-2022-02-08-9.log bitbucket-search.log