Loki是受Prometheus啓發由Grafana Labs團隊開源的水平可擴展,高度可用的多租戶日誌聚合系統。 開發語言: Google Go。它的設計具備很高的成本效益,而且易於操做。使用標籤來做爲索引,而不是對全文進行檢索,也就是說,你經過這些標籤既能夠查詢日誌的內容也能夠查詢到監控的數據籤,極大地下降了日誌索引的存儲。系統架構十分簡單,由如下3個部分組成 :linux
只要在應用程序服務器上安裝promtail來收集日誌而後發送給Loki存儲,就能夠在Grafana UI界面經過添加Loki爲數據源進行日誌查詢(若是Loki服務器性能不夠,能夠部署多個Loki進行存儲及查詢)。做爲一個日誌系統不關只有查詢分析日誌的能力,還能對日誌進行監控和報警git
promtail收集並將日誌發送給loki的 Distributor 組件github
Distributor會對接收到的日誌流進行正確性校驗,並將驗證後的日誌分批並行發送到Ingester後端
Ingester 接受日誌流並構建數據塊,壓縮後存放到所鏈接的存儲後端api
Querier 收到HTTP查詢請求,並將請求發送至Ingester 用以獲取內存數據 ,Ingester 收到請求後返回符合條件的數據 ;瀏覽器
若是 Ingester 沒有返回數據,Querier 會從後端存儲加載數據並遍歷去重執行查詢 ,經過HTTP返回查詢結果tomcat
一、示例安裝環境:服務器
服務器 | 系統 | IP |
loki主機 | Centos 7.6 | 10.0.0.171 |
promtail主機 | Centos 7.6 | 10.0.0.175 |
二、下載安裝軟件架構
curl -O -L "https://github.com/grafana/loki/releases/download/v1.5.0/loki-linux-amd64.zip" curl -O -L "https://github.com/grafana/loki/releases/download/v1.5.0/promtail-linux-amd64.zip" wget https://dl.grafana.com/oss/release/grafana-6.7.4-1.x86_64.rpm
三、自定義配置文件(loki.yaml和promtail.yaml),由本身建立:app
loki.yaml:
auth_enabled: false server: http_listen_port: 3100 ingester: lifecycler: address: 127.0.0.1 ring: kvstore: store: inmemory replication_factor: 1 final_sleep: 0s chunk_idle_period: 5m chunk_retain_period: 30s schema_config: configs: - from: 2018-04-15 store: boltdb object_store: filesystem schema: v9 index: prefix: index_ period: 168h storage_config: boltdb: directory: /tmp/loki/index filesystem: directory: /tmp/loki/chunks limits_config: enforce_metric_name: false reject_old_samples: true reject_old_samples_max_age: 168h #chunk_store_config: # max_look_back_period: 0 #table_manager: # chunk_tables_provisioning: # inactive_read_throughput: 0 # inactive_write_throughput: 0 # provisioned_read_throughput: 0 # provisioned_write_throughput: 0 # index_tables_provisioning: # inactive_read_throughput: 0 # inactive_write_throughput: 0 # provisioned_read_throughput: 0 # provisioned_write_throughput: 0 # retention_deletes_enabled: false # retention_period: 0
promtail.yaml:
# Promtail Server Config server: http_listen_port: 9080 grpc_listen_port: 0 # Positions positions: filename: /tmp/positions.yaml # Loki服務器的地址 clients: - url: http://127.0.0.1:3100/loki/api/v1/push scrape_configs: - job_name: linux static_configs: - targets: - localhost labels: job: messages host: localhost __path__: /var/log/messages*
四、安裝Grafana
#安裝依賴 yum install initscripts fontconfig yum install freetype yum install urw-fonts #安裝 rpm -ivh grafana-6.7.4-1.x86_64.rpm
五、啓動loki
systemctl start grafana-server.service
nohup ./loki-linux-amd64 -config.file=/etc/loki/loki.yaml &
六、啓動promtail
nohup ./promtail-linux-amd64 -config.file=/etc/loki/config.yaml &
七、重啓Grafana
systemctl restart grafana-server.service
八、從瀏覽器打開grafana:http:IP:3000
點擊」Greate a data source「
添加HTTP的參數,而後」Save & Test「.而後進入"Explore:
5、在被監控機(10.0.0.175)安裝promtail日誌採集系統,並採集 Tomcat運行日誌和Web訪問日誌
修改配置文件config.yaml
# Promtail Server Config server: http_listen_port: 9080 grpc_listen_port: 0 # Positions positions: filename: /tmp/positions.yaml # Loki服務器的地址 clients: - url: http://10.0.0.141:3100/loki/api/v1/push scrape_configs: - job_name: WEB static_configs: - targets: - localhost labels: job: tomcat host: localhost __path__: /application/tomcat/logs/*.log,/application/tomcat/logs/catalina.out
啓動promtail
nohup ./promtail-linux-amd64 -config.file=/etc/loki/config.yaml &
接着在loki主機重啓grafana
systemctl start grafana-server.service
至此,LOKI日誌聚合系統安裝和配置完成。
注:若有須要LOKI的軟件和配置文件的請留言。