Skip to content

Install Alloy Binary and Start as a Service

Video Lecture

Install Alloy Binary and Start as a Service Install Alloy Binary and Start as a Service

 (Pay Per View)

You can use PayPal to purchase a one time viewing of this video for $1.49 USD.

Pay Per View Terms

  • One viewing session of this video will cost the equivalent of $1.49 USD in your currency.
  • After successful purchase, the video will automatically start playing.
  • You can pause, replay and go fullscreen as many times as needed in one single session for up to an hour.
  • Do not refresh the browser since it will invalidate the session.
  • If you want longer-term access to all videos, consider purchasing full access through Udemy or YouTube Memberships instead.
  • This Pay Per View option does not permit downloading this video for later viewing or sharing.
  • All videos are Copyright © 2019-2025 Sean Bradley, all rights reserved.

Description

Now we will create the Alloy agent service that will act as the collector for Loki.

We can also get the Alloy binary from github.

To check the latest version of Alloy, visit its releases page.

https://github.com/grafana/alloy/releases

#
cd /usr/local/bin
#
curl -O -L "https://github.com/grafana/alloy/releases/download/v1.10.2/alloy-linux-amd64.zip"
#
unzip "alloy-linux-amd64.zip"

And allow the execute permission on the Alloy binary.

#
chmod a+x "alloy-linux-amd64"

Create the Alloy config

Create a new file named config.alloy.

#
nano config.alloy

Copy/paste this content below into it.

alloy v1.10.2

local.file_match "system" {
        path_targets = [{
                __address__ = "localhost",
                __path__    = "/var/log/*log",
                job         = "varlogs",
                stream      = "stdout",
        }]
}

loki.source.file "system" {
        targets               = local.file_match.system.targets
        forward_to            = [loki.write.default.receiver]
        legacy_positions_file = "/tmp/positions.yaml"
}

loki.write "default" {
        endpoint {
                url = "http://localhost:3100/loki/api/v1/push"
        }
        external_labels = {}
}

Configure Alloy as a Service

Now we will configure Alloy as a service so that we can keep it running in the background.

Create user specifically for the Alloy service

#
useradd --system alloy

Create a file named alloy.service.

#
nano /etc/systemd/system/alloy.service

And add this script,

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[Unit]
Description=Alloy service
After=network.target

[Service]
Type=simple
User=alloy
ExecStart=/usr/local/bin/alloy-linux-amd64 run --storage.path=/tmp/alloy/ /usr/local/bin/config.alloy

[Install]
WantedBy=multi-user.target

Now start and check the service is running.

#
#
#
service alloy start
service alloy status
systemctl enable alloy.service

We can now leave the new Alloy service running.

Read Alloy logs

#
journalctl -u alloy

Explore in Grafana

Open the Explore tab, select the Loki datasource, and use {job="varlogs"} as your first query.

Add alloy user to adm group.

So add the user alloy to the adm group

#
usermod -a -G adm alloy

Verify that the user is now in the adm group

#
id alloy

Restart Alloy and check status

#
#
service alloy restart
service alloy status

To Convert a Promtail Config to Alloy

This command will read an existing promtail-local-config.yaml, re-create it in the Alloy format and save it as config.alloy.

#
#
cd /usr/local/bin
alloy-linux-amd64 convert --source-format=promtail --output=config.alloy promtail-local-config.yaml

Alloy Web UI

Alloy has a self hosted user interface hosted on address http://localhost:12345 that can be used to view its status.

This UI can only be accessed from localhost. If you want to view it from an external connection, you can set the --server.http.listen-addr property.

#
nano /etc/systemd/system/alloy.service

Edit this line in the script.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[Unit]
Description=Alloy service
After=network.target

[Service]
Type=simple
User=alloy
ExecStart=/usr/local/bin/alloy-linux-amd64 run --server.http.listen-addr=0.0.0.0:12345 --storage.path=/tmp/alloy/ /usr/local/bin/config.alloy

[Install]
WantedBy=multi-user.target

Now start and check the service is running.

#
#
service alloy start
service alloy status

You should now be able to access it from the address http://your-ip-or-domain:12345

However, this will not be encrypted. If you have set up Alloy as a service as shown above, you have a domain name, SSL and an NGinx reverse proxy as described in this course, you can set the --server.http.ui-path-prefix property and add an NGinx proxy pass.

Set the --server.http.ui-path-prefix

#
nano /etc/systemd/system/alloy.service

Edit this line in the script.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[Unit]
Description=Alloy service
After=network.target

[Service]
Type=simple
User=alloy
ExecStart=/usr/local/bin/alloy-linux-amd64 run --server.http.ui-path-prefix=/alloy --storage.path=/tmp/alloy/ /usr/local/bin/config.alloy

[Install]
WantedBy=multi-user.target

Add the NGinx Proxy Pass

#
nano /etc/nginx/sites-enabled/your-grafana-servers-domain-name.conf

Add this location directive.

    location /alloy/ {
        proxy_set_header Host $http_host;
        proxy_pass http://localhost:12345/alloy/;
    }