Blog personnel d'Alex Sbille sur les technologies, et autres de mes centres d’intérêts.

Aller au contenu | Aller au menu | Aller à la recherche

System Administration Linux

Fil des billets - Fil des commentaires

vendredi 30 octobre 2015

Gérer vos mots de passe de façon sécurisée et sur plusieurs périphériques

J'utilise https://github.com/pfn/keepasshttp/ avec seafile et chromium https://chrome.google.com/webstore/detail/chromeipass/ompiailgknfdndiefoaoiligalphfdae/related?hl=en

Sur le pc client: wget https://raw.github.com/pfn/keepasshttp/master/KeePassHttp.plgx apt-get install mono-complete apt-cache policy keepass2 apt-get install keepass2 cp /home/x/Téléchargements/KeePassHttp.plgx /usr/lib/keepass2/ chmod 644 /usr/lib/keepass2/KeePassHttp.plgx

Partage

vendredi 19 septembre 2014

Mosh

Si comme moi vous avez une ligne adsl qui se met a sauter a chaque flash de foudre ou que vous devez parfois vous connecter en ssh à l'aide d'une connexion cellulaire, je vous conseille vivement d'utiliser cet outil: Mosh

Mosh est un outil permettant de se connecter sur un terminal malgré une connexion facheuse sans que votre prompt se gèle lorsque le ping part en vrille.

apt-get install mosh

Lire le manuel : Utilisation de Mosh

Petite contrainte toutes fois, il faut l'installer à distance aussi, il faut donc avoir la main sur le client et le serveur.

Partage

jeudi 10 avril 2014

Chiffrer ses données avec TCPlay, fork de Truecrypt

La license de truecrypt étant parfois critiquée, je préfère me tourner vers un équivalent libre : TCPlay

L'installation sous debian :

apt-get install tcplay
whereis tcplay
tcplay: /usr/sbin/tcplay /usr/share/man/man8/tcplay.8.gz

Il faut ensuite trouver le premier périphérique de boucle disponible:

losetup -f
/dev/loop0

Puis là ou bon vous semble avec un conteneur de 20 Mo :

dd if=/dev/zero of=foo.tc bs=1 count=0 seek=20M
losetup /dev/loop0 foo.tc
tcplay -c -d /dev/loop0 -a whirlpool -b AES-256-XTS

La clé est demandée deux fois puis tcplay va remplir de volume de données aléatoires.

Il est ensuite nécessaire de relier le volume avec le loop et créer un système de fichiers dedans avant de le monter pour la première fois.

tcplay -m foo.tc -d /dev/loop0
mkfs.ext4 /dev/mapper/foo.tc
mount /dev/mapper/foo.tc /mnt/truecrypt/

Puis pour démonter;

umount /mnt/truecrypt 
dmsetup remove foo.tc 
losetup -d /dev/loop0

Enfin, pour remonter à nouveau:

losetup /dev/loop0 foo.tc 
tcplay -m foo.tc -d /dev/loop0
mount /dev/mapper/foo.tc /mnt/truecrypt/

Partage

lundi 7 avril 2014

Get java oracle working with chromium in debian jessy distro

I use openjdk-7-jre 90% of time but somes applications requires more, so:

echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
apt-get update
apt-get install oracle-java7-installer

For choice management:
update-alternatives --config java
Il existe 3 choix pour l'alternative java (qui fournit /usr/bin/java).

  Sélection   Chemin                                          Priorité  État
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-oracle/jre/bin/java          1072      mode automatique
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      mode manuel
  2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      mode manuel
  3            /usr/lib/jvm/java-7-oracle/jre/bin/java          1072      mode manuel

Appuyez sur <Entrée> pour conserver la valeur par défaut[*] ou choisissez le numéro sélectionné :
ln -s /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so  /usr/lib/chromium/plugins

Partage

vendredi 4 avril 2014

Mettre le tmpdir de Mysql / Mariadb dans la ram / tmpfs

Sur les disque dur mécaniques, les écritures de mysql sont parfois vraiement mauvaises, même en améiorant sensiblement le my.cnf, j'avais besoin d'aller plus loin.

Alors j'ai mis en place un disque tmpfs réservé au sockage du tmpdir:

Préparation de la config de mysql avec seulement une ligne à changer pour modifier la valeur de tmpdir:

nano /etc/mysql/my.cnf

Ajouter ou remplacer la ligne suivante avec le nouveau chemin:

tmpdir          = /var/lib/mysqltmp

Récupérer les privilèges de mysql qu'il puisse exploiter le tmpfs :

id mysql
uid=110(mysql) gid=113(mysql) groupes=113(mysql)

Ajout de la ligne dans le /etc/fstab

nano /etc/fstab

For 500 MB space:

tmpfs   /var/lib/mysqltmp   tmpfs   rw,gid=113,uid=110,size=500m,mode=0750,noatime   0 0

Pas besoin de rebooter, juste:

mount -a && service mysql restart
[ ok ] Stopping MariaDB database server: mysqld.
[ ok ] Starting MariaDB database server: mysqld . ..
[info] Checking for corrupt, not cleanly closed and upgrade needing tables..
df -h
tmpfs                                                    500M     0  500M   0% /var/lib/mysqltmp

Partage

Mysql / Mariadb tmpdir on tmpfs

On spinning disks, write is dramatically slow for some applications, after tweaking my.cnf, I needed more.

So I'm setting up a tmpfs disk an put mysql tmpdir in it:

Prepare mysql config with only replace the tmpdir value with the future path:

nano /etc/mysql/my.cnf

Add or replace tmpdir value with

tmpdir          = /var/lib/mysqltmp

Create the tmpfs with privileges:

Get uid and gid of mysql / mariadb

id mysql
uid=110(mysql) gid=113(mysql) groupes=113(mysql)

Add a line in the /etc/fstab

nano /etc/fstab

For 500 MB space:

tmpfs   /var/lib/mysqltmp   tmpfs   rw,gid=113,uid=110,size=500m,mode=0750,noatime   0 0

No need to restart, just

mount -a && service mysql restart
[ ok ] Stopping MariaDB database server: mysqld.
[ ok ] Starting MariaDB database server: mysqld . ..
[info] Checking for corrupt, not cleanly closed and upgrade needing tables..
df -h
tmpfs                                                    500M     0  500M   0% /var/lib/mysqltmp

Partage

lundi 24 mars 2014

Loggin ip adress of visitors with Varnish3 and Apache2 as a backend

It is natural to find varnish public ip in apache logs but not very secure in my context, so I'll need to configure Varnish 3 using req.http.X-Forwarded-For and apache2 with mod_rpaf

With a debian like:

On the backend server

apt-get install libapache2-mod-rpaf
nano /etc/apache2/mods-enabled/rpaf.conf
<IfModule rpaf_module>
    RPAFenable On

    # When enabled, take the incoming X-Host header and
    # update the virtualhost settings accordingly:
    RPAFsethostname On

    # Define which IP's are your frontend proxies that sends
    # the correct X-Forwarded-For headers:
    RPAFproxy_ips 5.39.38.60 127.0.0.1 ::1

    # Change the header name to parse from the default
    # X-Forwarded-For to something of your choice:
    RPAFheader X-Forwarded-For

</IfModule>
service apache2 reload

On the reverse proxy / varnish server:

Insert after the start of sub vcl_recv :

if (req.restarts == 0) {
  if (req.http.X-Forwarded-For) {
    set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
  } else {
    set req.http.X-Forwarded-For = client.ip;
  }
}

Then reload the configuration and verify a2 logs.

Partage

Log de l'adresse ip du visiteur dans apache2 derrière un reverse proxy varnish3

Varnish, comme tout reverse proxy laissera naturellement son adresse ip dans les logs du backend, ici apache. Dans mon cas, dans un contexte de sécurité, il est nécessaire que le reverse proxy utilise req.http.X-Forwarded-For pour annoncer au backend l'adresse ip du client.

Avec une debian like:

Sur le serveur de backend

apt-get install libapache2-mod-rpaf
nano /etc/apache2/mods-enabled/rpaf.conf
<IfModule rpaf_module>
    RPAFenable On

    # When enabled, take the incoming X-Host header and
    # update the virtualhost settings accordingly:
    RPAFsethostname On

    # Define which IP's are your frontend proxies that sends
    # the correct X-Forwarded-For headers:
    RPAFproxy_ips 5.39.38.60 127.0.0.1 ::1

    # Change the header name to parse from the default
    # X-Forwarded-For to something of your choice:
    RPAFheader X-Forwarded-For

</IfModule>
service apache2 reload

Sur le reverse proxy / varnish:

Insérer après le début de sub vcl_recv :

if (req.restarts == 0) {
  if (req.http.X-Forwarded-For) {
    set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
  } else {
    set req.http.X-Forwarded-For = client.ip;
  }
}

Suivi d'un reload de la configuration.

Partage

dimanche 2 mars 2014

Mass extention rename with linux bash

for f in *.JPG; do mv $f `basename $f .JPG`.jpeg; done;

Partage

Renommage à la chaîne d'extensions sous linux

for f in *.JPG; do mv $f `basename $f .JPG`.jpeg; done;

Partage

vendredi 28 février 2014

Multi-threaded Uncompression of bz2 files.

I use lbzip2 (exist as a debian package) for unp very large compressed files (mysql dumps).

lbzip2 -d big_file.tar.bz2

The big advantage of this program for me was the availability of set the number of decompressor threads with the -n argument.

We also can compress files with compression level choice.

http://lbzip2.org/quickstart

Partage

Décompression Multi-threaded de fichiers bz2.

J'utilise lbzip2 en packet debian pour décompresser de gros fichiers compressés comme par exemple de gros dumps mysql.

lbzip2 -d big_file.tar.bz2

L'avantage pour moi dans le choix de ce programme est la possibilité de choisir le nombre de threads alloués avec l'argument -n.

Il est aussi possible de compresser des fichiers avec le choix du niveau de compression.

http://lbzip2.org/quickstart

Partage

Supprimer des doublons avec linux et fdupes

On installe le programme et lance un état des lieux avec:

apt-get install && fdupes -r /target/folder

Voir l'espace occupé avant le nettoyage:

du -sh /target/folder

Supprimer les doublons! (d argument) Seulement conserver le premier fichier trouvé et automatiquement valider la suppression des doubles (N argument).

fdupes -r -dN /target/folder

{{ + /media/neuro/Lexar/2010-11-05/2012-01-17/IMG_1523.JPG

  - /media/neuro/Lexar/2010-11-05/2012-07-16/IMG_1523.JPG
  - /media/neuro/Lexar/2012-01-29/IMG_1523-1.JPG
  - /media/neuro/Lexar/2012-01-29/IMG_1523.JPG
  - /media/neuro/Lexar/2012-09-30/IMG_1523.JPG}}

Voir l'espace occupé pour voir le gain gagné:

du -sh /target/folder

Partage

Find and clean multiples sames files with linux

First, install and test fdupes with:

apt-get install && fdupes -r /target/folder

View size before:

du -sh /target/folder

Clean with delete! (d argument) We keep only one file and no ask before delete (N argument).

fdupes -r -dN /target/folder

{{

  + /media/neuro/Lexar/2010-11-05/2012-01-17/IMG_1523.JPG
  - /media/neuro/Lexar/2010-11-05/2012-07-16/IMG_1523.JPG
  - /media/neuro/Lexar/2012-01-29/IMG_1523-1.JPG
  - /media/neuro/Lexar/2012-01-29/IMG_1523.JPG
  - /media/neuro/Lexar/2012-09-30/IMG_1523.JPG}}

View size after:

du -sh /target/folder

Partage

lundi 24 février 2014

Move a system from single hdd to software raid

Tested into a Debian 8 distro with raid5 and raid1.

Migrate any existing system ext3 (multiple or single partitions) with a stand alone hdd on a Software replicated raid.

Install mdadm before the system is replicated on the new array or chrooting will be neccesary for booting the future system on the raid.

apt-get install mdadm

#with ubuntu like

sudo apt-get remove dmraid

Retrive disks infos

fdisk -l

Create partitions on the new drives before building the array.

Grub partition need at lest of 1MB but it can be more in the future.

parted /dev/sda
unit kb
p free
#if needed with fresh drives : mklabel gpt
mkpart primary ext3 0 10M
mkpart primary ext3 10M 100%
#(very important)
set 1 bios_grub on
p free
q
partprobe /dev/sda
partprobe /dev/sdb

And do th same for each drives of the future array, grub will be installed on each disks.

Other way for flag grub_on

parted /dev/sda1 set 1 bios_grub on
parted /dev/sdb1 set 1 bios_grub on

Create the filesystem for raid on all disks

mkfs -t ext3 /dev/sda2
mkfs -t ext3 /dev/sdb2

Create the array (here raid1)

mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda2 /dev/sdb2

View live progression very long for 2TB drives

watch -n 1 cat /proc/mdstat

Create filesystem on the raid.

-m 2 for 2% of inodes

-m 2 pour 2% d'inodes

mkfs.ext3 /dev/md0 -m 2

Put a new line in the fstab

blkid
nano /etc/fstab

UUID=87b54395-1737-435b-b2a8-b4120ee4060d /             ext3 relatime 0 0

Update mdadm.

cat /etc/mdadm/mdadm.conf
mdadm --detail --scan --verbose >> /etc/mdadm/mdadm.conf
cat /etc/mdadm/mdadm.conf

Mount it.

mkdir /media/raid1/ && mount /dev/md0 /media/raid1/ &&  df -h && cd  /media/raid1/

At this time, synchronize the actual system on the raid.

rsync -aAXv --stats --progress /* /media/raid1/ --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/net*,/lost+found}

Chroot in the future live system.

cd /media/raid1/
mount -t proc proc proc/
mount --rbind /sys sys/
mount --rbind /dev dev/
chroot /media/raid1 /bin/bash

Update the fstab with goods uuid.

blkid
cp /etc/fstab /etc/fstab.bkp
nano /etc/fstab

Install grub on all drives of the array.

grub-install /dev/sda
grub-install /dev/sdb
update-grub
#or
update-grub2

Update the initial ram disk for automount the array during boot

update-initramfs -u

Exit from chroot and reboot, in my case, I unplug the old harddrive

All should run like a charm included grub.

fdisk -l

Attention : identifiant de table de partitions GPT (GUID) détecté sur « /dev/sdb » ! L'utilitaire sfdisk ne prend pas GPT en charge. Utilisez GNU Parted.

Disque /dev/sdb : 2000.4 Go, 2000398934016 octets

255 têtes, 63 secteurs/piste, 243201 cylindres, total 3907029168 secteurs

Unités = secteurs de 1 * 512 = 512 octets

Taille de secteur (logique / physique) : 512 octets / 4096 octets

taille d'E/S (minimale / optimale) : 4096 octets / 4096 octets

Identifiant de disque : 0x00000000

Périphérique Amorce  Début        Fin      Blocs     Id  Système

/dev/sdb1               1  3907029167  1953514583+  ee  GPT

La partition 1 ne commence pas sur une frontière de cylindre physique.

Attention : identifiant de table de partitions GPT (GUID) détecté sur « /dev/sda » ! L'utilitaire sfdisk ne prend pas GPT en charge. Utilisez GNU Parted.

Disque /dev/sda : 2000.4 Go, 2000398934016 octets

255 têtes, 63 secteurs/piste, 243201 cylindres, total 3907029168 secteurs

Unités = secteurs de 1 * 512 = 512 octets

Taille de secteur (logique / physique) : 512 octets / 512 octets

taille d'E/S (minimale / optimale) : 512 octets / 512 octets

Identifiant de disque : 0x00000000

Périphérique Amorce  Début        Fin      Blocs     Id  Système

/dev/sda1               1  3907029167  1953514583+  ee  GPT

Disque /dev/md0 : 2000.3 Go, 2000262529024 octets

2 têtes, 4 secteurs/piste, 488345344 cylindres, total 3906762752 secteurs

Unités = secteurs de 1 * 512 = 512 octets

Taille de secteur (logique / physique) : 512 octets / 4096 octets

taille d'E/S (minimale / optimale) : 4096 octets / 4096 octets

Identifiant de disque : 0x00000000

Le disque /dev/md0 ne contient pas une table de partitions valable

Links helped me:

http://velenux.wordpress.com/2012/07/12/grub-failing-to-install-on-debianubuntu-with-gpt-partitions/

http://forums.linuxmint.com/viewtopic.php?f=90&t=95928

http://forums.debian.net/viewtopic.php?f=5&t=92810

http://unix.stackexchange.com/questions/28443/does-grub2-support-putting-boot-on-a-raid5-partition

http://askubuntu.com/questions/252795/convert-running-system-to-raid-5

https://wiki.archlinux.org/index.php/Full_System_Backup_with_rsync

https://wiki.archlinux.org/index.php/Change_Root

https://wiki.archlinux.org/index.php/Convert_a_single_drive_system_to_RAID

Partage

- page 1 de 2