kafka 定時刪除數據
kafka 刪除數據其實刪除其日誌,kafka 的數據其實是kafka 的message 固化到硬盤形成的,她允許配置成一定的策略來刪除數據,。
數據刪除的方式:首先進入kafka的安裝目錄,找到其中的config文件夾,然後進入,在裏面找到server.properties 文件, 編輯該文件 vi server.properties
操作如下:
cd /usr/oozie
cd config
vi server.properties
在文件中找到 如下文件,
############################# Log Retention Policy #############################
# The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.
# The minimum age of a log file to be eligible for deletion due to age
log.retention.hours=168
# A size-based retention policy for logs. Segments are pruned from the log unless the remaining
# segments drop below log.retention.bytes. Functions independently of log.retention.hours.
#log.retention.bytes=1073741824
# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=1073741824
# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000
從上面的選項中,可以看到這幾個可以設置的地方
/* 數據可以保留的最大時長, 達到這個時長的時候, 會刪除數據 */
log.retention.hours=168
/* 數據保留的最大值, 達到這個值, 會刪除這個數據 */
log.segment.bytes=1073741824
/* 當一個日誌塊達到指定的值時,會創建新的日塊*/
log.segment.bytes=1073741824
/* 檢查每個日誌塊的時間間隔 */
log.retention.check.interval.ms=300000
爲了避免在刪除時阻塞讀操作,採用了copy-on-write形式的實現,刪除操作進行時,讀取操作的二分查找功能實際是在一個靜態的快照副本上進行的
文章也會在公衆號更新,歡迎關注!