Attention ceci est mon brouillon avant de faire une belle documentation sur Docker (il y a à boire et à manger).
Petit résumé rapide de mes précédents posts, à noter que grâce au tag Docker on peut retrouver tous les articles sur le sujet.
Post n° | Intérêt | Résumé |
1 | 20% | Mauvaise installation à cause de la partition Docker. Mais début des commandes sous Docker : docker run , docker rmi, docker run, docker ps, |
2 | 70% | On voit l’intérêt de l’ajout de la partition Btrfs, on découvre le fichier Dockerfile qui est utilisé pour faire les docker build. |
3 | 70% | On a vu la redirection de port avec l’option -p . Et aussi docker search qui permet de voir tous les containers existant. On a aussi l’installation du container PostgreSQL. |
4 | 50% | Installation du container PostgreSQL mais pas comme je l’aurai voulu car je n’arrive pas à initialiser les utilisateurs dans le Dockerfile. Et les sources de server.c . |
5 | 30% | Découverte de la commande docker run swarn. J’ai pas vraiment approfondi la notion. |
6 | 60% | Un nouveau serveur : server2.c , on découvre la commande docker exec env. On a aussi la création d’un server3.c qui exploite les liens entre containers (–link) |
7 | 10% | Un échec complet sur l’installation de HAproxy. |
8 | 80% | Bonne configuration de NGINX et de HAproxy. |
9 | 10% | Un échec complet sur la redirection des logs syslog vers un autre serveur. |
10 | 90% | La création d’un server5.c qui permet de faire des insertions dans la base, d’envoyer des logs à syslog et de tester les configuration de HAproxy et Nginx. |
Il y a eu des hauts des des bas dans cette découverte de Docker.
Maintenant je reviens sur les tests de hier, je me demande si c’est pas ma configuration du kernel qui faisait que le programme de stress ralentissait. Je fais donc les modifications suivantes :
[root@localhost ~]# cat /proc/sys/net/ipv4/tcp_fin_timeout 60 [root@localhost ~]# cat /proc/sys/net/ipv4/tcp_tw_recycle 0 [root@localhost ~]# cat /proc/sys/net/ipv4/tcp_tw_reuse 0 [root@localhost ~]# echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout [root@localhost ~]# echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle [root@localhost ~]# echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
Maintenant je vais recycler plus vite les sockets. Par contre je vais me remettre sur HAproxy qui me semble plus fiable.
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b37844241909 nginx "nginx -g 'daemon off" 54 minutes ago Up 54 minutes 0.0.0.0:80->80/tcp, 443/tcp mon-nginx-v7 eb76431e86e0 my-server5 "/sbin/server5" About an hour ago Up About an hour 0.0.0.0:8083->80/tcp my-server4-4 1e87ae6b009b my-server5 "/sbin/server5" About an hour ago Up About an hour 0.0.0.0:8082->80/tcp my-server4-3 5b9099ae80d0 my-server5 "/sbin/server5" About an hour ago Up About an hour 0.0.0.0:8081->80/tcp my-server4-2 4fb8f79456af my-server5 "/sbin/server5" About an hour ago Up About an hour 0.0.0.0:8080->80/tcp my-server4-1 2fc533c55725 postgres "/docker-entrypoint.s" 24 hours ago Up 24 hours 0.0.0.0:5432->5432/tcp postgres2 [root@localhost ~]# docker stop b37844241909 b37844241909 [root@localhost ~]# docker start 1f22de2c194b 1f22de2c194b [root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1f22de2c194b my-haproxy-v15 "/docker-entrypoint.s" About an hour ago Up 3 seconds 0.0.0.0:80->80/tcp mon-haproxy-v15b eb76431e86e0 my-server5 "/sbin/server5" About an hour ago Up About an hour 0.0.0.0:8083->80/tcp my-server4-4 1e87ae6b009b my-server5 "/sbin/server5" About an hour ago Up About an hour 0.0.0.0:8082->80/tcp my-server4-3 5b9099ae80d0 my-server5 "/sbin/server5" About an hour ago Up About an hour 0.0.0.0:8081->80/tcp my-server4-2 4fb8f79456af my-server5 "/sbin/server5" About an hour ago Up About an hour 0.0.0.0:8080->80/tcp my-server4-1 2fc533c55725 postgres "/docker-entrypoint.s" 24 hours ago Up 24 hours 0.0.0.0:5432->5432/tcp postgres2 [root@localhost ~]# ./client_stress localhost 80 Start Nombre 500 le temps 1 Nombre 1000 le temps 3 Nombre 1500 le temps 5 Nombre 2000 le temps 9 Nombre 2500 le temps 11 Nombre 3000 le temps 13 Nombre 3500 le temps 15 Nombre 4000 le temps 17 Nombre 4500 le temps 20 Nombre 5000 le temps 23 Nombre 5500 le temps 25 Nombre 6000 le temps 28 Nombre 6500 le temps 31 Nombre 7000 le temps 34 Nombre 7500 le temps 37 Nombre 8000 le temps 39 Nombre 8500 le temps 41 Nombre 9000 le temps 45 Nombre 9500 le temps 50 Nombre 10000 le temps 65 Nombre 10500 le temps 81 Nombre 11000 le temps 83 Nombre 11500 le temps 89 Nombre 12000 le temps 104
Perdu ce n’est pas linéaire, mais la piste était bonne 🙂 . Si je regarde à partir d’un autre terminal je n’ai pas énormément de sessions ouvertes :
[root@localhost ~]# netstat -nat | awk '{print $6}' | sort | uniq -c | sort -n 1 Adresse 1 établies) 7 ESTABLISHED 12 LISTEN 23 CLOSE_WAIT 23 FIN_WAIT2 26 SYN_SENT 109 TIME_WAIT
Je vais refaire une passe sur syslog, si je stoppe mon HAproxy et que je lance le server5.
[root@localhost ~]# docker stop 1f22de2c194b
1f22de2c194b
[root@localhost ~]# ./server5
Default interface is : enp0s3
Local ip is : 192.168.10.159
POSTGRES2_PORT_5432_TCP_ADDR : (null)
OK : Table STATISTIQUE
^C
[root@localhost ~]# tail -f /var/log/messages -n2
Apr 15 20:31:28 localhost server5[12140]: Local mode
Apr 15 20:31:28 localhost server5[12140]: End of check of table
J’ai bien des logs dans le syslog.
Maintenant je vais rediriger mon syslog, pour cela je lance un nouveau server :
[root@localhost ~]# docker run -p 8084:80 --link postgres2:postgres2 --name my-server4-5 --log-driver=syslog --log-opt syslog-address=udp://127.0.0.1:514 --log-opt syslog-facility=daemon -d my-server5 6b6b20000ee28f2b5ef5d634537be21ef3a493c7f83c233ed57b08b14fecbc1a
Mais si je fais un tail dans le syslog local je n’ai rien 🙁 . Je vais donc employer les grands moyen et mettre tcpdump sur mon serveur.
[root@localhost ~]# yum install tcpdump ... [root@localhost ~]# docker network inspect bridge [ { "Name": "bridge", "Id": "55fda48e57b67e66f6c0a55a123956056b9eb2c9dec518dbab92f946bc52a4c6", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "172.17.0.0/16" } ] }, "Internal": false, "Containers": { "1e87ae6b009be77a8795620aada0855b23f309d427f3d30ba9b822b09e98ae57": { "Name": "my-server4-3", "EndpointID": "2a4cd8aba5d7e3440b100e9056eba4e7b22eb9a0959785849839404306cd4cf0", "MacAddress": "02:42:ac:11:00:05", "IPv4Address": "172.17.0.5/16", "IPv6Address": "" }, "2fc533c557259f65236a97e1e4eb7123867d4c0e0cae784a620cc9c96e55c168": { "Name": "postgres2", "EndpointID": "7b73488b725254d34f441cb5df7b621379ac762f8a3c3d49a8577a3f25959cdd", "MacAddress": "02:42:ac:11:00:02", "IPv4Address": "172.17.0.2/16", "IPv6Address": "" }, "4fb8f79456af940d23ecd9913cb737326d2f9e9dc61ecb09e3ad99c669b57543": { "Name": "my-server4-1", "EndpointID": "8f6807afc74bcc0cae68960dc42736bf4556653164a2125570b4ebd049210b72", "MacAddress": "02:42:ac:11:00:03", "IPv4Address": "172.17.0.3/16", "IPv6Address": "" }, "5b9099ae80d024518259d65c3519b05149164e4f0f8a1a7959ec17f032724a0c": { "Name": "my-server4-2", "EndpointID": "0a1844d89e32d8e8fe2b0dd741f3853657e6e44e85c3b54d060d0f1b7e446465", "MacAddress": "02:42:ac:11:00:04", "IPv4Address": "172.17.0.4/16", "IPv6Address": "" }, "6b6b20000ee28f2b5ef5d634537be21ef3a493c7f83c233ed57b08b14fecbc1a": { "Name": "my-server4-5", "EndpointID": "43c1655064f132964f0d4b2c02a9061f74beaea77ee3b9005d39ac721b67006b", "MacAddress": "02:42:ac:11:00:07", "IPv4Address": "172.17.0.7/16", "IPv6Address": "" }, "eb76431e86e0b7519e8314e93b5e8a48acfb2a26e60305564ccc1c35a69b2907": { "Name": "my-server4-4", "EndpointID": "77d41c7ac4d85291e586aaa07f21383eb3c64cb50650f18d6a2e2f93a77ce722", "MacAddress": "02:42:ac:11:00:06", "IPv4Address": "172.17.0.6/16", "IPv6Address": "" } }, "Options": { "com.docker.network.bridge.default_bridge": "true", "com.docker.network.bridge.enable_icc": "true", "com.docker.network.bridge.enable_ip_masquerade": "true", "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", "com.docker.network.bridge.name": "docker0", "com.docker.network.driver.mtu": "1500" }, "Labels": {} } ] [root@localhost ~]# tcpdump udp port 514 -i docker0 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on docker0, link-type EN10MB (Ethernet), capture size 65535 bytes
Dans une autre fenêtre :
[root@localhost ~]# docker stop 6b6b20000ee2 6b6b20000ee2 [root@localhost ~]# docker start 6b6b20000ee2 6b6b20000ee2
Idem si j’écoute sur local :
[root@localhost ~]# tcpdump udp port 514 -i lo tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on docker0, link-type EN10MB (Ethernet), capture size 65535 bytes
On va reprendre plus simple, normalement avec cette commande je devrais avoir un message dans /var/log/messages :
[root@localhost ~]# docker run -d --log-driver=syslog --log-opt tag="super" ubuntu echo "mon test syslog" Unable to find image 'ubuntu:latest' locally latest: Pulling from library/ubuntu 72b39c1d4615: Pull complete 46a2d5ede4a6: Pull complete d7caf6e91ad4: Pull complete c7ac9f284354: Pull complete a3ed95caeb02: Pull complete Digest: sha256:c77ff4fba908a2d4a366d893e1a08b63271483fefd4d50b3d96909550ae3aae9 Status: Downloaded newer image for ubuntu:latest 729856be0fc4594aef9a6d77087b0a09f65dca9e180a5f42da2133aa3191551e
Normalement j’ai « mon test syslog »
[root@localhost ~]# grep "mon test" /var/log/messages Apr 15 21:29:23 localhost docker/super[856]: mon test syslog
Oups je viens de comprendre … j’avais modifié la configuration de mon rsyslog avec ceci :
# Save boot messages also to boot.log local7.* /var/log/boot.log local0.* /var/log/docker-0.log local1.* /var/log/docker-1.log local5.* /var/log/docker-5.log
Mais je n’ai rien via les containers …
Je reprends donc avec mon test précédent :
[root@localhost ~]# docker run -p 8084:80 --link postgres2:postgres2 --name my-server4-5 --log-driver=syslog --log-opt tag="my-server4-5" -d my-server5 a814b5991a873102d3d7d07a0786e44c5c3d6a701252a953bf7e6b6a7ce36321 [root@localhost ~]# grep "my-server4-5" /var/log/*
Je dois pas faire le printf sur le bon flux, je vais donc faire :
fprintf (stdout,"Default interface is : %s \n", p);
à la place de
printf ("Default interface is : %s \n", p);
Mais aussi :
fprintf (stderr,"Socket error");
à la place de
perror("Socket error");
Normalement de printf(« ») c’est pareil que le fprintf(stdout, » ») mais comme je doute de tout…
Voici donc ce que donne le server6.c :
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/un.h>
#include "libpq-fe.h"
#include <syslog.h>
#define MYPORT 80
#define BACKLOG 5
#define MAXCLIENTS 5
#define MAXDATASIZE 100
long
getMicrotime ()
{
struct timeval currentTime;
gettimeofday (¤tTime, NULL);
return currentTime.tv_sec * (int) 1e6 + currentTime.tv_usec;
}
int
main (void)
{
int sockfd = -1, new_fd, numbytes, highest = 0, i;
int clients[MAXCLIENTS];
long clients_t[MAXCLIENTS];
char clients_ip[MAXCLIENTS][MAXDATASIZE];
char buffer[MAXDATASIZE];
char localip[MAXDATASIZE];
struct sockaddr_in my_addr, their_addr;
socklen_t sin_size;
struct timeval tv;
fd_set readfds;
char conninfo[MAXDATASIZE];
PGconn *conn;
PGresult *res;
FILE *f;
char line[100], *p, *c;
const char *google_dns_server = "8.8.8.8";
int dns_port = 53;
struct sockaddr_in serv;
int sock = socket (AF_INET, SOCK_DGRAM, 0);
setlogmask (LOG_UPTO (LOG_NOTICE));
openlog ("server5", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
f = fopen ("/proc/net/route", "r");
while (fgets (line, 100, f))
{
p = strtok (line, " \t");
c = strtok (NULL, " \t");
if (p != NULL && c != NULL)
{
if (strcmp (c, "00000000") == 0)
{
fprintf (stdout,"Default interface is : %s \n", p);
break;
}
}
}
if (sock < 0)
{
fprintf (stderr,"Socket error\n");
syslog (LOG_ERR, "Error on socket");
closelog ();
}
memset (&serv, 0, sizeof (serv));
serv.sin_family = AF_INET;
serv.sin_addr.s_addr = inet_addr (google_dns_server);
serv.sin_port = htons (dns_port);
int err = connect (sock, (const struct sockaddr *) &serv, sizeof (serv));
struct sockaddr_in name;
socklen_t namelen = sizeof (name);
err = getsockname (sock, (struct sockaddr *) &name, &namelen);
const char *p2 = inet_ntop (AF_INET, &name.sin_addr, localip, 100);
if (p2 != NULL)
{
fprintf (stdout,"Local ip is : %s \n", localip);
}
else
{
fprintf (stdout,"Error number : %d . Error message : %s \n", errno,
strerror (errno));
strcpy (localip, "Error");
}
close (sock);
fprintf (stdout,"POSTGRES2_PORT_5432_TCP_ADDR : %s \n",
getenv ("POSTGRES2_PORT_5432_TCP_ADDR"));
if (getenv ("POSTGRES2_PORT_5432_TCP_ADDR") == NULL)
{
sprintf (conninfo, "hostaddr=%s port=%s user=postgres password=%s",
"127.0.0.1", "5432", "password");
syslog (LOG_NOTICE, "Local mode");
}
else
{
sprintf (conninfo, "hostaddr=%s port=%s user=postgres password=%s",
getenv ("POSTGRES2_PORT_5432_TCP_ADDR"),
getenv ("POSTGRES2_PORT_5432_TCP_PORT"),
getenv ("POSTGRES2_ENV_POSTGRES_PASSWORD"));
syslog (LOG_NOTICE, "Docker mode");
}
/* Ceinture et breteille */
fprintf(stdout,"Stdout is descriptor %d\n", fileno(stdout));
fprintf(stdout,"Stderr is descriptor %d\n", fileno(stderr));
freopen("/dev/stdout", "w", stdout);
freopen("/dev/stderr", "w", stderr);
fprintf(stdout,"Stdout is descriptor %d\n", fileno(stdout));
fprintf(stdout,"Stderr is descriptor %d\n", fileno(stderr));
conn = PQconnectdb (conninfo);
if (PQstatus (conn) != CONNECTION_OK)
{
fprintf (stderr,
"Connection to database failed: %s \n", PQerrorMessage (conn));
}
else
{
res = PQexec (conn, "select count(*) from STATISTIQUE;");
if (PQresultStatus (res) != PGRES_TUPLES_OK)
{
fprintf (stdout, "KO : Table STATISTIQUE \n");
PQclear (res);
res =
PQexec (conn,
"CREATE TABLE STATISTIQUE ( ID serial primary key, CLIENT CHAR(20) NOT NULL, SERVER CHAR(20) NOT NULL, TEMPS_MILLI INT NOT NULL, TEMPS_CUR INT);");
if (PQresultStatus (res) != PGRES_COMMAND_OK)
{
fprintf (stdout, "KO : Table STATISTIQUE (CREATE) \n");
PQclear (res);
}
else
{
fprintf (stdout,"OK : Table STATISTIQUE (CREATE) \n");
PQclear (res);
}
}
else
{
fprintf (stdout,"OK : Table STATISTIQUE \n");
PQclear (res);
}
}
PQfinish (conn);
syslog (LOG_NOTICE, "End of check of table");
if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) == -1)
{
fprintf (stderr, "socket error\n");
syslog (LOG_ERR, "Error on socket");
closelog ();
exit (-1);
}
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons (MYPORT);
my_addr.sin_addr.s_addr = INADDR_ANY;
bzero (&(my_addr.sin_zero), 8);
if (bind (sockfd, (struct sockaddr *) &my_addr, sizeof (struct sockaddr)) ==
-1)
{
fprintf (stderr, "bind error\n");
syslog (LOG_ERR, "Error on bind");
closelog ();
exit (-1);
}
if (listen (sockfd, BACKLOG) == -1)
{
fprintf (stderr, "listen error\n");
syslog (LOG_ERR, "Error on listen");
closelog ();
exit (-1);
}
bzero (clients, sizeof (clients));
highest = sockfd;
while (1)
{
sin_size = sizeof (struct sockaddr_in);
tv.tv_sec = 0;
tv.tv_usec = 250000;
FD_ZERO (&readfds);
for (i = 0; i < MAXCLIENTS; i++) { if (clients[i] != 0) { FD_SET (clients[i], &readfds); } } FD_SET (sockfd, &readfds); if (select (highest + 1, &readfds, NULL, NULL, &tv) >= 0)
{
if (FD_ISSET (sockfd, &readfds))
{
if ((new_fd =
accept (sockfd, (struct sockaddr *) &their_addr,
&sin_size)) == -1)
{
fprintf (stderr, "accept error\n");
syslog (LOG_ERR, "Error on accept");
continue;
}
for (i = 0; i < MAXCLIENTS; i++) { if (clients[i] == 0) { clients[i] = new_fd; clients_t[i] = getMicrotime (); break; } } if (i != MAXCLIENTS) { if (new_fd > highest)
{
highest = clients[i];
}
fprintf (stdout,"Connexion received from %s (slot %i) ",
inet_ntoa (their_addr.sin_addr), i);
strcpy (clients_ip[i], inet_ntoa (their_addr.sin_addr));
syslog (LOG_NOTICE, "Connexion received from %s (slot %i) ",
inet_ntoa (their_addr.sin_addr), i);
send (new_fd, "\nHELLO\n", 7, MSG_NOSIGNAL);
}
else
{
send (new_fd, "\nTOO MANY CLIENT\n", 17, MSG_NOSIGNAL);
close (new_fd);
}
}
for (i = 0; i < MAXCLIENTS; i++)
{
if (FD_ISSET (clients[i], &readfds))
{
if ((numbytes =
recv (clients[i], buffer, MAXDATASIZE, 0)) <= 0)
{
fprintf (stdout,"Connexion lost from slot %i", i);
syslog (LOG_NOTICE, "Connexion lost from slot %i", i);
close (clients[i]);
clients[i] = 0;
}
else
{
buffer[numbytes] = '\0';
fprintf (stdout,"Received from slot %i : %s", i, buffer);
syslog (LOG_NOTICE, "Received from slot %i : %s", i,
buffer);
if (strncmp (buffer, "POSTGRES", 6) == 0)
{
conn = PQconnectdb (conninfo);
if (PQstatus (conn) != CONNECTION_OK)
{
fprintf (stderr,
"Connection to database failed: %s \n",
PQerrorMessage (conn));
send (new_fd, "\nDB KO\n", 7, MSG_NOSIGNAL);
syslog (LOG_ALERT,
"Connection to database failed: %s",
PQerrorMessage (conn));
}
else
{
send (new_fd, "\nDB OK\n", 7, MSG_NOSIGNAL);
}
PQfinish (conn);
}
if (strncmp (buffer, "DBINSERT", 6) == 0)
{
conn = PQconnectdb (conninfo);
if (PQstatus (conn) != CONNECTION_OK)
{
fprintf (stderr,
"Connection to database failed: %s \n",
PQerrorMessage (conn));
send (new_fd, "\nDBINSERT KO (1)\n", 16,
MSG_NOSIGNAL);
syslog (LOG_ALERT,
"Connection to database failed: %s",
PQerrorMessage (conn));
}
else
{
char query_string[256];
send (new_fd, "\nDBINSERT OK\n", 7,
MSG_NOSIGNAL);
sprintf (query_string,
"INSERT INTO STATISTIQUE (CLIENT,SERVER,TEMPS_MILLI,TEMPS_CUR) VALUES ('%s','%s','%ld','%ld')",
clients_ip[i], localip,
getMicrotime () - clients_t[i],
time (0));
res = PQexec (conn, query_string);
if (PQresultStatus (res) != PGRES_COMMAND_OK)
{
send (new_fd, "\nDBINSERT KO (2)\n", 16,
MSG_NOSIGNAL);
send (new_fd, query_string, strlen(query_string), MSG_NOSIGNAL);
send (new_fd, "\n", 1, MSG_NOSIGNAL);
PQclear (res);
}
else
{
send (new_fd, "\nDBINSERT OK (1)\n", 16,
MSG_NOSIGNAL);
PQclear (res);
}
}
PQfinish (conn);
}
if ((strncmp (buffer, "QUIT", 4) == 0))
{
fprintf (stdout,"Connexion QUIT from slot %i \n", i);
syslog (LOG_NOTICE,
"End of cnx : QUIT (slot n°%i)", i);
close (clients[i]);
clients[i] = 0;
}
if ((strncmp (buffer, "TIME", 4) == 0))
{
fprintf (stdout,"TIME from slot %i : %ld ms \n", i,
getMicrotime () - clients_t[i]);
}
if ((strncmp (buffer, "EXIT", 4) == 0))
{
fprintf (stdout,"Connexion EXIT from slot %i \n", i);
syslog (LOG_NOTICE,
"End of cnx : EXIT (slot n°%i)", i);
close (clients[i]);
clients[i] = 0;
}
if ((strncmp (buffer, "CLOSE", 5) == 0))
{
fprintf (stdout,"Connexion CLOSE from slot %i \n", i);
syslog (LOG_NOTICE,
"End of cnx : CLOSE (slot n°%i)", i);
close (clients[i]);
clients[i] = 0;
}
if ((strncmp (buffer, "INTERFACE", 9) == 0))
{
send (new_fd, "\n", 1, MSG_NOSIGNAL);
send (new_fd, localip, strlen (localip),
MSG_NOSIGNAL);
send (new_fd, "\n", 1, MSG_NOSIGNAL);
}
if ((strncmp (buffer, "IP", 2) == 0))
{
send (new_fd, "\n", 1, MSG_NOSIGNAL);
send (new_fd, p, strlen (p), MSG_NOSIGNAL);
send (new_fd, "\n", 1, MSG_NOSIGNAL);
}
if ((strncmp (buffer, "CLIENT", 6) == 0))
{
send (new_fd, "\n", 1, MSG_NOSIGNAL);
send (new_fd, clients_ip[i], strlen (clients_ip[i]),
MSG_NOSIGNAL);
send (new_fd, "\n", 1, MSG_NOSIGNAL);
}
if ((strncmp (buffer, "DBCNX", 2) == 0))
{
send (new_fd, "\n", 1, MSG_NOSIGNAL);
send (new_fd, conninfo, strlen (conninfo),
MSG_NOSIGNAL);
send (new_fd, "\n", 1, MSG_NOSIGNAL);
}
}
}
}
}
else
{
fprintf (stderr, "select error\n");
syslog (LOG_ERR, "Error on select");
continue;
}
}
return 0;
}
Quand on lance le programme on voit bien que « ceinture et bretelle » ne sert à rien :
[root@localhost ~]# ./server6 Default interface is : enp0s3 Local ip is : 192.168.10.159 POSTGRES2_PORT_5432_TCP_ADDR : (null) Stdout is descriptor 1 Stderr is descriptor 2 Stdout is descriptor 1 Stderr is descriptor 2 OK : Table STATISTIQUE
Compilation, build, run …
[root@localhost ~]# gcc -o server6 server6.c -lpq [root@localhost ~]# docker build -t my-server6 . [root@localhost ~]# docker run -p 8085:80 --link postgres2:postgres2 --name my-server6-1 --log-driver=syslog --log-opt tag="my-server6-1" -d my-server6 2912a5b6f004d75e9c91e74e133a0934497269abb06d1036650adfbb9c9c9744 [root@localhost ~]# grep "my-server6" /var/log/* grep: /var/log/anaconda: est un dossier grep: /var/log/audit: est un dossier /var/log/messages:Apr 15 22:37:00 localhost docker/my-server6-1[856]: Default interface is : eth0 /var/log/messages:Apr 15 22:37:00 localhost docker/my-server6-1[856]: Local ip is : 172.17.0.8 /var/log/messages:Apr 15 22:37:00 localhost docker/my-server6-1[856]: POSTGRES2_PORT_5432_TCP_ADDR : 172.17.0.2 /var/log/messages:Apr 15 22:37:00 localhost docker/my-server6-1[856]: Stdout is descriptor 1 /var/log/messages:Apr 15 22:37:00 localhost docker/my-server6-1[856]: Stderr is descriptor 2
Super cela fonctionne, j’ai bien les logs dans syslog maintenant. Mais j’ai du mal à comprendre pourquoi cela n’était pas le cas avant …
A noter que la commande logs ne fonctionne pas dans le cas d’une configuration syslog.
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2912a5b6f004 my-server6 "/sbin/server6" 3 minutes ago Up 3 minutes 0.0.0.0:8085->80/tcp my-server6-1 a814b5991a87 my-server5 "/sbin/server5" About an hour ago Up About an hour 0.0.0.0:8084->80/tcp my-server4-5 eb76431e86e0 my-server5 "/sbin/server5" 4 hours ago Up 4 hours 0.0.0.0:8083->80/tcp my-server4-4 1e87ae6b009b my-server5 "/sbin/server5" 4 hours ago Up 4 hours 0.0.0.0:8082->80/tcp my-server4-3 5b9099ae80d0 my-server5 "/sbin/server5" 4 hours ago Up 4 hours 0.0.0.0:8081->80/tcp my-server4-2 4fb8f79456af my-server5 "/sbin/server5" 4 hours ago Up 4 hours 0.0.0.0:8080->80/tcp my-server4-1 2fc533c55725 postgres "/docker-entrypoint.s" 26 hours ago Up 26 hours 0.0.0.0:5432->5432/tcp postgres2 [root@localhost ~]# docker logs 2912a5b6f004 "logs" command is supported only for "json-file" and "journald" logging drivers (got: syslog)
C’est fini pour aujourd’hui.