Compare commits

..

No commits in common. "247a12ffba1b5df4de9284625a05d8d2e0237a6c" and "b2ad3c800ac562a255b07940e09a742c0e3177c8" have entirely different histories.

View File

@ -47,8 +47,11 @@ function install_prometheus() {
echo "Copying Prometheus binary to $PROMETHEUS_DIR..."
cp prometheus-$PROMETHEUS_VERSION.linux-amd64/prometheus $PROMETHEUS_DIR
echo "Copying promtool binary to /usr/local/bin"
sudo cp prometheus-$PROMETHEUS_VERSION.linux-amd64/promtool /usr/local/bin
echo "Copying promtool to /usr/local/bin..."
cp prometheus-$PROMETHEUS_VERSION.linux-amd64/promtool /usr/local/bin/
echo "Creating necessary directories for Prometheus data and config..."
mkdir -p $CONFIG_DIR $DATA_DIR
echo "Creating Prometheus configuration file in $CONFIG_DIR..."
cat <<EOF > $CONFIG_DIR/prometheus.yml
@ -66,16 +69,16 @@ scrape_configs:
EOF
echo "Creating $PROMETHEUS_USER user and group..."
sudo groupadd --system $PROMETHEUS_GROUP
sudo useradd -s /sbin/nologin --system -g $PROMETHEUS_GROUP $PROMETHEUS_USER
groupadd --system $PROMETHEUS_GROUP
useradd -s /sbin/nologin --system -g $PROMETHEUS_GROUP $PROMETHEUS_USER
echo "Setting ownership of directories and files..."
sudo chown -R $PROMETHEUS_USER:$PROMETHEUS_GROUP $CONFIG_DIR $DATA_DIR
sudo chown -R $PROMETHEUS_USER:$PROMETHEUS_GROUP /usr/local/bin/prometheus
sudo chown -R $PROMETHEUS_USER:$PROMETHEUS_GROUP /usr/local/bin/node_exporter
chown -R $PROMETHEUS_USER:$PROMETHEUS_GROUP $CONFIG_DIR $DATA_DIR
chown -R $PROMETHEUS_USER:$PROMETHEUS_GROUP /usr/local/bin/prometheus
chown -R $PROMETHEUS_USER:$PROMETHEUS_GROUP /usr/local/bin/node_exporter
echo "Creating systemd service for Prometheus..."
cat <<EOF | sudo tee /etc/systemd/system/prometheus.service > /dev/null
cat <<EOF > /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Time Series Database
Wants=network-online.target
@ -95,11 +98,11 @@ WantedBy=default.target
EOF
echo "Reloading systemd daemon..."
sudo systemctl daemon-reload
systemctl daemon-reload
echo "Enabling Prometheus service..."
sudo systemctl enable prometheus.service
systemctl enable prometheus.service
echo "Starting Prometheus service..."
sudo systemctl start prometheus.service
systemctl start prometheus.service
echo "Checking status of Prometheus service..."
systemctl status prometheus.service
}
@ -126,10 +129,10 @@ function install_node_exporter() {
tar xvfz node_exporter-$NODE_EXPORTER_VERSION.linux-amd64.tar.gz
echo "Copying Node Exporter binary to $BINARY_DIR..."
sudo cp node_exporter-$NODE_EXPORTER_VERSION.linux-amd64/node_exporter $BINARY_DIR
cp node_exporter-$NODE_EXPORTER_VERSION.linux-amd64/node_exporter $BINARY_DIR
echo "Creating systemd service for Node Exporter..."
cat <<EOF | sudo tee /etc/systemd/system/node_exporter.service > /dev/null
cat <<EOF > /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
Wants=network-online.target
@ -147,11 +150,11 @@ WantedBy=default.target
EOF
echo "Reloading systemd daemon..."
sudo systemctl daemon-reload
systemctl daemon-reload
echo "Enabling Node Exporter service..."
sudo systemctl enable node_exporter.service
systemctl enable node_exporter.service
echo "Starting Node Exporter service..."
sudo systemctl start node_exporter.service
systemctl start node_exporter.service
echo "Checking status of Node Exporter service..."
systemctl status node_exporter.service
}
@ -177,12 +180,9 @@ function install_grafana() {
echo "Starting Grafana service..."
sudo systemctl start grafana-server
echo "Checking status of Grafana service..."
systemctl status grafana-server
sudo systemctl status grafana-server
}
# Prompt for sudo password and validate it
sudo -v
# Main script execution
show_menu