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.11.3/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.11.3

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.

#
#
#
#
systemctl daemon-reload
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

Connect Alloy to Grafana Cloud

Connect Alloy to Grafana Cloud Connect Alloy to Grafana Cloud

If you are doing this course using Grafana Cloud as instructed in this course, and not creating your own self hosted Grafana infrastructure, then you will need a server to install Alloy onto in order to participate in the next many lessons.

In this video I quickly create a new server, name it "Anything Server" and install the Alloy service onto it as described above.

When configuring the Alloy loki.write endpoint, ensure to point it to your Grafana Cloud Loki endpoint, including your basic auth information.

alloy v1.11.3

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 = "<Your URL>/loki/api/v1/push"

                basic_auth {
                    username = "<Your User>"
                    password = "<Your Grafana.com API Token>"
                }
        }
}

Start Alloy and check status.

#
#
service alloy start
service alloy status

If the status is ok, then go into your Grafana Cloud instance --> Explore tab, and select the data source named grafanacloud-<Your Stack Name>-logs

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.

#
#
#
systemctl daemon-reload
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/;
    }