https://grafana.com/docs/loki/latest/installation/local/
InstallandrunLokilocallyInordertologeventswithLoki,youmustdownloadandinstallbothPromtailandLoki.Lokiistheloggingengine.PromtailsendslogstoLoki.InstallandrunNavigatetothereleasepage.ScrolldowntotheAssetssectionundertheversionthatyouwanttoinstall.DownloadtheLokiandPromtail.zipfilesthatcorrespondtoyoursystem.Note:DonotdownloadLogCLIorLokiCanaryatthistime.LogCLIallowsyoutorunLokiqueriesinacommandlineinterface.LokiCanaryisatooltoauditLokiperformance.Unzipthepackagecontentsintothesamedirectory.Thisiswherethetwoprogramswillrun.Inthecommandline,changedirectory(cdonmostsystems)tothedirectorywithLokiandPromtail.Copyandpastethecommandsbelowintoyourcommandlinetodownloadgenericconfigurationfiles:wgethttps://raw.githubusercontent.com/grafana/loki/master/cmd/loki/loki-local-config.yamlwgethttps://raw.githubusercontent.com/grafana/loki/master/cmd/promtail/promtail-local-config.yamlEnterthefollowingcommandtostartLoki:Windows.\loki-windows-amd64.exe--config.file=loki-local-config.yamlLinux./loki-linux-amd64-config.file=loki-local-config.yamlLokirunsanddisplaysLokilogsinyourcommandlineandonhttp://localhost:3100/metrics.Congratulations,Lokiisinstalledandrunning!Next,youmightwanteditthePromtailconfigfiletogetlogsintoLoki.Releasebinaries-openSUSELinuxonlyEveryreleaseincludesbinariesforLokiwhichcanbefoundontheReleasespage.CommunityopenSUSELinuxpackagesThecommunityprovidespackagesofLokiforopenSUSELinux.Toinstall:Addtherepositoryhttps://download.opensuse.org/repositories/security:/logging/ to your system. For example, if you are using Leap 15.1, run sudo zypper ar https://download.opensuse.org/repositories/security:/logging/openSUSE_Leap_15.1/security:logging.repo ; sudo zypper refInstalltheLokipackagewithzypperinlokiEnabletheLokiandPromtailservices:systemdstartloki&&systemdenablelokisystemdstartpromtail&&systemdenablepromtailModifytheconfigurationfilesasneeded:/etc/loki/promtail.yamland/etc/loki/loki.yaml.
$curl-O-L"https://github.com/grafana/loki/releases/download/v2.2.0/loki-linux-amd64.zip"#extractthebinary$unzip"loki-linux-amd64.zip"#makesureitisexecutable$chmoda+x"loki-linux-amd64"wgethttps://github.com/grafana/loki/releases/download/v2.2.0/promtail-linux-amd64.zip
GetlogsintoLokiAfteryouinstallandrunLoki,youprobablywanttogetlogsfromotherapplicationsintoit.TogetapplicationlogsintoLoki,youneedtoeditthePromtailconfigfile.DetailedinformationaboutconfiguringPromtailisavailableinPromtailconfiguration.Thefollowinginstructionsshouldhelpyougetstarted.Ifyouhaven’talready,downloadaPromtailconfigurationfile.Keeptrackofwhereitis,becauseyouwillneedtociteitwhenyourunthebinary.wgethttps://raw.githubusercontent.com/grafana/loki/master/cmd/promtail/promtail-local-config.yamlOpentheconfigfileinthetexteditorofyourchoice.Itshouldlooksimilartothis:server:http_listen_port:9080grpc_listen_port:0positions:filename:/tmp/positions.yaml`11111111111111111111111scrape_configs:-job_name:systemstatic_configs:-targets:-localhostlabels:job:varlogs__path__:/var/log/*logThe seven lines under scrape_configs are what send the logs that Loki generates to Loki, which then outputs them in the command line and http://localhost:3100/metrics.Copy the seven lines under scrape_configs, and then paste them under the original job (you can also just edit the original seven lines).Below is an example that sends logs from a default Grafana installation to Loki. We updated the following fields:job_name - This differentiates the logs collected from other log groups.targets - Optional for static_configs, however is often defined because in older versions of Promtail it was not optional. This was an artifact from directly using the Prometheus service discovery code which required this entry.labels - Static label to apply to every log line scraped by this definition. Good examples would be environment name, job name, or app name.path - The path to where the logs are stored that I want Loki to consume.- job_name: grafanastatic_configs:- targets:- grafanalabels:job: grafana__path__: "C:/Program Files/GrafanaLabs/grafana/data/log/grafana.log"Enter the following command to run Promtail. Examples below assume you have put the config file in the same directory as the binary.Windows`.\promtail-windows-amd64.exe --config.file=promtail-local-config.yaml`Linux./promtail-linux-amd64 -config.file=promtail-local-config.yamlYou should now see your application logs. If you are using Grafana, you might need to refresh your instance in order to see the logs.