How To Install Grafana on CentOS 9 Stream
This article is a step-by-step guide on how to install Grafana software on CentOS 9 Stream. Grafana is a popular open-source visualization and analytics monitoring software. It renders graphs, charts, and alerts when connected to supported data sources. It is commonly used with time series databases like Prometheus, SQL databases like MySQL logging, and document databases like Loki, etc. You can additionally install hundreds of plugins and dashboards from the official library.
1. Update your system
Before installing any tools on your CentOS 9, you should first update your RPM packages with YUM.
This step is optional but you may required to do it to keep your system safe.
# yum update
# yum upgrade
This step may take a couple of minutes if you haven’t updated your packages for a long time.
2. Add the Grafana repositories to your local YUM Repos
To be able to install Grafana with YUM, you need to add the official Grafana repositories to your local YUM-allowed repositories.
Create a new file named “grafana.repo”, and paste the following content in it.
# touch grafana.repo
Next, we will run the following command to add the repository to our /etc/yum.repos.d/grafana.repo file. The command should look like this.
# nano /etc/yum.repos.d/grafana.repo
[grafana] name=grafana baseurl=https://packages.grafana.com/oss/rpm repo_gpgcheck=1 enabled=1 gpgcheck=1 gpgkey=https://packages.grafana.com/gpg.key sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt
Save your file and update your repositories one more time.
# yum update
3. Install Grafana with YUM
Now that your repositories are linked to Grafana official repositories, you are ready to install the latest version of Grafana on CentOS 9
To install Grafana with YUM, run the following command
# yum install grafana
Make sure to press “y” when you are asked if you want to install Grafana.
You will also be asked if you want to import the GPG key from Grafana, hit “y” to proceed with the installation.
4. Inspect your grafana-service systemd service
By default, Grafana created a systemd service for you.
First, you are going to make sure that the service was created, but you are also going to use it as a way to determine where files and folders are located on your host.
You will for example be given the data folder (where dashboards are stored) or the log folders to inspect your logs.
To inspect your Grafana service, run the following command
$ cat /usr/lib/systemd/system/grafana-server.service
[Unit]
Description=Grafana instance
Documentation=http://docs.grafana.org
Wants=network-online.target
After=network-online.target
After=postgresql.service mariadb.service mysql.service
[Service]
EnvironmentFile=/etc/sysconfig/grafana-server
User=grafana
Group=grafana
Type=notify
Restart=on-failure
WorkingDirectory=/usr/share/grafana
RuntimeDirectory=grafana
RuntimeDirectoryMode=0750
ExecStart=/usr/sbin/grafana-server \
--config=${CONF_FILE} \
--pidfile=${PID_FILE_DIR}/grafana-server.pid \
--packaging=deb \
cfg:default.paths.logs=${LOG_DIR} \
cfg:default.paths.data=${DATA_DIR} \
cfg:default.paths.plugins=${PLUGINS_DIR} \
cfg:default.paths.provisioning=${PROVISIONING_CFG_DIR}
LimitNOFILE=10000
TimeoutStopSec=20
.....
UMask=0027
[Install]
WantedBy=multi-user.target
This file is very important because it gives you much more information about your Grafana instance.
As you can see from this file :
- The Grafana server binary is located at /usr/sbin/grafana-server.
- The file that defines all the environment variables is located at /etc/sysconfig/grafana-server
- The configuration file is given via the CONF_FILE environment variable.
- The PID of the file is also determined by the PID_FILE_DIR environment variable.
- Logging, data, plugins, and provisioning paths are given by environment variables.
Here’s the content of the environment variable file (etc/sysconfig/grafana-server)
GRAFANA_USER=grafana
GRAFANA_GROUP=grafana
GRAFANA_HOME=/usr/share/grafana
LOG_DIR=/var/log/grafana
DATA_DIR=/var/lib/grafana
MAX_OPEN_FILES=10000
CONF_DIR=/etc/grafana
CONF_FILE=/etc/grafana/grafana.ini
RESTART_ON_UPGRADE=true
PLUGINS_DIR=/var/lib/grafana/plugins
PROVISIONING_CFG_DIR=/etc/grafana/provisioning
# Only used on systemd systems
PID_FILE_DIR=/var/run/grafana
Also, a Grafana user and group were created for you on your instance.
Those credentials will be used to access and modify some of the files related to Grafana your CentOS 9
5. Start your grafana-server service
Start the Grafana service and enable it to start on boot.
# systemctl start grafana-server
# systemctl enable grafana-server
The Grafana service we want is the status.
# systemctl status grafana-server
Your Grafana server is now up and running on CentOS 9
6. Changing your firewall rules
Before configuring your Grafana server, you are going to open port 3000 via TCP on your server.
Grafana uses the port 3000 for Web Administration, as a consequence, the web interface may be inaccessible if you don’t open this port.
To open the port 3000 on CentOS 9, run this command
# firewall-cmd --add-port=3000/tcp --permanent
# firewall-cmd --reload
Make sure that everything is correctly set.
# firewall-cmd --list-all | grep ports
7. Launch Grafana v6 Web UI
Now that everything is configured properly, you should be able to have a look at the Grafana v6 Web UI.
To open the Grafana Web UI, navigate with your web browser.
http://serverip:3000
As a reminder, here are all the defaults for Grafana:
The default port for Grafana is 3000.
You will be presented with this screen when launching the application for the first time.
The default login for Grafana is ‘admin’ and the default password is also ‘admin’.
When setting those credentials, you will be asked to change your password.
Choose a password, and click on ‘Save‘.
You should now see the default screen for Grafana
Conclusion
And that’s it! You now have Grafana set up with a basic configuration! Go ahead and explore the settings and what you have built, and then
Good luck!