Grafana in an OmniOS pkgsrc branded zone

       381 words, 2 minutes

I run a lot of bhyve VMs on my OmniOS server because that’s the way I’m used to go with exposing services. For fun knowledge purposes, I decided that I would replace my Grafana virtual machine with an Illumos zone.

Thanks to pkgsrc, this is really easy and straightforward.

Create a pkgsrc branded zone

I already have an ZFS pool dedicated to hosting my zones. It is named tank/zones.
Adapt this to your storage organization.

The pkgsrc branded zone is created using the zadm command tool.
EDIT 2024-10-13: Adding CPU and Memory limits to the zone.

# zadm create -b pkgsrc grafana
{
   "autoboot" : "true",
   "brand" : "pkgsrc",
   "capped-cpu" : {
      "ncpus" : "1.00"
   },
   "capped-memory" : {
      "physical" : "512M",
      "swap" : "1G"
   },
   "dns-domain" : "example",
   "ip-type" : "exclusive",
   "net" : [
      {
         "allowed-address" : "192.0.2.101/24",
         "defrouter" : "192.0.2.1",
         "global-nic" : "private0",
         "physical" : "grafana0"
      }
   ],
   "resolvers" : [
      "192.0.2.1",
      "9.9.9.9",
      "2620:fe::9"
   ],
   "zonename" : "grafana",
   "zonepath" : "/zones/grafana"
}
# zadm start grafana

# zlogin grafana

OpenSSH is already installed and enabled. But the configuration needs a bit of tweaking to my linkings.

# mkdir ~/.ssh
# cat > ~/.ssh/authorized_keys
ssh-ed25519 ...

# vi /etc/ssh/sshd_config
(...)
PermitRootLogin prohibit-password
(..)
PasswordAuthentication no

# svcadm restart svc:/network/ssh:default

Now the zone is accessible as any other I.T. asset.

Install and configure Grafana

Update pkgsrc and install Grafana:

# pkgin update
# pkgin in grafana

Configure Grafana:

# vi /opt/local/etc/grafana.conf

As explained by the post-install message:

This package has SMF support. You may use svcadm(1M) to ’enable’, ‘disable’ or ‘restart’ services. To enable the instance(s) for this package, run: /usr/sbin/svcadm enable -r svc:/pkgsrc/grafana:default

Use svcs(1) to check on service status. See smf(5) for more information.

Start Grafana:

# /usr/sbin/svcadm enable -r svc:/pkgsrc/grafana:default

Use a Web browser to access http://zone.example:3000/ and start managing Grafana.

In the case of the migration of an existing instance, there may be differences in the storage organization.

I copied the content of my OpenBSD instance straight in the proper directories and adapted my original config.ini.
All went ok: I could log into Grafana using my user and access my configured databases and dashboards.

That’s All Folks! Yes, as simple as this.