28/10
This commit is contained in:
parent
69e72fff97
commit
06914042fa
@ -0,0 +1,86 @@
|
||||
#!/bin/bash
|
||||
# Script d'installation et déploiement ArchiWeb
|
||||
# À exécuter en tant que root ou avec sudo
|
||||
|
||||
set -e # Arrêt si une commande échoue
|
||||
set -o pipefail
|
||||
|
||||
echo "=== Mise à jour du système ==="
|
||||
sudo apt update && sudo apt upgrade -y
|
||||
|
||||
echo "=== Installation Java 17 et Maven ==="
|
||||
sudo apt install -y openjdk-17-jdk maven wget gnupg lsb-release
|
||||
|
||||
echo "=== Vérification des versions ==="
|
||||
java -version
|
||||
mvn -version
|
||||
|
||||
echo "=== Installation de Tomcat 10 ==="
|
||||
cd /opt
|
||||
sudo wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.47/bin/apache-tomcat-10.1.47.tar.gz
|
||||
sudo tar -xvzf apache-tomcat-10.1.47.tar.gz
|
||||
sudo mv apache-tomcat-10.1.47 tomcat
|
||||
sudo chown -R vagrant:vagrant /opt/tomcat
|
||||
|
||||
echo "=== Configuration des variables d'environnement ==="
|
||||
if ! grep -q "CATALINA_HOME" ~/.bashrc; then
|
||||
echo "export CATALINA_HOME=/opt/tomcat" >> ~/.bashrc
|
||||
echo 'export PATH=$PATH:$CATALINA_HOME/bin' >> ~/.bashrc
|
||||
fi
|
||||
source ~/.bashrc
|
||||
|
||||
echo "=== Création du service systemd pour Tomcat ==="
|
||||
cat <<EOF | sudo tee /etc/systemd/system/tomcat.service
|
||||
[Unit]
|
||||
Description=Apache Tomcat 10.1.47
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
Environment=JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
|
||||
Environment=CATALINA_HOME=/opt/tomcat
|
||||
ExecStart=/opt/tomcat/bin/startup.sh
|
||||
ExecStop=/opt/tomcat/bin/shutdown.sh
|
||||
User=vagrant
|
||||
Group=vagrant
|
||||
RestartSec=10
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable tomcat
|
||||
sudo systemctl start tomcat
|
||||
sudo systemctl status tomcat --no-pager
|
||||
|
||||
echo "=== Déploiement du WAR ArchiWeb ==="
|
||||
sudo cp /vagrant/archiweb-api-1.0.0.war /opt/tomcat/webapps/
|
||||
|
||||
echo "=== Installation PostgreSQL 18 ==="
|
||||
echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
|
||||
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
|
||||
sudo apt update
|
||||
sudo apt install -y postgresql-18 postgresql-client-18 postgresql-contrib
|
||||
|
||||
echo "=== Configuration de PostgreSQL ==="
|
||||
sudo -u postgres psql <<EOF
|
||||
DROP DATABASE IF EXISTS archiweb_db;
|
||||
CREATE DATABASE archiweb_db;
|
||||
CREATE USER archiweb_user WITH ENCRYPTED PASSWORD 'archiweb_pass';
|
||||
GRANT ALL PRIVILEGES ON DATABASE archiweb_db TO archiweb_user;
|
||||
\q
|
||||
EOF
|
||||
|
||||
# Modification du fichier pg_hba.conf pour md5
|
||||
PG_HBA="/etc/postgresql/18/main/pg_hba.conf"
|
||||
sudo sed -i "s/^local\s\+all\s\+all\s\+peer/local all all md5/" $PG_HBA
|
||||
sudo systemctl restart postgresql
|
||||
sudo systemctl status postgresql --no-pager
|
||||
|
||||
echo "=== Import des schémas et données ==="
|
||||
sudo -u archiweb_user psql -U archiweb_user -d archiweb_db -f /vagrant/database/schema.sql -W <<< "archiweb_pass"
|
||||
sudo -u archiweb_user psql -U archiweb_user -d archiweb_db -f /vagrant/database/data.sql -W <<< "archiweb_pass"
|
||||
|
||||
echo "=== Installation et déploiement terminé ==="
|
||||
@ -0,0 +1,111 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Variables
|
||||
PROMTAIL_VERSION="v3.1.1"
|
||||
PROMTAIL_DIR="/opt/promtail"
|
||||
CONFIG_DIR="/etc/promtail"
|
||||
TOMCAT_LOG_DIR="/opt/tomcat/logs"
|
||||
LOKI_URL="http://192.168.56.20:3100/loki/api/v1/push"
|
||||
PROMTAIL_USER="promtail"
|
||||
PROMTAIL_GROUP="promtail"
|
||||
TOMCAT_GROUP="tomcatlogs"
|
||||
|
||||
# 1. Installation de Promtail
|
||||
echo "=== Installation de Promtail ==="
|
||||
mkdir -p $PROMTAIL_DIR
|
||||
cd $PROMTAIL_DIR
|
||||
wget -q https://github.com/grafana/loki/releases/download/$PROMTAIL_VERSION/promtail-linux-amd64.zip
|
||||
apt-get update && apt-get install -y unzip
|
||||
unzip -o promtail-linux-amd64.zip
|
||||
mv promtail-linux-amd64 promtail
|
||||
chmod +x promtail
|
||||
|
||||
# 2. Création de l'utilisateur promtail
|
||||
id -u $PROMTAIL_USER &>/dev/null || useradd -r -s /bin/false $PROMTAIL_USER
|
||||
chown -R $PROMTAIL_USER:$PROMTAIL_GROUP $PROMTAIL_DIR || true
|
||||
|
||||
# 3. Configuration Promtail
|
||||
echo "=== Configuration Promtail ==="
|
||||
mkdir -p $CONFIG_DIR
|
||||
|
||||
cat > $CONFIG_DIR/config-promtail.yaml <<EOF
|
||||
server:
|
||||
http_listen_port: 9080
|
||||
grpc_listen_port: 0
|
||||
|
||||
positions:
|
||||
filename: /tmp/positions.yaml
|
||||
|
||||
clients:
|
||||
- url: $LOKI_URL
|
||||
|
||||
scrape_configs:
|
||||
- job_name: tomcat
|
||||
static_configs:
|
||||
- targets:
|
||||
- localhost
|
||||
labels:
|
||||
job: tomcat
|
||||
host: applicatif-vm
|
||||
type: catalina
|
||||
__path__: $TOMCAT_LOG_DIR/catalina*.log
|
||||
- targets:
|
||||
- localhost
|
||||
labels:
|
||||
job: tomcat
|
||||
host: applicatif-vm
|
||||
type: localhost
|
||||
__path__: $TOMCAT_LOG_DIR/localhost*.log
|
||||
- targets:
|
||||
- localhost
|
||||
labels:
|
||||
job: tomcat
|
||||
host: applicatif-vm
|
||||
type: access
|
||||
__path__: $TOMCAT_LOG_DIR/localhost_access_log*.txt
|
||||
- targets:
|
||||
- localhost
|
||||
labels:
|
||||
job: tomcat
|
||||
host: applicatif-vm
|
||||
type: out
|
||||
__path__: $TOMCAT_LOG_DIR/catalina.out
|
||||
EOF
|
||||
|
||||
# 4. Création du service systemd
|
||||
echo "=== Création du service systemd ==="
|
||||
cat > /etc/systemd/system/promtail.service <<EOF
|
||||
[Unit]
|
||||
Description=Promtail service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=$PROMTAIL_USER
|
||||
ExecStart=$PROMTAIL_DIR/promtail -config.file=$CONFIG_DIR/config-promtail.yaml
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# 5. Gestion des permissions Tomcat logs
|
||||
echo "=== Configuration des permissions Tomcat logs ==="
|
||||
groupadd -f $TOMCAT_GROUP
|
||||
usermod -aG $TOMCAT_GROUP $PROMTAIL_USER || true
|
||||
usermod -aG $TOMCAT_GROUP vagrant || true
|
||||
chown -R vagrant:$TOMCAT_GROUP $TOMCAT_LOG_DIR
|
||||
chmod -R 750 $TOMCAT_LOG_DIR
|
||||
chmod -R g+r $TOMCAT_LOG_DIR/*.log
|
||||
|
||||
# 6. Activation du service Promtail
|
||||
echo "=== Activation du service Promtail ==="
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now promtail
|
||||
systemctl restart promtail
|
||||
systemctl status promtail --no-pager
|
||||
|
||||
# 7. Vérification des logs
|
||||
echo "=== Vérification des logs ==="
|
||||
ls -ld $TOMCAT_LOG_DIR
|
||||
ls -l $TOMCAT_LOG_DIR | head
|
||||
Loading…
x
Reference in New Issue
Block a user