#!/bin/bash
yum -y install vim wget net-tools curl unzip
ip=`curl ifconfig.me`
read -p "安装服务端还是客户端?server/client: " s
function client {
mkdir -p /usr/local/promtail
cd /usr/local/promtail
curl -O -L "https://github.com/grafana/loki/releases/download/v1.5.0/promtail-linux-amd64.zip"
unzip promtail-linux-amd64.zip
read -p "Loki服务器:" ip
wget ftp://106.12.106.146:/pub/promtail.yaml
sed -i "s/ip/$ip/g" /usr/local/promtail/promtail.yaml
echo "需要填写日志路径,修改/usr/local/promtail/promtail.yaml"
echo "修改日志路径之后再使用 nohup ./promtail-linux-amd64 -config.file=./promtail.yaml > ./promtail.log 2>&1 & 这条命令启动"
echo "图形界面可参考:https://www.jianshu.com/p/7240f1de22f2"
}
function server {
mkdir -p /data
mkdir -p /data/loki
mkdir -p /data/loki/{
chunks,index}
mkdir -p /usr/local/loki
cd /usr/local/loki
curl -O -L "https://github.com/grafana/loki/releases/download/v1.5.0/loki-linux-amd64.zip"
unzip loki-linux-amd64.zip
wget ftp://106.12.106.146/pub/config.yaml
sed -i "s/ip/$ip/g" /usr/local/loki/config.yaml
cd /usr/local/loki && nohup ./loki-linux-amd64 -config.file=./config.yaml >./loki.log 2>&1 &
mkdir -p /opt/src && cd /opt/src
wget https://dl.grafana.com/oss/release/grafana-7.1.0-1.x86_64.rpm
yum -y install grafana-7.1.0-1.x86_64.rpm
mkdir -p /var/run/grafana
chown -R grafana:grafana /var/run/grafana
systemctl daemon-reload
systemctl enable grafana-server.service
systemctl start grafana-server.service
netstat -antulp | grep 3000
netstat -antulp | grep 3100
echo "grafana页面地址是 http://$ip:3000 账号密码为admin"
echo "Loki的服务URL为 htto://$ip:3100"
}
if [ $s == "server" ];then
server
elif [ $s == client ];then
client
else
echo "输入错误"
fi
页面配置,参考网址:https://www.jianshu.com/p/7240f1de22f2
loki是日志处理
promtail是收集日志
grafana是UI页面
loki跟grafana建议安装在同一台