传统运维 - VictoriaMetrics
2023-08-04
#!/bin/bash
function CreateVmStorageService(){
cat > /usr/lib/systemd/system/vmstorage.service << EOF
[Unit]
Description=vmstorage Service
After=network.target
[Service]
Type=simple
User=root
Restart=on-failure
RestartSec=5s
ExecStart=/data/victoria-metrics/bin/vmstorage -retentionPeriod=15d -storageDataPath=/data/victoria-metrics/data/vmstorage -memory.allowedBytes=3GB -httpListenAddr=:8482 -vminsertAddr=:8400 -vmselectAddr=:8401 -dedup.minScrapeInterval=30s
[Install]
WantedBy=multi-user.target
EOF
}
function CreateVmInsertService(){
cat > /usr/lib/systemd/system/vminsert.service << EOF
[Unit]
Description=vminsert Service
After=network.target
[Service]
Type=simple
User=root
Restart=on-failure
RestartSec=5s
ExecStart=/data/victoria-metrics/bin/vminsert -replicationFactor=2 -storageNode=172.31.18.203:8400 -storageNode=172.31.20.0:8400 -memory.allowedBytes=1GB -httpListenAddr=:8480
[Install]
WantedBy=multi-user.target
EOF
}
function CreateVmSelectService(){
cat > /usr/lib/systemd/system/vmselect.service << EOF
[Unit]
Description=vmselect Service
After=network.target
[Service]
Type=simple
User=root
Restart=on-failure
RestartSec=5s
ExecStart=/data/victoria-metrics/bin/vmselect -dedup.minScrapeInterval=30s -storageNode=172.31.18.203:8401 -storageNode=172.31.20.0:8401 -memory.allowedBytes=1GB -httpListenAddr=:8481
[Install]
WantedBy=multi-user.target
EOF
}
# 配置变量
VM_HOME='/data/victoria-metrics'
VMSOTRAGE_PORT='8482' #vmstorage监听端口
VMSOTRAGE_INSERT_PORT='8400' #vmstorage对vminsert提供服务的监听端口
VMSOTRAGE_SELECT_PORT='8401' #vmstorage对vmselect提供服务的监听端口
VMINSERT_PORT='8480' #vminsert监听端口
VMSELECT_PORT='8481' #vmselect监听端口
VMAGENT_PORT='8429' #vmagent监听端口
SELECT_STORAGE_NODE_LIST=''
INSERT_STORAGE_NODE_LIST=''
NODE_LIST='172.31.18.203 172.31.20.0'
for NODE_IP in $(echo ${NODE_LIST} | awk '{split($0,arr,",");for(i in arr) print arr[i]}')
do
INSERT_STORAGE_NODE_LIST="${INSERT_STORAGE_NODE_LIST}\"${NODE_IP}:${VMSOTRAGE_INSERT_PORT}\","
SELECT_STORAGE_NODE_LIST="${SELECT_STORAGE_NODE_LIST}\"${NODE_IP}:${VMSOTRAGE_SELECT_PORT}\","
done
# 创建程序目录
mkdir -p ${VM_HOME}/{bin,logs,data,config}
CreateVmStorageService
CreateVmInsertService
CreateVmSelectService
apps="vmstorage vminsert vmselect"
for app in ${apps}
do
systemctl stop ${apps}.service
cp /usr/local/src/${app}-prod /data/victoria-metrics/bin/${app}
systemctl enable ${apps}.service
systemctl restart ${apps}.service
done