二进制安装PLG日志服务

文章目录

      • 一.下载二进制文件
        • 安装解压工具
        • 解压授权
        • grafana 安装
      • 二.下载配置文件,修改并开机自启
        • 修改配置文件
        • 开启syslog日志
        • systemd 管理服务

下载loki-linux-amd64.zip 和 promtail-linux-amd64.zip grafana 使用yum安装
loki官方下载地址:https://github.com/grafana/loki/releases
https://grafana.com/grafana/download 配置文件官网
https://grafana.com/docs/loki/latest/installation/local/

一.下载二进制文件

mkdir -p /opt/plg/{loki,promtail,tools} && cd /opt/plg/tools
wget https://github.com/grafana/loki/releases/download/v2.1.0/loki-linux-amd64.zip
wget https://github.com/grafana/loki/releases/download/v2.1.0/promtail-linux-amd64.zip

安装解压工具

ubuntu: apt-get install -y unzip
centos: yum -y install unzip 

解压授权

unzip loki-linux-amd64.zip && mv loki-linux-amd64 /opt/plg/loki/ && chmod a+x /opt/plg/loki//loki-linux-amd64
unzip promtail-linux-amd64.zip && mv promtail-linux-amd64 /opt/plg/promtail/ && chmod a+x /opt/plg/promtail/promtail-linux-amd64

grafana 安装

#Ubuntu:
    sudo apt-get install -y adduser libfontconfig1
    wget https://dl.grafana.com/oss/release/grafana_7.4.3_amd64.deb
    sudo dpkg -i grafana_7.4.3_amd64.deb
    systemctl start grafana-server.service
    systemctl enable grafana-server.service

#Centos:
    wget https://dl.grafana.com/oss/release/grafana-7.4.3-1.x86_64.rpm
    sudo yum install grafana-7.4.3-1.x86_64.rpm
    systemctl start grafana-server.service
    systemctl enable grafana-server.service

二.下载配置文件,修改并开机自启

wget -O /opt/plg/loki/loki-local-config.yaml  https://raw.githubusercontent.com/grafana/loki/master/cmd/loki/loki-local-config.yaml
wget -O /opt/plg/promtail/promtail-local-config.yaml  https://raw.githubusercontent.com/grafana/loki/master/cmd/promtail/promtail-local-config.yaml
#单个启动测试是否能成功
./loki-linux-amd64 -config.file=./etc/loki-local-config.yaml
./promtail-linux-amd64 -config.file=./etc/promtail-local-config.yaml
启动loki-local-config.yaml 会提示: 
failed parsing config: ./loki-local-config.yaml: yaml: unmarshal errors:
    line 7: field wal not found in type ingester.Config

修改配置文件

使用这个loki-local-config.yaml文件时还需要修改一下,去掉里面的这几行,
wal:
    enabled: true
    dir: /tmp/wal
    recover: true
#修改loki数据存储路径
mkdir -p /data/loki/tmp
vim loki-local-config.yaml
:%s+/tmp/+/data/loki/tmp/+

#promtail yaml文件存放路径
vim  promtail-local-config.yaml
:%s+/tmp/+/data/loki/+

开启syslog日志

yum -y install rsyslog
systemctl start rsyslog
ubuntu 去 /etc/rsyslog.d/50-default.conf 解开注释重启即可 

systemd 管理服务

useradd  -s /sbin/nologin -M loki
chown -R loki:loki /opt/plg/loki/
chown -R loki:loki /data/loki/

cat >/usr/lib/systemd/system/loki.service <<EOF
[Unit]
Description=loki
After=network.target
Documentation=https://grafana.com/oss/loki/
[Service]
Type=simple
ExecStart=/opt/plg/loki/loki-linux-amd64 \\
    -config.file=/opt/plg/loki/loki-local-config.yaml
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

cat > /usr/lib/systemd/system/promtail.service <<EOF
[Unit]
Description=promtail
Documentation=https://github.com/topics/promtail
After=network.target
[Service]
Type=simple
ExecStart=/opt/plg/promtail/promtail-linux-amd64 \\
    --config.file=/opt/plg/promtail/promtail-local-config.yaml
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
#设置自启
systemctl daemon-reload
systemctl start loki
systemctl start promtail
systemctl start grafana-server
systemctl enable loki
systemctl enable promtail
systemctl enable grafana-server

你可能感兴趣的:(prometheus,loki,promtail,grafana)