-
Notifications
You must be signed in to change notification settings - Fork 0
/
prerequisites.sh
101 lines (69 loc) · 2.52 KB
/
prerequisites.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
cd $HOME
echo "------- checking for go, will be installed if not installed already -------"
command_exists () {
type "$1" &> /dev/null ;
}
if command_exists go ; then
echo "Golang is already installed"
else
echo "-----Installing dependencies-----"
sudo apt-get update
sudo apt-get install build-essential jq -y
wget https://dl.google.com/go/go1.20.3.linux-amd64.tar.gz
tar -xvf go1.20.3.linux-amd64.tar.gz
sudo mv go /usr/local
echo "-------updating bashrc-------"
export GOPATH=$HOME/go
export GOROOT=/usr/local/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:/usr/local/go/bin:$GOBIN
echo "" >> ~/.bashrc
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export GOROOT=/usr/local/go' >> ~/.bashrc
echo 'export GOBIN=$GOPATH/bin' >> ~/.bashrc
echo 'export PATH=$PATH:/usr/local/go/bin:$GOBIN' >> ~/.bashrc
source ~/.bashrc
mkdir -p "$GOBIN"
fi
echo "-------Installing grafana-------"
sudo apt-get install -y adduser libfontconfig1 musl
wget https://dl.grafana.com/oss/release/grafana_10.2.1_amd64.deb
sudo dpkg -i grafana_10.2.1_amd64.deb
echo "-------Starting grafana server using systemd-------"
sudo systemctl daemon-reload
sudo systemctl start grafana-server
echo "-------Installing prometheus-------"
wget https://github.com/prometheus/prometheus/releases/download/v2.22.1/prometheus-2.22.1.linux-amd64.tar.gz
tar -xvf prometheus-2.22.1.linux-amd64.tar.gz
tar -xvf prometheus-2.22.1.linux-amd64.tar.gz
cp prometheus-2.22.1.linux-amd64/prometheus $GOBIN
cp prometheus-2.22.1.linux-amd64/prometheus.yml $HOME
echo "----- writing prometheus.yml-----"
echo "
- job_name: 'avail-monitor'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:1234'] >> "$HOME/prometheus.yml"
echo "------- Setting up prometheus system service -------"
echo "[Unit]
Description=Prometheus
After=network-online.target
[Service]
Type=simple
ExecStart=$HOME/go/bin/prometheus --config.file=$HOME/prometheus.yml
Restart=always
RestartSec=3
LimitNOFILE=4096
[Install]
WantedBy=multi-user.target" | sudo tee "/lib/systemd/system/prometheus.service"
echo "------starting prometheus -----------"
sudo systemctl daemon-reload
sudo systemctl enable prometheus.service
sudo systemctl start prometheus.service
rm ~/grafana_10.2.1_amd64.deb
rm ~/prometheus-2.22.1.linux-amd64.tar.gz
rm ~/go1.20.3.linux-amd64.tar.gz
rm -rf ~/prometheus-2.22.1.linux-amd64
echo "------- Installation completed successfully -------"