Deploying Grafana on Linux

Download and Install Package

Go to [official website](https://grafana.com/grafana/download) to download the latest version of the installation package. Here we take grafana-enterprise_12.2.1_18655849634_linux_amd64.tar.gz as an example.

1wget https://dl.grafana.com/grafana-enterprise/release/12.2.1/grafana-enterprise_12.2.1_18655849634_linux_amd64.tar.gz
2tar -zxvf grafana-enterprise_12.2.1_18655849634_linux_amd64.tar.gz

Extract and Install

1tar -zxvf grafana-enterprise_12.2.1_18655849634_linux_amd64.tar.gz
2mv grafana-enterprise_12.2.1_18655849634_linux_amd64 /opt/grafana

Modify Configuration

Copy the default configuration file and modify the relevant settings.

1cp /opt/grafana/conf/defaults.ini /opt/grafana/conf/grafana.ini

Modify the /opt/grafana/conf/grafana.ini file, mainly changing the configuration in the [paths] and [server] sections.

1[paths]
2# Store DB, plugin installation, and other runtime data. In production, it can be mounted on a separate disk.
3data = /opt/grafana/data
4# Temporary files in `data` directory older than given duration will be removed
5temp_data_lifetime = 24h
6# Log directory.
7logs = /opt/grafana/data/log
8# Local plugin directory.
9plugins = /opt/grafana/data/plugins
10# Directory for automated provisioning of datasources / dashboards.
11provisioning = /opt/grafana/conf/provisioning
12# Directories that are permitted to contain local repositories.
13# This is a list. Each entry is delimited by a pipe (|). No leading or trailing spaces are supported.
14# These do not need to be absolute paths, in which case they'll be relative to the path where you are running Grafana.
15# Empty entries will return an error, unless the string is just a single pipe.
16# Example: permitted_provisioning_paths = /tmp|/etc/grafana/repositories|conf/provisioning
17permitted_provisioning_paths = devenv/dev-dashboards|conf/provisioning
18[server]
19# http or https (use https when TLS is enabled).
20protocol = http
21# Minimum TLS version allowed. By default, this value is empty. Accepted values are: TLS1.2, TLS1.3. If nothing is set, TLS1.2 will be taken
22min_tls_version = ""
23# Bind address, leave empty to bind all addresses (0.0.0.0).
24http_addr =
25# Grafana Web port. If 3000 is occupied, you can change it, for example, to 4000.
26http_port = 3000
27# The public facing domain name used to access Grafana from a browser
28domain = localhost
29# Redirect to correct domain if host header does not match domain
30# Prevents DNS rebinding attacks
31enforce_domain = false
32# The full public facing url
33root_url = %(protocol)s://%(domain)s:%(http_port)s/
34# Serve Grafana from subpath specified in `root_url` setting. By default it is set to `false` for compatibility reasons.
35serve_from_sub_path = false
36# Log web requests
37router_logging = false
38# The path relative working path
39static_root_path = public
40# enable gzip
41enable_gzip = false
42# https certs & key file
43cert_file =
44cert_key =
45cert_pass =
46# Certificates file watch interval
47certs_watch_interval =
48# Unix socket gid
49# Changing the gid of a file without privileges requires that the target group is in the group of the process and that the process is the file owner
50# It is recommended to set the gid as http server user gid
51# Not set when the value is -1
52socket_gid = -1
53# Unix socket mode
54socket_mode = 0660
55# Unix socket path
56socket = /tmp/grafana.sock
57# CDN Url
58cdn_url =
59# Sets the maximum time in minutes before timing out read of an incoming request and closing idle connections.
60# `0` means there is no timeout for reading the request.
61read_timeout = 0
62# Email configuration, here using 163 email as an example for alert sending
63[smtp]
64enabled = true
65host = smtp.163.com:465
66user = [email protected]
67# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
68password = NZHOSHWRKWQZTXMGPWD
69cert_file =
70key_file =
71skip_verify = true
72from_address = [email protected]
73from_name = Grafana
74ehlo_identity =
75startTLS_policy =
76enable_tracing = false

Start Service

1./bin/grafana-server --config=/opt/grafana/conf/grafana.ini --homepath=/opt/grafan

Verify Service

Access http://192.168.0.1:3000, if you can see the Grafana homepage, the installation is successful. The default username and password are admin/admin.

Configure Auto Start on Boot

Create a systemd service file:

1# /etc/systemd/system/grafana.service
2[Unit]
3Description=Grafana Monitoring
4After=network.target
5[Service]
6ExecStart=/opt/grafana/bin/grafana-server --config=/opt/grafana/conf/grafana.ini --homepath=/opt/grafana
7Restart=always
8[Install]
9WantedBy=multi-user.target

Reload the systemd configuration and enable the service:

1systemctl daemon-reload
2systemctl enable grafana
3systemctl start grafana

Now, Grafana should automatically run at system startup. You can use the following commands to check the service status:

1# Check service status
2systemctl status grafana
3# Check service logs
4journalctl -u grafana -f

Leave a Comment