Archives de catégorie : Système

Déployer Docker Compose et Swarm sur coreOS

Cet article reprend une partie du post Running an etcd-Backed Docker Swarm Cluster
et de Installing Docker Compose in CoreOS
Le code source complet de cet article se trouve mis en application sur mon fork coreos-vagrant
il fait suite à l’article Docker sur CoreOS par Vagrant

Prérequis

git clone https://github.com/heralight/coreos-vagrant.git
cp config.rb.2.sample   config.rb
cp user-data.2.sample user-data
vagrant up
vagrant ssh core-01

Après un vagrant up, vérifions l’état du cluster etcd.

core@core-01 ~ $ etcdctl cluster-health
member 25d6ce33763c5524 is healthy: got healthy result from http://172.17.8.102:2379
member 6ae27f9fa2984b1d is healthy: got healthy result from http://172.17.8.101:2379
member ff32f4b39b9c47bd is healthy: got healthy result from http://172.17.8.103:2379
cluster is healthy
core@core-01 ~ $ etcdctl member list
25d6ce33763c5524: name=core-02 peerURLs=http://172.17.8.102:2380 clientURLs=http://172.17.8.102:2379 isLeader=false
6ae27f9fa2984b1d: name=core-01 peerURLs=http://172.17.8.101:2380 clientURLs=http://172.17.8.101:2379 isLeader=true
ff32f4b39b9c47bd: name=core-03 peerURLs=http://172.17.8.103:2380 clientURLs=http://172.17.8.103:2379 isLeader=false

Installer Docker Compose

Rapide

Vous retrouverez ce script dans la partie module du projet.
Vous n’avez pas besoins de l’executer à la main si vous utilisez vagrant, dans le fichier config.rb, modifier $vagrant_module_docker_compose à vrai (par défaut).
Ainsi vos instances seront provisionner avec Docker Compose.

En détails

Sur chaque noeud, executer:

curl -L https://github.com/docker/compose/releases/download/1.7.1/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
sudo mkdir -p /opt/bin
sudo mv ~/docker-compose /opt/bin/docker-compose
sudo chown root:root /opt/bin/docker-compose
sudo chmod +x /opt/bin/docker-compose

Vérifions l’installation:

core@core-01 ~ $ whereis docker-compose
docker-compose: /opt/bin/docker-compose

Installer Docker Swarm avec support etcd

Dans l’article précédent, nous avons configurer nos 3 instances avec etcd2 en ip statique.
Nous allons profiter de cette fonctionalité pour configurer Docker Swarm.

Rapide

Vous retrouverez ce script dans la partie module du projet.
Vous n’avez pas besoins de l’executer à la main si vous utilisez vagrant, dans le fichier config.rb, modifier $vagrant_module_docker_swarm à vrai (par défaut).
Ainsi vos instances seront provisionner avec Docker Swarm.

En détails

Ainsi chaque noeud doit s’inscrire à etcd, comme les 3 instances coreos sont synchronizées, nous pouvons executer:

docker run -d swarm join --addr=monip:2375 etcd://monip:2379/swarm

Après cela, vérifions sont bon fonctionnement sur n’importe quel noeud.

core@core-01 ~ $ etcdctl ls /swarm/docker/swarm/nodes
/swarm/docker/swarm/nodes/172.17.8.101:2375
/swarm/docker/swarm/nodes/172.17.8.102:2375
/swarm/docker/swarm/nodes/172.17.8.103:2375

nous avons besoins d’un manager Swarm, par défaut nous prendre core-01.
Comme nous faisons tourner un moteur docker sur toutes nos instances, swarm simulant un moteur docker, nous aurons un conflit.
Pour palier à ce problème, nous allons rediriger le port de Swarm vers 8333.

docker run -d -p 32375:2375 swarm manage etcd://172.17.8.101:2379/swarm

nous pouvons vérifier notre installation:

docker -H tcp://172.17.8.101:32375 info

Use tmpfs for mounting ~/.cache directory

from a question on askubuntu.com

you can use /dev/shm (default tmpfs device on unix)

you can do something like this in your ~/.xprofile :


#!/bin/sh
rm -rf /dev/shm/${USER}cache
mkdir /dev/shm/${USER}cache
chmod 700 /dev/shm/${USER}cache
rm -rf /home/${USER}/.cache
ln -s /dev/shm/${USER}cache /home/${USER}/.cache

Nautilus – GLib Library Hack to sort file like LS

You can find my github project at https://github.com/heralight/GlibSortFileNameHackLibrary

For years, everybody list files on unix based on LC_COLLATE.
Then Gnome developpers decide to interpret number in filename…

Strange choice, and we cannot personalize this.

ls show something like

001  004  1  A  B  a  b

and for example, nautilus show:

1 001  004  A  B  a  b

This behavior use command g_utf8_collate_key_for_filename from Glib library.
Thank you to
* https://bugs.launchpad.net/ubuntu/+source/nautilus/+bug/322271
* https://bugzilla.gnome.org/show_bug.cgi?id=355152
* https://bugs.launchpad.net/ubuntu/+source/thunar/+bug/684317
* + 30 related bugs opened

This little override this function with g_utf8_collate_key.

Pre-required

Compilation dependencies

sudo apt-get install libglib2.0-dev

Generate

make all

Install and usage

To override this behavior, this library need to be preload before each program who use Glib library.
Todo that you can

set it before call from command line or from .desktop shortcut:

LD_PRELOAD=/pathToYourLib/glibSortFileNameHack.so nautilus

set globally on gnome session:

echo "export LD_PRELOAD=/pathToYourLib/glibSortFileNameHack.so" >> ~/.gnomerc

and restart your gnome session. Be careful, this settings produce effect on whole gnome session.

or more simply

make install

this command will create a libs directory in your home, copy library, and append LD_PRELOAD to ~/.gnomerc

Troubleshooting

Before open an issue, please follow this guide

Test required

to verify that it works, create some dummy files.

e.g.:

touch 001
touch 004
touch 1
touch 4
touch a
touch A
touch b
touch B

ls will show:

001  004  1  4  a  A  b  B

nautilus on a standard installation will show:

1 001 4 004  a  A  b  B

With hack nautilus will show

001  004  1  4  a  A  b  B

Nautilus

before anything, kill any nautilus process

ps -aux | grep nautilus
kill -9 nautilusProcess

launch it from lib directory to test it:

LD_PRELOAD=./glibSortFileNameHack.so nautilus .

Related bug : https://bugzilla.gnome.org/show_bug.cgi?id=754777

Enjoy !