Outils pour utilisateurs

Outils du site


hive:ded

Ruches


Ce soft permet de gérer plusieurs ruchers et colonies, il fonctionne aussi bien en local qu'en ligne.
Pour le moment il est en test en local sur une machine Linux Debian 11.

1. Installation des outils WEB pour faire fonctionner Ruches



TomCat9


wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.65/bin/apache-tomcat-9.0.65.tar.gz
mkdir /opt/tomcat
tar xzvf apache-tomcat-9.0.65.tar.gz -C /opt/tomcat --strip-components=1
chown -R tomcat:tomcat /opt/tomcat/
chmod -R u+x /opt/tomcat/bin
  • Créez ensuite le groupe et l'utilisateur
groupadd tomcat9
useradd -s /bin/false -g tomcat9 -d /etc/tomcat9 tomcat9
vim /opt/tomcat/conf/tomcat-users.xml
 
<!-- user manager can access only manager section -->
<role rolename="manager-gui" />
<user username="manager" password="manager" roles="manager-gui" />
 
<!-- user admin can access manager and admin section both -->
<role rolename="admin-gui" />
<user username="admin" password="admin" roles="manager-gui,admin-gui" />

ou ceci permettant à manager de se connecter

<role rolename="admin"/>
<role rolename="admin-gui"/>
<role rolename="manager"/>
<role rolename="manager-gui"/>
<user username="admin" password="admin" roles="admin,admin-gui,manager,manager-gui"/>
  • Activer l'accès distant à Tomcat
vim /opt/tomcat/webapps/manager/META-INF/context.xml
 
Commentez la section ajoutée pour la restriction d'adresse IP afin d'autoriser les connexions de n'importe où.
 
<Contexte antiResourceLocking="false" privilege="true" >
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
  <!--<Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />-->
  ...
</Context>

Modifiez également le fichier context.xml pour l'interface du gestionnaire d'hôte et commentez la section similaire comme ci-dessus.

vim /opt/tomcat/webapps/host-manager/META-INF/context.xml
 
<Context antiResourceLocking="false" privileged="true" >
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
  <!--  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
  allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
  • Créer un fichier d'unité Tomcat Systemd pour environnement Java
vim /etc/systemd/system/tomcat.service
 
[Unit]
Description=Tomcat
After=network.target
 
[Service]
Type=forking
 
User=tomcat
Group=tomcat
 
#Environment="JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64"
Environment="JAVA_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
 
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
 
[Install]
WantedBy=multi-user.target
  • Rechargez le service démon systemd pour charger le fichier
  • Démarrer le service tomacat
  • Activer le service au boot
  • Vérifier le service
systemctl daemon-reload && systemctl start tomcat.service && systemctl enable tomcat.service && systemctl status tomcat.service
 
● tomcat.service - Tomcat
     Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-08-29 18:18:41 CEST; 5ms ago
    Process: 20993 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
   Main PID: 21000 (java)
      Tasks: 1 (limit: 8224)
     Memory: 1.8M
        CPU: 11ms
     CGroup: /system.slice/tomcat.service
             └─21000 /usr/lib/jvm/java-1.17.0-openjdk-amd64/bin/java -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache>
 
aoû 29 18:18:41 ok systemd[1]: Starting Tomcat...
aoû 29 18:18:41 ok startup.sh[20993]: Tomcat started.
aoû 29 18:18:41 ok systemd[1]: Started Tomcat.
  • Accéder au serveur
 http://localhost:8080/
\\
 
  * **Administrer le serveur & définir l'utilisateur ayant accès à Tomcat**
<code bash>
vim /etc/tomcat9/tomcat-users.xml
 
<role rolename="admin"/>
<role rolename="admin-gui"/>
<role rolename="manager"/>
<role rolename="manager-gui"/>
<user username="admin" password="admin" roles="admin,admin-gui,manager,manager-gui"/>
 
systemctl start tomcat9 && systemctl status tomcat9
  • Se connecter au serveur Tomcat9
http://localhost:8080/manager/html
login: admin
psswd: admin

:-)

Apache


  • Installation de Apache2
apt install -y apache2
  • Démarrer le serveur
systemctl start apache2 && systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-08-27 14:27:46 CEST; 6ms ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 9528 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 9532 (apache2)
      Tasks: 56 (limit: 8224)
     Memory: 21.5M
        CPU: 27ms
     CGroup: /system.slice/apache2.service
             ├─9532 /usr/sbin/apache2 -k start
             ├─9534 /usr/sbin/apache2 -k start
             └─9535 /usr/sbin/apache2 -k start
 
aoû 27 14:27:46 ok systemd[1]: Starting The Apache HTTP Server...
aoû 27 14:27:46 ok systemd[1]: Started The Apache HTTP Server.

:-)

PhP 8.1


apt update && sudo apt upgrade -y
apt-get install ca-certificates apt-transport-https software-properties-common wget curl lsb-release -y
curl -sSL https://packages.sury.org/php/README.txt | sudo bash -x
apt update && apt upgrade
apt install php8.1 libapache2-mod-php8.1 -y
systemctl restart apache2
apt install php8.1-fpm libapache2-mod-fcgid
a2enmod proxy_fcgi setenvif && a2enconf php8.1-fpm
systemctl restart apache2 && systemctl status php8.1-fpm
php --version
echo '<?php phpinfo(); ?>' > /var/www/html/info.php
http://192.168.1.2/info.php

:-)

PostGreSQL


  • Installer le serveur
apt install -y postgresql postgresql-contrib
  • Démarrer le serveur
start postgresql@13-main.service && systemctl status postgresql@13-main.service 
● postgresql@13-main.service - PostgreSQL Cluster 13-main
     Loaded: loaded (/lib/systemd/system/postgresql@.service; enabled-runtime; vendor preset: enabled)
     Active: active (running) since Sat 2022-08-27 13:54:16 CEST; 49min ago
   Main PID: 791 (postgres)
      Tasks: 7 (limit: 8224)
     Memory: 32.0M
        CPU: 1.039s
     CGroup: /system.slice/system-postgresql.slice/postgresql@13-main.service
             ├─791 /usr/lib/postgresql/13/bin/postgres -D /var/lib/postgresql/13/main -c config_file=/etc/postgresq>
             ├─800 postgres: 13/main: checkpointer
             ├─801 postgres: 13/main: background writer
             ├─802 postgres: 13/main: walwriter
             ├─803 postgres: 13/main: autovacuum launcher
             ├─804 postgres: 13/main: stats collector
             └─805 postgres: 13/main: logical replication launcher
 
aoû 27 13:54:13 ok systemd[1]: Starting PostgreSQL Cluster 13-main...
aoû 27 13:54:16 ok systemd[1]: Started PostgreSQL Cluster 13-main.
  • Administrer le serveur en donnant un mot de passe à administrateur “postgres”
-bash-5.1# su - postgres
-bash-5.1$ psql
psql (13.7 (Debian 13.7-0+deb11u1))
Saisissez « help » pour l'aide.
 
postgres=# \password postgres
Saisir le nouveau mot de passe de l'utilisateur « postgres » : postgres
Saisissez-le à nouveau : postgres
postgres=# exit

:-)

phpPgAdmin


Install phpPgAdmin www.itzgeek.com

  • Installation du module phpPgAdmin
Pour php 8.1
apt install -y phppgadmin php8.1-pgsql
 
Pour php 7.4
apt install -y phppgadmin php-pgsql
  • Configuration du module phpPgAdmin
vim /etc/phppgadmin/config.inc.php
# line 105 : change to [false] if you allow to login with priviledged user like postgres, root
$conf['extra_login_security'] = true;
 
# line 111 : change to [true] if you set config that database owners can look only their own databases
$conf['owned_only'] = false;
  • Configuration coté Apache du module phpPgAdmin
vim /etc/apache2/conf-enabled/phppgadmin.conf
 
Alias /phppgadmin /usr/share/phppgadmin
 
<Directory /usr/share/phppgadmin>
 
<IfModule mod_dir.c>
DirectoryIndex index.php
</IfModule>
AllowOverride None
 
# Only allow connections from localhost:
#Require local
Require all granted
 
#ou alors
Require local
Require ip 10.0.0.0/24
 
<IfModule mod_php.c>
  php_flag magic_quotes_gpc Off
  php_flag track_vars On
  #php_value include_path .
</IfModule>
<IfModule !mod_php.c>
  <IfModule mod_actions.c>
    <IfModule mod_cgi.c>
      AddType application/x-httpd-php .php
      Action application/x-httpd-php /cgi-bin/php
    </IfModule>
    <IfModule mod_cgid.c>
      AddType application/x-httpd-php .php
      Action application/x-httpd-php /cgi-bin/php
    </IfModule>
  </IfModule>
</IfModule>
 
</Directory>
 
systemctl restart apache2 && systemctl status apache2
 
http://192.168.1.2/phppgadmin/
postgres
postgres

:-)

2. Modifications pour faire fonctionner Ruches


Installation des paquets


apt install -y git maven ntp libtcnative-1 xz-utils curl
apt install -y  ufw sudo
apt clean


Téléchargement des paquets du site https://gitlab.com/ruches/


cd /var/www/html/
ls
index.html  info.php
git clone https://gitlab.com/ruches/ruches.git
git clone https://gitlab.com/ruches/ruches-doc.git


Modification pour Apache


rm /etc/apache2/sites-enabled/*
cp /var/www/html/ruches-doc/docs/install/vhost.conf /etc/apache2/sites-available
 
vim /etc/apache2/sites-available/vhost.conf
<VirtualHost *:80>
  # Redirection http vers https
  #Servername monbeaurucher.fr
  #Redirect "/" "https://monbeaurucher.fr/"
  Servername ok.home.lan
  Redirect "/" "https://ok.home.lan/"
</VirtualHost>
 
<VirtualHost *:443>
  #Servername monbeaurucher.fr
  Servername ok.home.lan
  ServerAdmin webmaster@localhost
  RedirectMatch "^/$" "/ruches"
  DocumentRoot /var/www/html
 
  ErrorLog ${APACHE_LOG_DIR}/ruches_error.log
  CustomLog ${APACHE_LOG_DIR}/ruches_access.log combined
 
  # Re-directions vers Tomcat pour l'application ruches
  # Penser à activer les modules apache proxy et proxy_ajp
  # Déclarer le port 8009 pour le protocole AJP dans tomcat/conf/server.xml
  ProxyPass /ruches ajp://localhost:8009/ruches
  ProxyPassReverse /ruches ajp://localhost:8009/ruches
 
  # Penser à activer les modules apache ssl
  SSLEngine on
  ### Le certif fourni par l'hebergeur et la clé privé
 
#  SSLCertificateFile      /etc/ssl/certs/ssl-cert-ruches.fr.pem
#  SSLCertificateKeyFile /etc/ssl/private/ssl-cert-ruches.key
 
   SSLCertificateFile      /etc/ssl/certs/ssl-cert-snakeoil.pem
   SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
</VirtualHost>
  • Activation du fichier vhost.conf
/usr/sbin/a2ensite vhost.conf
  • Activation des modules apache ssl (https) proxy et proxy_ajp (redirect apache tomcat)
/usr/sbin/a2enmod ssl && /usr/sbin/a2enmod proxy && /usr/sbin/a2enmod proxy_ajp
systemctl start apache2.service && systemctl status apache2.service

:-)

Modification de Tomcat


cp server.xml /opt/tomcat/conf
cp context.xml /opt/tomcat/conf/Catalina/localhost

:-)

création du fichier war


cd /var/www/html/ruches
mvn clean package -DskipTests
...
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  11.830 s
[INFO] Finished at: 2022-08-27T19:02:02+02:00
 
 
cp /var/www/html/ruches/target/ruches.war  /var/lib/tomcat9/webapps/ruches.war

:-)

Création de la base de données


Modification de connexion


  • Définir les paramètres de l'application dans les fichiers Tomcat:
    • /opt/tomcat/webapps/ruches/WEB-INF/classes/application.properties
    • /opt/tomcat/conf/Catalina/localhost/context.xml
    • (voir exemple de context dans le répertoire docs/context.xml)
vim /opt/tomcat/conf/Catalina/localhost/**context.xm
 
<?xml version="1.0" encoding="UTF-8"?>
<Context>
  <Resource auth="Container" type="javax.sql.DataSource"
                name="jdbc/ruches" url="jdbc:postgresql://localhost:5432/ruchesmin"
                username="postgres" password="postgres"
                driverClassName="org.postgresql.Driver" />
  <Resources cacheMaxSize="15360" />
  <Parameter name="accueil.titre" value="Les Abeilles de la bas"/>
<!--<Parameter name="proxyHost" value="xxxx"/>
    <Parameter name="proxyPort" value="8080"/>-->
  <Parameter name="ign.data.key" value="ortho,parcellaire,agriculture,essentiels,qsdfqreqffefesf"/>
  <Parameter name="gg.map.key" value="sqfererghthsez"/>
  <Parameter name="openweathermap.key" value="qgtrhytyk"/>
  <Parameter name="logging.level.ooioo" value="INFO"/>
  <Parameter name="logging.file.name" value="${catalina.base}/logs/ruches.log"/>
  <Parameter name="logging.file" value="${catalina.base}/ruches.log"/>
  <Parameter name="spring.resources.cache.cachecontrol.max-age" value="7d" />
  <Parameter name="rucher.butinage.rayons" value="750,1500,3000,6000" />
  <Parameter name="hausse.reste.miel" value="1" />
  <Parameter name="essaime.suffix" value="_e" />
</Context>
vim /opt/tomcat/webapps/ruches/WEB-INF/classes/application.properties
# https://www.baeldung.com/cachable-static-assets-with-spring-mvc
spring.resources.cache.cachecontrol.max-age=7d
 
# https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/annotation/Scheduled.html
# https://docs.oracle.com/cd/E12058_01/doc/doc.1014/e12030/cron_expressions.htm#insertedID0
# https://riptutorial.com/spring/example/21209/cron-expression
# tous les jours à 1h 21min 10s
# second, minute, hour, day of month, month, day of week
notification.cron=0 0 0 * * ?
notification.destinataires=ooioo@free.fr
notification.objet=Ruches Notifications
// pour une entete de mail multiligne ajouter un espace suivi d'un \ à la fin
//   des lignes
notification.entete=Hello !\n\n
notification.pied=\nBye !
 
# spring.batch.jdbc.initialize-schema=always
 
# pagination nbre de lignes par défaut
#   à choisir parmi 10, 25, 50, 100
#    parseInt ajouté dans include.html sinon 0 ajouté en préfixe
#       et la pagination ne fonctionne pas
datatables.pageLength=25
 
# Rayons des cercles de distances de butinage
rucher.butinage.rayons=1000,2000,3000,4000,5000
 
# suffixe pour nouveau nom d'essaim après essaimage
essaime.suffix=_e
 
# Poids en kg estimé du reste du miel dans une hausse après récolte
# utilisé pour calculer le poids de miel récolté dans la hausse
# avec une simple pesée avant récolte de la hausse
hausse.reste.miel = 1
 
# rayon de dispersion des ruches dans le rucher
rucher.ruche.dispersion=10
rucher.map.zoom=20
ruchers.map.zoom=10
dist.ruches.loins=200
dist.ruchers.loins=20
retard.ruches.evenement=4
accueil.titre=Ruches
 
// clé inutilisée si fichier autoconf ign
ign.data.key=ortho,parcellaire,agriculture
gg.map.key=yyyyy
gg.map.url=https://maps.googleapis.com/maps/api/js?key=${gg.map.key}&callback=initMap
 
openweathermap.key=zzzzzz
 
# spring boot actuator
management.endpoints.web.base-path=/admin/logs
management.endpoints.enabled-by-default=false
management.endpoint.logfile.enabled=true
management.endpoints.jmx.exposure.exclude=*
management.endpoints.web.exposure.include=logfile
 
# rest
spring.data.rest.basePath=/rest
 
server.error.whitelabel.enabled=false
 
# test version 2.3.1
# server.error.include-binding-errors=always
# jpa - hibernate
# spring.jpa.hibernate.ddl-auto=update
# https://stackoverflow.com/questions/38040572/spring-boot-loading-initial-data
# spring.datasource.initialization-mode=always
# spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MariaDB103Dialect
 
# base de donnees
# spring.datasource.driverClassName=org.postgresql.Driver
# spring.datasource.url=jdbc:postgresql://localhost:5432/ruchesdev
# spring.datasource.username=postgres
# spring.datasource.password=postgres
spring.datasource.jndi-name=java:comp/env/jdbc/ruches
 
# Pour eviter plantage si 2 instances d'applications spring sur le meme tomcat
# https://stackoverflow.com/questions/27440985/unable-to-register-mbean-hikaridatasource-hikaripool-0-with-key-datasource
# sur la deuxieme instance :
## spring.jmx.default-domain: test
 
# mail
# 587
# 465 SSL/TLS  Mot de passe chiffre  Utilisateur p.n
spring.mail.host=smtp.free.fr
spring.mail.port=587
spring.mail.username=xxxxx
spring.mail.password=xxxxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
# spring.mail.properties.mail.smtp.starttls.enable
email.from=xxx@free.fr
 
# logs
# https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html
logging.level.root=ERROR
logging.level.ooioo=INFO
logging.pattern.console=%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger.%M - %X{username} - %msg%n
logging.pattern.file=%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger.%M - %X{username} - %msg%n
#logging.level.org.springframework.web=INFO
#logging.level.org.hibernate=ERROR
#logging.level.org.thymeleaf=ERROR
#logging.level.org.thymeleaf.TemplateEngine.CONFIG=ERROR
#logging.level.org.thymeleaf.TemplateEngine.TIMER=ERROR
#logging.level.org.thymeleaf.TemplateEngine.cache.TEMPLATE_CACHE=ERROR
#logging.level.org.thymeleaf.TemplateEngine.cache.EXPRESSION_CACHE=ERROR
# log dans un fichier
logging.file.name=/tmp/ruches.log
-- connexion à la base de données
   définir paramètres de connexion dans context.xml
-- logging.file : le chemin des fichiers log
-- accueil.titre : le titre à afficher dans le bandeau de la page d'accueil
-- ign.data.key : la clé de connexion à l'API IGN
-- gg.map.key : la clé de connexion à l'API Google maps
-- gg.map.url : l'URL de connexion à l'API Google maps
-- openweathermap.key : la clé de connexion à l'API openWeatherMap


Script d'installation et d'upgrade

Script pour l'installation pour de test en local

#Pour décompresser le .tar.gz
tar -xzvf script_ruches.tar.gz
 
#Rendre exécutable les deux scripts
chmod +x Ruches_install ruches_upgrade
 
#En root exécuter:
./Ruches_install #pour l'installation
./ruches_upgrade #pour l'upgrade

Le script d'installation sera bientôt modifier pour ne plus écraser votre config Apache, Tomcat et PostgreSQL !


NuxBSD

hive/ded.txt · Dernière modification : de 127.0.0.1