URL: https://linuxfr.org/wiki/ubuntu-debian-installation-complete-de-shinobi-community-edition Title: [Ubuntu/Debian] Installation complète de Shinobi Community Edition Authors: voxdemonix Date: 2018年12月16日T14:35:40+01:00 License: CC By-SA Tags: shinobicctv, tutoriel, caméra, video_surveillance et sécurité Score: 0 Introduction ============ Dans ce tutoriel sera presque tout expliqué afin de transformer une machine fraîchement installée en serveur ShinobiCCTV Community Edition. Pour une présentation du logiciel, voyez cet article : [🎦 Présentation de ShinobiCCTV Community Edition 👁️](https://linuxfr.org/news/presentation-de-shinobicctv-community-edition) Ndlr : ajouter anti-bruteforce (fail2ban?) et sécurisation. **Pages principales de la WEBUI de Shinobi :** - http://your_shinobi:8080 ⇒ Dashboard. - http://your_shinobi:8080/admin ⇒ Ici les utilisateurs créés par l'Administrateur pourront créer des "sous-utilisateurs", permettant de partager l'accès a des caméras. - http://your_shinobi:8080/super ⇒ Gestion de l'administrateur, des comptes utilisateurs et de quelques paramètres de bases. Désinstallation =============== **Supprimez la base de données.** ```bash mysql -uroot -p -e "DROP DATABASE ccio;" mysql -uroot -p -e "DROP USER ‘shinobi’@’localhost’;" mysql -uroot -p -e "DROP USER ‘shinobi’@’10.8.%.%’;" ``` **Désinstallez les logiciels et supprimez les dossiers.** (/!\ ndlr : je ne suis pas sur que le dev a testé sa propre procédure de désinstallation, procédure en attente de test) ```bash pm2 kill sudo npm uninstall pm2 -g sudo apt remove ffmpeg mariadb-server nodejs -y && sudo apt autoremove -y && sudo apt-get autoclean sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp /opt/local/bin/node /opt/local/include/node /opt/local/lib/node_modules /usr/local/lib/node* /usr/local/include/node* -rf /usr/local/bin/node* -rf /home/Shinobi ``` Installation de A-Z =================== Logiciels --------- ```bash mv /tmp/ wget https://gitlab.com/Shinobi-Systems/Shinobi-Installer/raw/master/shinobi-install.sh sudo bash shinobi-install.sh ``` Mémoire --------- ### Logs **Si vous le souhaitez, vous pouvez ranger les logs de votre système en mémoire [RAM](https://fr.wikipedia.org/wiki/M%C3%A9moire_vive). C'est fortement conseillé si votre système est sur une carte [SD](https://fr.wikipedia.org/wiki/Carte_SD)/[eMMC](https://fr.wikipedia.org/wiki/Carte_MMC#eMMC) ou pour gagner des performance en cas d'utilisation de [HDD](https://fr.wikipedia.org/wiki/Disque_dur). C'est déconseillé sur [SSD](https://fr.wikipedia.org/wiki/Solid-state_drive).** ```bash cd /tmp/ curl -Lo log2ram.tar.gz https://github.com/azlux/log2ram/archive/master.tar.gz tar xf log2ram.tar.gz cd log2ram-master chmod +x install.sh && sudo ./install.sh cd .. rm -r log2ram-master ``` ### Base de données **Créez votre base de données et son utilisateur multi-accès. Pensez à adapter la commande (surtout le mot de passe). NE CHANGEZ PAS LE NOM DE LA BASE DE DONNÉES.** ```bash mysql -u root -p -e "GRANT ALL PRIVILEGES ON ccio.* TO 'shinobi'@'localhost' identified by 'my_super_password'; GRANT ALL PRIVILEGES ON ccio.* TO 'shinobi'@'10.8.%.%' identified by 'my_super_password'; FLUSH PRIVILEGES; ``` **Éditez _/home/Shinobi/conf.json_ et ajoutez-y les informations de votre base de données.** ```bash nano /home/Shinobi/conf.json ``` **Initialisez la base de données.** ```bash mysql -u shinobi -p shinobi < /home/Shinobi/sql/framework.sql mysql -u shinobi -p shinobi < /home/Shinobi/sql/tables.sql mysql -u shinobi -p shinobi < /home/Shinobi/sql/database.sql ``` ### Stockage **[Agrégez vos disques afin de créer un JBOD](https://linuxfr.org/wiki/tuto-howto-debian-ubuntu-creer-un-jbod-raid0-non-strip-avec-zfs) (sorte de _super-partition_)** **Déplacez le stockage principale de Shinobi vers votre nouvelle _super-partition_.** ```bash mkdir /media/raidSSD/videos mv /home/Shinobi/videos/* /media/raidSSD/videos/ rm -R /home/Shinobi/videos ln -s /media/raidSSD/videos /home/Shinobi/videos ``` **Redémarrez Shinobi.** ```bash pm2 reload pm2 --update-env restart all ``` Ajouter un Frontend HaProxy avec HTTPS -------------------------------------- Dans ce tutoriel, les pages /admin et /super seront bloquées par mesure de sécurité. Si vous voulez y accédez, connectez-vous directement sur votre noeud Shinobi sans passer par le frontend. Toutes les commandes suivantes doivent être lancée en root (admin). **Installation des logiciels nécessaires.** ```bash apt-get update apt-get install -y haproxy letsencrypt ``` Générez votre certificat TLS (https). Attention vous avez une limite mensuel. ```bash letsencrypt certonly --register-unsafely-without-email --standalone --agree-tos --domains www.hello.world ``` **Éditez le cron de root.** ```bash crontab -e ``` **Copiez-collez les commandes suivantes. Elles mettront à jours la liste de blocage et les certificats https tout les mois. Pensez à remplacer www.hello.world par votre propre nom de domaine valide.** ```bash 30 12 27 * * ( sudo service haproxy stop ; letsencrypt renew --standalone ; sudo -E bash -c 'cat /etc/letsencrypt/live/www.hello.world/fullchain.pem /etc/letsencrypt/live/www.hello.world/privkey.pem> /etc/haproxy/certs/www.hello.world.pem' ; sudo service haproxy restart ) @monthly ( wget -P /etc/haproxy/banlist/ https://gitlab.com/voxdemonix/divers-script/raw/master/Shinobi/HaProxy_Banlists/Ban_User-Agent.list ; chown root:root -R /etc/haproxy/banlist ; chmod 744 -R /etc/haproxy/banlist ; sudo service haproxy reload ) ``` **Créez le dossier où HaProxy va ranger vos certificats et vos banlistes.** ```bash mkdir -p /etc/haproxy/certs/ mkdir /etc/haproxy/banlist chown root:root -R /etc/haproxy/certs chmod 744 -R /etc/haproxy/certs chown root:root -R /etc/haproxy/banlist chmod 744 -R /etc/haproxy/banlist ``` **Concaténez votre clés publique et privée. Recommencez pour chaque nom de domaine.** Remplacez le nom de domaine en exemple par le votre. ```bash DOMAIN='www.hello.world' sudo -E bash -c 'cat /etc/letsencrypt/live/$DOMAIN/fullchain.pem /etc/letsencrypt/live/$DOMAIN/privkey.pem> /etc/haproxy/certs/$DOMAIN.pem' ``` **Éditez le fichier de configuration de HaProxy.** ```bash nano /etc/haproxy/haproxy.cfg ``` **Cet exemple vous permet d'adapter votre configuration.** ``` global log /dev/log local0 log /dev/log local1 notice chroot /var/lib/haproxy stats socket /run/haproxy/admin.sock mode 660 level admin stats timeout 30s user haproxy group haproxy daemon # Default SSL material locations ca-base /etc/ssl/certs crt-base /etc/ssl/private # Default ciphers to use on SSL-enabled listening sockets. # For more information, see ciphers(1SSL). This list is from: # https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/ ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS ssl-default-bind-options no-sslv3 defaults log global mode http option httplog option dontlognull timeout connect 5000 timeout client 50000 timeout server 50000 errorfile 400 /etc/haproxy/errors/400.http errorfile 403 /etc/haproxy/errors/403.http errorfile 408 /etc/haproxy/errors/408.http errorfile 500 /etc/haproxy/errors/500.http errorfile 502 /etc/haproxy/errors/502.http errorfile 503 /etc/haproxy/errors/503.http errorfile 504 /etc/haproxy/errors/504.http frontend Frontend_HTTP bind *:80 v4v6 bind *:443 v4v6 ssl crt /etc/haproxy/certs/www.hello.world.pem # option dontlog-normal # un-comment this line for logging only problem (recommanded if logs are on SD/eMMC card) option httpclose option forwardfor reqadd X-Forwarded-Proto:\ https # security tcp-request inspect-delay 5s acl bad_gateway hdr_sub(X-Tor2Web) -i 1 # ban tor2web bridge (tor hidden service protection) tcp-request content reject if bad_gateway # ban tor2web # ban User-Agent acl blockedagent hdr_sub(user-agent) -i -f /etc/haproxy/banlist/Ban_User-Agent.list # ban user agent list (https://gitlab.com/voxdemonix/divers-script/blob/master/Shinobi/HaProxy_Banlists/Ban_User-Agent.list) http-request deny if blockedagent # ban user agent list http-request deny if { hdr_cnt(user-agent) eq 0 } # ban empty user agent # ban pages acl restricted_page path_beg,url_dec -f /etc/haproxy/banlist/Ban_URL.list http-request deny if restricted_page # Define hosts # www.hello.world acl host_www.hello.world hdr(host) -i www.hello.world use_backend server_shinobi if host_www.hello.world backend server_shinobi mode http log global option httplog # ici on log tout afin de détecter toute tentative d'intrusion balance roundrobin http-request add-header X-Forwarded-Proto https if { ssl_fc } # force https acl http ssl_fc,not http-request redirect scheme https if http option forwardfor option httpchk GET /admin HTTP/1.0 cookie SERVERID insert indirect nocache # YOUR SERVER HERE server ShinobiServer ShinobiServer:8080 cookie ShinobiServer check #ssl verify none ``` Si HaProxy et Shinobi sont situé sur deux machines différentes, il est franchement recommendé de chiffrer les communications entre les deux. Vous pouvez utiliser openssh, pivpn (openvpn) ou autre. **Téléchargez les banlists et accordez dessus les bonnes permissions.** ```bash wget -P /etc/haproxy/banlist/ https://gitlab.com/voxdemonix/divers-script/raw/master/Shinobi/HaProxy_Banlists/Ban_User-Agent.list wget -P /etc/haproxy/banlist/ https://gitlab.com/voxdemonix/divers-script/raw/master/Shinobi/HaProxy_Banlists/Ban_URL.list chown root:root -R /etc/haproxy/banlist chmod 744 -R /etc/haproxy/banlist ``` **Redémarrez HaProxy.** ```bash service haproxy reload ``` NB : par sécurité, vous pouvez suivre en direct les logs de votre serveurs depuis votre pc personnel via un simple conky. Pour ce faire, [voyez ici](https://linuxfr.org/forums/linux-debian-ubuntu/posts/petit-partage-conky-pour-logs-apache2-dnschef-openvpn-haproxy). Farm Link ========= - [[Tuto/HowTo] [Debian/Ubuntu] Complete Install of Shinobi Community Edition](https://wiki.0rion.netlib.re/doku.php?id=tutorial_en:tuto_howto_debian_ubuntu_install_shinobi) (article d'origine) - [Shinobi Forum](https://forum.shinobi.video/) - [Shinobi Discord](https://discordapp.com/invite/mdhmvuH) - [GitLab - Shinobi](https://gitlab.com/Shinobi-Systems/Shinobi) - [Facebook - Shinobi](https://www.facebook.com/Shinobi-1223193167773738) - [Twitter - Shinobi](https://twitter.com/ShinobiCCTV)