新地址體驗:http://www.zhouhong.icu/post/139
一、Logstash介紹
Logstash是elastic技術棧中的一個技術。它是一個數據采集引擎,可以從數據庫采集數據到es中。我們可以通過設置自增id主鍵或者時間來控制數據的自動同步,這個id或者時間就是用於給logstash進行識別的
id:假設現在有1000條數據,Logstatsh識別后會進行一次同步,同步完會記錄這個id為1000,以后數據庫新增數據,那么id會一直累加,Logstatsh會有定時任務,發現有id大於1000了,則增量加入到es中
時間:同理,一開始同步1000條數據,每條數據都有一個字段,為time,初次同步完畢后,記錄這個time,下次同步的時候進行時間比對,如果有超過這個時間的,那么就可以做同步,這里可以同步新增數據,或者修改元數據,因為同一條數據的時間更改會被識別,而id則不會。
二、安裝Logstash
Elasticsearch安裝,集群搭建請移步:
ES安裝:http://www.zhouhong.icu/post/128
ES集群搭建、與SpringBoot整合:http://www.zhouhong.icu/post/138
准備:
- 數據庫:db_mblog
- 表:mto_post
- Logstatsh
- mysql-connector-java-8.0.11.jar
數據准備:
CREATE TABLE `mto_post` ( `id` DOUBLE , `author_id` DOUBLE , `channel_id` DOUBLE , `comments` DOUBLE , `created` DATETIME , `favors` DOUBLE , `featured` DOUBLE , `status` DOUBLE , `summary` VARCHAR (420), `tags` VARCHAR (192), `thumbnail` VARCHAR (384), `title` VARCHAR (192), `views` DOUBLE , `weight` DOUBLE ); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('35','1','1','0','2020-02-11 11:17:24','0','0','0','如果有來生,要做一棵樹, 站成永恆。沒有悲歡的姿勢, 一半在塵土里安詳, 一半在風里飛揚; 一半灑落蔭涼, 一半沐浴陽光。 非常沉默、非常驕傲。 從不依靠、從不尋找。 如果有來生,要化成一陣風, 一瞬間也能成為永恆。 沒有善感的情懷, 沒有多情的...','','//qiniusave.zhouhong.icu/3NSPTP433IDHNH7G9FLEL1ANU3.jpg','如果有來生---三毛','110','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('37','1','1','0','2020-02-13 13:51:34','2','0','0','從明天起,做一個幸福的人 喂馬、劈柴,周游世界 從明天起,關心糧食和蔬菜 我有一所房子,面朝大海,春暖花開; 從明天起,和每一個親人通信 告訴他們我的幸福 那幸福的閃電告訴我的 我將告訴每一個人; 給每一條河每一座山取一個溫暖的名字 陌生人,我也...','夏日','//qiniusave.zhouhong.icu/2VPB7PA4NFLG1MP764H1NRMILN.jpg','面朝大海,春暖花開','64','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('38','1','1','0','2020-02-21 13:55:27','1','0','0','人生有一首詩, 當我們擁有它的時候, 往往並沒有讀懂它; 而當我們能夠讀懂它的時候, 它卻早已遠去, 這首詩的名字就叫 青春。 青春是那么美好, 在這段不可復制的旅途當中, 我們擁有獨一無二的記憶, 不管它是迷茫的、孤獨的、不安的, 還是歡騰的、...','時光','//qiniusave.zhouhong.icu/1VHFIK2DVSGUCJNPDL707NEBIN.jpg','青春','95','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('39','1','5','0','2021-01-15 14:45:42','0','1','0','>歡迎訪問我的博客園:Tom-shushu的博客園 56、關於緩存穿透,緩存擊穿,緩存雪崩,熱點數據失效問題的解決方案 55、CENTOS7下用FASTDFS搭建圖片服務器 54、JAVA實現PDF和EXCEL生成和數據動態插入以及導出 5...','博客園搬家','//qiniusave.zhouhong.icu/GJEPCOMLNME5EVODJVRQV1EL.jpg','我的博客園博文搬新家啦^_^','224','3'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('40','1','1','1','2020-03-21 20:59:27','0','0','0','我有時喜歡一個人行走。閑暇之余,能夠不做閑人,卻又不能夠沒有閑情。這樣一來,我有時就喜歡一個人行走。在這個喧囂的世界里,唯有一個人行走才沒有羈絆束縛;唯有一個人行走才能感覺到自己真實的心跳;唯有一個人行走才能放縱屬於自己的那份情緒。在一個人中享受...','微笑','//qiniusave.zhouhong.icu/QL7IAJGT9I3MIC7QNAEVI80FP.jpg','獨處--領悟','207','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('43','1','5','0','2020-04-19 02:46:56','0','1','0','關於緩存穿透,緩存擊穿,緩存雪崩,熱點數據失效問題的解決方案 1.我們使用緩存時的業務流程大概為: 當我們查詢一條數據時,先去查詢緩存,如果緩存有就直接返回,如果沒有就去查詢數據庫,然后返回。這種情況下就可能出現下面的一些現象。 2.緩存穿透 ...','Redis 緩存,博客園遷移','//qiniusave.zhouhong.icu/13I57KJ8PRII7RIQIP60F5RTFA.jpg','關於緩存穿透,緩存擊穿,緩存雪崩,熱點數據失效問題的解決方案','30','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('44','1','4','0','2020-04-24 15:06:24','0','0','0','LeetCode傳送門:判斷一個整數是否是回文數 package com.zhouhong.LeetCode; import java.util.Stack; public class LeetCode0009 { //判斷一個整數是否是回文數。...','LeetCode','//qiniusave.zhouhong.icu/3P1G4QARU5FC6CD80AB0J4QCPF.jpg','LeetCode0009:判斷一個整數是否是回文數','5','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('45','1','4','0','2020-05-07 21:10:47','0','0','0','傳送門:LeetCode26原地刪除重復出現的排序元素 package com.zhouhong.LeetCode; //給定一個排序數組,你需要在 原地 刪除重復出現的元素,使得每個元素只出現一次,返回移除后數組的新長度。 // 不要使用額外的...','雙指針,LeetCode','//qiniusave.zhouhong.icu/3F64LCIEC353EFOU9RH35S10C1.jpg','LeetCode0026:原地刪除重復出現的排序元素','7','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('46','1','4','0','2020-06-15 10:15:04','0','0','0','傳送門:LeetCode27原地移除目標值 package com.zhouhong.LeetCode; //給你一個數組 nums 和一個值 val,你需要 原地 移除所有數值等於 val 的元素,並返回移除后數組的新長度。 // 不要使用額外...','LeetCode,雙指針,數組','//qiniusave.zhouhong.icu/3LLSKK2ETVUCHKFMML1HMEJ3H5.jpg','LeetCode0027:原地移除目標值','5','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('47','1','4','0','2020-09-19 17:31:01','0','0','0','傳送門:LeetCode0034找出排序數組中給定值的開始結束位置 package com.zhouhong.LeetCode; import java.util.ArrayList; /** *給定一個按照升序排列的整數數組 nums,和一個目...','LeetCode,數組','//qiniusave.zhouhong.icu/3U38M4FL08SO1SBFU7282F15AH.jpg','LeetCode0034:找出排序數組中給定值的開始結束位置','9','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('48','1','4','0','2020-10-08 12:36:30','0','0','0','傳送門:LeetCode0035搜索插入位置 package com.zhouhong.LeetCode; /** * 給定一個排序數組和一個目標值,在數組中找到目標值,並返回其索引。 * 如果目標值不存在於數組中,返回它將會被按順序插入的位置。...','數組,二分搜索,LeetCode','//qiniusave.zhouhong.icu/4F2BNHQL652GQVN6EU6EAKUCU.jpg','LeetCode0035:搜索插入位置','8','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('49','1','4','0','2020-10-11 18:41:03','0','0','0','傳送門:LeetCode0075顏色分類排序 package com.zhouhong.LeetCode; import java.util.Arrays; //給定一個包含紅色、白色和藍色,一共 n 個元素的數組,原地對它們進行排序,使得相同顏...','快排,LeetCode','//qiniusave.zhouhong.icu/1CRLSEE4KFD9RT3SMRBBI7RDTT.jpg','LeetCode0075:顏色分類排序','7','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('50','1','4','0','2020-10-15 15:47:24','0','0','0','傳送門:LeetCode0136只出現一次的元素 package com.zhouhong.LeetCode; import java.util.Arrays; //給定一個非空整數數組,除了某個元素只出現一次以外,其余每個元素均出現兩次。找出那...','LeetCode,雙指針','//qiniusave.zhouhong.icu/2GTM1BRNT8EARTTVKAAOJ4KOJM.jpg','LeetCode0136:只出現一次的元素','12','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('51','1','4','0','2020-10-20 09:57:02','0','0','0','傳送門:LeetCode0164最大間距,排序后兩兩數字直接最大的差值 package com.zhouhong.LeetCode; import java.util.Arrays; //給定一個無序的數組,找出數組在排序之后,相鄰元素之間最大的...','LeetCode,雙指針','//qiniusave.zhouhong.icu/G7MRRA45B1G2BDEE422V93PMH.jpg','LeetCode0164:最大間距,排序后兩兩數字直接最大的差值','13','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('52','1','4','0','2020-11-07 15:59:40','0','0','0','傳送門:LeetCode0206翻轉一個單鏈表 package com.zhouhong.LeetCode; public class LeetCode0206 { public class ListNode { int val; ListNod...','LeetCode,鏈表','//qiniusave.zhouhong.icu/25D5QTG1CPRRAO1MTGH5CAIB08.jpg','LeetCode0206:翻轉一個單鏈表','13','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('53','1','4','0','2020-11-19 16:02:28','0','0','0','傳送門:LeetCode0242有效的字母異位詞 package com.zhouhong.LeetCode; import java.util.Arrays; //給定兩個字符串 s 和 t ,編寫一個函數來判斷 t 是否是 s 的字母異位詞。...','LeetCode','//qiniusave.zhouhong.icu/1ICO3UF95GO0C91NVNOI76E5E5.jpg','LeetCode0242:有效的字母異位詞','21','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('66','1','4','0','2020-12-01 11:28:56','0','0','0','傳送門:LeetCode283移動零 給定一個數組 nums,編寫一個函數將所有 0 移動到數組的末尾,同時保持非零元素的相對順序。 必須在原數組上操作,不能拷貝額外的數組。盡量減少操作次數。 一、雙指針解決 /** * 分為兩種情況:...','LeetCode,雙指針','//qiniusave.zhouhong.icu/2VPB7PA4NFLG1MP764H1NRMILN.jpg','LeetCode0283:移動零','19','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('67','1','4','1','2020-12-06 19:32:54','0','0','0','傳送門:LeetCode0287尋找重復的數 給定一個包含 n + 1 個整數的數組 nums,其數字都在 1 到 n 之間(包括 1 和 n),可知至少存在一個重復的整數。假設只有一個重復的整數,找出這個重復的數。 說明:// 不能更改原數組(...','LeetCode,雙指針','//qiniusave.zhouhong.icu/2HSPJJEUOQP9DC4AGG7D92CJ09.jpg','LeetCode0287:尋找重復的數','34','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('68','1','4','0','2020-12-10 20:37:29','0','0','0','數組中有一個數字出現的次數超過數組長度的一半,請找出這個數字。例如輸入一個長度為9的數組{1,2,3,2,2,2,5,4,2}。由於數字2在數組中出現了5次,超過數組長度的一半,因此輸出2。如果不存在則輸出0 /** * 排序后,次數大於一半,...','字符串,算法','//qiniusave.zhouhong.icu/3L7DV6AKJ0SEJ5D4QQ408C78LE.jpg','找出次數超過數組一半長度的數','32','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('69','1','4','0','2020-12-28 21:42:13','0','0','0','方法一、循環實現 static void method1(){ Scanner in = new Scanner(System.in); String str = in.nextLine(); char[] arr = str.toCharAr...','算法','//qiniusave.zhouhong.icu/TO6E9PCMLB92EL0AR1HQJ5GA8.jpg','5種方法實現字符串翻轉','27','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('70','1','8','0','2021-01-11 16:44:46','1','0','0','package com.zhouhong.util; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; imp...','工具','//qiniusave.zhouhong.icu/2GTM1BRNT8EARTTVKAAOJ4KOJM.jpg','SQL轉Java工具','25','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('71','1','4','0','2021-01-13 00:18:37','0','0','0','傳送門:LeetCode0455分發餅干 一、題目描述 假設你是一位很棒的家長,想要給你的孩子們一些小餅干。但是,每個孩子最多只能給一塊餅干。 對每個孩子 i,都有一個胃口值 g[i],這是能讓孩子們滿足胃口的餅干的最小尺寸;並且每塊餅...','貪心算法,LeetCode','//qiniusave.zhouhong.icu/3MBBFME404DS6EMAVMAA4LHAPK.jpg','貪心算法--LeetCode0455分發餅干','17','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('72','1','4','0','2021-01-19 01:53:11','0','0','0','LeetCode0509斐波那契數列 一、題目 斐波那契數,通常用 F(n) 表示,形成的序列稱為 斐波那契數列 。該數列由 0 和 1 開始,后面的...','動態規划,LeetCode,斐波那契','//qiniusave.zhouhong.icu/1ES930G0D90TIIDB7LLGGDFGG.jpg','動態規划--LeetCode0509斐波那契數列,不同方法耗時比較','61','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('74','14','8','0','2021-01-21 23:45:20','0','0','0','1.空格:默認匹配、普通匹配 location / { root /home; } 2.= :精確匹配(表示匹配到 /home/resources/img/face.png 這張圖片) location = /resourc...','Nginx','//qiniusave.zhouhong.icu/2U5F2D30E1BGD8GTVVI830BDF7.jpg','Nginx配置文件nginx.conf中location的匹配原則','19','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('79','1','8','0','2021-01-23 12:50:08','0','0','0','跨域問題的本質: 兩個站點域名不一樣,就會出現跨域問題。 所以跨域問題的本質是域名不同 一、跨域問題解決 1、CORS跨域資源共享---Cross-origin resource sharing 它允許瀏覽器向跨源服務器,發出XMLHttpReq...','跨域,Nginx,架構','//qiniusave.zhouhong.icu/2R5POVKLSG2JTH0B3LVVR337QP.jpg','Nginx、SprongBoot Cors解決跨域問題與Nginx中靜態資源防盜鏈配置','10','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('80','1','8','0','2021-01-23 13:21:46','0','0','0','一、Linux下Nginx的安裝 1.去官網 http://nginx.org/download/下載對應的Nginx安裝包,推薦使用穩定版本。 2.上傳Nginx到Linux服務器。 3.安裝依賴環境 (1)安裝gcc環境 yum inst...','Nginx,架構','//qiniusave.zhouhong.icu/3J6TGJ2KOSSEDFCEJHR056M91E.jpg','Nginx安裝/進程模型/事件處理機制/詳細配置/定時切割日志','19','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('82','1','4','0','2021-01-24 01:08:41','0','0','0','傳送門:LeetCode0070爬樓梯問題 題目: 假設你正在爬樓梯。需要 n 階你才能到達樓頂。每次你可以爬 1 或 2 個台階。你有多少種不同的方法可以爬到樓頂呢? 跟斐波那契數列一樣 解法一、使用動態規划方法解決 cl...','斐波那契,LeetCode,動態規划','//qiniusave.zhouhong.icu/2NMPPF6J9ENNRG7IDS8O1HU9Q7.jpg','動態規划--LeetCode0070爬樓梯問題','14','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('83','1','8','0','2021-01-24 11:22:05','0','0','0','一、Nginx模塊化體系結構 event module:事件模塊 phase handler:處理客戶端請求和內容相應 output filter:輸出過濾,例如gzip,upstream 反向代理模塊,會把請求打到真正的服務器去處理 load ...','Nginx,架構,負載均衡','//qiniusave.zhouhong.icu/3894VA2SDV5G84FUN95A4FEADG.jpg','Nginx集群、負載均衡解析','14','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('84','1','8','0','2021-01-24 13:26:04','0','0','0','一、四層負載均衡 四層負載均衡 : 能夠為企業網絡設備或者服務器帶來更好的服務,提高吞吐量、提升並發性能、增強服務器的處理能力,並且可以提高服務器計算能力,使得我們的網絡設備更加靈活。 負載均衡是當有大量的並發請求來到服務器的時...','架構,Nginx','//qiniusave.zhouhong.icu/1H8HTTRSR9J46EN8BDDOGU353S.jpg','四層、七層和DNS負載均衡','22','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('85','1','8','0','2021-01-24 13:55:57','0','0','0','一、利用Nginx構建三台TomCat集群 我們現在有四台機器,一台用來做Nginx負載用,另外三台為正常的集群節點。 配置反向代理: 配置一個server虛擬主機,用來監聽端口,用來接收http請求 location配置proxy_pass ...','Nginx,負載均衡','//qiniusave.zhouhong.icu/FHLEQ8SEBVO0PB26OVO3P7PQT.jpg','Nginx集群構建以及負載均衡策略---輪詢、加權輪詢','19','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('86','1','8','0','2021-01-24 14:53:54','0','0','0','一、max_conns max_conns 用於限制一台服務器的最大連接數,默認值是0表示無限制,每個工作進程都能生效,限流,老版本要商業版才能使用; # worker進程設置1個,便於測試觀察成功的連接數 worker_processes 1;...','Nginx,架構','//qiniusave.zhouhong.icu/1MGQUSCKEGCA91VF9AOH26MNUR.jpg','Nginx中upstream指令參數解析和keepalive提高吞吐量','28','0'); INSERT INTO `mto_post` (`id`, `author_id`, `channel_id`, `comments`, `created`, `favors`, `featured`, `status`, `summary`, `tags`, `thumbnail`, `title`, `views`, `weight`) VALUES('98','1','8','0','2021-01-24 21:45:33','0','0','0','一、今天登錄我的網站,突然發現報了下面的一個錯誤: 我的第一反應是:超時了應該是Nginx代理沒有設置超時時間,默認的超時時間估計太小了,然后就按照正常的方式用Xshell連接服務器,應該是網絡或者是其他的原因吧,好巧不巧的我的Xshell連接...','問題','//qiniusave.zhouhong.icu/2D98FKFVS216MBOIS5TS9CTR7R.jpg','Nginx報504 gateway timeout錯誤的解決方法','33','0');
官方鏈接:
https://www.elastic.co/cn/downloads/past-releases
注:使用Logstatsh的版本號與elasticsearch版本號需要保持一致
本插件用於同步,es6.x起自帶,這個是集成在了 logstash中的。所以直接配置同步數據庫的配置文件即可。
-
解壓
tar -zxvf logstash-6.4.3.tar.gz
-
將解壓文件夾移到 /usr/local 下面
mv logstash-6.4.3 /usr/local
-
進入目錄新建文件夾
cd /usr/local/logstash-6.4.3/ mkdir sync
-
進入 sync 目錄新建 logstash-db-sync.conf 和 my_blog.sql 兩個文件
-
logstash-db-sync.conf 內容如下
-
-
input { jdbc { # 設置 MySql/MariaDB 數據庫url以及數據庫名稱 jdbc_connection_string => "jdbc:mysql://192.168.2.158:3306/db_mblog?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=GMT" # 用戶名和密碼 jdbc_user => "root" jdbc_password => "root" # 數據庫驅動所在位置,可以是絕對路徑或者相對路徑(在maven 倉庫里面可以得到) jdbc_driver_library => "/usr/local/logstash-6.4.3/sync/mysql-connector-java-8.0.11.jar" # 驅動類名 jdbc_driver_class => "com.mysql.cj.jdbc.Driver" # 開啟分頁 jdbc_paging_enabled => "true" # 分頁每頁數量,可以自定義 jdbc_page_size => "10000" # 執行的sql文件路徑 statement_filepath => "/usr/local/logstash-6.4.3/sync/my_blog.sql" # 設置定時任務間隔 含義:分、時、天、月、年,全部為*默認含義為每分鍾跑一次任務 schedule => "* * * * *" # 索引類型 type => "_doc" # 是否開啟記錄上次追蹤的結果,也就是上次更新的時間,這個會記錄到 last_run_metadata_path 的文件 use_column_value => true # 記錄上一次追蹤的結果值 last_run_metadata_path => "/usr/local/logstash-6.4.3/sync/blog_track_time" # 如果 use_column_value 為true, 配置本參數,追蹤的 column 名,可以是自增id或者時間 tracking_column => "updated_time" # tracking_column 對應字段的類型 tracking_column_type => "timestamp" # 是否清除 last_run_metadata_path 的記錄,true則每次都從頭開始查詢所有的數據庫記錄 clean_run => false # 數據庫字段名稱大寫轉小寫 lowercase_column_names => false } } output { elasticsearch { # es地址 hosts => ["192.168.2.120:9200"] # 同步的索引名 index => "my_blog" # 設置_docID和數據相同 document_id => "%{id}" } # 日志輸出 stdout { codec => json_lines } }
-
my_blog.sql 文件內容如下
-
SELECT a.id AS id, a.comments AS comments, a.created AS created, a.favors AS favors, a.featured AS featured, a.status AS mstatus, a.summary AS summary, a.tags AS tags, a.thumbnail AS thumbnail, a.title AS title, a.views AS views, a.weight AS weight FROM mto_post a WHERE a.created >= :sql_last_value
-
-
進入 bin 目錄啟動
-
./logstash -f /usr/local/logstash-6.4.3/sync/logstash-db-sync.conf
-
-
查看
可見數據已經成功添加至ES中。
-
自定義模板配置ik中文分詞器
-
GET http://192.168.2.120:9200/_template/logstash 獲取到 logstash 修改相關內容,在 /usr/local/logstash-6.4.3/sync 下面新建 logstash-ik.json 將獲取到的內容修改后復制進去
-
logstash-ik.json內容如下:
-
{ "order": 0, "version": 1, "index_patterns": ["*"], "settings": { "index": { "refresh_interval": "5s" } }, "mappings": { "_default_": { "dynamic_templates": [ { "message_field": { "path_match": "message", "match_mapping_type": "string", "mapping": { "type": "text", "norms": false } } }, { "string_fields": { "match": "*", "match_mapping_type": "string", "mapping": { "type": "text", "norms": false, "analyzer": "ik_max_word", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } } ], "properties": { "@timestamp": { "type": "date" }, "@version": { "type": "keyword" }, "geoip": { "dynamic": true, "properties": { "ip": { "type": "ip" }, "location": { "type": "geo_point" }, "latitude": { "type": "half_float" }, "longitude": { "type": "half_float" } } } } } }, "aliases": {} }
-
將 logstash-ik.json 引入配置文件 logstash-db-sync.conf output模塊中做如下修改:
-
output { elasticsearch { # es地址 hosts => ["192.168.2.120:9200"] # 同步的索引名 index => "my_blog" # 設置_docID和數據相同 document_id => "%{id}" # 定義模板名稱 template_name => "myik" # 模板所在位置 template => "/usr/local/logstash-6.4.3/sync/logstash-ik.json" # 重寫模板 template_overwrite => true # 默認為true,false關閉logstash自動管理模板功能,如果自定義模板,則設置為false manage_template => false } # 日志輸出 stdout { codec => json_lines } }
-
啟動
-
./logstash -f /usr/local/logstash-6.4.3/sync/logstash-db-sync.conf
-