Install Victoria Metrics

Install with delivered script

Redpeaks Cockpit deliver a script to install automatically victoria metrics.

Victoria metrics will be installed by default in /opt/victoria.

Run the install.sh script in victoria-metrics

Alternatively, you can download the latest package from Victoria metrics repository

Look for package victoria-metrics-linux-amd64-vx.yy.zz.tar.gz

Prepare VM files system

You need to prepare two file systems:

One for hosting database data

One for hosting database backups

Install manually

mkdir /YOUR_FOLDER/victoriametrics
vi /etc/systemd/system/victoriametrics.service

Content victoriametrics.service file :

[Unit]
Description=Victoria Metrics
After=network.target
[Service]
Type=simple
StartLimitBurst=5
StartLimitInterval=0
Restart=on-failure
RestartSec=1
PIDFile=/YOUR_FOLDER/victoriametrics/victoriametrics.pid
ExecStart=/usr/local/bin/victoriametrics -storageDataPath /YOUR_FOLDER/victoriametrics-data -retentionPeriod 6 -graphiteListenAddr=:2003 -dedup.minScrapeInterval=1ms
ExecStop=/bin/kill -s SIGTERM $MAINPID
[Install]
WantedBy=multi-user.target

chmod 755 /etc/systemd/system/victoriametrics.service
mkdir /etc/systemd/system/victoriametrics.service.d
vi /etc/systemd/system/victoriametrics.service.d/ulimit.conf

Create the file ulimit.conf with following content :

[Service]
LimitNOFILE=32000
LimitNPROC=32000

wget https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/vX.XX.X/victoria-metrics-amd64-vX.XX.X.tar.gz
tar -zxvf victoria-metrics-amd64-vX.XX.X.tar.gz
cp -R victoria-metrics-prod /usr/local/bin/victoriametrics
systemctl enable victoriametrics
firewall-cmd --zone=public --add-port=2003/tcp --permanent
firewall-cmd --reload
systemctl start victoriametrics

Backups

To configure backups, we are going to use victoria metrics vmbackup utility.

Get the latest LTS version of the files (Use AMD64 for typical linux system):

wget https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/vX.XX.X/vmutils-amd64-vX.XX.X.tar.gz
tar -zxvf vmutils-amd64-vX.XX.X.tar.gz

Create a script do_vm_backup.sh:

#!/bin/sh
vmbackup-prod -storageDataPath=[VM_DATA_FOLDER] -snapshot.createURL=http://localhost:8428/snapshot/create -dst=fs://[VM_BACKUP_FOLDER]

Change file permissions

chmod 700 do_vm_backup.sh

Edit crontab

crontab -e
0 */1 * * * /[PATH_TO_SCRIPT]/do_vm_backup.sh

The backup will now run once per hour

Restore

To restore a backup, we are going to use the vmrestore utility:

systemctl stop victoriametrics
vmrestore-prod -src=fs:///[PATH_TO_BACKUPS] -storageDataPath=[VM_DATA_FOLDER]
systemctl start victoriametrics