版本:3.0.0
编译
git clone -b v3.0.0 https://github.com/grafana/loki.git
cd loki
yum install -y systemd-devel
go build --tags=promtail_journal_enabled ./clients/cmd/promtail
#./promtail
#./tools/packaging/promtail.service
#./README.md
#./LICENSE
打包
PACKAGE_DIR=promtail-3.0.0
mkdir ${PACKAGE_DIR}
mv promtail ${PACKAGE_DIR}
mv tools/packaging/promtail.service ${PACKAGE_DIR}
mv README.md ${PACKAGE_DIR}
mv LICENSE ${PACKAGE_DIR}
cat << "EOF" > ${PACKAGE_DIR}/config.yml
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /var/lib/promtail/positions.yaml
clients:
- url: http://127.0.0.1:3100/loki/api/v1/push
scrape_configs:
- job_name: system
static_configs:
- targets:
- localhost
labels:
job: varlogs
host: localhost
agent: promtail
__path__: /var/log/*log
- job_name: nginx
static_configs:
- targets:
- localhost
labels:
job: nginx
host: localhost
agent: promtail
__path__: /var/log/nginx/*log
EOF
tar -zcvf ${PACKAGE_DIR}.tgz ${PACKAGE_DIR}
Rpmbuild
which rpmbuild || dnf -y install rpm-build
mkdir -p /root/rpmbuild/SOURCES/
mv ${PACKAGE_DIR}.tgz /root/rpmbuild/SOURCES/
cat << "EOF" > promtail.spec
%define debug_package %{nil}
Name: promtail
Version: 3.0.0
Release: 1%{?dist}
Summary: Loki Promtail for Linux-x86_64
URL: https://github.com/grafana/loki
Source: promtail-3.0.0.tgz
License: MIT
%description
Loki Promtail for linux-x86_64
%prep
%setup -q
%pre
getent group promtail >/dev/null || groupadd -f promtail
getent passwd promtail >/dev/null || \
useradd -r -g promtail -d /var/lib/promtail -s /sbin/nologin \
-c "promtail daemon" promtail
exit 0
%post
chown -R promtail:promtail /var/lib/promtail
%preun
systemctl stop promtail
%postun
systemctl daemon-reload
userdel promtail
%build
%install
install -m 755 -d %{buildroot}%{_bindir}
install -m 755 -d %{buildroot}/usr/lib/systemd/system/
install -m 755 -d %{buildroot}/var/lib/promtail/
install -Dm755 promtail %{buildroot}/usr/bin/promtail
install -Dm644 config.yml %{buildroot}/etc/promtail/config.yml
install -Dm644 promtail.service %{buildroot}/usr/lib/systemd/system/promtail.service
%files
/var/lib/promtail/
/usr/lib/systemd/system/promtail.service
/usr/bin/promtail
/etc/promtail/config.yml
%doc README.md LICENSE
EOF
构建
rpmbuild -bb promtail.spec
ls -l /root/rpmbuild/RPMS/x86_64/promtail-3.0.0-1.el9.x86_64.rpm