thanos1

#!/bin/bash
#获取本地IP(网卡不确定)
# ip addr show eth0 | awk '/^[0-9]+: / {}; /inet.*global/ {print gensub(/(.*)\/(.*)/, "\\1", "g", $2)}'
HOSTIP=`ip addr show eth0 |grep eth0|grep inet|awk -F '/' '{print $1}'|awk '{print $2}'`
endpoint=oss-cn-east-3-internal.unicloudsrv.com
access_key=tl0yZHXne5zW7i7w
secret_key=ETpbXimrqtjCOG61D1fdUGh4gG4HF1
#资源地址
#资源准备
wget -P /usr/local/bin/ http://172.20.8.251/node_exporter
wget -P /usr/local/bin/ http://172.20.8.251/prometheus
wget -P /etc/ http://172.20.8.251/prometheus.yml
wget -P /usr/local/bin/ http://172.20.8.251/thanos
chmod +x /usr/local/bin/node_exporter
chmod +x /usr/local/bin/prometheus
chmod +x /usr/local/bin/thanos
#资源初始化
init(){
#将node_exporter添加到system
cat > /etc/systemd/system/node_exporter.service <<EOF
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/bin/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
#将prometheus添加到system
cat > /etc/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target

[Service]
User=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus --config.file=/etc/prometheus.yml --storage.tsdb.max-block-duration=2h --storage.tsdb.min-block-duration=2h --web.enable-lifecycle
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF
#将sidecar添加到system
cat > /etc/systemd/system/sidecar.service <<EOF
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target

[Service]

User=prometheus
Type=simple
ExecStart=thanos sidecar --tsdb.path=/prometheus/data --prometheus.url=http://localhost:9090 --http-address=0.0.0.0:19191 --grpc-address=0.0.0.0:19091 --objstore.config-file=/root/thanos-config.yaml

[Install]
WantedBy=multi-user.target
EOF
#将query添加到system
cat > /etc/systemd/system/query.service <<EOF
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target

[Service]

User=prometheus
Type=simple
ExecStart=thanos query --http-address=0.0.0.0:19192 --store=localhost:19090 --store=localhost:19914

[Install]
WantedBy=multi-user.target
EOF
#将store添加到system
cat > /etc/systemd/system/store.service <<EOF
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target

[Service]

User=prometheus
Type=simple
ExecStart=thanos store --data-dir=/store --objstore.config-file=/root/thanos-config.yaml --http-address=0.0.0.0:19904 --grpc-address=0.0.0.0:19914 --index-cache-size=250MB --sync-block-duration=5m --min-time=-2w --max-time=-1h

[Install]
WantedBy=multi-user.target
EOF

adduser prometheus
sed -i "s/localhost/${HOSTIP}/g" /etc/prometheus.yml
systemctl daemon-reload
systemctl start prometheus.service && systemctl enable prometheus.service
systemctl start node_exporter.service && systemctl enable node_exporter.service
systemctl start sidecar.service && systemctl enable sidecar.service
systemctl start query.service && systemctl enable query.service
systemctl start store.service && systemctl enable store.service
}
init

posted @ 2022-01-14 14:32  癌细胞V  阅读(53)  评论(0)    收藏  举报