久久精品国产亚洲高清|精品日韩中文乱码在线|亚洲va中文字幕无码久|伊人久久综合狼伊人久久|亚洲不卡av不卡一区二区|精品久久久久久久蜜臀AV|国产精品19久久久久久不卡|国产男女猛烈视频在线观看麻豆

    1. <style id="76ofp"></style>

      <style id="76ofp"></style>
      <rt id="76ofp"></rt>
      <form id="76ofp"><optgroup id="76ofp"></optgroup></form>
      1. 千鋒教育-做有情懷、有良心、有品質(zhì)的職業(yè)教育機構(gòu)

        手機站
        千鋒教育

        千鋒學(xué)習(xí)站 | 隨時隨地免費學(xué)

        千鋒教育

        掃一掃進入千鋒手機站

        領(lǐng)取全套視頻
        千鋒教育

        關(guān)注千鋒學(xué)習(xí)站小程序
        隨時隨地免費學(xué)習(xí)課程

        當(dāng)前位置:首頁  >  技術(shù)干貨  > 輕量級日志系統(tǒng)Loki--安裝配置

        輕量級日志系統(tǒng)Loki--安裝配置

        來源:千鋒教育
        發(fā)布人:yyy
        時間: 2023-06-27 13:19:00 1687843140

          Loki對標(biāo)EFK/ELK,由于其輕量的設(shè)計,備受歡迎,Loki相比EFK/ELK,它不對原始日志進行索引,只對日志的標(biāo)簽進行索引,而日志通過壓縮進行存儲,通常是文件系統(tǒng)存儲,所以其操作成本更低,數(shù)量級效率更高

          由于Loki的存儲都是基于文件系統(tǒng)的,所以它的日志搜索時基于內(nèi)容即日志行中的文本,所以它的查詢支持LogQL,在搜索窗口中通過過濾標(biāo)簽的方式進行搜索和查詢。

          Loki分兩部分,Loki是日志引擎部分,Promtail是收集日志端,然后通過Grafana進行展示.

          1.安裝grafana

        wget https://dl.grafana.com/oss/release/grafana-8.2.5.linux-amd64.tar.gz
        tar -zxvf grafana-8.2.5.linux-amd64.tar.gz
        mv grafana-8.2.5 /usr/local/grafana

           創(chuàng)建Systemd服務(wù)

        cat>/usr/lib/systemd/system/grafana-server.service<<EOF
        [Unit]
        Description=Grafana Server
        After=network.target

        [Service]
        Type=simple
        User=root
        WorkingDirectory=/usr/local/grafana
        ExecStart=/usr/local/grafana/bin/grafana-server

        Restart=on-failure
        LimitNOFILE=65536

        [Install]
        WantedBy=multi-user.target
        EOF

           服務(wù)開機自啟

        systemctl daemon-reload
        systemctl enable grafana-server.service && systemctl start grafana-server.service

           /usr/local/grafana/conf/defaults.ini為默認(rèn)配置文件

          工作端口,默認(rèn)為3000。

          Loki的官方文檔

          https://grafana.com/docs/loki/latest/installation

          Loki·安裝

          從官方文檔看,Loki支持源碼安裝、Docker、Helm、Local、Tanka

          我選擇local,就是編譯好的二進制可執(zhí)行文件

          安裝步驟:

          鏡像網(wǎng)址

          https://hub.fastgit.org/grafana

          1.下載二進制可執(zhí)行文件

          https://hub.fastgit.org/grafana/loki/releases/download/v2.4.1/loki-linux-amd64.zip

          unzip loki-linux-amd64.zip && mv loki-linux-amd64 /usr/bin/loki

          chmod o+x /usr/bin/loki

          創(chuàng)建工作目錄并下載配置文件

          mkdir -p /data/loki

          參考配置文件

          https://hub.fastgit.org/grafana/loki/blob/main/cmd/loki/loki-local-config.yaml

          最終lok.yml如下

        vim /data/loki/lok.yml

        auth_enabled: false

        server:
        http_listen_port: 3100
        grpc_listen_port: 9096

        common:
        path_prefix: /data/loki
        storage:
        filesystem:
        chunks_directory: /data/loki/chunks
        rules_directory: /data/loki/rules
        replication_factor: 1
        ring:
        instance_addr: 127.0.0.1
        kvstore:
        store: inmemory

        schema_config:
        configs:
        - from: 2020-10-24
        store: boltdb-shipper
        object_store: filesystem
        schema: v11
        index:
        prefix: index_
        period: 24h
        ##報警地址
        ruler:
        alertmanager_url: http://localhost:9093

        #啟用Redis緩存配置
        auth_enabled: false

        server:
        http_listen_port: 3100
        grpc_listen_port: 9096

        common:
        path_prefix: /data/loki
        storage:
        filesystem:
        chunks_directory: /data/loki/chunks
        rules_directory: /data/loki/rules
        replication_factor: 1
        ring:
        instance_addr: 127.0.0.1
        kvstore:
        store: inmemory

        schema_config:
        configs:
        - from: 2020-10-24
        store: boltdb-shipper
        object_store: filesystem
        schema: v11
        index:
        prefix: index_
        period: 24h

        frontend:
        compress_responses: true

        query_range:
        split_queries_by_interval: 24h
        results_cache:
        cache:
        redis:
        endpoint: 192.168.1.6:6379
        expiration: 10s
        db: 1
        cache_results: true

        chunk_store_config:
        chunk_cache_config:
        redis:
        endpoint: 192.168.1.6:6379
        expiration: 10s
        db: 1
        write_dedupe_cache_config:
        redis:
        endpoint: 192.168.1.6:6379
        expiration: 1h
        db: 2

        ruler:
        alertmanager_url: http://localhost:9093

           創(chuàng)建相關(guān)目錄

          mkdir -p /data/loki/{chunks,rules,logs}

          啟動

        nohup  loki  --config.file=/data/loki/loki.yml  > /data/loki/logs/loki.log 2>&1 &

           啟動腳本

        #!/bin/bash
        CONFILE='/data/loki/loki.yml'
        PIDFILE='/data/loki/loki.pid'
        LOGFILE='/data/loki/loki.log'
        OPTS='/usr/bin/loki --config.file='
        PID=`ps -ef | grep ${CONFILE} | grep 'config.file' | awk '{print $2}'`
        if [ ! ${PID} ]; then
        nohup ${OPTS}${CONFILE} >${LOGFILE} 2>&1 & echo $! >${PIDFILE} &
        sleep 3
        echo "loki PID:`ps -ef | grep ${CONFILE} | grep 'config.file' | awk '{print $2}'`"
        PID=`ps -ef | grep ${CONFILE} | grep 'config.file' | awk '{print $2}'`
        if [ ! ${PID} ] ; then echo "loki config error, tail -f ${LOGFILE}!"
        fi
        else
        echo "loki is running,PID:`cat ${PIDFILE}`"
        fi

           安裝promtail進行收集日志

          Promtail是收集日志端

          下載安裝

        wget  https://hub.fastgit.org/grafana/loki/releases/download/v2.4.1/promtail-linux-amd64.zip
        unzip promtail-linux-amd64.zip && mv promtail-linux-amd64 /usr/bin/promtail && chmod o+x /usr/bin/promtail

           配置參考文件

          官網(wǎng)配置文件文檔

        https://hub.fastgit.org/grafana/loki/blob/main/clients/cmd/promtail/promtail-local-config.yaml

          

        server:
        http_listen_port: 9080
        grpc_listen_port: 0

        positions:
        filename: /tmp/positions.yaml

        clients:
        - url: http://localhost:3100/loki/api/v1/push

        scrape_configs:
        - job_name: system
        static_configs:
        - targets:
        - localhost
        labels:
        job: varlogs
        __path__: /var/log/*log

           參數(shù)說明

        server部分定義監(jiān)聽端口,positions定義讀取的文件偏移量存儲位置,clients定義loki接口地址,最后一部分scrape_configs是重點部分
        promtail通過scrape_configs部分配置收集日志的相關(guān)信息,以測試配置文件為例:
        job_name 用來區(qū)分日志組
        static_configs 收集日志的靜態(tài)配置
        targets 收集日志的節(jié)點,這個參數(shù)其實是在自動發(fā)現(xiàn)的時候使用的
        labels 定義一個要收集的日志文件和一組可選的附加標(biāo)簽
        job 標(biāo)簽名稱,在grafana索引的時候用到的標(biāo)簽名稱
        __path__ 定義日志收集的文件或路徑,支持正則
        配置文件修改完成后,就可以啟動promtail了,和loki啟動方法一樣,通過--config.file指定配置文件啟動

           promtail,類似于tail,它只監(jiān)聽新增日志,不會像filebeat一樣,讀取日志所有內(nèi)容,這是和filebeat的一個區(qū)別

          最終配置,啟用靜態(tài)與文件自動發(fā)現(xiàn)

          mkdir -p /data/promtail

          vim /data/promtail/promtail.yml

        server:
        http_listen_port: 9080
        grpc_listen_port: 0

        positions:
        filename: /tmp/positions.yaml

        clients:
        - url: http://192.168.1.6:3100/loki/api/v1/push

        scrape_configs:
        - job_name: system
        static_configs:
        - targets:
        - localhost
        labels:
        job: varlogs
        __path__: /var/log/*log
        file_sd_configs:
        - files:
        - /data/promtail/log_file/*.json
        refresh_interval: 1m

           啟動

          創(chuàng)建相關(guān)文件 

        mkdir -p /data/promtail/log_file/

          

        文件自動發(fā)現(xiàn)配置
        vim /data/promtail/log_file/mail.json
        [
        {
        "targets": [ "localhost" ],
        "labels": {
        "__path__": "/var/log/maillog",
        "job": "mailserver"
        }
        }
        ]

          開機自啟動

        nohup  promtail --config.file=/data/promtail/promtail.yml  >/data/promtail/promtail.log 2>&1 &

           啟動腳本

          vim /data/promtail/start.sh

        #!/bin/bash
        CONFILE='/data/promtail/promtail.yml'
        PIDFILE='/data/promtail/promtail.pid'
        LOGFILE='/data/promtail/promtail.log'
        OPTS='/usr/bin/promtail --config.file='
        PID=`ps -ef | grep ${CONFILE} | grep 'config.file' | awk '{print $2}'`
        if [ ! ${PID} ]; then
        nohup ${OPTS}${CONFILE} >${LOGFILE} 2>&1 & echo $! >${PIDFILE} &
        sleep 3
        echo "promtail PID:`ps -ef | grep ${CONFILE} | grep 'config.file' | awk '{print $2}'`"
        PID=`ps -ef | grep ${CONFILE} | grep 'config.file' | awk '{print $2}'`
        if [ ! ${PID} ] ; then echo "promtail config error, tail -f ${LOGFILE}!"
        fi
        else
        echo "promtail is running,PID:`cat ${PIDFILE}`"
        fi

         chmod o+x /data/promtail/start.sh

          查看是否工作

        [root@openrestry promtail]# netstat -ntpl | grep loki
        tcp6 0 0 :::9096 :::* LISTEN 1721/loki
        tcp6 0 0 :::3100 :::* LISTEN 1721/loki
        [root@openrestry promtail]# netstat -ntpl | grep promtail
        tcp6 0 0 :::40210 :::* LISTEN 1833/promtail
        tcp6 0 0 :::9080 :::* LISTEN 1833/promtail

           在Grafana中添加顯示輸出

          登錄http://Grafana:3000,添加loki數(shù)據(jù)源

        聲明:本站稿件版權(quán)均屬千鋒教育所有,未經(jīng)許可不得擅自轉(zhuǎn)載。
        10年以上業(yè)內(nèi)強師集結(jié),手把手帶你蛻變精英
        請您保持通訊暢通,專屬學(xué)習(xí)老師24小時內(nèi)將與您1V1溝通
        免費領(lǐng)取
        今日已有369人領(lǐng)取成功
        劉同學(xué) 138****2860 剛剛成功領(lǐng)取
        王同學(xué) 131****2015 剛剛成功領(lǐng)取
        張同學(xué) 133****4652 剛剛成功領(lǐng)取
        李同學(xué) 135****8607 剛剛成功領(lǐng)取
        楊同學(xué) 132****5667 剛剛成功領(lǐng)取
        岳同學(xué) 134****6652 剛剛成功領(lǐng)取
        梁同學(xué) 157****2950 剛剛成功領(lǐng)取
        劉同學(xué) 189****1015 剛剛成功領(lǐng)取
        張同學(xué) 155****4678 剛剛成功領(lǐng)取
        鄒同學(xué) 139****2907 剛剛成功領(lǐng)取
        董同學(xué) 138****2867 剛剛成功領(lǐng)取
        周同學(xué) 136****3602 剛剛成功領(lǐng)取
        相關(guān)推薦HOT
        PUE是什么?

        一、PUE是什么PUE,即功耗比(Power Usage Effectiveness),是數(shù)據(jù)中心的能源效率指標(biāo)。它是數(shù)據(jù)中心總功耗與設(shè)備功耗的比值,用于評估數(shù)據(jù)中...詳情>>

        2023-10-15 07:13:07
        graph cut和graph cuts有什么區(qū)別?

        1.語境不同graph cut”通常在描述一個操作時使用,比如”perform a graph cut”,它指的是在圖中找到一個切割,將圖劃分為兩個...詳情>>

        2023-10-15 07:02:16
        什么是雙機熱備?

        一、雙機熱備的原理雙機熱備是指在系統(tǒng)中配置兩臺服務(wù)器(主服務(wù)器和備份服務(wù)器),兩者通過高速網(wǎng)絡(luò)連接進行實時數(shù)據(jù)同步和狀態(tài)同步。主服務(wù)器...詳情>>

        2023-10-15 06:37:02
        偏最小二乘支持向量機和支持向量機回歸的區(qū)別是什么?

        1.模型構(gòu)建的理論基礎(chǔ)不同支持向量機回歸(SVR)基于統(tǒng)計學(xué)習(xí)理論,其主要思想是找到一個超平面,使得大部分?jǐn)?shù)據(jù)點都在這個超平面的一定范圍內(nèi),...詳情>>

        2023-10-15 06:30:45
        VAE、GAN和transformer有什么區(qū)別?

        1.模型結(jié)構(gòu)不同VAE(變分自編碼器)是一種生成模型,其基于概率圖模型和自編碼器,能夠?qū)W習(xí)數(shù)據(jù)的潛在分布。GAN(生成對抗網(wǎng)絡(luò))同樣是一種生成...詳情>>

        2023-10-15 06:10:12
        山丹县| 中山市| 昂仁县| 安徽省| 富蕴县| 张掖市| 东城区| 噶尔县| 固始县| 辽宁省| 高雄市| 石棉县| 安宁市| 牡丹江市| 乌鲁木齐市| 桃园县| 缙云县| 日喀则市| 衡山县| 子长县| 伊吾县| 玉田县| 铜鼓县| 玉山县| 醴陵市| 平乐县| 青川县| 醴陵市| 罗田县| 微山县| 内黄县| 高邑县| 嘉义县| 高安市| 阿拉尔市| 云安县| 云林县| 郸城县| 民勤县| 巴塘县| 册亨县|