自动安装grafana + alertmanager + prometheus+ telegraf并建立systemctl托管文件

#!/bin/bash

start() {
cat <<EOF
    1.需要用到的命令wget apt-get tar
EOF
}
install_1() {
   install_grafana="grafana-8.5.2.linux-amd64.tar.gz"
   echo "1. 开始检测是否安装grafana"
   ss -ntulp |grep grafana 
if [ $? = 0 ]; then
   echo "绘图软件grafana已安装"
else 
   echo "开始安装grafana$"
   mkdir -p /opt/granfana
   wget https://dl.grafana.com/oss/release/${install_grafana}
   tar -xvzf ${install_grafana} -C /opt/granfana
   [ $? = 0 ] && echo "下载解压完成" || echo "下载解压失败"
fi
}
tuoguan() {
    echo "开始创建grafana托管文件"
    vim /etc/systemd/system/granfana.service

cat <<EOF >/etc/systemd/system/grafana.service

[Unit]
Description="grafana"
After=network.target


[Service]
Type=simple
ExecStart=/opt/granfana/grafana-8.5.2/bin/grafana-server web > /opt/granfana/grafana-8.5.2/bin/web.log 
WorkingDirectory=/opt/granfana/grafana-8.5.2/bin
Restart=always

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable  grafana
systemctl restart grafana
systemctl status  grafana
}

main () {
      start
      install_1
      tuoguan
}
main


# 安装 alertmanager
#!/bin/bash

start() {
cat <<EOF
    1.需要用到的命令wget apt-get tar
EOF
}
install_1() {
    ss -ntulp |grep alertmanager
    VERSION=alertmanager-0.24.0.linux-amd64.tar.gz
if [ $? = 0 ]; then
    echo "alertmanager 已安装"
else
    echo "开始安装 ${VERSION}"
    wget https://github.com/prometheus/alertmanager/releases/download/v0.24.0/${VERSION}
    tar -xvzf ${VERSION} -C /opt/alertmanager
    vim /etc/systemd/system/alertmanager.service
cat <<EOF >/etc/systemd/system/alertmanager.service

[Unit]
Description="alertmanager"
After=network.target

[Service]
ExecStart=/opt/alertmanger/alertmanager-0.24.0.linux-amd64/alertmanager --config.file=/opt/alertmanger/alertmanager-0.24.0.linux-amd64/alertmanager.yml --storage.path=/opt/alertmanger/alertmanager-0.24.0.linux-amd64/data --web.listen-address=:9093 --data.retention=120h
WorkingDirectory=/opt/alertmanger/alertmanager-0.24.0.linux-amd64
Restart=always

[Install]
WantedBy=multi-user.target

EOF
systemctl daemon-reload
systemctl enable  alertmanager
systemctl restart alertmanager
systemctl status  alertmanager
}
main() {
    start
    install_1
}
main


# 安装 prometheus
# install prometheus
mkdir -p /opt/prometheus
wget https://s3-gz01.didistatic.com/n9e-pub/prome/prometheus-2.28.0.linux-amd64.tar.gz -O prometheus-2.28.0.linux-amd64.tar.gz
tar xf prometheus-2.28.0.linux-amd64.tar.gz
cp -far prometheus-2.28.0.linux-amd64/*  /opt/prometheus/

# service 
cat <<EOF >/etc/systemd/system/prometheus.service
[Unit]
Description="prometheus"
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple

ExecStart=/opt/prometheus/prometheus  --config.file=/opt/prometheus/prometheus.yml --storage.tsdb.path=/opt/prometheus/data --web.enable-lifecycle --enable-feature=remote-write-receiver --query.lookback-delta=2m --web.listen-address=:8091

Restart=on-failure
SuccessExitStatus=0
LimitNOFILE=65536
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=prometheus


[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable prometheus
systemctl restart prometheus
systemctl status prometheus



# 安装telegraf

#!/bin/sh

version=1.20.4
tarball=telegraf-${version}_linux_amd64.tar.gz
wget https://dl.influxdata.com/telegraf/releases/$tarball
tar xzvf $tarball

mkdir -p /opt/telegraf
cp -far telegraf-${version}/usr/bin/telegraf /opt/telegraf

cat <<EOF > /opt/telegraf/telegraf.conf
[global_tags]

[agent]
  interval = "10s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "0s"
  precision = ""
  hostname = ""
  omit_hostname = false

[[outputs.opentsdb]]
  host = "http://127.0.0.1"
  port = 19000
  http_batch_size = 50
  http_path = "/opentsdb/put"
  debug = false
  separator = "_"

[[inputs.cpu]]
  percpu = true
  totalcpu = true
  collect_cpu_time = false
  report_active = true

[[inputs.disk]]
  ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]

[[inputs.diskio]]

[[inputs.kernel]]

[[inputs.mem]]

[[inputs.processes]]

[[inputs.system]]
  fielddrop = ["uptime_format"]

[[inputs.net]]
  ignore_protocol_stats = true

EOF

cat <<EOF > /etc/systemd/system/telegraf.service
[Unit]
Description="telegraf"
After=network.target

[Service]
Type=simple
ExecStart=/opt/telegraf/telegraf --config telegraf.conf --config-directory /opt/telegraf/telegraf.d

WorkingDirectory=/opt/telegraf
SuccessExitStatus=0
LimitNOFILE=65536
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=telegraf
KillMode=process
KillSignal=SIGQUIT
TimeoutStopSec=5
Restart=always


[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable telegraf
systemctl restart telegraf
systemctl status telegraf


posted @ 2022-07-06 19:17  GEGEWU-  阅读(151)  评论(0)    收藏  举报