一、部署方式
- Helm charts for single-node and cluster versions of VictoriaMetrics.
- Kubernetes operator for VictoriaMetrics.
- Ansible role for installing cluster VictoriaMetrics (by VictoriaMetrics).
- Ansible role for installing cluster VictoriaMetrics (by community).
- Ansible role for installing single-node VictoriaMetrics (by community).
- Snap package for VictoriaMetrics.
二、Snap 部署 - 懒人方法
Install victoriametrics on CentOS
sudo yum install epel-release
sudo yum install snapd
sudo systemctl enable --now snapd.socket
sudo ln -s /var/lib/snapd/snap /snap
sudo snap install victoriametrics
[sysadmin@VM-201-69-centos ~]$ sudo snap stop victoriametrics
Stopped.
[sysadmin@VM-201-69-centos ~]$ sudo snap start victoriametrics
Started.
[sysadmin@VM-201-69-centos ~]$ sudo snap restart victoriametrics
Restarted.
[sysadmin@VM-201-69-centos ~]$ sudo snap remove victoriametrics
victoriametrics removed
三、二进制安装 - 自定义部署
下载 VictoriaMetrics 二进制可执行文件 or Docker image ,然后以命令行参数启动。
victoriametrics_repo_url: "https://github.com/VictoriaMetrics/VictoriaMetrics"
victoriametrics_download_url: "{{ victoriametrics_repo_url }}/releases/download/{{ victoriametrics_version }}/victoria-metrics-{{ victoriametrics_version }}.tar.gz"
victoriametrics_version: "v1.28.0"
victoriametrics_system_user: "victoriametrics"
victoriametrics_system_group: "{{ victoriametrics_system_user }}"
victoriametrics_delete_auth_key: "secret"
victoriametrics_snapshot_auth_key: "secret"
victoriametrics_service_args: ""
创建部署脚本 deploy_victoriametric.sh
,如下
#!/bin/bash
# 设置环境变量
version=$1
gitrepo_url=https://github.com/VictoriaMetrics/VictoriaMetrics
single_download_url=$gitrepo_url/releases/download/$version/victoria-metrics-linux-amd64-$version.tar.gz
single_out=victoria-metrics-linux-amd64-$version.tar.gz
single_download_checksum=$gitrepo_url/releases/download/$version/victoria-metrics-linux-amd64-"$version"_checksums.txt
single_checksum_file=victoria-metrics-linux-amd64-"$version"_checksums.txt
cluster_download_url=$gitrepo_url/releases/download/$version/victoria-metrics-linux-amd64-$version-cluster.tar.gz
cluster_out=victoria-metrics-linux-amd64-$version-cluster.tar.gz
cluster_download_checksum=$gitrepo_url/releases/download/$version/victoria-metrics-linux-amd64-"$version"-cluster_checksums.txt
cluster_checksum_file=victoria-metrics-linux-amd64-"$version"-cluster_checksums.txt
running_user=victoriametrics
running_group=$running_user
victoriametrics_delete_auth_key="secret"
victoriametrics_snapshot_auth_key="secret"
victoriametrics_service_args=""
mkdir -p vm_download/ & cd vm_download/
cd vm_download/
#下载二进制包
#wget $single_download_url
#wget $single_download_checksum
#wget $cluster_download_url
#wget $cluster_download_checksum
#创建用户和用户组
#useradd -u 1003 $running_user
#解压
tar xzf $single_out
#校验
#sha256sum -c $single_checksum_file --status
sha256sum -c $single_checksum_file
checksum_status=$?
if [ $checksum_status ];then
echo "Download succeed!"
else
echo "Download fail!"
fi
#部署二进制文件
install -o victoriametrics -g victoriametrics -m 0755 victoria-metrics-prod /usr/local/bin/victoriametrics
#
mkdir -p /run/victoriametrics && chown victoriametrics:victoriametrics /run/victoriametrics
mkdir -p /lvmdata/victoriametrics/data/ && chown -R victoriametrics:victoriametrics /lvmdata/victoriametrics/
#配置systemd管理服务
cat > /etc/systemd/system/victoriametrics.service <<EOF
[Unit]
Description=VictoriaMetrics
After=network.target
[Service]
Type=simple
StartLimitBurst=5
StartLimitInterval=0
Restart=on-failure
RestartSec=1
PIDFile=/run/victoriametrics/victoriametrics.pid
ExecStart=/usr/local/bin/victoriametrics -storageDataPath /lvmdata/victoriametrics/data/ -retentionPeriod 1098
ExecStop=/bin/kill -s SIGTERM $MAINPID
User=victoriametrics
[Install]
WantedBy=multi-user.target
EOF
#ulimit
mkdir -p /etc/systemd/system/victoriametrics.service.d
cat > /etc/systemd/system/victoriametrics.service.d/ulimit.conf << EOF
[Service]
LimitNOFILE=32000
LimitNPROC=32000
EOF
systemctl daemon-reload
执行脚本 sudo sh deploy_victoriametric.sh v1.100.1
启动 victoriametrics
https://docs.victoriametrics.com/single-server-victoriametrics/#how-to-start-victoriametrics
[sysadmin@VM-201-69-centos ~]$ sudo systemctl start victoriametrics
[sysadmin@VM-201-69-centos ~]$ sudo systemctl status victoriametrics
● victoriametrics.service - VictoriaMetrics
Loaded: loaded (/etc/systemd/system/victoriametrics.service; disabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/victoriametrics.service.d
└─ulimit.conf
Active: active (running) since Sun 2024-04-21 23:17:23 CST; 4s ago
Main PID: 7555 (victoriametrics)
CGroup: /system.slice/victoriametrics.service
└─7555 /usr/local/bin/victoriametrics -storageDataPath /lvmdata/victoriametrics/data/ -retentionPeriod 1098
Apr 21 23:17:23 VM-201-69-centos victoriametrics[7555]: 2024-04-21T15:17:23.927Z info VictoriaMetrics/lib/logger/flag.go:20 -storageDataPath="/lvmdata/victoriametrics/data/"
Apr 21 23:17:23 VM-201-69-centos victoriametrics[7555]: 2024-04-21T15:17:23.927Z info VictoriaMetrics/app/victoria-metrics/main.go:73 starting VictoriaMetrics at "[:8428]"...
Apr 21 23:17:23 VM-201-69-centos victoriametrics[7555]: 2024-04-21T15:17:23.927Z info VictoriaMetrics/app/vmstorage/main.go:106 opening storage at "/lvmdata/victoriametri...onPeriod=1098Apr 21 23:17:23 VM-201-69-centos victoriametrics[7555]: 2024-04-21T15:17:23.936Z info VictoriaMetrics/lib/memory/memory.go:42 limiting caches to 2324162150 bytes, leaving...wedPercent=60Apr 21 23:17:24 VM-201-69-centos victoriametrics[7555]: 2024-04-21T15:17:24.009Z info VictoriaMetrics/app/vmstorage/main.go:120 successfully opened storage "/lvmdata/vict... sizeBytes: 0Apr 21 23:17:24 VM-201-69-centos victoriametrics[7555]: 2024-04-21T15:17:24.010Z info VictoriaMetrics/app/vmselect/promql/rollup_result_cache.go:126 loading rollupResult ...lupResult"...Apr 21 23:17:24 VM-201-69-centos victoriametrics[7555]: 2024-04-21T15:17:24.012Z info VictoriaMetrics/app/vmselect/promql/rollup_result_cache.go:155 loaded rollupResult c... sizeBytes: 0Apr 21 23:17:24 VM-201-69-centos victoriametrics[7555]: 2024-04-21T15:17:24.012Z info VictoriaMetrics/app/victoria-metrics/main.go:84 started VictoriaMetrics in 0.085 seconds
Apr 21 23:17:24 VM-201-69-centos victoriametrics[7555]: 2024-04-21T15:17:24.012Z info VictoriaMetrics/lib/httpserver/httpserver.go:118 starting server at http://127.0.0.1:8428/
Apr 21 23:17:24 VM-201-69-centos victoriametrics[7555]: 2024-04-21T15:17:24.012Z info VictoriaMetrics/lib/httpserver/httpserver.go:119 pprof handlers are exposed at http:.../debug/pprof/Hint: Some lines were ellipsized, use -l to show in full.
[sysadmin@VM-201-69-centos ~]$ ps axu |grep victoriametrics
victori+ 7555 0.3 0.2 1242892 10820 ? Ssl 23:17 0:00 /usr/local/bin/victoriametrics -storageDataPath /lvmdata/victoriametrics/data/ -retentionPeriod 1098
sysadmin 7648 0.0 0.0 112812 984 pts/0 S+ 23:17 0:00 grep --color=auto victoriametrics
[sysadmin@VM-201-69-centos ~]$ sudo netstat -anpl |grep victor
tcp 0 0 0.0.0.0:8428 0.0.0.0:* LISTEN 7555/victoriametric
unix 3 [ ] STREAM CONNECTED 788533965 7555/victoriametric
网友评论