Sie sind auf Seite 1von 152

Administration de systmes UNIX Formation ARS 2011 2012

Partie 4 Thierry Besanon

Formation Permanente de lUniversit Pierre et Marie Curie

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

1 / 277

Chapitre 1

Courrier lectronique
Explications sur le pourquoi de ce chapitre Voir aussi le cours de Lionel DAVID.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

2 / 277

1 Courrier lectronique

Chapitre 1 Courrier lectronique

1.1 Composantes du systme du courrier lectronique

1.1 Composantes du systme du courrier lectronique

Cest un systme complexe dont la complexit crot sans cesse.

Il a de fortes interactions avec Internet, avec les Intranets.

De nombreuses implmentations sont disponibles (X400, SMTP, Microsoft Exchange, etc.).

Le systme est modulaire, son bon fonctionnement reposant sur des descriptions publiquement disponibles des dtails des dirents protocoles.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

3 / 277

1 Courrier lectronique

1.1 Composantes du systme du courrier lectronique

Rseau

Destinataire du courrier non local

Courriers destination dun utilisateur local

Transmission au facteur local

MTA

MDA
Distribution personnalise Bote aux lettres Emission dun courrier

Consultation des courriers

MUA

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

4 / 277

1 Courrier lectronique

1.1 Composantes du systme du courrier lectronique

Terminologie : MTA (Mail Transfer Agent agent de routage) En fonction de ladresse de destination, il passe le message un certain agent de transport. Plusieurs MTA existent : Sendmail, Postx MDA (Mail Delivery Agent agent de transport) Il reoit un message, une destination et se charge de lacheminement. Il est spcialis dans un type dacheminement. (synonyme mailer ) MUA (Mail User Agent agent utilisateur) Il sert la composition des messages quil envoie lagent de routage.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

5 / 277

1 Courrier lectronique

1.1 Composantes du systme du courrier lectronique

Normes utilises : RFC 822, description du format des messages RFC 821, description du protocole SMTP (Simple Mail Transfer Protocol) RFC 974, description de linteraction dun MTA avec le DNS RFC 1035 RFC 1123 Attention : documents techniques hermtiques la lecture complique Cf ftp://ftp.lip6.fr/pub/rfc/rfc/ Les problmes de mail sont adresser postmaster . Les MTA font lhypothse que cette adresse existe. Cette adresse doit tre lue par un humain.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

6 / 277

1 Courrier lectronique

Chapitre 1 Courrier lectronique

1.2 Sendmail

1.2 Sendmail

SENDMAIL : Conu en 1982, par Eric Allman (<eric@cs.berkeley.edu>) Site ociel http://www.sendmail.org/ Principal logiciel pour router les courriers des systmes UNIX rpandus Souple, puissant Sait sadapter aux nouveaux standards (aspects multimedia) Syntaxe dicile

Outils annexes simpliant la conguration : par exemple kit jussieu ftp://ftp.jussieu.fr/jussieu/sendmail/kit/kit-5.3.4.tar.Z ftp://ftp.jussieu.fr/jussieu/sendmail/kit/doc-kit-5.3.4.ps.Z

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

7 / 277

1 Courrier lectronique

Chapitre 1 Courrier lectronique

1.3 Sendmail plugins : MILTER

1.3 Sendmail plugins : MILTER

SENDMAIL soccupe de router les mails. Donc : hors de question de compliquer le code par un antivirus hors de question de compliquer le code par un antispam hors de question de compliquer le code par. . . Bref, hors de question de compliquer le code par nimporte quoi qui na pas de rapport avec le routage de mails. Par contre, possibilit dinterfacer SENDMAIL des fonctionnalits externalises grce lAPI MILTER fourni par les dveloppeurs de SENDMAIL. Cf http://www.milter.org/ pour de la documentation ou des plugins.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

8 / 277

1 Courrier lectronique

1.3 Sendmail plugins : MILTER

MILTER = communication entre SENDMAIL et des programmes externes via des sockets UNIX.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

9 / 277

1 Courrier lectronique

Chapitre 1 Courrier lectronique

1.4 Postx

1.4 Postx

http://www.postfix.org Futur successeur de SENDMAIL certainement dans quelques annes. Une rexion sur SENDMAIL a conduit crire postx sous une forme non monolithique. Plusieurs dmons vont soccuper chacun dune tche bien prcise et nutilisent pour cela que le minimum de privilges systme limitant le risque de piratage :
transport aliases .forward

rewrite

resolve

local

mailbox

local

"sendmail"

maildrop

pickup cleanup incoming active qmgr smtp Internet

Internet

smtpd

canonical RBL access

virtual

deferred

relocated

pipe

UUCP, etc.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

10 / 277

1 Courrier lectronique

1.4 Postx

Le chier de conguration est une succession daectation de valeurs des variables. Approche radicalement dirente de celle de SENDMAIL plus proche dune programmation de la conguration. Approche de postx identique celle du kit jussieu pour SENDMAIL (ou vice versa). Possibilit de modier on the y le comportement de postx. Par exemple ltablissement dune connexion PPP ou lors de sa cloture, on peut depuis le script PPP dire postx dchanger les mails maintenant avec lextrieur. Avec SENDMAIL, il faudrait arrter SENDMAIL, mettre en place une nouvelle conguration sendmail.cf , relancer SENDMAIL, ensemble de manuvres lourdes.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

11 / 277

1 Courrier lectronique

Chapitre 1 Courrier lectronique

1.5 Postx plugins

1.5 Postx plugins

Il existe un mcanisme MILTER dans POSTFIX.

Utilisation de sockets UNIX aussi.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

12 / 277

1 Courrier lectronique

Chapitre 1 Courrier lectronique

1.6 Boites aux lettres : folders

1.6 Boites aux lettres : folders

Deux formats classiques de folders sous UNIX : folder MBOX folder MAILDIR

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

13 / 277

1 Courrier lectronique

Chapitre 1 Courrier lectronique

1.7 Boites aux lettres : folder MBOX

1.7 Boites aux lettres : folder MBOX

Un chier stocke tous les mails reus du MDA et manipuls par les MUA :

Classiquement /var/mail/$USERNAME . Problmes de verrouillage du chier lors des lectures/critures, de manipulation de grosses boites aux lettres, etc.
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 14 / 277

1 Courrier lectronique

1.7 Boites aux lettres : folder MBOX

Structure dun mail :

From samag@neodata.com Mon Nov 19 21:27:41 2001 Return-Path: <samag@neodata.com> Received: from localhost (localhost [127.0.0.1]) by apollinaire.paris4.sorbonne.fr (8.11.6/8.11.6) with ESMTP id fAJKRfY03543 for <Thierry.Besancon@localhost>; Mon, 19 Nov 2001 21:27:41 +0100 (MET) Received: from sorbon.sorbonne.fr [195.220.107.3] by localhost with POP3 (fetchmail-5.9.4) for Thierry.Besancon@localhost (single-drop); Mon, 19 Nov 2001 21:27:41+0100 (MET) Received: from neodata.com ([206.27.153.2]) by sorbon.sorbonne.fr (8.11.0/jtpda-5.3.3) with ESMTP id fAJKQnO06486 for <Thierry.Besancon@paris4.sorbonne.fr>; Mon, 19 Nov 2001 21:26:50+0100 (MET) Received: from bennett (bennett.neo.comm.eds.com [192.85.230.134]) by neodata.com (8.10.2+Sun/8.9.1) with ESMTP id fAJKRBK17328; Mon, 19 Nov 2001 13:27:11 -0700 (MST) Received: by bennett (8.8.8+Sun/SMI-SVR4) id NAA14733; Mon, 19 Nov 2001 13:26:57 -0700 (MST) Date: Mon, 19 Nov 2001 13:26:57 -0700 (MST) From: samag@neodata.com X-Gnus-Mail-Source: directory:~/Mail/incoming/ Message-Id: <200111192026.NAA14733@bennett> To: Thierry.Besancon@paris4.sorbonne.fr Subject: NEW ORDER Suite sur transparent suivant

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

15 / 277

1 Courrier lectronique

1.7 Boites aux lettres : folder MBOX

Structure dun mail (suite) :


X-AntiVirus: scanned for viruses by AMaViS 0.2.1 (http://amavis.org/) X-UIDL: Tjg!!<n*"!6i+"!J@O!! Status: RO X-Content-Length: 299 SYS ADMIN appreciates your inquiry and welcomes the opportunity to serve your needs.

En rsum : une ligne commencant par From (attention lespace suivant le From) autres enttes une ligne blanche marquant la n des enttes et le dbut du corps du mail corps du mail une ligne blanche aprs le corps du mail
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 16 / 277

1 Courrier lectronique

1.7 Boites aux lettres : folder MBOX

Structure dun mail (suite) :

Attention : si le corps du message contient une ligne commencant par From , la ligne est transforme en >From . Pourquoi ?

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

17 / 277

1 Courrier lectronique

1.7 Boites aux lettres : folder MBOX

Le format folder MBOX est manipulable par plusieurs MUA. Le MUA le plus simple pour cela est la commande Mail (ou mail ou mailx ).
% Mail "/var/mail/besancon": 4 messages 4 new >N 1 besancon@example.c Thu Aug 24 01:45 32/1175 N 2 besancon@example.c Fri Aug 25 01:45 32/1175 N 3 besancon@example.c Sat Aug 26 01:45 32/1175 N 4 me@localhost.com Mon Aug 28 00:27 44/1624 ---> 4 From apache@example.com Mon Aug 28 00:27:00 2006 Date: Mon, 28 Aug 2006 00:24:59 +0200 (MEST) To: besancon@example.com Subject: Account details for besancon at drupal MIME-Version: 1.0 Content-transfer-encoding: 8Bit From: me@localhost.com besancon,

Output from "cron" comman Output from "cron" comman Output from "cron" comman Account details for besan

Thank you for registering at drupal. You may now log in to http://drupal.imj.loc username: besancon c T.Besanon (v14.0.631) password: urM87U9eFi
Administration UNIX ARS 2011 2012 Partie 4 18 / 277

1 Courrier lectronique

Chapitre 1 Courrier lectronique

1.8 Boites aux lettres : folder MAILDIR

1.8 Boites aux lettres : folder MAILDIR

Un chier stocke un seul mail.

Plus de problme de verrouillage du chier lors des lectures/critures. http://www.courier-mta.org/mbox-vs-maildir/


c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 19 / 277

1 Courrier lectronique

1.8 Boites aux lettres : folder MAILDIR

En rsum : une ligne commencant par From (attention lespace suivant le From) autres enttes une ligne blanche marquant la n des enttes et le dbut du corps du mail corps du mail Attention : si le corps du message contient une ligne commencant par From , la ligne nest pas transforme. Pourquoi ? pas de ligne blanche aprs le corps du mail. Pourquoi ?

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

20 / 277

1 Courrier lectronique

1.8 Boites aux lettres : folder MAILDIR

Comment stocker les mails au format MAILDIR ? La structure dun folder MAILDIR appel FOLDER implique plusieurs rpertoires : FOLDER/new FOLDER/cur (cur pour current ) FOLDER/tmp Le MDA place un nouveau mail dabord par le rpertoire FOLDER/tmp temporairement le temps de calculer un nom de chier unique. Le nouveau mail est ensuite plac dans le rpertoire FOLDER/new par le MDA. La lecture dun mail entraine son dplacement de FOLDER/new vers FOLDER/cur avec ajout dun suxe indiquant les oprations faites par le MUA sur le mail.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

21 / 277

1 Courrier lectronique

1.8 Boites aux lettres : folder MAILDIR

Le nom du chier stockant un mail doit tre unique et en gnral a le format time.pid.host . Voir : http://www.qmail.org/man/man5/maildir.html http://cr.yp.to/proto/maildir.html Par exemple :
1185708514.M707068P58898V0700FF01I06974E18_1.mail. .example.com,S=989 :2,S avec : 1185708514 = temps depuis lorigine en secondes ;
ctime(1185708514) = Sun Jul 29 13:28:34 2007 M707068 = compteur en microsecondes de gettimeofday() P58898 = process ID du MDA V0700FF01 = UNIX device number I06974E18 = UNIX inode number mail.example.com = nom de la machine UNIX du MDA S=989 = taille du mail en octets

1185188613.000035.mbox:2,RS ; ici cest le rsultat dune

conversion par le programme MB2MD


c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 22 / 277

1 Courrier lectronique

1.8 Boites aux lettres : folder MAILDIR

Aprs manipulation par le MUA, on ajoute un suxe :2,flags avec ag : ag P (Passed ) = mail resent/forwarded/bounced ag R (Replied ) = mail rpondu ag S (Seen) = mail lu ag T (Trashed ) = mail mis la poubelle ag D (Draft ) = mail brouillon ag F (Flagged ) = mail tagg pour usage ultrieur Par exemple :
1185708514.M707068P58898V0700FF01I06974E18_1.mail. example.com,S=989 :2,S 1185188613.000035.mbox :2,RS

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

23 / 277

1 Courrier lectronique

1.8 Boites aux lettres : folder MAILDIR

Possibilit de folders MAILDIR imbriqus. Par exemple : ce qui donnera sous UNIX les rpertoires .system.sa-blacklist/ , .system.sa-false-negative/ , .system.sa-false-positive/ , .system.sa-whitelist/ (avec les classiques sous-rpertoires cur , new et tmp )

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

24 / 277

1 Courrier lectronique

1.8 Boites aux lettres : folder MAILDIR

On peut convertir un folder MBOX vers un folder MAILDIR : http://batleth.sapeinti-sat.org/projects/mb2md.html

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

25 / 277

1 Courrier lectronique

Chapitre 1 Courrier lectronique

1.9 Protocole de consultation : POP

1.9 Protocole de consultation : POP

SMTP

Serveur de mails

POP

download des mails

Client POP Mail folders

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

26 / 277

1 Courrier lectronique

1.9 Protocole de consultation : POP

POP Post Oce Protocol ; RFC 1939

Port POP : 110

Port POP + SSL : 995

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

27 / 277

1 Courrier lectronique

Chapitre 1 Courrier lectronique

1.10 Protocole de consultation : IMAP

1.10 Protocole de consultation : IMAP

SMTP

Serveur de mails

Mail folders

IMAP

download des entetes des mails download des corps des mails sur demande Client IMAP

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

28 / 277

1 Courrier lectronique

1.10 Protocole de consultation : IMAP

RFC 2060 (protocole IMAP4rev1), RFC 2086 (ACL, extension de IMAP4), RFC 2087 (quota, extension de IMAP4)

Port IMAP : 143

Port IMAP + SSL : 993

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

29 / 277

1 Courrier lectronique

Chapitre 1 Courrier lectronique

1.11 Comparaison de session POP et IMAP xxx

1.11 Comparaison de session POP et IMAP xxx

Comparatif de session POP et IMAP : (extrait de http://cri.univ-lyon2.fr/doc/ImapMaisCEstTresSimple.html )


% telnet pop.example.com 110 +OK POP3 server ready USER pdupont +OK Name is a valid mailbox PASS XXXXXXXX +OK Maildrop locked and ready % * . . telnet imap.example.com 143 OK IMAP4 server ready LOGIN pdupont XXXXXXXX OK User logged in

LIST +OK scan listing follows 1 169 2 811 3 813


c T.Besanon (v14.0.631)

. * * * * * * . . * * * .

SELECT INBOX FLAGS (Answered Flagged Draft Deleted Seen) OK [PERMANENTFLAGS (Answered Flagged Draft Dele 3 EXISTS 3 RECENT OK [UNSEEN 1] OK [UIDVALIDITY 901006906] OK [READ-WRITE] Completed UID FETCH 1:* RFC822.SIZE 1 FETCH (UID 1425 RFC822.SIZE 169) 2 FETCH (UID 1426 RFC822.SIZE 811) 3 FETCH (UID 1427 RFC822.SIZE 813) OK Completed
ARS 2011 2012 Partie 4 30 / 277

Administration UNIX

1 Courrier lectronique

1.11 Comparaison de session POP et IMAP xxx

RETR 1 +OK Message follows Return-Path: <root@example.com> From: root@example.com To: root@example.com Subject: essai chien chapeau essai chien chapeau .

. UID FETCH 1425 BODY[] * 1 FETCH (FLAGS (Recent Seen) UID 1425 BODY[] 16 Return-Path: <root@example.com> From: root@example.com To: root@example.com Subject: essai chien chapeau essai chien chapeau . OK Completed

DELE 1 +OK message deleted

QUIT +OK Connection closed by foreign host.

. UID STORE 1425 +FLAGS (Deleted) * 1 FETCH (FLAGS (Recent Deleted Seen) UID 1425) . OK Completed . EXPUNGE * 1 EXPUNGE * 2 EXISTS * 2 RECENT . OK Completed . LOGOUT * BYE LOGOUT received . OK Completed Connection closed by foreign host.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

31 / 277

1 Courrier lectronique

Chapitre 1 Courrier lectronique

1.12 Antivirus

1.12 Antivirus

Plusieurs antivirus sont disponibles sous UNIX : CLAMAV (gratuit) ; http://www.clamav.org SOPHOS (commercial) ; http://www.sophos.com nombreux autres logiciels commerciaux

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

32 / 277

1 Courrier lectronique

Chapitre 1 Courrier lectronique

1.13 Antispam

1.13 Antispam

Plusieurs antispam sont disponibles sous UNIX : BOGOFILTER (gratuit) ; http://bogofilter.sourceforge.net DSPAM (gratuit) ; http://dspam.nuclearelephant.com SPAMASSASSIN (gratuit) ; http://www.spamassassin.org AMAVIS (gratuit) ; http://www.amavis.org nombreux autres logiciels commerciaux

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

33 / 277

1 Courrier lectronique

1.13 Antispam

Humour :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

34 / 277

1 Courrier lectronique

Chapitre 1 Courrier lectronique

1.14 Annexe 1

1.14 Annexe 1

Ci joint dans la version imprime de ce cours, un document sur la conception dune messagerie.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

35 / 277

The following paper was originally published in the Proceedings of the USENIX Symposium on Internet Technologies and Systems Monterey, California, December 1997

A Highly Scalable Electronic Mail Service Using Open Systems

Nick Christenson, Tim Bosserman, David Beckemeyer EarthLink Network, Inc.

For more information about USENIX Association contact: 1. Phone: 510 528-8649 2. FAX: 510 548-5738 3. Email: office@usenix.org 4. WWW URL: http://www.usenix.org/

A Highly Scalable Electronic Mail Service Using Open Systems


Nick Christenson, Tim Bosserman, David Beckemeyer EarthLink Network, Inc. Information Technology Pasadena, CA 91107 npc@earthlink.net, tboss@earthlink.net, david@earthlink.net

Abstract
Email is one of the most important of the Internet services. As a very large, fast growing, Internet Service Provider, EarthLink requires a robust and powerful email architecture that will support rapid expansion. This paper describes such an architecture, its motivations, its future, and the di culties in implementing a service on this scale.

1 Introduction
Electronic mail has a special standing in the ranks of Internet services. Of the direct services an ISP provides to its subscribers, email is certainly one of the most important. As a consequence, it requires special attention to keep email running as well as expected. Additionally, there are several issues that are far more problematic for email than for other services. Email typically requires more resources than any other service. This is because the storage needs, the processing power, and the bandwidth requirements are extreme. Furthermore, there are problems regarding authentication and provisioning that are often not required for other services. Despite its criticality, little work has been made available publicly on robust, large scale electronic mail systems. The few references we have found, such as Grubb96 , have neither addressed what we consider to be the key problems, nor have they been able to scale to the capacity that we require. This isn't too surprising. Providing email service for hundreds of thousands or millions of users is a problem nobody had to solve before the advent of the national or international Internet or on line service provider. Until now, none of these organizations have chosen to come forward and publish their service architecture. Additionally, the architecting of very high performance truly distributed services is still in its infancy. The issues of distributed storage and load

balancing have few, if any, available solutions that are both robust enough and perform satisfactorily for our purposes. The astute reader will certainly notice that the architecture we describe here bears a great deal of similarity to what we have already described as our news service architecture Christ97a . This, of course, is no accident. We've found a general set of principles which we have adapted to meet the needs of both services, and many of the important issues discussed in that article are equally applicable here. In the design of any of our service architectures, we have several requirements that must be met before we would consider deployment. For email, the rst of these is message integrity. It is absolutely essential that messages, once they are accepted by our system, be delivered to their proper destination intact. Second, the system must be robust. That is, in as much as is possible, the system should survive component outages gracefully. Additionally, the entire system design should minimize the number of single points of failure. Third, the system must be scalable. When EarthLink began deployment of the current architecture, in January of 1996, we had about 25 000 subscribers. In September of 1997, EarthLink provided email service for over 350 000 subscribers with a 99.9+ service uptime record. In fact, we expect the current system to scale to well over 1 000 000 users without signi cant alteration of the architecture as presented here. Moreover, one should be able to accomplish the scaling of any service with a minimum of outage time, preferably with none. In all cases the performance of the service must be at least adequate, and the service must be maintainable. Problems must be easily recognizable, and it should be obvious, whenever possible, what is the cause of the outage. Further, its solution should be easy to implement and, in the meantime, the impact of the outage should be small and locally con ned. Finally, we would like the service architecture to be cost e ective, not just in terms of
; ; ; ;

equipment acquisition, but, more critically, in terms of maintenance.

2 Architecture Description
There are several logically distinct components which make up the operation of EarthLink's email service. The rst, which we call the front end" of our email system front de ned as the portion which receives data from the Internet are the systems that receive mail for username@earthlink.net". These machines are also called the SMTP machines. The second component is the POP service, the servers to which subscribers connect to retrieve their mail. These same computers also send the mail originating from our subscribers to the Internet. At the time of this writing, EarthLink has not deployed an IMAP service. The third component is the le servers, which do nothing except store the mailboxes, mail queues, and auxiliary les associated with the email service. The fourth component is the authentication database which holds the username password information, information on where mailboxes are stored, and data on auxiliary email services to which that account may have subscribed. This architecture is demonstrated graphically in Figure 1 included at the end of this paper. All the servers we use in this architecture, except for the le servers, are running some avor of Unix. With the exception of our le servers and the authentication database servers, our architecture calls for all of the servers involved in our email service as well as all our other services to be dataless. That is, each server should store on local disk its own operating system, service software, swap space, temporary le storage for nonessential data|and nothing else. This allows us to add or subtract servers from service with which the Internet or our subscribers interact without a ecting the data stored.

2.1 Front End


Mail Exchange MX DNS records for earthlink.net and mail.earthlink.net point, with high preference, to a series of servers in Round Robin. These servers all run a recent version of the freely distributable stock sendmail Allman86 as their SMTP MTA Simple Mail Transfer Protocol, Mail Transfer Agent; see Postel82 for details. Writing and maintaining an SMTP MTA is a di cult and expensive task. Therefore, we have geared our architecture to allow us to use sendmail without any source modi cation. Since sendmail typically un-

dergoes several signi cant revisions during each calendar year, it's important that we be able to use sendmail in a form as close to the stock distribution as possible, since updating a modi ed sendmail every few months to re ect local modi cations would be about as time consuming as maintaining our own MTA. An electronic mail message to be delivered to username@earthlink.net" follows the DNS MX records for earthlink.net. We maintain several machines with high precedence MX records using Round Robin DNS to distribute the load. If any of these machines become overloaded or otherwise unavailable, we maintain a single machine with a lower precedence MX record to act as a spillway. This server does not deliver email directly, but it does hold it for forwarding to the rst available front end server. Our backup MX machine could easily be con gured to deliver email itself, but we have chosen not to do this to protect against the possibility of transient errors in the mailbox locking process. This way, if the locking scheme becomes overloaded, we have a server that can still accept mail on behalf of the earthlink.net" domain. It is our intention to minimize at all times the amount of email queued around the Internet for delivery to EarthLink. The key to using the stock sendmail in our architecture is to insure that the sendmail program itself attempts to do no authentication or lookup of user names. This is actually quite simple to do. One merely must remove the w" ag in the entry for the local delivery agent in the sendmail.cf le. Even if one runs a standard authentication scheme, we've found that this modi cation provides a considerable performance boost if one has a large, unhashed i.e. linear lookup passwd le, and the service is not completely inundated with email intended for non existent users. The portion of the mail reception service that we did modify heavily was the mail delivery agent. This is the program that receives the mail from the MTA and actually appends it to the user's mailbox. On most systems, this program is bin mail. The sendmail distribution provides a delivery agent called mail.local which we have rewritten to use our authentication methods and understand how we store mailboxes. This is a small program which hasn't changed substantially in years, so it is easy to maintain; hence, it is a better place to add knowledge about our email architecture than a moving target like sendmail. In addition to authentication and mailbox location, the mail delivery agent also knows about mailbox quotas which we impose on our subscribers. If

the current mailbox size is over the quota for that user, the default being 10 MB, then the message is bounced back to the MTA with reason, User npc, mailbox full." In addition to preventing resource abuse on the part of subscribers, this also helps mitigate possible damaging e ects of mail bombing by malicious people on the Internet. We believe that a 10 MB quota is quite generous, especially considering over a 28.8 modem using very high quality line speeds and no network bottlenecks, one could expect to take over an hour to download the contents of a 10 MB mailbox.

tation we started with was Qualcomm's POP daemon version 2.2, although like mail.local, we have modi ed it substantially. In the near future, we plan to completely rewrite the POP daemon tuned for efciency in our environment implementing many of the lessons learned from developments in Web server software.

2.3 Mailbox Storage


On a conventional Unix platform, mailboxes are typically stored in var mail or var spool mail. The passwd le, used to store valid user names for incoming mail and to authenticate POP connections, is usually located in etc, and mail which cannot be delivered immediately is stored in var spool mqueue. This is where our mail architecture started out as well, but we made some signi cant changes as we went along. As with Usenet news, we use the Network Appliance Hitz95 family of servers as our network le storage for essentially the same reasons: Very good performance, high reliability of the systems, easy maintenance, and the advantages provided by the WAFL lesystem Hitz94 . Due to performance considerations, the spool is split across several le servers and each is mounted on the SMTP and POP servers as var mail, where  is the number of the mount point, in single digits as of this writing. Currently, we're using version 2 of the NFS protocol. While version 3 does give some signi cant performance bene ts, we give it all back because of the implementation of the READDIRPLUS procedure Callag95 which prefetches attribute information on all les in that directory, whether we need them or not. Since we store a large number of les in the same directory and are only interested in operating on one of them at a time, this is signi cant overhead that we don't need. On balance, for our email system, the performance di erence between versions 2 and 3 of the NFS protocol is so small as to defy precise measurement. We typically change it whenever we suspect the current version might be responsible for some strange behavior we notice. The NFS version has never turned out to be the problem, so we usually leave that version in place until we feel the need to change it again in order to eliminate it as a factor in some other problem we face. Even though the Network Appliance's WAFL lesystem provides excellent protection against the performance penalties one normally encounters when there are very large numbers of les in a single

2.2 POP Daemon


What we call the back end" of our architecture is a set of machines using Round Robin DNS which act as the POP servers. They are the targets of the A records, but not the MX records, for earthlink.net and mail.earthlink.net. These are the servers to which the subscribers connect to retrieve and send email. If these machines receive email bound for user@earthlink.net from our subscribers, Internet machines compliant with the SMTP protocol must follow the MX records and send this message to a front end machine, these messages are redirected to our SMTP machines at the front end. The POP servers do no local delivery. They do, however, deliver directly to the Internet. We've debated the notion of having the POP servers forward mail on to yet another set of servers for Internet delivery, but have thus far elected against it. The bene t to doing this would be further compartmentalization of physical server function by logical operation, which we consider to be inherently good. We'd also reduce the likelihood of POP session slowdowns in the case that a subscriber oods the server with an inordinate amount of mail to be delivered. If the POP and Internet delivery functions were separate, the POP server would expend very few resources to hand this mail o to the delivery servers, whereas it would otherwise be required to try to send and possibly queue this mail itself. On the other hand, we don't observe this being a signi cant problem. Additionally, if we had a separate Internet delivery service within our mail architecture, we'd have to deploy an additional machine to maintain our complete N+1 redundancy to every component, at additional cost. Someday, we probably will make such a separation, but it does not seem to be justi ed for the present volume. Like the delivery agent, the POP daemon must also know about both our modi ed authentication system and mailbox locations. The base implemen-

directory using most other le systems, there are still signi cant advantages to breaking them up further. Since we have more les and require more storage and throughput than we can realize with any one le server, we need to split the spool up and provide some mechanism to locate mailboxes within this tree. So, we create a balanced hash for each mailbox over 319 possible subdirectories the prime base of the hash and divide these directories over the number of le servers that compose the spool. Thus, a path to a mailbox may look something like var mail2 00118 npc. The POP daemon and the local delivery agent are the only parts of the mail system that need to know about these locations. Once we have this mechanism for multiple locations of mailboxes in place, we are able to extend this to allow us to dynamically balance the mailboxes or expand capacity. In addition to the notion of the proper" location of each mailbox, both mail.local and popper the POP daemon understand the notion of the old" mailbox location. If the system receives email for a given mailbox, mail.local checks the proper" location for the mailbox, and if it nds it there, appends the message in the normal manner. If the mailbox isn't there, it checks the old" location for the mailbox. If it is found there, mail.local locks the mailbox in both locations, moves it to the new location and appends the message in the normal manner. If the mailbox exists in neither place, it creates a new mailbox in the proper" location. The POP daemon also knows this information. It looks in the proper" location rst, and if it is not there, it consults the old" location. In either case, it operates on the mailbox entirely in the place where it was found. Only mail.local actually moves the mailbox. We felt that it would be better to con ne the mailbox moving logic in the simpler of the two programs. Because the mailbox can only be in one of the two places and the delivery agent and POP daemon use a common locking system described below, there's no danger of confusion as to the mailbox location. The data on what constitutes the old" and proper" mailbox locations are kept in the authentication database explained below, and this information is returned to the client process when authentication information is accessed. This feature has a major bene t for our mail system. This allows us to move large numbers of mailboxes around without interrupting service. For example, if we have three le servers containing mailboxes and they are either getting to be full or running out of bandwidth capacity, we can create a new mount point, var mail4 for instance, mount a new

le server on the mail servers, create the hash value subdirectories that will reside there, and then slide a new mail.local and popper in place POP daemon rst! that know which of the subdirectories from each of the rst three le servers will now be housed on the fourth. Then, as mailboxes receive new mail, they are moved onto the new le server. After a few hours, days, or weeks depending on how much of a hurry we're in, we can start a second process of individually locking and moving mailboxes independent of any other activity on the systems. Thus, we have now expanded our email system without any downtime.

2.4 Authentication
One thing we quickly realized is that the standard Unix authentication systems were wholly inadequate for a service of this magnitude. The rst problem one runs into is that depending on the speci c operating system, one is typically con ned to between 30 000 and 65 535 distinct user identities. Fortunately, since none of these users have shell access to these servers or any access other than POP access, we can have a single UID own every one of these mailboxes as long as the POP daemon is careful not to grant access to other mailboxes without re authenticating. While this postpones several problems, it isn't su cient by itself to scale as far as we'd like. First, several Unix operating systems behave quite strangely, not to mention inappropriately, when the passwd le exceeds 60 000 lines. This isn't completely unexpected|after all how many OS vendor test suites are likely to include these cases| but some of these problems manifest themselves a great distance from the passwd le and, thus, can be di cult to track. Just as important, when the passwd le gets this large, the linear lookups of individual user names become expensive and time consuming. Therefore, the rst thing we did was make a hashed passwd like le using the Berkeley NEWDB scheme Seltze91 that both popper and mail.local would consult for authentication. This eliminated the need to carry a large passwd le and greatly increased performance of the system. A separate machine working in a tight loop continually rebuilt the hashed passwd le as the text le was continually being modi ed by the the new account provisioning system. The next logical extension of this was to store the passwd le in a SQL database and replace getpwnam calls with SQL equivalents. This provides another quantum improvement. First, this
; ; ;

eliminates the necessity of continually rebuilding the hash le from the at le, with savings in processor and delay times for user account modi cation. Second, this database may be used by other applications including RADIUS Rigney97 , Usenet news, etc.... Third, it's a logical place to store additional important information about that account. For example, when a username lookup by mail.local or a username password pair is authenticated for popper, the old" and proper" mailbox locations are returned to the application rather than having to be stored in at les on the system or hardcoded into the respective binary. We also intend to use this database as a repository for a great deal more information, for example storing variable mailbox quotas and lists of domains from whom to refuse mail on a user by user basis, etc.... Obviously, this database is critical to not only the operation of our electronic mail system, but to other components of our overall service architecture as well. If the authentication service isn't operating, electronic mail comes to a halt. Because of this, we have taken special pains to make certain that this application is always on line by using a clustered system with failover using a dual attached storage unit for the database to meet our high availability requirements. If it becomes necessary, we can still fail over to the old common hashed passwd le with only a marginal loss of functionality and performance.

small for our purposes. We can routinely require thousands of outstanding lock requests on a given NFS mounted lesystem at any one time, and few commercial solutions have lock tables large enough and or lock table lookup algorithms fast enough to meet our needs.

Today
Therefore, wherever possible, we use the le system to perform locking. This consists of requesting an open system call to create a new lock le with the O EXCL ag of a le of a predetermined name, typically mailboxname.lock, in a given location, which would typically be the mail spool. In our case, in order to keep the spool directory sizes down as much as possible and performance as high as possible, we store these les on their own shared le system. This may set o alarms in the heads of those familiar with NFS. One might well ask, How can you be certain that this is atomic on an NFS system? How do other clients know that one has locked a given le?" Recent implementations of NFS client software ignores the attribute cache on open calls which attempt to exclusively create a new le. Note, however, that other open calls do not ignore the attribute cache. This means that if a process's exclusive open on the lock le succeeds, that process has successfully locked that le. This allows us to use le locking on the mailboxes, as long as we are mortally certain that all NFS clients operate in exactly the same way. One can nd both NFS v2 and v3 implementations that behave this way. It cannot be overstated how important it is to be certain that all NFS clients behave in this manner. It is always possible that the process which creates the lock will die without having the opportunity to remove it. For this reason, all processes creating locks must touch the lock les to update their attributes periodically so that if these processes die, after a certain amount of time other processes will know that an existing lock is no longer valid and can be eliminated. Therefore, we need a function that, again, will bypass the cache and be guaranteed to immediately update the attributes on the lock le. Let us suppose that one process on one NFS client has created a lock on the mailbox npc". Let us also suppose that a process on a di erent NFS client then tried to lock that mailbox immediately afterwards and discovered the existing lock, as it must. It's always possible that the rst process has somehow died, so it's important to understand how long the second process must wait before it can assume that

2.5 File Locking


In any distributed system, concurrency issues are of paramount importance. In our email system, these manifest themselves in terms of le locking. It is so important, we have given the topic its own section in this paper to discuss the issues which the implementor faces.

Yesterday
For data stored on local disk, flock su ces to ward against two processes attempting to process the same message or modify the same mailbox at the same time. Since all of our persistent data is accessed over NFS, this presents some signi cant problems for us. When using flock on an NFS mounted le system, these calls get translated to requests via rpc.lockd. Now, lockd isn't the most robust le locking mechanism ever devised. It isn't advisable to bank on lockd working entirely as advertised. In addition to this, many systems have lockd tables too

the rst process no longer exists, at which time it can delete the lock le, lock the le itself, and perform operations on that mailbox. Again, let us suppose that all the NFS clients are set to refresh their mailbox lock every ve minutes, and that the NFS attribute cache is set on each client to be three minutes. One scenario is for a process on client1 to successfully lock the mailbox and then have client2 immediately attempt to lock the same mailbox and fail. At this point, the information on the locked mailbox is saved for three minutes, the duration of the attribute cache, after which client2 gets the same attribute information as before, because ve minutes has not elapsed, therefore client1 has not yet refreshed the lock. At the ve minute mark, client1 refreshes the lock le using utime, since it also bypasses the NFS cache and operates synchronously on the lock le, but client2 has not noticed because it will be looking at the attributes in its cache until the six minute mark, when its cache expires, and it can now gets the updated information. This is represented graphically in Figure 2.
client1 locks mbox client2 attempts to get lock Attribute cache on client2 expires client2 gets same lock info client1 refreshes lock client 2 notices new lock

concerns. If the le servers ever get saturated with requests, the server can seem to disappear" to client processes for many seconds or even minutes. This can happen as part of normal subscriber growth if one does not upgrade the capacity to handle load before it is needed. In these circumstances, problems usually manifest themselves as a sudden change in performance response from acceptable to unacceptable over a very small change in load. The mathematicians would call this a catastrophic response, where ...gradually changing forces produce sudden e ects." Zeeman77 If a le server's load is near, but not at the critical point, it can be pushed over the edge by a sudden change in the pro le of normal email use or by a small number of malicious or negligent individuals.
client1 creates lock client1 dies client2 attempts to get lock lock expires client2 learns that lock expires

0 1 2 3 4 5 6 7 8 minutes Figure 3

0 1 2 minutes

Figure 2

The worst case scenario is presented in Figure 3. Here we have client1 creating a lock on a mailbox and then immediately dying. Just before the lock is scheduled to be updated, client2 attempts to lock the mailbox and fails. Client2 cannot learn that the lock hasn't been updated until just before the eight minute mark, at which point it has license to remove the lock le and proceed with its actions. Unfortunately, this potentially gives us a window of eight minutes in which real users may not be able to access their mailboxes under pathological conditions. For example, if the subscriber interrupts a POP session at the wrong moment, the POP daemon on the mail server may exit without cleaning up its lock le. Further, we explain below why we must delay even longer than this to allow for other

It is self evident that one wants to provide enough surplus performance to prevent small changes from breaking the performance envelope, and certainly we strive for this, yet it is not always possible. As an example, consider a two week period in August 1996 where the total volume of email EarthLink was called upon to handle doubled for reasons that are still not fully understood. While not routine, these events are not uncommon in the ISP business and, because the subscriber has a much greater ability to impact service, represent a fundamental di erence between providing Internet services and, for example, providing electric power or dial tone service. In any case, when one enters into one of these catastrophic regimes, one often encounters pathologic behavior on the part of any or all of the components of the service. Client requests can come too fast for the servers to handle; consequently the RPC packets can get dropped before they are processed. This can result in retransmissions by multiple clients, and on top of an already saturated system, the problem is compounded.

Let us suppose that we have a saturated system where the client base demand is 105 of the server's capacity to deliver it over a given period of time, not counting the load put on the server because of retransmissions. Each of these clients will now retransmit their requests after a number of tenths of seconds speci ed by the timeo value in the etc vfstab or equivalent le. If this request does not receive a response, the client waits for twice timeo and retransmits again. This process is repeated until the value of the retry variable is reached. If retry is exceeded, then the client prints a message, typically NFS server raid not responding, still trying," and continues to retry at the maximum retry value. This maximum value will never exceed 30 seconds Stern91 . Under these conditions, we cannot achieve a steady state" condition, the amount of tra c grows, quite dramatically, without bound until something breaks. If this condition were to persist for 30 minutes, at this time as much as 25 of the requests sent to the servers may be over 5 minutes old. Note that this represents a true pathological condition, it's highly unlikely that a client machine would either be able to maintain this load given the lack of responsiveness of the server, or that the client load would be constant, but we haven't yet developed our mathematical models su ciently to account for all the known variables, so we're being conservative. Given these assumptions, if we are adding 2 000 000 new email messages to our spool in a day, a half an hour of operation at this level of saturation with a lock timeout of only 5 minutes, we must expect there to be on the order of a thousand mailbox corruptions due to multiple processes proceeding to modify mailboxes on the assumption that they have exclusive access to it. This is because they have encountered expired lock les which are actually valid, the owning process just hasn't been able to get the server to ack it's update of the lock le. The mathematics behind this analysis and an in depth examination of the rami cations of this will be fully explored in Christ97b . Therefore, it is important that our locking mechanism allow for the possibility that a client process may not be able to get their request through to the server for several minutes after the normal locking timeout window has closed. We use a lock timeout value of 15 minutes to allow for this possibility. With regard to locking, one area of concern we have is with sendmail. Current versions want to use flock to lock les in mail queues. On our email system, the depth of these queues is extreme and the number of processes that can concurrently be
; ;

trying to drain them can be as high as several hundred per machine, requiring a large number of outstanding lock requests at any one time, often too many for either the client lock daemon or the le server to accommodate. Because of this, we have two choices. Either we can put the mail queues on locally attached disk, violating our stateless architecture principle and losing the bene ts of the WAFL le system in handling directories with large numbers of les, or we can modify sendmail to use a di erent locking mechanism, thus violating our intention to use an unmodi ed SMTP MTA. Fortunately, the current sendmail implementation has very modular locking code which can be easily replaced without fundamentally altering the distribution. However, we'd like any folks working on sendmail to consider allowing a preference for various locking mechanisms to be de ne'd in the source code.

Tomorrow
While the mailbox locking mechanism we've just described has worked satisfactorily, it is not without its drawbacks. One drawback is the fact that locks may be orphaned, and other clients must wait up to 15 minutes before being able to assume they are no longer valid. Another drawback is that the synchronous NFS operations we employ greatly increase the load placed on the NFS servers which hold the lock les. Therefore, we are in the process of designing and building our next generation lock management system. In accordance with our design parameters, what we really want is a distributed lock system with no single points of failure. It has to maintain state in the case of a crash or hardware failure, and it must be able to handle at least several hundred transactions per second. We tried using a SQL database for this purpose, but we were not satis ed with the performance. A program like a large commercial database such as this requires too much overhead to be e cient in this manner. However, we can learn from the database style locking mechanisms and, essentially, strip away those portions of the database system which we don't need to create our own lean and mean network lock server. We plan to deploy two machines clustered together around a shared RAID system to act as our lock service. If the primary machine were to su er some form of failure, the other would take over with a target transition time of less than ve seconds. We intend to deploy the same hardware con guration

that we use for our authentication database. All the lock requests get written to the le system using unbu ered writes before they are acknowledged so that in case of machine failure there is no loss of state. The clients open up a socket to the lock daemon on the lock server and request a lock for a given mailbox, which the daemon either accepts or denies. If it is denied, the client waits for some pseudo random time and tries again. We project that this system will scale well into the millions of mailboxes for a single set of lock managers. To get this scheme to scale inde nitely, it's a simple matter of having the clients query di erent lock servers for di erent ranges of mailbox names.

3 Operation
One of our primary design goals was to deploy a system that would be cost e ective to maintain. This service accomplishes those goals in several ways. First, by centralizing authentication in a single system, we reduce the problems associated with both maintaining multiple parallel authentication systems and insuring that they are synchronized. This is a considerable overhead savings. Second, one of the key criteria in selecting the Network Appliance as our storage system was its ease of maintenance. Because its operating system has been stripped down, eliminating functionality not necessary to its operation as a le server, the server is less likely to fail and, if it does fail, it is easier to discover and remedy the problem due to the greatly reduced number of degrees of freedom presented by the operating system. Third, because the POP servers themselves are dataless, they require much less maintenance than their stateful equivalents. The only les which differ between these computers are those that contain their host names and or IP addresses. This means that new servers can be brought online in a very short time via cloning an active server. Just as signi cant, it means that since these machines contain no important persistent data aside from the operating system, there are few reasons for system administration to log on to the system and make changes. This helps eliminate one of the arch nemeses of distributed computing| state drift," the tendency for systems intended to be identical or nearly identical to become more and more di erent over time. At EarthLink, one of the things we do most often is to grow an existing service to accommodate

more subscribers. The e orts we have made to allow this to happen easily and with a minimum of interruption contribute greatly to lowering the cost of operation. We've already explained how we use the concept of old" and proper" mailbox locations to scale both le system storage and bandwidth by adding additional le servers easily and with no downtime. The network implementation we're using at this time is switched FDDI, which also scales well. As we've already mentioned the POP servers are dataless and, therefore, should lack of these resources present a problem, in very little time, and again, with a minimum of e ort, we can clone and deploy a new system. This results in our email service being extremely scalable on short notice. We attempt to maintain + 1 redundancy in every possible component of the system. Our data storage systems use RAID to protect against single disk failure. We keep extra data storage servers near line in case of failure for rapid exchange with the downed system. We keep extra FDDI cards in the switch and an extra switch chassis nearby in case these components fail. We also keep one more SMTP and POP server online than loading metrics indicate is necessary. Thus, if one fails, we can pull it out of Round Robin DNS without impacting service, aside from the problems caused by the initial component failure. Additionally, we get the bene t of not having to repair the failed server immediately. Instead, we can take time to ensure that everything else is in proper running order, and then we can diagnose and repair the failed server at our leisure. On top of all this, we use a monitoring system that ags problems with each component of the service in our Network Operations Center, which is sta ed 24x7x365 and contacts appropriate on site personnel.
N

4 Shortcomings
We consider the architecture presented above to have considerable merit as one of the better solutions available for satisfying high volume mail service. It is, of course, not without its limitations, some of which we mention here. One of the rst problems is with sendmail as an MTA. When Eric Allman developed the original sendmail, it was not envisioned that it would still be in service over fteen years later and be pushed, rewritten, and extended to the extent that it has. It is a testament to the skill of its creator and maintainer that it has performed as well as it has for this long. Nonetheless, if one were to code an SMTP MTA today, we doubt

anyone would want it to take the form of sendmail. Despite this, we don't see an MTA that would provide enough signi cant advantages that we would want to migrate to it in the immediate future. Of course, these statements about sendmail could have been uttered ve years ago without alteration. The bottom line is that we would prefer to run an SMTP MTA that is tighter, more e cient, and has fewer potential places for security bugs to creep in, but there isn't one available that meets our needs at this time. Probably the biggest problem with our architecture is that due to the nature of NFS, when we add additional le servers to address our performance and storage needs, we end up adding multiple single points of failure. Despite the fact that the Network Appliance le servers have been quite stable and recover quickly from problems, we feel that this is not easily scalable forever. Therefore, it is our opinion that at some point we need to abandon NFS as our distributed systems protocol for something better. Our ideal protocol would be very high performance; be completely distributed and, thus, highly scalable, local failures would cause local, not global outages, and would allow for redundant storage that eliminates local single points of failure. Unfortunately, given the current state of distributed computing, it's hard enough to nd a system that adequately addresses one of these points, and nothing seems close to providing good solutions for all of them. Consequently, we are currently in the process of designing our own distributed system to accommodate our next generation architecture requirements.

6 Conclusion
In conclusion, we believe we have architected a mechanism to extend a standard, freely distributable, open systems email system to handle from hundreds of thousands to millions of distinct email accounts with a minimum of modi cation to the underlying components. We also believe that this system meets, to the best of our ability to deliver, the required criteria we set out in the Introduction.

7 Acknowledgments
The authors of this paper are by no means the only folks who have put a lot of e ort into the development and operation of this system. We wish to especially thank Jay Cai and Max Chern who did a signi cant portion of the software development on this system. Thanks to Steve Dougherty and Mark Wagnon, who provided helpful comments, and to Jim Larson, who provided valuable input on the precise mathematics of packet retransmissions. Also, a great deal of thanks go to Trent Baker and his system administration team who maintain all our services: Gianni Carlo Contardo, Jason Savoy, Marty Greer, Alwin Sun, Horst Simon, Jewel Clark, Tom Hsieh, Lori Bar eld, David Van Sandt, Larry Wang, Hong Zhang, and Kenny Chen. We also wish to extend a special thank you to Scott Holstad who made many excellent editorial improvements to early versions of this paper.

References
Albitz97 P. Albitz, C Liu, DNS and BIND, 2nd Ed., O'Reilly & Associates, Inc., Sebastopol, CA, 1997, p. 212. Allman86 E. Allman, Sendmail: An Internetwork Mail Router, BSD UNIX Documentation Set, University of California, Berkeley, CA, 1986. Callag95 B. Callaghan, B. Pawlowski, P. Stau bach, RFC 1813, NFS Version 3 Protocol Speci cation, June 1995. Christ97a N. Christenson, D. Beckemeyer, T. Baker, A Scalable News Architecture on a Single Spool, ;login: vol. 22 1997, no. 3, pp. 41 45. Christ97b N. Christenson, J. Larson, Work in progress.

5 Current Data
Today, the system described here is in operation as EarthLink's core electronic mail system. At the time of this writing, this system supports about 460,000 mailboxes for over 350,000 users. The system processes, incoming and outgoing, over 13,000,000 email messages each week. This means we average about 20 incoming messages each second. We average about 20 new POP connections second and hold open about 600 concurrent active POP daemons at peak time, with spikes to over 1000 concurrent outstanding POP connections at any one time.

Grubb96 M. Grubb, How to Get There From Here: Scaling the Enterprise Wide Mail Infrastructure, Proceedings of the Tenth USENIX Systems Administration Conference LISA '96, Chicago, IL, 1996, pp. 131 138. Hitz94 D. Hitz, J. Lau, M. Malcom, File System Design for an NFS File Server Appliance, Proceedings of the 1994 Winter USENIX, San Francisco, CA, 1994, pp. 235 246. Hitz95 D. Hitz, An NFS File Server Appliance, http: www.netapp.com technology level3 3001.html. Postel82 J. Postel, RFC 821, Simple Mail Transfer Protocol, August 1982. Rigney97 C. Rigney, A. Rubens, W. Simpson, S. Willens, RFC 2058, Remote Authentication Dial In User Service RADIUS, January 1997. Seltze91 M. Seltzer, O. Yigit, A New Hashing Package for UNIX, Proceedings of the 1991 Winter USENIX, Dallas, TX, 1991. Stern91 H. Stern, Managing NFS and NIS, O'Reilly & Associates, Inc., Sebastopol, CA, 1991, chapter 12. Zeeman77 E. Zeeman, Catastrophe Theory, Selected Papers 1972-1977, Addison Wesley Publishing Company, Inc., Reading, MA, 1977, p. ix.

SMTP Servers SMTP

Auth NFS

INTERNET
Authentication Service File Servers File Servers

Auth NFS

SMTP

POP Servers POP & SMTP

SUBSCRIBERS

Figure 1

Chapitre 2

SAMBA
Explications sur le pourquoi de ce chapitre

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

36 / 277

2 SAMBA

Chapitre 2 SAMBA

2.1 Introduction

2.1 Introduction

Voir cours de Franck RUPIN.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

37 / 277

Chapitre 3

Systmes dimpression
Explications sur le pourquoi de ce chapitre Limpression est un sujet dicile : Congurations dimpression innombrables. Les gens snervent facilement lorsque cela imprime mal. On nabordera que des notions et les tendances.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

38 / 277

3 Systmes dimpression

Chapitre 3 Systmes dimpression

3.1 Langage dimpression Postscript

3.1 Langage dimpression Postscript

Langage cr par la socit Adobe ( http://www.adobe.com ) Dessin vectoriel. Le nom dun chier Postscript se nit en gnral par le suxe .ps ou .eps . Systme de coordonnes au sein dune page Postscript Format amricain (dit letter ) : 612 x 795 Format europen (dit a4 ) : 595 x 842

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

39 / 277

3 Systmes dimpression

3.1 Langage dimpression Postscript

Langage de description de page, fonctionnant avec une stack (pile). Par exemple 1 + 6 5 peut se coder : forme 1 6 5 sub add forme 1 6 add 5 sub forme 1 6 5 neg add add etc. ce qui donne avec la premire forme :
sub add

5 6 1 1 1 2

Un document imprimer = un programme excuter


c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 40 / 277

3 Systmes dimpression

3.1 Langage dimpression Postscript

Le contenu dun chier Postscript commence par les 2 premiers caractres %! . Les chiers Postscript destins tre inclus dans dautres documents sont dits Encapsulated Postscript (ou EPSF) et commencent par une ligne du genre :
%!PS-Adobe-2.0 EPSF-1.2

suivie dautres lignes de commentaires actifs :


%%Creator:Adobe Illustrator(TM) 1.0b2%%Title:golfer art+ %%CreationDate:1/6/87 9:32 AM %%DocumentFonts:Helvetica-Bold %%BoundingBox:7 31 577 726

dont %%BoundingBox: qui dtermine les dimensions du dessin.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

41 / 277

3 Systmes dimpression

3.1 Langage dimpression Postscript

Par exemple, le code suivant :

%! /Times-Roman findfont 40 scalefont setfont 60 500 moveto (TEST DE LIMPRIMANTE) show 175 300 moveto (T.BESANCON) show showpage

TEST DE LIMPRIMANTE

T.BESANCON

donne, une fois imprim, la page suivante :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

42 / 277

3 Systmes dimpression

3.1 Langage dimpression Postscript

Les dessins en Postscript peuvent tre complexes :

Poids de ce dessin vectoriel (par tte) : 78606 octets, ce qui est faible par rapport du bitmap
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 43 / 277

3 Systmes dimpression

3.1 Langage dimpression Postscript

Un document imprimer = un programme excuter La partie logicielle qui excute le chier Postscript est un interprteur Postscript. Linterprteur Postscript le plus connu est ghostscript. Cf http://www.ghostscript.com Initialement disponible sur UNIX, il est maintenant disponible sur Windows et sur Macintosh sous une forme avec interface graphique : ftp://ftp.lip6.fr/pub/gnu/ghostview/ (GUI UNIX) http://wwwthep.physik.uni-mainz.de/~plass/gv/ (GUI pour UNIX) http://www.cs.wisc.edu/~ghost/gsview/ (GUI pour Windows) http://www.cs.wisc.edu/~ghost/macos/ (GUI pour Macintosh)
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 44 / 277

3 Systmes dimpression

3.1 Langage dimpression Postscript

Lintrt de ghostscript est : visualiser des chiers Postscript comme les documentations convertir des chiers Postscript en dautres formats :
FAX PDF PCL pour imprimante PC etc.

Mais la principale utilisation de ghostscript doit tre certainement maintenant sur Linux o il sert convertir du Postscript en langage PCL qui est compris par les imprimantes PC.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

45 / 277

3 Systmes dimpression

3.1 Langage dimpression Postscript

Quelques utilisations intressantes : calculer la BoundingBox dune gure Postscript :


gs -sDEVICE=bbox fichier.ps

acher au format A4 :
gs -sPAPERSIZE=a4 fichier.ps

convertir du Postscript en PDF au format A4 :


ps2pdf13 -sPAPERSIZE=a4 fichier.ps (ps2pdf13 est un shell script construit autour de gs avec les bonnes

options)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

46 / 277

3 Systmes dimpression

3.1 Langage dimpression Postscript

Comment imprimer un chier texte sur une imprimante Postscript ? Rponse : aprs lavoir converti en Postscript Quelques outils : outil a2ps, cf http://www.gnu.org/software/a2ps/ outil gnu enscript, cf http://www.gnu.org/software/enscript/

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

47 / 277

3 Systmes dimpression

3.1 Langage dimpression Postscript

Comment imprimer plusieurs pages cte cte (format dit N up ) ? Rponse : convertir en chier Postscript normal le chier original puis regrouper les pages sur la mme page via un autre code Postscript Quelques outils : outil a2ps, cf http://www.gnu.org/software/a2ps/ outil mpage, cf http://www.mesa.nl/pub/mpage/

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

48 / 277

3 Systmes dimpression

Chapitre 3 Systmes dimpression

3.2 Langage dimpression PCL

3.2 Langage dimpression PCL

PCL Printer Command Language Langage de description de la page imprimer. Dvelopp par HP pour ses imprimantes. 6 versions de PCL : PCL 1 (annes 1980), PCL 2 (annes 1980), PCL 3 (1984), PCL 4 (1985), PCL 5 (HP Laserjet III), PCL 6 (HP Lasetjet 4000) Les commandes PCL sont des squences descape. Par exemple EcE&l3A (passe en papier letter). Pour convertir du Postscript en PCL, faire :
gs -q -sSAFER -sDEVICE=deskjet -sOoutputFile=fichier.pcl -dNOPAUSE fichier.ps

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

49 / 277

3 Systmes dimpression

Chapitre 3 Systmes dimpression

3.3 Langage dimpression PJL

3.3 Langage dimpression PJL

PJL Printer Job Language Language de contrle de limpression des jobs. Par exemple : slection du bac dentre ou de sortie de papier impression recto verso taille du papier chier PCL ou chier Postscript etc. Exemple de commande : ESC%-12345X@PJL DEFAULTS DENSITY=5 Le logiciel ifhp associ LPRng sait tirer pleinement parti du langage PJL. Cf http://www.lprng.org
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 50 / 277

3 Systmes dimpression

Chapitre 3 Systmes dimpression

3.4 Limprimante vintage

3.4 Limprimante vintage

Limprimante vintage : imprimante matricielle etc. avec ruban encre papier listing avec bande dentrainement sectionnable connexion par voie srie 9600 bauds, gestion du ux XON/XOFF

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

51 / 277

3 Systmes dimpression

3.4 Limprimante vintage

Lundi 25 Juin 2007 00:42:23

woman1.txt
.. . . "..:I:... . ..:.:....:II: .... . .:.::.:I:.:II:...... ....::.:.:.:I:.... . .....:.:I::.:II:...... . ...:.:.::.:.::II::...... . .....:.::. .:::II:.:..... . .:..:...:.:I....... .. .. :. .:. ..:.::.::.:... :.... .. .:.:.:. .::I:.:.. ... : ... .. ..:.:. .:.II:.:.. . .:.. .. . . .. .. :.:.. .:.:I:.:. . . ..:..:. :..:. . . .:. :.:. .:.:I:.:. . . ..:I::. :: :: .. .. .. :..:. .:.:I:. ..:.:I:. :: ::. . . ..:. .:.. .:II: ..:IIIM. ::. :. . .:.::.:::..:.AII:. .::.. :I .::.::. . :..:.:II:.:I: ..: . .::PBIX:: ..:.. :. . . .. ::III:. :.:APPF:. . .P.IP:::: :I:..::. . .. . .:.:II: A..:.PB: . . .... .:.:.::. :... . .. . .: .:IIIM:. . . ... . .:. :.:.. :... . . .I.::I:IIA. .. ... ..::....: .. . . .:II..:IA:. .. ..:. . .:.: .. .. . . ..::I:..::A:. . .:. ..:.. .:.::AA..:..:. .. . :II:I:. :A:. ..: :. . : ..:::AMI: ..:.... .:III.::I II:.:...::::::::. .:::AMV:: .:: .. ..":IIMI::. . I:..::....::. . .:AII:: :.: . . . . IIMMI:....V::. :::: ...:AIIV:.:. .. . . . :IIMI:. .:.:.V:. . ...:MI: .:: :. . .. . . :IMII:: ::.IA.. .. .A ...::: .:. . :. ...I:I:.: ..AMMA. . ...AMIV:: . . : .. :. .::::II:.I:.MIMMIMMMMMIMMIMV:..:: .I.:. .. . . . .. :::I:.::IMMMMMMMMMMMMIMI. ..:IMI.. . :... . " .::.MMMI:MMMMMMMIMI. :IIMMII:. I I I . :.:.. . ..::. .IV".:I:IIIMIMMIM. .:IMI::.: .. . . . .:.:: .. ::. ..:.::I:I:IMMMIA..II.:...: . ... . .. ..:::: ...::.IIMII:: .:.:..:..:III:.:: . . .. . . ::.: . .. :IIMI:.:.. ..: . .:I:" ...:.:. .. .. .. .:.:::I:. . . . .IMII:.: .. ..".::.:II:.:. .: ... . .. .. . .::.:......::II:.: . ...... . .. .:II:.:: ... .. .. ..:.::.I . . . .. .:. .... ...:.. . . ..:.::. :.. . .. ..::I:. . .. ..:.... . ..... .. . ..::. .. .I:. .. . .:.: I. . .. ..:.. . . .. ..... .:. .:.. .:I.... . .:::I:. . . .. .:. . .. .. . ... .:..I . ... . .:::I:. . . .. .:. . .. .. . ... .:.:.:. . .::I. . .. ....:. . .. . .. .. ..:..:.. :. . . .. .. .:.... . . .... ... . .:.:.:.. . :. . . . .. .:.... . . ........ .:.:.::. . . :. . . . . . .. .::..: . ..:.. . ::.:.:.. . . :.. . . . . . .. ..:.: .. .. .: .. :::.::.:. . . :.. . . . . .. .. ...:: .. .. . .:. . V:I:::::.. . .. ::. . . .. .. ... .:.:: .. . . .. .. . VI:I:::::.. .:. :.. . . .. ..:.. ..I:... . . . .. ... . VII:I:I:::. . :::, :.. . . . .. ..:..:.:I:.:. . . .. . .:. . VMIII:I::.. ::: ::.. . . .. ..:..:.MI:. . . . .... . :MMIMIII:I:: :: :. . . .. .. ..:.:.:MI:. . . .. ..... . MMMMIMIII: . :.. . . . .. .:.:.:.MI:. . . .. ... . IMMMMIMMIMI. :.. . . . .. ..:..IM:. . . .. .. ... . MMMMMMMMMI :.. . . .. ..:.:.:MI.. . . .. . :::::. MIM:""" :. . . . .. ..::.:.VII. . . .. .:::::. MIM :.. . . .. .:.:.:.VI. . . . ...::I"A:. MMV :. . . . .. ..:.:.VI. . . ....::I::.MV: :. . . . . .. .:..II:. . . . ....::: AV. :.. . . .. ... .:..VI:. . . .. .:. ..: .AV. :.. . . .. ..:.:.:MAI:.:...:.:.:.:.AII:. I:. . .. ... .:.:.VMMII:..:.:..:A:.:.. IA.. . . .. ..:.:.:VMMMMIMIMMIMI:.::. MAI. . . .. ..:.:.:MMMIMIMMMIMI:..:. MIA: . . . .. ...:.VMMMIMIIMI::.:... MIMI:. . .. ... .::.MMMIIMIIMI:::.. MII:.:. . .. ... .::VMMIMI:I::.:.. AI:..:.. . . .. ..:.VMIII:I::.:. . AI:. ..:.. . . .. .. VMIII:I:... . AI:. . .:.. . . . ... VMIII::... . .A:. . :.. . . .. .:.. VMII::.. . A:. . . ::. .. .. . .:.. "VMI::.. . .:.. . . :.. .:..... .::.. VMI:.. ... . . . . . :.:. ..:. . .::.. VI:.. . .. .. . . . . ...:... . .. . .:::. V:.. . .. .. . . .. ..:::.... .:. . ..::.. V.. . . . .. . . . . .. ..:::A. ..:. . . .::.. :.. . .. .. .. . . . ... ..::IA.. .. . . ..::. :.. . .. .. ... . . .. .... .:.::IA. . .. . ..:.::. :. . . . . .. . . . .. ..:..:.::IIA. . . .. .:.::. :. . .. . . . . . .. ... ..:.::I:OMA. . . . ..:.::. . . .: .. . . . . ... .:.. .:I:IIMMA. . . .. .::I:. . .::. . . . .. ..:. .::.:IIMIIMMMA. . .. ..:I:. . . A::.. . . ...:..:.::I:IMIMIMMMMA. . . ..::I:. . :MI:.. . . .. .:.:.::I:IMIMIIMIMMMA. . .. .::I:. .. AI:.. .. . . .. .:.:.::II:IMIIIMIMIMMMA. . . ..::I:. .. :MI:.. . . . . .. .::.:I:IMIMIIIMIMIIMMMA.. . .. .::I:. .. AI:.:.. . . . ... .::.::I:IMIIMIMIMIMIMIMMA. . . ..::I:. . MI:. .. . . . . .. .:..::IIMIMIMIIIIMMIIMMMMA. . . .:::I:. . . MI:.. . . . . .. ..:.::I:IIMMIIMIMIMIMMMMV" .. . ..:::II: . . MI::.. . . . .. .:..:::IIMIMIIMIMIIMMMM" . .. . ..::III: . . II::.:.. . . . .. ......:..IMMMIMMMMMM2.. . . . . ... .:.:IMI:.. II:I::.. . . . . .....::.:IMMMMMMMM:.. . . . . .:..:::IIMII.. MI::.:. . . . . . ...:.::.::.MMMMM::.:.... . . .. . :.. ..:IMMI:: MII::.:.. . . . .. .:..:.. MMMI::.::.:.. . . . .. :...:II:III III::.:... . . . ...:.:... . MII:I::.:.. . . .. . . :.:::...:: VII::.:.. . . . .. ...:.... VMI:I::.:.. . . ... .. .::.:..:.: VII::.:.. . . ..:.::.. : :MMII:I::.:.. . . .. .. .:::... III:I::.. .. . . .. .:.:.. . :VNIMI:I::.:... . . .. .. .:. ..

Page 1

caractres normaux caractres gras par rcriture dun caractre une seconde fois sur lui-mme : A = A backspace A = A^HA idem pour caractres souligns = A backspace underscore = A^H_ peu ou pas de polices de caractres peu ou pas de possibilits de tailles varies de caractres documents au format texte uniquement etc.
c T.Besanon (v14.0.631) Administration UNIX

pas de graphiques ou de dessin (sauf ASCII art)

ARS 2011 2012 Partie 4

52 / 277

3 Systmes dimpression

3.4 Limprimante vintage

Rsum des caractristiques des impressions sur ce type dimprimantes : connexion non rseau par voie srie (plus tard par voie parallle)

imprimer = cat rapport.txt > /dev/tty0a

Dans cette logique, un logiciel dimpression est avant tout capable de grer des voies sries.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

53 / 277

3 Systmes dimpression

Chapitre 3 Systmes dimpression

3.5 Limprimante moderne

3.5 Limprimante moderne

Limprimante moderne : photocopieur, imprimante rseau, scanner, fax

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

54 / 277

3 Systmes dimpression

3.5 Limprimante moderne

Caractristiques : Photocopieur :
codes daccs quotas de photocopies relev des compteurs serveur web intgr : protection des accs, certicats HTTPS, etc.

Imprimante rseau :
conguration rseau minimale (adresse IP, netmask, routeur, . . .) conguration rseau avance : ACL pour contrler les accs dimpression, demail, de partage de chiers disque dur local (pour stocker des polices supplmentaires, des logos, des documents frquemment imprims, etc.)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

55 / 277

3 Systmes dimpression

3.5 Limprimante moderne

Caractristiques (suite) : Scanner (vers formats TIFF ou PDF) avec envoi des chiers numriss par email ou rcupration par FTP des chiers numriss :
logiciels spciques sur le poste de travail de lutilisateur, drivers TWAIN, etc. attention aux logiciels ne travaillant que sur un seul subnet ethernet ! conguration des paramtres de messagerie lectronique conguration dun annuaire LDAP dentreprise ou des contacts de lentreprise conguration de partages rseau pour accder aux chiers scanns stocks sur le photocopieur, conguration des ACL rseau pour FTP, ...

Systme dexploitation
bugs (exemple gestion LDAP sur photocopieur CANON couleur) disque dur + problmes de disques durs licences logicielles (codes dactivation, dongles, etc.)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

56 / 277

3 Systmes dimpression

3.5 Limprimante moderne

Rsum des caractristiques des impressions sur ce type dimprimantes : connexion rseau par TCP/IP protocoles rseau implments dans limprimante

imprimer = dialogue selon des protocoles avec un hte TCP/IP qui prend en charge un chier au jargon spcique imprimer physiquement
Dans cette logique, un logiciel dimpression est avant tout capable de dialoguer en rseau selon des protocoles spciaux.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

57 / 277

3 Systmes dimpression

Chapitre 3 Systmes dimpression

3.6 Scenarios dimpressions possibles

3.6 Scenarios dimpressions possibles

Pleins de scenarios sont possibles dans le monde de limpression :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

58 / 277

3 Systmes dimpression

3.6 Scenarios dimpressions possibles

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

59 / 277

3 Systmes dimpression

3.6 Scenarios dimpressions possibles

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

60 / 277

3 Systmes dimpression

3.6 Scenarios dimpressions possibles

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

61 / 277

3 Systmes dimpression

3.6 Scenarios dimpressions possibles

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

62 / 277

3 Systmes dimpression

Chapitre 3 Systmes dimpression

3.7 Mcanismes et protocoles dimpression

3.7 Mcanismes et protocoles dimpression

Dans un environnement rel, les mcanismes dimpression permettent aux utilisateurs de saranchir : de la connaissance des noms techniques des priphriques ; du risque dimpressions mlanges lorsque deux utilisateurs essayent dimprimer en mme temps ; des dtails matriels tels que labsence momentane de papier ; de la ncessit dattendre que limpression en cours se termine ; etc.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

63 / 277

3 Systmes dimpression

3.7 Mcanismes et protocoles dimpression

Pour rsoudre tous ces problmes, il a t conu des spouleurs (spoolers). Le principe en est simple : Les utilisateurs dposent leurs chiers dans un rpertoire convenu, laide de la commande dimpression . Cest la requte dimpression. Un dmon systme surveille ce rpertoire (le dattente), en extrait un chier, limprime, puis extrait le suivant, limprime, etc. Des commandes permettent aux utilisateurs de savoir ce quil y a dans la le dattente et ventuellement de dtruire une de leurs requtes. Des commandes permettent ladministrateur de grer ce mcanisme :
cration dune nouvelle le dattente pour une nouvelle imprimante ; autorisation ou interdiction des dpts dans des les dattente ; autorisation ou interdiction des impressions ; redirection des travaux dimpression dune imprimante une autre imprimante ; etc.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

64 / 277

3 Systmes dimpression

Chapitre 3 Systmes dimpression

3.8 Situation logicielle en 2012

3.8 Situation logicielle en 2012

Plusieurs logiciels : mcanisme LP (SOLARIS) obsolte mcanisme LPR obsolte mcanisme LPRng (LINUX, UNIX) http://www.lprng.com a tendance devenir obsolte mcanisme CUPS (LINUX, UNIX, Windows 2000/XP/2003, MacOSX) bas sur IPP (Internet Printing Protocol ) http://www.cups.org a la cte

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

65 / 277

3 Systmes dimpression

3.8 Situation logicielle en 2012

Principes globaux de tous ces mcanismes : machines clientes dun serveur dimpression le serveur dimpression a des queues dimpression pour les diverses imprimantes fonctionalits de gestion des queues plus ou moins labores selon le protocole : LP < LPR < LPRng < CUPS

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

66 / 277

Chapitre 4

Systme de multifentrage : X
Explications sur le pourquoi de ce chapitre

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

67 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.1 Introduction : systme de multi fentrage

4.1 Introduction : systme de multi fentrage

Systme de multifentrage (Window System) : ensemble de programmes, de bibliothques de programmation ralisant une interface homme / machine btie sur lutilisation de divers quipements : clavier souris cran graphique autres priphriques (spaceball, plaquette graphique, . . .) Lcran tente de raliser un modle de bureau. Lide vient des travaux de Xerox, repris par Apple, repris par le projet Athena du MIT.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

68 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.2 Systme de multifentrage : X

4.2 Systme de multifentrage : X

Pour Unix, le systme de multi fentrage est un systme appel : X ou X Window System ou X11 Ce nest pas X Windows ! Historiquement : X11 sur UNIX XFree86 spciquement pour LINUX Xorg suite querelles sur XFree86 = retour lquipe de X11
http://www.x.org

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

69 / 277

4 Systme de multifentrage : X

4.2 Systme de multifentrage : X

Consortium de vendeurs dUNIX pour mettre au point X. Historique des versions : X10 X11R3 X11R4 X11R5 X11R6 X11R7 SUN a sa propre implmentation de X drive des X11R[3-7] : SUN OPENWINDOWS

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

70 / 277

4 Systme de multifentrage : X

4.2 Systme de multifentrage : X

Le systme graphique X est construit sur un modle client serveur et est la base un protocole de communication :

Application X
Message (dessine un cercle, etc.)

Serveur X

Affichage

Reponse (OK, NOT OK, etc.)

Erreur

Evenement (clavier, clic souris, etc.)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

71 / 277

4 Systme de multifentrage : X

4.2 Systme de multifentrage : X

Serveur X : optimis pour ses performances graphiques rpond aux requtes du client X envoie au client X des informations vnementielles ( clic du bouton droit de la souris , appui sur la touche A avec Shift en mme temps , etc.) Client X : eectue les calculs manipule les chiers envoie des requtes au serveur X ( trace un cercle , ache du texte , quelles sont les possibilits couleurs de lcran ? , etc.) Souvent serveur X = client X = mme machine. Parfois serveur X != client X deux machines en rseau. Parfois !
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 72 / 277

4 Systme de multifentrage : X

4.2 Systme de multifentrage : X

Parfois serveur X != client X deux machines en rseau. Parfois ! Cest donc un peu plus quun systme de multifentrage : il est rparti.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

73 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.3 Serveur X

4.3 Serveur X

Serveur X : Au sens large : un serveur graphique Le serveur X gre les priphriques :


crans monochromes, niveaux de gris, couleurs, un ou plusieurs crans souris, cran tactile, stylet, palette graphique claviers boutons, mollettes

La conguration matrielle du serveur X peut varier considrablement (mme si eet dunication suite la mode du PC) le client X doit en tenir compte et doit savoir sadapter.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

74 / 277

4 Systme de multifentrage : X

4.3 Serveur X

A noter quil existe des serveurs X sur Windows et sur MacOS X. Sur Windows, utiliser CYGWIN ( http://www.cygwin.com ) :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

75 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.4 Client X

4.4 Client X

Client X : Client X == application Lapplication doit tre congurable :


Environnement multi plateformes UNIX Environnement multi serveurs X Environnement multi utilisateurs

Lapplication ne doit jamais rien supposer du serveur X. Elle doit tenir compte de tous les cas envisageables et tre paramtre en consquence. Ncessit que les applications soient congurables !

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

76 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.5 Chemins daccs

4.5 Chemins daccs

On rencontre : Standard X11R4 et X11R5 :


/use/bin/X11/ /use/lib/X11/ /use/include/X11/

Standard X11R6 et X11R7 :


/use/X11R6/bin/ /use/X11R6/lib/ /use/X11R6/include/

Standard SUN OPENWINDOWS


/use/openwin/bin/ /use/openwin/lib/ /use/openwin/include/

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

77 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.6 Variable denvironnement DISPLAY

4.6 Variable denvironnement DISPLAY

La variable DISPLAY dnit le serveur X qui sera utilis. Formes possibles de la variable : nom-machine.domaine:numro-serveur.numro-cran adresse-ip:numro-serveur.numro-cran :0.0 (anciennement unix:0.0 ) ; sens spcial de cette forme : communication locale rapide via IPC et non pas via le rseau TCP/IP plus lent dans ce cas On notera numro-serveur : une mme machine peut faire tourner plusieurs serveurs X do la ncessit de les numroter. Cas gnral : un seul serveur X numro = 0. On notera numro-cran : une mme machine peut avoir plusieurs crans do la ncessit de les numroter. Cas gnral : un seul cran numro = 0.
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 78 / 277

4 Systme de multifentrage : X

4.6 Variable denvironnement DISPLAY

Exemples : cerise.example.com:0.0 localhost:11.0 :0.0 192.168.0.1:0.0

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

79 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.7 Clavier

4.7 Clavier

La gestion du clavier est quelque chose de compliqu. . . Tous les types de claviers doivent pouvoir tre supports (FR, EN, RU, etc.). Par exemple des claviers braille :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

80 / 277

4 Systme de multifentrage : X

4.7 Clavier

Par exemple des boites boutons ou molettes (marque SILICON GRAPHICS) :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

81 / 277

4 Systme de multifentrage : X

4.7 Clavier

Code clavier

1ere conversion

SERVEUR X

Keycode Shift 2eme conversion Alt Graph Keysym

Keycode + Keysym + Status

CLIENT X

Alt, Num Lock, Alt Graph, Meta, Ctrl, Caps Lock, Shift
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 82 / 277

4 Systme de multifentrage : X

4.7 Clavier

Keycode X dnit une association entre le code gnr par la touche du clavier et un code de la touche au niveau du serveur X : cest le keycode. Il existe un keycode et un seul par touche du clavier. On ne peut pas modier lassociation entre le code du clavier et le keycode (sauf recompiler le serveur X). On peut obtenir le keycode par lutilitaire xev .

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

83 / 277

4 Systme de multifentrage : X

4.7 Clavier

Exemple de XEV : appui sur la touche p :


% xev ... KeyPress event, serial 20, synthetic NO, window 0xc00001, root 0x2f, subw 0x0, time 2631657543, (103,101), root:(927,454), state 0x2, keycode 26 (keysym 0x70, p), same_screen YES, XLookupString gives 1 characters: "p" KeyRelease event, serial 22, synthetic NO, window 0xc00001, root 0x2f, subw 0x0, time 2631657607, (103,101), root:(927,454), state 0x2, keycode 26 (keysym 0x70, p), same_screen YES, XLookupString gives 1 characters: "p" ...

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

84 / 277

4 Systme de multifentrage : X

4.7 Clavier

Exemple de XEV : appui sur la touche p avec SHIFT en mme temps :


% xev ... KeyPress event, serial 22, synthetic NO, window 0xc00001, root 0x2f, subw 0x0, time 2631671991, (103,101), root:(927,454), state 0x2, keycode 232 (keysym 0xffe1, Shift_L), same_screen YES, XLookupString gives 0 characters: "" KeyPress event, serial 22, synthetic NO, window 0xc00001, root 0x2f, subw 0x0, time 2631672071, (103,101), root:(927,454), state 0x3, keycode 26 (keysym 0x50, P), same_screen YES, XLookupString gives 1 characters: "P" KeyRelease event, serial 22, synthetic NO, window 0xc00001, root 0x2f, subw 0x0, time 2631672127, (103,101), root:(927,454), state 0x3, keycode 26 (keysym 0x50, P), same_screen YES, XLookupString gives 1 characters: "P" KeyRelease event, serial 22, synthetic NO, window 0xc00001, root 0x2f, subw 0x0, time 2631672215, (103,101), root:(927,454), state 0x3, keycode 232 (keysym 0xffe1, Shift_L), same_screen YES, XLookupString gives 0 characters: "" ...
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 85 / 277

4 Systme de multifentrage : X

4.7 Clavier

Keysym X dnit un nom symbolique pour chaque caractre utilisable. On parle de keysym. Le chier <X11/keysymdef.h> dnit les valeurs numriques de ces noms symboliques.
... #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define XK_dollar XK_percent XK_ampersand XK_apostrophe XK_parenleft XK_parenright XK_asterisk XK_plus XK_comma XK_minus XK_period XK_slash XK_0 XK_1 XK_2 XK_3 XK_4 0x024 0x025 0x026 0x027 0x028 0x029 0x02a 0x02b 0x02c 0x02d 0x02e 0x02f 0x030 0x031 0x032 0x033 0x034 #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define ... XK_5 XK_6 XK_7 XK_8 XK_9 XK_colon XK_semicolon XK_less XK_equal XK_greater XK_question XK_at XK_A XK_B XK_C XK_D XK_E 0x035 0x036 0x037 0x038 0x039 0x03a 0x03b 0x03c 0x03d 0x03e 0x03f 0x040 0x041 0x042 0x043 0x044 0x045

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

86 / 277

4 Systme de multifentrage : X

4.7 Clavier

Au dmarrage du serveur X, il y a mise en place de correspondances entre keycode et keysyms. On peut modier les correspondances via la commande xmodmap . X accepte au maximum 5 keysyms pour un keycode via le jeu des modicateurs comme Shift, Ctrl, etc.. Exemple des modicateurs dune machine SOLARIS
% xmodmap -pm xmodmap: up to 2 keys per modifier, (keycodes in parentheses): shift lock control mod1 mod2 mod3 mod4 mod5 Shift_L (0xe8), Shift_R (0xec) Control_L (0x40) Control_L (0xe7), Control_R (0xeb) Meta_L (0xea), Meta_R (0xee) Mode_switch (0xed) Num_Lock (0x5a) Alt_L (0xe9)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

87 / 277

4 Systme de multifentrage : X

4.7 Clavier

Liste des keycodes et de leurs keysyms associs (exemple pris sur une machine SUN avec un clavier QWERTY) :
% xmodmap -pk There are 5 KeySyms per KeyCode; KeyCodes range from 8 to 254. KeyCode Value ... 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 ...
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 88 / 277

Keysym (Keysym) ... Value (Name) ... 0x0056 0x0057 0x0058 0x0059 0x005a 0x0031 0x0032 0x0033 0x0034 0x0035 0x0036 0x0037 0x0038 0x0039 0x0030 (V) (W) (X) (Y) (Z) (1) (2) (3) (4) (5) (6) (7) (8) (9) (0)

0x0021 0x0040 0x0023 0x0024 0x0025 0x005e 0x0026 0x002a 0x0028 0x0029

(exclam) (at) (numbersign) (dollar) 0x20ac (EuroSign) (percent) 0x20ac (EuroSign) (asciicircum) (ampersand) (asterisk) (parenleft) (parenright)

4 Systme de multifentrage : X

4.7 Clavier

Liste des keycodes et de leurs keysyms associs avec achage sous une forme compatible avec la syntaxe de XMODMAP pour les modications (exemple pris sur une machine SUN avec un clavier QWERTY) :
% xmodmap -pke ... keycode 32 = V keycode 33 = W keycode 34 = X keycode 35 = Y keycode 36 = Z keycode 37 = 1 keycode 38 = 2 keycode 39 = 3 keycode 40 = 4 keycode 41 = 5 keycode 42 = 6 keycode 43 = 7 keycode 44 = 8 keycode 45 = 9 keycode 46 = 0 ...

exclam at numbersign dollar EuroSign percent EuroSign asciicircum ampersand asterisk parenleft parenright

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

89 / 277

4 Systme de multifentrage : X

4.7 Clavier

Pour modier le fonctionnement du clavier , deux syntaxes : xmodmap -e keysym symbole = valeur xmodmap -e keycode code = valeur Par exemple : on veut associer la touche F2 (clavier SUN QWERTY) : Le keycode de F2 est 66. Le keysym dorigine associ la touche est 0xbf. Le keysym associ est daprs <X11/keysymdef.h> 0x0e9 ( XK_eacute ). xmodmap -e keycode 66 = 0x0e9 A noter sur SOLARIS le script /usr/openwin/bin/xmakemap qui renvoie limage de la conguration actuelle du clavier.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

90 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.8 Souris

4.8 Souris

Tous les types de souris doivent pouvoir tre supports. . .

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

91 / 277

4 Systme de multifentrage : X

4.8 Souris

Plus classiquement :

Cest un outil de dsignation ayant de 1 3 boutons. La position est suivie lcran par un curseur. Le curseur est toujours ach au premier plan. Pour permuter les boutons de la souris : xmodmap -e pointer = 3 2 1
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 92 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.9 Ecran

4.9 Ecran

y x

Il est de type bitmap (achage point). Limage est obtenue par balayage dune mmoire dcran (frame buer) contenant une valeur par point lcran (pixel).
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 93 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.10 Fentre / icne

4.10 Fentre / icne

y x h w

Une fentre est un rectangle lcran caractris par un emplacement, une bordure, ses dimensions. Une icne est la trace visible lcran dune fentre temporairement non ache. Les fentres sont organises en arbre au niveau interne dans le serveur X. La racine de larbre est la root window cre linitialisation du serveur et couvrant tout lcran. Vulgairement, cest le fond dcran.
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 94 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.11 Copier / coller

4.11 Copier / coller

Pour copier, on slectionne avec le bouton gauche de la souris. Pour coller, on clique avec le bouton du milieu de la souris.

This is the text to select. All text around it is unselected.

This is the text to select.

All text around it is unselected.

Modiable.
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 95 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.12 Principe de personnalisation des clients

4.12 Principe de personnalisation des clients

Personnalisation via des ressources ou des arguments de la ligne de commande :

O R D R E D E R E C H E R C H E

$XFILESEARCHPATH
ou

/usr/X11R6/lib/X11/app-defaults

$XUSERFILESEARCHPATH
ou ou

$XAPPLRESDIR $HOME

propriete RESOURCE_MANAGER (xrdb)


ou

$HOME/.Xdefaults

$XENVIRONMENT
ou

$HOME/.Xdefaults-nom-host

Arguments de la ligne de commande

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

96 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.13 Options de la ligne de commande

4.13 Options de la ligne de commande

Il y a des options standard pour la plupart des clients car leur programmation sappuye sur une bibliothque appele Xt . Exemples : display : -display cerise.example.com:0.0 couleur des caractres : -fg couleur couleur de fond des fentres : -bg couleur caractres : -fn font dimensions et emplacement de la fentre : -geometry WIDTHHEIGHTXOFFYOFF
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 97 / 277

4 Systme de multifentrage : X

4.13 Options de la ligne de commande

Retour sur loption -geometry WIDTHHEIGHTXOFFYOFF :


+0+0 X +100+100 +600+100 X -450+150 -200+150 -0+0

-450-200 +100-100 X +0-0


c T.Besanon (v14.0.631) Administration UNIX

-200-200

+600-100 X -0-0
ARS 2011 2012 Partie 4 98 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.14 Ressources

4.14 Ressources

Une ressource = variable congure dans un chier ASCII (analogie : base de registres de Windows ou ressources Macintosh) 4 niveaux de ressources : ressources dnies par le systme ressources dnies par le client X ressources dnies par le serveur X ressources dnies par lutilisateur
c T.Besanon (v14.0.631)

O R D R E D E R E C H E R C H E

$XFILESEARCHPATH
ou

/usr/X11R6/lib/X11/app-defaults

$XUSERFILESEARCHPATH
ou ou

$XAPPLRESDIR $HOME

propriete RESOURCE_MANAGER (xrdb)


ou

$HOME/.Xdefaults

$XENVIRONMENT
ou

$HOME/.Xdefaults-nom-host

Arguments de la ligne de commande

Administration UNIX

ARS 2011 2012 Partie 4

99 / 277

4 Systme de multifentrage : X

4.14 Ressources

Ressources dnies par le systme


O R D R E D E R E C H E R C H E $XFILESEARCHPATH
ou

/usr/X11R6/lib/X11/app-defaults

$XUSERFILESEARCHPATH
ou ou

$XAPPLRESDIR $HOME

propriete RESOURCE_MANAGER (xrdb)


ou

$HOME/.Xdefaults

$XENVIRONMENT
ou

$HOME/.Xdefaults-nom-host

Arguments de la ligne de commande

Traditionnellement /usr/X11R6/lib/X11/app-defaults/ . Ce rpertoire regroupe les chiers correspondants aux classes des applications. Par exemple XTerm pour lapplication X xterm , Bitmap pour lapplication X bitmap , etc. Ces ressources sont lues par les clients X qui tournent sur la machine de ce rpertoire.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

100 / 277

4 Systme de multifentrage : X

4.14 Ressources

Ressources dnies par le client X


O R D R E D E R E C H E R C H E $XFILESEARCHPATH
ou

/usr/X11R6/lib/X11/app-defaults

$XUSERFILESEARCHPATH
ou ou

$XAPPLRESDIR $HOME

propriete RESOURCE_MANAGER (xrdb)


ou

$HOME/.Xdefaults

$XENVIRONMENT
ou

$HOME/.Xdefaults-nom-host

Arguments de la ligne de commande

Traditionnellement $HOME . Ce mcanisme sapplique aux applications X dveloppes avec la librairie Xt . Le chier de ressources porte le nom de lapplication. Par exemple XTerm pour lapplication X xterm , Bitmap pour lapplication X bitmap , etc. Ces ressources sont lues par les clients X qui tournent sur la machine de ce rpertoire.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

101 / 277

4 Systme de multifentrage : X

4.14 Ressources

Ressources dnies par le serveur X


O R D R E D E R E C H E R C H E $XFILESEARCHPATH
ou

/usr/X11R6/lib/X11/app-defaults

$XUSERFILESEARCHPATH
ou ou

$XAPPLRESDIR $HOME

propriete RESOURCE_MANAGER (xrdb)


ou

$HOME/.Xdefaults

$XENVIRONMENT
ou

$HOME/.Xdefaults-nom-host

Arguments de la ligne de commande

Des ressources peuvent tre places dans une base de donnes dans la mmoire du serveur X. Ces ressources sont donc communes tous les clients de ce serveur X. Les clients les lisent lors de leur dmarrage, plus aprs. La commande xrdb sert manipuler cette base de donnes en mmoire dans le serveur X.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

102 / 277

4 Systme de multifentrage : X

4.14 Ressources

Ressources dnies par lutilisateur


O R D R E D E R E C H E R C H E $XFILESEARCHPATH
ou

/usr/X11R6/lib/X11/app-defaults

$XUSERFILESEARCHPATH
ou ou

$XAPPLRESDIR $HOME

propriete RESOURCE_MANAGER (xrdb)


ou

$HOME/.Xdefaults

$XENVIRONMENT
ou

$HOME/.Xdefaults-nom-host

Arguments de la ligne de commande

Ce mcanisme permet davoir un chier propre plusieurs systmes mme si le homedir est partag (via NFS) entre ces systmes.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

103 / 277

4 Systme de multifentrage : X

4.14 Ressources

Syntaxes des ressources Syntaxes : nom-application.attribut: valeur classe.nom.sous-nom...attribut: valeur

Par exemple :
xterm.background: black xterm.foreground: yellow

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

104 / 277

4 Systme de multifentrage : X

4.14 Ressources

Un client X est construit autour dun arbre de widgets (boutons, dropdown menus, etc.) fournis par les bibliothques de programmation.

On a en fait une arborescence de ressources.

Programme editres pour les manipuler.


c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 105 / 277

4 Systme de multifentrage : X

4.14 Ressources

La syntaxe utilise des caractres joker : caractre . : sparateur des lments dans la dnition de la ressource caractre * : permet de remplacer un ou plusieurs lments dans la dnition de la ressource caractre ? : permet de remplacer un et un seul lment dans la dnition de la ressource Par exemple :
xterm.background: black xterm.foreground: yellow

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

106 / 277

4 Systme de multifentrage : X

4.14 Ressources

Notion de : classe application de la classe fentre dune application

Cest la ressource la plus prcise qui est prise en compte.

Par exemple : mon-application.sous-fentre.side.background: yellow prime sur mon-application.sous-fentre.background: blue qui prime sur mon-application.background: red

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

107 / 277

4 Systme de multifentrage : X

4.14 Ressources

xrdb Rappel :
O R D R E D E R E C H E R C H E $XFILESEARCHPATH
ou

/usr/X11R6/lib/X11/app-defaults

$XUSERFILESEARCHPATH
ou ou

$XAPPLRESDIR $HOME

propriete RESOURCE_MANAGER (xrdb)


ou

$HOME/.Xdefaults

$XENVIRONMENT
ou

$HOME/.Xdefaults-nom-host

Arguments de la ligne de commande

Des ressources peuvent tre places dans une base de donnes dans la mmoire du serveur X. La commande xrdb sert manipuler cette base de donnes en mmoire dans le serveur X. xrdb = X server Resource DataBase utility

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

108 / 277

4 Systme de multifentrage : X

4.14 Ressources

Syntaxes : xrdb -query : liste les ressources actuelles du serveur X xrdb -merge fichier : fusionne un chier de ressources avec les ressources du serveur X xrdb -load fichier : crase les ressources du serveur X par celles du chier indiqu xrdb -remove : eace les ressources du serveur X xrdb -symbols : ache la liste des symboles prdnis (voir ci-dessus pour la partie CPP) xrdb utilise cpp du langage C. Donc le chier de ressources charger peut contenir les directives classiques de CPP : #include #ifdef etc. Intrt : un seul chier mais pouvant traiter plusieurs cas de gures.
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 109 / 277

4 Systme de multifentrage : X

4.14 Ressources

Par exemple :
#ifndef COLOR XTerm*cursorColor: black XTerm*pointerColor: black #else /* COLOR is DEFINED :-) */ XTerm*cursorColor: red XTerm*pointerColor: red #endif

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

110 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.15 Couleurs

4.15 Couleurs

On peut dsigner une couleur sous un nom symbolique : /usr/X11R6/lib/X11/rgb.txt dnit ainsi 738 couleurs (les noms ne sont pas forcment parlants). Par exemple : Pink On peut aussi donner une couleur via ses composantes Rouge Vert Bleu (RGB en anglais) sous la forme rgb:red/green/blue . Ainsi Pink quivaut rgb:255/192/203 . Ancienne syntaxe supporte pour compatibilit :
#RGB #RRGGBB #RRRGGGBBB #RRRRGGGGBBBB (4 bits each) (8 bits each) (12 bits each) (16 bits each)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

111 / 277

4 Systme de multifentrage : X

4.15 Couleurs

A partir de X11R5, adoption de la gestion des couleurs via X Color Management System (XCMS). Le chier /usr/X11R6/lib/X11/Xcms.txt dcrit des couleurs. Par exemple :
XCMS_COLORDB_START 0.1 red green blue aquamarine cadet blue cornflower blue navy blue navy brown gray0 gray10 gray20 ... gray80 gray90 gray100 XCMS_COLORDB_END CIEXYZ:0.3811/0.2073/0.0213 CIEXYZ:0.3203/0.6805/0.1430 CIEXYZ:0.2483/0.1122/1.2417 CIEXYZ:0.5512/0.7909/0.9759 CIEXYZ:0.2218/0.2815/0.4708 CIEXYZ:0.3400/0.3109/1.1067 CIEXYZ:0.0478/0.0216/0.2392 CIEXYZ:0.0478/0.0216/0.2392 CIEXYZ:0.1333/0.0772/0.0217 TekHVC:0.0/0.0/0.0 TekHVC:0.0/10.0/0.0 TekHVC:0.0/20.0/0.0 TekHVC:0.0/80.0/0.0 TekHVC:0.0/90.0/0.0 TekHVC:0.0/100.0/0.0

Commande associe : xcmsdb


c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 112 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.16 Polices de caractres

4.16 Polices de caractres

Les fontes ont des noms trs dtaills. Par exemple :


-adobe-courier-medium-r-normal--10-100-75-75-m-60-iso8859-1

adobe : concepteur de la police courier : famille de la police medium : graisse (bold, medium, extra bold, light, etc.) r : angle (roman, italic, etc.) normal : largeur (normal, narrow, etc.) vide : style complmentaire 10 : hauteur en pixels 100 : hauteur en points (un point = 1/72e de pouce) 75 : rsolution horizontale de conception de la police 75 : rsolution verticale de conception de la police m : espacement (p = proportionnel, m = monospace, etc.) 60 : largeur moyenne en 1/10e de pixel iso8859-1 : jeu de caractres
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 113 / 277

4 Systme de multifentrage : X

4.16 Polices de caractres

Plusieurs formats sont possibles. Liste non exhaustive : BDF (Bitmap Distribution Format), SNF (Server Natural Font), PCF (Portable Compiled Font), Type1 PostScript depuis X11R6, True Type (http://www.freetype.org/), PEX, Speedo

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

114 / 277

4 Systme de multifentrage : X

4.16 Polices de caractres

On peut utiliser la commande xlsfonts pour avoir la liste des fontes utilisables sur son poste X.

Les polices sont utilisables via les ressources. Par exemple :


XTerm*Font: Emacs*paneFont: 7x13bold -adobe-times-medium-r-normal--14-140-75-75-p-74-iso8859-1

Les polices sont utilisables via la ligne de commande. Par exemple :


% xfd -fn 9x15bold

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

115 / 277

4 Systme de multifentrage : X

4.16 Polices de caractres

Les fontes sont stockes dans larborescence /usr/X11R6/lib/X11/fonts/ contenant plusieurs sous rpertoires dont : 75dpi/ : polices de rsolution de 75 dpi 100dpi/ : polices de rsolution de 100 dpi misc/ : polices diverses Notion de font path. Conguration du font path via la commande xset : xset -q xset +fp /chemin/vers/rpertoire/de/fontes/ xset fp+ /chemin/vers/rpertoire/de/fontes/ xset -fp /chemin/vers/rpertoire/de/fontes/ xset fp rehash Lordre des rpertoires est signicatif.
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 116 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.17 Rpertoires de polices de caractres

4.17 Rpertoires de polices de caractres

Un rpertoire de polices de caractres a une structure prcise :


% ls /usr/X11R6/lib/X11/fonts/misc 10x20.pcf.Z Screen6.pcf.Z 12x24.pcf.Z Screen7.pcf.Z 12x24rk.pcf.Z Serif10.pcf.Z 5x7.pcf.Z Serif11.pcf.Z 5x8.pcf.Z Serif12.pcf.Z 6x10.pcf.Z Serif14.pcf.Z 6x12.pcf.Z Serif16.pcf.Z 6x13.pcf.Z clB6x10.pcf.Z 6x13B.pcf.Z clB6x12.pcf.Z 6x9.pcf.Z clB8x10.pcf.Z 7x13.pcf.Z clB8x12.pcf.Z 7x13B.pcf.Z clB8x13.pcf.Z ...

clR8x10.pcf.Z clR8x12.pcf.Z clR8x13.pcf.Z clR8x14.pcf.Z clR8x16.pcf.Z clR8x8.pcf.Z clR9x15.pcf.Z cursor.pcf.Z deccurs.pcf.Z decsess.pcf.Z fonts.alias fonts.dir

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

117 / 277

4 Systme de multifentrage : X

4.17 Rpertoires de polices de caractres

Fichier fonts.dir : ce chier contient la liste des polices du rpertoire ; plus exactement des lignes au format : fichier-de-la-police nom-X-de-la-police . Par exemple :
... 6x13.pcf.Z -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1 ...

Fichier fonts.alias : ce chier contient des alias plus parlant que les noms complets des polices X. Par exemple :
... fixed ... "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1"

Lajout dune fonte ne se rsume pas copier le chier de la fonte dans le rpertoire !
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 118 / 277

4 Systme de multifentrage : X

4.17 Rpertoires de polices de caractres

Pour ajouter une police, il faudra faire appel la commande mkfontdir :


1 2 3 4 5

crer le rpertoire des polices si ncessaire : mkdir /tmp/fonts copier la police dans le rpertoire : cp toto.pcf /tmp/fonts crer le chier fonts.dir : mkfontdir crer ventuellement des alias : vi /tmp/fonts/fonts.alias ajouter le nouveau rpertoire son font path : xset +fp /tmp/fonts/ ; Attention : il faut le slash nal /tmp/fonts/ reconstituer la liste jour des polices X : xset fp rehash vrication des polices disponibles : xlsfonts ou xset -q utilisation des nouvelles polices : application-X.exe -fn nouvelle-fonte

6 7 8

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

119 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.18 Serveur de polices de caractres

4.18 Serveur de polices de caractres

Lajout de polices X sur un parc de machines est une opration pnible (voir transparent prcdent). Apparition dun mcanisme de serveur de fontes X. Administration simplie car centralisation des polices. En X11R5 : programme fs . En X11R6 et aprs : programme xfs .

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

120 / 277

4 Systme de multifentrage : X

4.18 Serveur de polices de caractres

Syntaxe : xfs [-config fichier-config] [-port n]

Par dfaut le chier de conguration est /etc/X11/fs/config .

Par dfaut le port TCP utilis est 7100 (voir /etc/services ).

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

121 / 277

4 Systme de multifentrage : X

4.18 Serveur de polices de caractres

Exemple de chier de conguration :


# allow a max of 10 clients to connect to this font server client-limit = 10 catalogue = /chemin/vers/fonts/ibm, /chemin/vers/fonts/ooffice, /chemin/vers/fonts/cmps, /chemin/vers/fonts/mathematica, /chemin/vers/fonts/msttcorefonts, /usr/X11R6/lib/X11/fonts/korean, /usr/X11R6/lib/X11/fonts/misc:unscaled, /usr/X11R6/lib/X11/fonts/75dpi:unscaled, /usr/X11R6/lib/X11/fonts/100dpi:unscaled, /usr/X11R6/lib/X11/fonts/Type1, /usr/X11R6/lib/X11/fonts/cyrillic, ... # how to log errors use-syslog = on # dont listen to TCP ports by default for security reasons # no-listen = tcp port = 7100

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

122 / 277

4 Systme de multifentrage : X

4.18 Serveur de polices de caractres

Utilisation dun serveur de fontes par : xset +fp tcp/xfs.example.com:7100 Liste des polices dun serveur de fontes par : fslsfonts -server tcp/xfs.example.com:7100 Test du serveur serveur de fontes par : fsinfo -server tcp/xfs.example.com:7100

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

123 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.19 Gestionnaire de fentres, window manager

4.19 Gestionnaire de fentres, window manager

Gestionnaire de fentres Window Manager client X au mme titre que les autres. Il permet de raliser les choses suivantes : dplacer ou redimensionner une fentre iconier ou non une fentre faire passer au premier ou au dernier plan une fentre dcorer les fentres crer ou dtruire les fentres lancer ou terminer des applications Lemploi dun gestionnaire de fentres na rien dobligatoire mais ce serait se priver de beaucoup de fonctionnalits. Il ne faut pas confondre le gestionnaire de fentres avec le serveur X.
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 124 / 277

4 Systme de multifentrage : X

4.19 Gestionnaire de fentres, window manager

Quelques exemples de fentres dcores par des window managers :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

125 / 277

4 Systme de multifentrage : X

4.20 Conguration de la session X, $HOME/.xsession, FAILSAFE Chapitre 4 Systme de multifentrage :X

4.20 Conguration de la session X, $HOME/.xsession, FAILSAFE

Sur une station avec une mire daccueil graphique, le script $HOME/.xsession est lanc lors de la connexion et il congure lenvironnement graphique de lutilisateur : applications X lancer automatiquement au dmarrage (par exemple des terminaux) rglages du clavier rglages de la souris etc. La dure de vie de la session sous X est celle du script $HOME/.xsession .

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

126 / 277

4 Systme de multifentrage : X

4.20 Conguration de la session X, $HOME/.xsession, FAILSAFE

Forme gnrale du script $HOME/.xsession :


#!/bin/sh client-X-1 & client-X-2 & ... appliX <--- pas de &

Le dernier client X nest pas lanc en tche de fond (sinon le script sarrte tout de suite et la session se ferme brutalement).

En gnral, le dernier client est le window manager.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

127 / 277

4 Systme de multifentrage : X

4.20 Conguration de la session X, $HOME/.xsession, FAILSAFE

Sil y a des erreurs, les messages de celles-ci sont crits dans le chier $HOME/.xsession-errors . En cas derreur grave dans $HOME/.xsession empchant le dmarrage de la session X, utiliser le mode FailSafe : disponible via les menus de la fentre daccueil de KDE disponible via les menus de la fentre daccueil de GNOME dans lenvironnement de base X :
entrer le nom de login 2 valider par la touche Retour 3 entrer le mot de passe 4 valider par la touche F1 et non pas par la touche Retour
1

Il apparait alors un simple xterm sans window manager. Lutiliser pour corriger les erreurs indiques dans le chier $HOME/.xsession-errors .

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

128 / 277

4 Systme de multifentrage : X

4.20 Conguration de la session X, $HOME/.xsession, FAILSAFE

Version KDE du FAILSAFE : via un menu :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

129 / 277

4 Systme de multifentrage : X

4.20 Conguration de la session X, $HOME/.xsession, FAILSAFE

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

130 / 277

4 Systme de multifentrage : X

4.20 Conguration de la session X, $HOME/.xsession, FAILSAFE

Pour lancer KDE, mettre au minimum dans son chier $HOME/.xsession


#!/bin/sh PATH=/usr/X11R6/bin:/usr/local/bin:$PATH export PATH startkde

Pour lancer GNOME, mettre au minimum dans son chier $HOME/.xsession


#!/bin/sh PATH=/usr/X11R6/bin:/usr/local/bin:$PATH export PATH enlightment & gnome-session

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

131 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.21 Environnements CDE, KDE, GNOME

4.21 Environnements CDE, KDE, GNOME

Objectif avou : fournir aux utilisateurs un environnement comparable au bureau de Windows, pratique, congurable souhait Plusieurs environnements sympatiques : CDE : cf http://www.cde.com KDE : cf http://www.kde.org GNOME : cf http://www.gnome.org CDE quasi mort. Guerre entre KDE et GNOME. SUN a adopt GNOME.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

132 / 277

4 Systme de multifentrage : X

4.21 Environnements CDE, KDE, GNOME

CDE :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

133 / 277

4 Systme de multifentrage : X

4.21 Environnements CDE, KDE, GNOME

KDE :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

134 / 277

4 Systme de multifentrage : X

4.21 Environnements CDE, KDE, GNOME

GNOME :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

135 / 277

4 Systme de multifentrage : X

4.21 Environnements CDE, KDE, GNOME

Revers de la mdaille : complexit de lenvironnement par rapport ce que lon faisait avant. Impossible de congurer manuellement lenvironnement. Par exemple lenvironnement graphique GNOME utilise une arborescence complexe de chiers utilisateur :
% du $HOME/.gnome* 22 .gnome/accels 18 .gnome/panel.d/default/launchers 38 .gnome/panel.d/default 40 .gnome/panel.d 2 .gnome/apps 2 .gnome/application-info 132 .gnome 14 .gnome-desktop 6 .gnome_private/panel.d/default 8 .gnome_private/panel.d 10 .gnome_private 2 .gnomerc-errors

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

136 / 277

4 Systme de multifentrage : X

4.21 Environnements CDE, KDE, GNOME

Par exemple lenvironnement graphique GNOME lance de nombreux process lors dune session X :
% ps -ax PID TT ... 203 ?? 214 ?? 226 ?? 228 ?? 275 ?? 277 ?? 280 ?? 282 ?? 285 ?? 290 ?? 292 ?? 300 ?? 301 ?? 303 ?? 1047 ?? 191 v0 202 v0 208 v0 209 v0 ... STAT R Ss Ss S Ss Ss Is I Is Ss Ss Is R I Is I+ I+ I I TIME COMMAND 53:03.26 0:00.85 0:05.55 0:03.47 0:18.31 0:18.97 0:00.02 0:00.28 0:00.85 0:01.16 0:01.24 0:00.01 0:13.20 0:00.01 0:00.22 0:00.00 0:00.00 0:00.00 0:00.40 X :0 -nolisten tcp (XFree86) gnome-smproxy --sm-config-prefix /.gnome-smproxy-kumf /usr/X11R6/bin/sawfish --sm-client-id default2 --sm-p xscreensaver -nosplash panel --sm-config-prefix /panel.d/default-tZvCrQ/ --s nautilus --sm-config-prefix /nautilus-DXsk2u/ --sm-cl gnome-name-service /usr/X11R6/bin/gconfd-1 12 oafd --ac-activate --ior-output-fd=16 tasklist_applet --activate-goad-server tasklist_apple deskguide_applet --activate-goad-server deskguide_app /bin/sh -c gnome-terminal --use-factory --start-facto gnome-terminal --use-factory --start-factory-server gnome-pty-helper oafd --ac-activate --ior-output-fd=22 /bin/sh /usr/X11R6/bin/startx xinit /users/sri/besancon/.xinitrc -- -nolisten tcp /bin/sh /users/sri/besancon/.xinitrc gnome-session

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

137 / 277

4 Systme de multifentrage : X

4.21 Environnements CDE, KDE, GNOME

Le recours un Control Center est indispensable :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

138 / 277

4 Systme de multifentrage : X

4.22 Rinitialisation des environnements KDE / Gnome Chapitre 4 Systme de multifentrage : X

4.22 Rinitialisation des environnements KDE / Gnome

Que faire si votre environnement KDE ou GNOME ne fonctionne plus ? Lancez la commande suivante spcique la Formation Permanente :
% ~besancon/resetX

et suivez les instructions. Attention : cela eacera toute conguration personnalise de KDE ou de GNOME !

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

139 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X 4.23 Scurit : xhost, MAGIC-COOKIE, xauth, ssh


4.23 Scurit : xhost, MAGIC-COOKIE, xauth, ssh

Rappel : principe client / serveur :

On veut pouvoir contrler quels clients X peuvent se connecter au serveur X.


c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 140 / 277

4 Systme de multifentrage : X

4.23 Scurit : xhost, MAGIC-COOKIE, xauth, ssh

Contrle daccs par machine La commande xhost permet de grer de faon basique les accs au serveur X :
% xhost access control enabled, only authorized clients can connect % xhost + machine2.example.com machine2.example.com being added to access control list % xhost access control enabled, only authorized clients can connect INET:machine2.example.com % xhost - machine2.example.com machine2.example.com being removed from access control list

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

141 / 277

4 Systme de multifentrage : X

4.23 Scurit : xhost, MAGIC-COOKIE, xauth, ssh

En pratique :
% echo $DISPLAY machine1.example.com:0.0 % xhost + machine2.example.com % rlogin machine2.example.com $ DISPLAY=machine1.example.com:0.0 $ export DISPLAY $ clientX ... $ exit <- affichage des fentres du client X distant

% xhost - machine1.example.com

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

142 / 277

4 Systme de multifentrage : X

4.23 Scurit : xhost, MAGIC-COOKIE, xauth, ssh

Dfauts de la commande xhost : Le principal dfaut de la commande xhost est dautoriser une machine et donc tout utilisateur y tant connect. Si lutilisateur fait xhost + sans comprendre tout client X peut se connecter ! Dangereux ! Exemples :
lecture / espionnage du clavier spyware Par exemple rcupration de mots de passe lors de su root Cf ftp://ftp.giga.or.at/pub/hacker/unix/xscan.tar.gz destruction de fentres par lutilisation de xkill par exemple capture dcran par lutilisation de xwd -root

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

143 / 277

4 Systme de multifentrage : X

4.23 Scurit : xhost, MAGIC-COOKIE, xauth, ssh

Contrle daccs par utilisateur : MAGIC-COOKIE, xauth Solution au problme de lautorisation XHOST : emploi dun cookie, pseudo secret connu du serveur rappeler lors dune demande de connexion au serveur X.
transmission du cookie au dmarrage

2bis

copie du cookie

dmarrage du terminal X : lancement de X direct

1 xdm
$HOME/.Xauthority

rseau Serveur X

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

144 / 277

4 Systme de multifentrage : X

4.23 Scurit : xhost, MAGIC-COOKIE, xauth, ssh

Qui peut connatre le cookie ? Celui qui peut accder au contenu du chier $HOME/.Xauthority
magic cookie A

ACCEPT

Transmission magic cookie A

CLIENT X 1

~alice/.Xauthority
Transmission magic cookie B

REFUS

~bob/.Xauthority
CLIENT X 2

rseau Serveur X

La scurit de X repose dans ce cas sur la scurit du lesystem. Do :


% ls -l $HOME/.Xauthority -rw------- 1 besancon software 1510 Dec 17 19:12 $HOME/.Xauthority

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

145 / 277

4 Systme de multifentrage : X

4.23 Scurit : xhost, MAGIC-COOKIE, xauth, ssh

Que faire si $HOME/.Xauthority nest pas disponible sur la machine distante ? Utiliser la commande xauth pour les oprations suivantes :
1

extraction du MAGIC-COOKIE du DISPLAY de la machine locale (login local = besancon ) copie sur la machine distante du MAGIC-COOKIE (le login distant peut tre dirent = tbesancon ) fusion sur la machine distante du MAGIC-COOKIE au chier $HOME/.Xauthority distant

ce qui se traduit par lune de ces commandes :


% xauth extract - $DISPLAY | rsh host2.example.com -l tbesancon xauth merge -

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

146 / 277

4 Systme de multifentrage : X

4.23 Scurit : xhost, MAGIC-COOKIE, xauth, ssh

Dfauts du mcanisme du MAGIC-COOKIE : le cookie transite en clair sur le rseau et peut donc tre rcupr par un mouchard.

Pas de rponse simple ce problme en dehors du protocole SUN-DES-1 mais trs peu rpandu (chirement des donnes dautorisation par DES et transfert par Secure RPC ce qui implique NIS = compliqu)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

147 / 277

4 Systme de multifentrage : X

4.23 Scurit : xhost, MAGIC-COOKIE, xauth, ssh

SSH et MAGIC-COOKIE Dfaut de la commande xauth : syntaxe lourde lorsque le chier $HOME/.Xauthority nest pas disponible sur la machine distante ; rappel :
% xauth extract - $DISPLAY | rsh host2.example.com -l tbesancon xauth merge -

Solution : SSH (voir http://www.openssh.org ) SSH incorpore de base un mcanisme de transmission automatique du DISPLAY et du cookie associ avec scurisation de la liaison par chirement de la communication.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

148 / 277

4 Systme de multifentrage : X
rseau

4.23 Scurit : xhost, MAGIC-COOKIE, xauth, ssh

Chiffrement Dechiffrement

S S H

S S H

Chiffrement Dechiffrement

client X

PSEUDO CLIENT X

PSEUDO SERVEUR X PSEUDO $DISPLAY = stationB:11.0

$DISPLAY = stationA:0.0

client X

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

149 / 277

4 Systme de multifentrage : X

Chapitre 4 Systme de multifentrage : X

4.24 X Display Manager Protocol

4.24 X Display Manager Protocol

XDMCP : X Display Management Control Protocol X Display Manager (processus xdm ) est un client qui contrle la connexion de lutilisateur et lance sa session. Visuellement, cest une fentre dauthentication :

cerise.example.com Login: Password:

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

150 / 277

4 Systme de multifentrage : X

4.24 X Display Manager Protocol

On a plusieurs programmes XDM disponibles : xdm : programme de base historique kdm : version KDE amliore de XDM gdm : version GNOME amliore de XDM

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

151 / 277

4 Systme de multifentrage : X

4.24 X Display Manager Protocol

Programmes plus ou moins complexes, riches, personnalisables :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

152 / 277

4 Systme de multifentrage : X

4.24 X Display Manager Protocol

Plusieurs chiers et shell-scripts de conguration de XDM :


Xservers Xaccess Xresources xdm-config GiveConsole TakeConsole Xsetup_0 Xsession .xsession .Xresources

/usr/X11R6/lib/X11/xdm
c T.Besanon (v14.0.631) Administration UNIX

$HOME
ARS 2011 2012 Partie 4 153 / 277

4 Systme de multifentrage : X

4.24 X Display Manager Protocol

chier xdm-config Cest un chier de ressources pour le programme xdm . Il indique les autres chiers de conguration ou des shell scripts.

chier Xservers A lorigine indique la liste des serveurs X grer ; partir de X11R4, le protocole XDMCP permet un DISPLAY de contacter XDM et de se faire grer

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

154 / 277

4 Systme de multifentrage : X

4.24 X Display Manager Protocol

chier Xaccess Il dnit la liste des serveurs X autoriss se connecter XDM ; un serveur X met une requte de gestion dun de ces types : requte direct requte indirect requte broadcast

Syntaxe utilisant des metacharacters : *.example.com , !cerise.example.com , etc.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

155 / 277

4 Systme de multifentrage : X

4.24 X Display Manager Protocol

Accs direct :
Requete XDMCP directe

Login:

xdm

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

156 / 277

4 Systme de multifentrage : X

4.24 X Display Manager Protocol

Accs indirect :

Requete XDMCP indirecte

xdm1 Login:

xdm2

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

157 / 277

4 Systme de multifentrage : X

4.24 X Display Manager Protocol

Accs broadcast :

xdm1
Requete XDMCP broadcast

xdm2

xdm3 Login:
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 158 / 277

4 Systme de multifentrage : X

4.24 X Display Manager Protocol

Possibilit davoir un chooser (slection de htes UNIX) : liste explicite dhtes :


ncd.example.com CHOOSER unix1.example.com unix2.example.com

liste par broadcast dhtes : ncd.example.com CHOOSER BROADCAST


Requete XDMCP indirecte

chooser

xdm

Liste predefinie ou broadcast

X
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 159 / 277

4 Systme de multifentrage : X

4.24 X Display Manager Protocol

chier Xresources Dnit les ressources utiliss par la fentre de connexion.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

160 / 277

4 Systme de multifentrage : X

4.24 X Display Manager Protocol

chiers GiveConsole , TakeConsole Ce sont des shells scripts. Ils dnissent les oprations systme faire la connexion et la dconnexion de lutilisateur. Par exemple : rendre lutilisateur propritaire de /dev/console rendre lutilisateur propritaire de /dev/fb rendre lutilisateur propritaire du priphrique de la carte son

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

161 / 277

4 Systme de multifentrage : X

4.24 X Display Manager Protocol

chier Xsession Dnit la session de lutilisateur aprs sa connexion.

En gnral, cest un shell script qui appelle le script $HOME/.xsession de lutilisateur, qui charge les ressources de lutilisateur, etc.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

162 / 277

4 Systme de multifentrage : X

4.24 X Display Manager Protocol

Par exemple sur SUN SOLARIS :


#!/bin/sh # redirect errors to a file in users home directory if we can for errfile in "$HOME/.xsession-errors" "${TMPDIR-/tmp}/xses-$USER" "/tmp/xses-$USER" do if ( cp /dev/null "$errfile" 2> /dev/null ) then chmod 600 "$errfile" exec > "$errfile" 2>&1 break fi done case $# in 1) case $1 in failsafe) exec xterm -geometry 80x24-0-0 ;; esac esac

Suite sur le transparent suivant. . .


c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 163 / 277

4 Systme de multifentrage : X

4.24 X Display Manager Protocol

Suite. . .

startup=$HOME/.xsession resources=$HOME/.Xresources if [ -f "$startup" ]; then exec "$startup" else if [ -f "$resources" ]; then xrdb -load "$resources" fi twm & exec xterm -geometry 80x24+10+10 -ls fi

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

164 / 277

4 Systme de multifentrage : X

Terminaux X / Clients lgers X / Autres terminaux Chapitre 4 Systme de multifentrage 4.25 :X

4.25 Terminaux X / Clients lgers X / Autres terminaux

Terminaux X Un terminal X est un poste de travail graphique : orant le systme graphique X sans systme dexploitation complexe grer et maintenir simple congurer

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

165 / 277

4 Systme de multifentrage : X

4.25 Terminaux X / Clients lgers X / Autres terminaux

Fonctionnement : boot du terminal requte DHCP ou BOOTP qui retourne ladresse IP et ladresse TFTP du serveur X tlcharger :
host droopy.example.com { hardware ethernet 00:80:96:04:71:63; fixed-address 192.168.1.69; filename "/hds/netOS/tX/prom/common/X.hds"; }

tlchargement par TFTP du serveur X du terminal et de sa conguration lancement du serveur X qui accroche le XDM dun serveur prcis par la conguration tlcharge Parfois, NFS est utilisable la place des tlchargements TFTP.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

166 / 277

4 Systme de multifentrage : X

4.25 Terminaux X / Clients lgers X / Autres terminaux

Aprs 2000, on constate : cot lev dun terminal X ; parfois plus cher quun poste PC Windows multimdia dsaection des constructeurs (HDS, NCD ont ferm boutique) manque de priphriques supports ; pas de oppy, pas de son, pas de USB. . .

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

167 / 277

4 Systme de multifentrage : X

4.25 Terminaux X / Clients lgers X / Autres terminaux

Terminaux lgers Un vrai terminal X est maintenant trop cher. Un vrai terminal X est maintenant trop limitatif : pas de multimdia Solution : le client lger

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

168 / 277

4 Systme de multifentrage : X

4.25 Terminaux X / Clients lgers X / Autres terminaux

Le client lger : ni un PC, ni un terminal X : succdan darchitecture de PC x86 faible consommation lectrique pas de ventilateur silencieux mmoire ash (pas de disque dur local) systme dexploitation de type LINUX minimaliste ou Windows CE support des priphriques rcents (USB, wake-on-lan, . . .)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

169 / 277

4 Systme de multifentrage : X

4.25 Terminaux X / Clients lgers X / Autres terminaux

Autres terminaux : Sunray

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

170 / 277

4 Systme de multifentrage : X

4.25 Terminaux X / Clients lgers X / Autres terminaux

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

171 / 277

4 Systme de multifentrage : X

4.25 Terminaux X / Clients lgers X / Autres terminaux

Caractristiques du SUNRAY : Pas de disque dur Pas dapplications locales Pas de conguration Pas de systme dexploitation Pas de barrette mmoire Pas de ventilateur Pas de paramtrage particulier Il est 10 fois plus lger quun PC et 12 fois moins volumineux Il peut mme sintgrer dans un cran cathodique 17 pouces ou un cran plat de 15 pouces...

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

172 / 277

4 Systme de multifentrage : X

4.25 Terminaux X / Clients lgers X / Autres terminaux

Avantages : Instantan, constant et simple Gestion centralise Jamais besoin de mise jour Silencieux 16 millions de couleurs (24 bits) Pas de setup Donc, pas de d-setup Pas de modications de vos applications AUCUN tranfert de chier au boot

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

173 / 277

4 Systme de multifentrage : X

4.25 Terminaux X / Clients lgers X / Autres terminaux

Caractristiques hardware : CPU Sparc 1280 x 1024 @ 76 Hz frame buer 24 bits 10/100Mb Ethernet Accs a Solaris , X11, Java , ICA fonctionnalits multimdia Lecteur de carte puce E/S audio qualit CD Entre vido NTSC/PAL Support USB ( 4 ports ) mais limit en pratique. . .

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

174 / 277

4 Systme de multifentrage : X

4.25 Terminaux X / Clients lgers X / Autres terminaux

Architecture rseau :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

175 / 277

4 Systme de multifentrage : X

4.25 Terminaux X / Clients lgers X / Autres terminaux

Architecture logicielle :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

176 / 277

4 Systme de multifentrage : X

4.25 Terminaux X / Clients lgers X / Autres terminaux

Architecture logicielle (2) :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

177 / 277

4 Systme de multifentrage : X

4.25 Terminaux X / Clients lgers X / Autres terminaux

Cohabitation avec Windows possible :

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

178 / 277

Chapitre 5

Langage SQL
Explications sur le pourquoi de ce chapitre

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

179 / 277

5 Langage SQL

Chapitre 5 Langage SQL

5.1 Introduction

5.1 Introduction

SQL Structured Query Language SQL permet : la dnition et la modication du schma de la base de donnes la manipulation des donnes linterrogation des donnes le contrle des accs la base

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

180 / 277

5 Langage SQL

Chapitre 5 Langage SQL

5.2 Dnition des exemples

5.2 Dnition des exemples

Voici les relations qui seront utilises dans ce cours :


Table AVION
Numav Capacite Type Entrepot

14 345

25 75

A400 B200 Table PILOTE

Garches Maubeuge

Matricule

Nom

Ville

Age

Salaire

1 2

Figue Lavande

Cannes Touquet

45 24

28004 11758

Table PASSAGER
Numtab Nomab

1 2

Nifance Tearice

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

181 / 277

5 Langage SQL

5.2 Dnition des exemples

Table VOL
Numvol Heure_depart Heure_arrivee Ville_depart Ville_arrivee

AL12 AF8

08-18 11-20

09-12 23-54

Paris Vaux

Lilles Rio

Table DEPART
Numvol Date_dep Numav Matricule

AL12 AL12

31-DEC-95 19-DEC-95

14 342

1 2

Table RESERVATION
Numab Numvol Date_sep

1 2

AL12 AL12

31-DEC-95 31-DEC-95

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

182 / 277

5 Langage SQL

Chapitre 5 Langage SQL


Cration dune relation

5.3 Description des donnes

5.3 Description des donnes

CREATE TABLE Pilote ( pl# Number(4), plnom char(20), adresse char(30) ) ;

Cration dune relation avec contraintes dintgrit


CREATE TABLE Pilote ( pl# Number(4) not null, plnom char(20), adresse char(30) ) ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

183 / 277

5 Langage SQL

5.3 Description des donnes

Cration dindex
CREATE UNIQUE INDEX IPL# ON Pilote(pl#);

Suppression dune relation


DROP TABLE Pilote ;

Modication du schma dune relation


ALTER TABLE Pilote ADD ( age number(2) ); ALTER TABLE Pilote MODIFY ( adresse char(50) ); ALTER TABLE Pilote MODIFY ( pl# not null );

Cration dune vue


CREATE VIEW VoldeParis AS ( SELECT vol#, va, hd, ha FROM Vol WHERE vd=Paris ) ;
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 184 / 277

5 Langage SQL

Chapitre 5 Langage SQL


Insertion des donnes

5.4 Manipulation des donnes

5.4 Manipulation des donnes

INSERT INTO Pilote values (1, Antoine, Annecy) ; INSERT INTO Pilote values (2, Arthur, Adge) ; INSERT INTO Pilote values (3, Jean, null) ;

Suppression des donnes


DELETE FROM Pilote WHERE pl# = 1 ;

Modication des donnes


UPDATE Pilote SET adresse = Aurillac WHERE pl#=2 ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

185 / 277

5 Langage SQL

Chapitre 5 Langage SQL

5.5 Contrle des accs

5.5 Contrle des accs

Fin normale (validation) dune transaction


COMMIT ;

Linstruction commit rend eectifs les changements eectus sur la base. Ils deviennent visibles aux autres utilisateurs. Annulation dune transaction
ROLLBACK ;

Linstruction rollback dfait toutes les modications eectues sur la base depuis le dbut de la transaction.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

186 / 277

5 Langage SQL

Chapitre 5 Langage SQL


Principe

5.6 Projection, Restriction

5.6 Projection, Restriction

SELECT AVION.numav FROM AVION WHERE AVION.capacite > 200 ;

Projection seule :
SELECT AVION.numav FROM AVION ;

Restriction seule :
SELECT AVION.* FROM AVION WHERE AVION.capacite > 200 ;

Exercice 1 : Quel est lge du pilote de matricule 15 ? Exercice 2 : Quels sont les pilotes de cette compagnie arienne ? (leur matricule, leur nom, leur ville, leur ge et leur salaire)
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 187 / 277

5 Langage SQL

5.6 Projection, Restriction

Tri Tri croissant : ORDER BY... ASC Tri dcroissant : ORDER BY... DESC
SELECT AVION.numav FROM AVION WHERE AVION.capacite > 200 ORDER BY AVION.numav DESC ;

Suppression des doubles


SELECT DISTINCT AVION.numav FROM AVION WHERE AVION.capacite > 200 ;

Omission du prxe
SELECT numav FROM AVION WHERE capacite > 200 ;
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 188 / 277

5 Langage SQL

5.6 Projection, Restriction

Emploi de variables
SELECT A.numav FROM AVION A WHERE A.capacite > 200 ;

Exercice 3 : Quels sont les types davions entreposs Tarascon, avec leur capacit, par ordre de capacits croissantes ? Prdicats dans le critre de slection Les prdicats disponibles : =, !=, >, <, >=, <= OR, AND, LIKE, NOT NULL, IN, NOT, BETWEEN X AND Y

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

189 / 277

5 Langage SQL

5.6 Projection, Restriction

SELECT numav FROM AVION WHERE capacite > 200 AND ( (ENTREPOT = Saint nom la Breteche) OR (ENTREPOT = Mantes la jolie) ) AND numav != 300 ; SELECT numav FROM AVION WHERE entrepot in (Saint nom la Breteche, Mantes la jolie) AND capacite BETWEEN 200 AND 210 AND TYPE LIKE B_EING%;

Exercice 4 : Quelles sont les villes ayant un nom commencant par L et o un pilote de moins de 20 ans gagne plus de 20000 F ? Exercice 5 : Quels sont les numros davions, avec leut entrept, ne rsidant pas Marolles-en-Hurepoix, ayant une capacit suprieure 200 ? (donns par ordre de numros dcroissants)
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 190 / 277

5 Langage SQL

5.6 Projection, Restriction

Les fonctions Quelques fonctions disponibles : fonction lower(a) fonction soundex(a) fonction abs(a)
SELECT numav FROM AVION WHERE LOWER(ENTREPOT) = le vesiney; SELECT MATRICULE, NOM FROM PILOTE WHERE SOUNDEX(NOM) = SOUNDEX(SINTEXUPERI) ; SELECT UPPER(NOM) FROM PILOTE WHERE ADRESSE = Cordillre des Andes ;

fonction sqrt(a) fonction length(a) etc.

Exercice 6 : Quelles sont les villes do part un vol pour Ajaccio ? (donner les rsultats en majuscule)
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 191 / 277

5 Langage SQL

5.6 Projection, Restriction

Les agrgats Quelques agrgats disponibles : agrgat avg() agrgat count() agrgat max() agrgat min() agrgat sum() agrgat stddev() agrgat variance() etc.

Exemple : Quel est le nombre davions ayant une capacit suprieure 200 ?
SELECT COUNT(NUMAV) FROM AVION WHERE CAPACITE > 200 ; SELECT COUNT(DISTINCT NUMAV) FROM AVION WHERE CAPACITE > 200 ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

192 / 277

5 Langage SQL

5.6 Projection, Restriction

Exercice 7 : Quel est le nombre davions en service (ie dans la relation DEPART), le 19 dcembre 1995 ? Exercice 8 : Quelle est la capacit moyenne des avions entreposs Pogo Togo ?

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

193 / 277

5 Langage SQL

Chapitre 5 Langage SQL


Prdicat dexistence

5.7 Les requtes imbriques

5.7 Les requtes imbriques

SELECT FROM WHERE EXISTS ( SELECT FROM WHERE ) ;

Exemple : Quels sont les pilotes qui habitent dans une ville o nest bas aucun avion ?
SELECT PILOTE.NOM FROM PILOTE WHERE NOT EXISTS ( SELECT AVION.* FROM AVION WHERE AVION.ENTREPOT = PILOTE.VILLE ) ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

194 / 277

5 Langage SQL

5.7 Les requtes imbriques

Requte lintrieur du IN Exemple : Quels sont les noms des pilotes qui habitent dans une ville o sont localiss des avions de capacit suprieure 250 ?
SELECT PILOTE.NOM FROM PILOTE WHERE VILLE IN ( SELECT ENTREPOT FROM AVION WHERE CAPACITE > 250 ) ;

Exercice 9 : Exprimer la requte suivante avec un EXISTS : Quels sont les noms des pilotes qui habitent dans une ville o sont localiss des avions de capacit suprieure 250 ? Exercice 10 : Exprimer la requte suivante avec un IN : Quels sont les noms des passagers ayant rserv pour le 1er avril 1996 ?

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

195 / 277

5 Langage SQL

Chapitre 5 Langage SQL

5.8 La jointure

5.8 La jointure

2 mthodes principales : prdicative requtes imbriques Exemple : Quels sont les noms des pilotes qui assurent un vol le vendredi 13 octobre 1996 ? Prdicative :
SELECT PILOTE.NOM FROM PILOTE, DEPART WHERE PILOTE.MATRICULE = DEPART.MATRICULE AND DEPART.DAPE_SEP = 13-10-95;

Imbrication :
SELECT NOM FROM PILOTE WHERE MATRICULE IN ( SELECT DEPART.MATRICULE FROM MATRICULE WHERE DATE_SEP = 13-10-95 ) ;
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 196 / 277

5 Langage SQL

5.8 La jointure

Il y a de nombreuses autres faons dexprimer une jointure. Par exemple :


SELECT PILOTE.NOM FROM PILOTE WHERE EXISTS ( SELECT * FROM DEPART WHERE PILOTE.MATRICULE = DEPART.MATRICULE AND DEPART.DATE_DEP = 13-10-95 ) ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

197 / 277

5 Langage SQL

5.8 La jointure

Exercice 11 : Quels sont les noms des pilotes qui assurent un vol le vendredi 13 octobre 1995, sur un avion de capacit suprieure 250 ? de manire prdicative laide de requtes imbriques Exercice 12 : Quelles sont les paires de pilotes (matricules) habitant dans la mme ville ? Exercice 13 : Quels sont les noms des pilotes qui conduisent lavion de numro 666 ? Exercice 14 : Quels sont les noms des pilotes qui habitent dans la ville o est entrepos lavion 666 ?

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

198 / 277

5 Langage SQL

Chapitre 5 Langage SQL

5.9 Lunion

5.9 Lunion

Quels sont les pilotes qui conduisent lavion de numro 666 OU qui habitent dans la ville o est entrepos lavion 666 ?
SELECT NOM FROM PILOTE, DEPART WHERE PILOTE.MATRICULE = DEPART.MATRICULE AND DEPART.NUMAV = 666 UNION SELECT NOM FROM PILOTE, AVION WHERE PILOTE.VILLE = AVION.ENTREPOT AND AVION.NUMAV = 666 ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

199 / 277

5 Langage SQL

Chapitre 5 Langage SQL

5.10 Lintersection

5.10 Lintersection

Quels sont les pilotes qui conduisent lavion de numro 666 ET qui habitent dans la ville o est entrepos lavion 666 ?
SELECT NOM FROM PILOTE, DEPART WHERE PILOTE.MATRICULE = DEPART.MATRICULE AND DEPART.NUMAV = 666 INTERSECT SELECT NOM FROM PILOTE, AVION WHERE PILOTE.VILLE = AVION.ENTREPOT AND AVION.NUMAV = 666 ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

200 / 277

5 Langage SQL

Chapitre 5 Langage SQL

5.11 La dirence

5.11 La dirence

Quels sont les pilotes qui conduisent lavion de numro 666 SAUF ceux qui habitent dans la ville o est entrepos lavion 666 ?
SELECT NOM FROM PILOTE, DEPART WHERE PILOTE.MATRICULE = DEPART.MATRICULE AND DEPART.NUMAV = 666 MINUS SELECT NOM FROM PILOTE, AVION WHERE PILOTE.VILLE = AVION.ENTREPOT AND AVION.NUMAV = 666 ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

201 / 277

5 Langage SQL

Chapitre 5 Langage SQL

5.12 La division

5.12 La division

Quels sont les pilotes qui conduisent tous les avions ? Quels sont les pilotes tels que, quel que soit lavion, ils le conduisent ? Quels sont les pilotes tels que, quel que soit lavion, il existe un dpart assur par ce pilote sur cet avion ? Quels sont les pilotes tels quil nexiste pas davion tel quil nexiste pas dpart de ce pilote sur cet avion ?
SELECT MATRICULE FROM PILOTE WHERE NOT EXISTS ( SELECT * FROM AVION WHERE NOT EXISTS ( SELECT * FROM DEPART WHERE DEPART.MATRICULE = PILOTE.MATRICULE AND DEPART.NUMAV = AVION.NUMAV ) ) ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

202 / 277

5 Langage SQL

5.12 La division

Exercice 15 : Quels sont les passagers qui ont rserv sur tous les vols ? Exercice 16 : Quel est le nombre de pilotes qui conduisent des avions en service ? (ie dans la relation DEPART)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

203 / 277

5 Langage SQL

Chapitre 5 Langage SQL

5.13 Group by

5.13 Group by

Loprateur GROUP BY partitionne la table. Exemple : Quel est le nombre de pilotes qui conduisent des avions en service, par avion ?
SELECT NUMAV, COUNT(DISTINCT DEPART.MATRICULE) FROM DEPART GROUP BY NUMAV ;

Exercice 17 : Quelle est la capacit moyenne des avions, par entrept et part type ?

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

204 / 277

5 Langage SQL

Chapitre 5 Langage SQL

5.14 Group by . . . HAVING

5.14 Group by . . . HAVING

Loprateur HAVING permet dintroduire une qualication sur les sous-tables issues du GROUP BY. Le HAVING est au GROUP BY ce que le WHERE est au FROM. Exemple : quels sont les avions qui assurent plus de 3 dpart ?
SELECT DEPART.NUMAV FROM DEPART GROUP BY NUMAV HAVING COUNT(*) > 3 ;

Exercice 18 : Quelles sont les villes o sont entreposs plus de 2 avions de type ICBM ?

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

205 / 277

5 Langage SQL

Chapitre 5 Langage SQL

5.15 Conclusion

5.15 Conclusion

SQL est un langage dinterrogation trs lisible, par tous les utilisateurs. SQL est un langage dans lequel il est relativement facile dcrire, pour un programmeur, condition de bien visualiser lordre dapplication des instructions :
1 2 3 4 5 6

From Where Group By Having Select Order By

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

206 / 277

5 Langage SQL

Chapitre 5 Langage SQL

5.16 Correction des exercices

5.16 Correction des exercices

Exercice 1 Quel est lge du pilote de matricule 15 ?


SELECT PILOTE.AGE FROM PILOTE WHERE MATRICULE = 15 ;

Exercice 2 Quels sont les pilotes de cette compagnie arienne (leur matricule, leur nom leur ville, leur ge et leur salaire)
SELECT * FROM PILOTE ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

207 / 277

5 Langage SQL

5.16 Correction des exercices

Exercice 3 Quels sont les types davions entreposs Tarascon, avec leur capacit, par ordre de capacit croissantes ?
SELECT DISTINCT TYPE, CAPACITE FROM AVION WHERE ENTREPOT = Tarascon ORDER BY CAPACITE ASC ;

Exercice 4 Quelles sont les villes ayant un nom commenant par L et o un pilote de moins de 20 ans gagne plus de 200000 F ?
SELECT VILLE FROM PILOTE WHERE AGE < 20 AND SALAIRE > 200000 AND VILLE LIKE L%;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

208 / 277

5 Langage SQL

5.16 Correction des exercices

Exercice 5 Quels sont les numros davions, avec leur entrept, ne rsidant pas Marolles-en-Hurepoix, ayant une capacit suprieure 200 ? (donns par ordre de numros dcroissants)
SELECT NUMAV, ENTREPOT FROM AVION WHERE ENTREPOT != Marolles-en-Hurepoix AND CAPACITE > 200 ORDER BY NUMAV DESC ;

Exercice 6 Quelles sont les villes do part un vol pour Ajaccio ? (donner les rsultats en majuscules)
SELECT UPPER(VILLE_DEPART) FROM VOL WHERE VILLE_ARRIVEE = Ajaccio;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

209 / 277

5 Langage SQL

5.16 Correction des exercices

Exercice 7 Quel est le nombre davions en service (ie dans la relation DEPART), le 19 dcembre 1995 ?
SELECT COUNT(DISTINCT NUMAV) FROM DEPART WHERE DATE_DEP = 19-12-95 ;

Exercice 8 Quelle est la capacit moyenne des avions entreposs Pogo Togo ?
SELECT AVG(ALL CAPACITE) FROM AVION WHERE AVION.ENTREPOT = Pogo Togo;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

210 / 277

5 Langage SQL

5.16 Correction des exercices

Exercice 9 Exprimer la requte suivante avec un EXISTS : Quels sont les noms des pilotes qui habitent dans une ville o sont localiss des avions de capacit suprieure 250 ?
SELECT PILOTE.NOM FROM PILOTE WHERE EXISTS ( SELECT * FROM AVION WHERE CAPACITE > 250 AND AVION.ENTREPOT = PILOTE.VILLE ) ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

211 / 277

5 Langage SQL

5.16 Correction des exercices

Exercice 10 Quels sont les noms des passagers ayant rserv pour le 1er avril 1996 ? (avec un IN)
SELECT PASSAGER.NOMAB FROM PASSAGER WHERE NUMAB IN ( SELECT RESERVATION.NUMAB FROM RESERVATION WHERE RESERVATION.DATE_DEP = 01-04-96 ) ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

212 / 277

5 Langage SQL

5.16 Correction des exercices

Exercice 11 a Quels sont les noms des pilotes qui assurent un vol le vendredi 13 octobre 1995, sur un avion de capacit suprieure 250 ? De manire prdicative :
SELECT PILOTE.NOM FROM PILOTE, DEPART, AVION WHERE PILOTE.MATRICULE = DEPART.MATRICULE AND DEPART.DATE_DEP = 13-10-95 AND DEPART.NUMAV = AVION.NUMAV AND AVION.CAPACITE > 250 ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

213 / 277

5 Langage SQL

5.16 Correction des exercices

Exercice 11 b Quels sont les noms des pilotes qui assurent un vol le vendredi 13 octobre 1995, sur un avion de capacit suprieure 250 ? A laide de requtes imbriques :
SELECT NOM FROM PILOTE WHERE MATRICULE IN ( SELECT DEPART.MATRICULE FROM DEPART WHERE DATE_DEP = 13-10-95 AND NUMAV IN ( SELECT AVION.NUMAV FROM AVION WHERE CAPACITE > 250 ) ) ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

214 / 277

5 Langage SQL

5.16 Correction des exercices

Exercice 12 Quelles sont les paires de pilotes (matricules) habitant dans la mme ville ?
SELECT P1.MATRICULE, P2.MATRICULE FROM PILOTE P1, PILOTE P2 WHERE P1.VILLE = P2.VILLE AND P1.MATRICULE > P2.MATRICULE ;

(il sagit dune auto jointure) Exercice 13 Quels sont les noms des pilotes qui conduisent lavion de numro 666 ?
SELECT NOM FROM PILOTE, DEPART WHERE PILOTE.MATRICULE = DEPART.MATRICULE AND DEPART.NUMAV = 666 ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

215 / 277

5 Langage SQL

5.16 Correction des exercices

Exercice 14 Quels sont les noms des pilotes qui habitent dans la ville o est entrepos lavion 666 ?
SELECT NOM FROM PILOTE, AVION WHERE PILOTE.VILLE = AVION.ENTREPOT AND AVION.NUMAV = 666;

Exercice 15 Quels sont les passagers qui ont rserv sur tous les vols ?
SELECT NUMAB FROM PASSAGER WHERE NOT EXISTS ( SELECT * FROM VOL WHERE NOT EXISTS ( SELECT * FROM RESERVATION WHERE RESERVATION.NUMAB = PASSAGER.NUMAB AND RESERVATION.NUMVOL = VOL.NUMVOL ) ) ;
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 216 / 277

5 Langage SQL

5.16 Correction des exercices

Exercice 16 Quel est le nombre de pilotes qui conduisent des avions en service ? (ie dans la relation DEPART)
SELECT COUNT(DISTINCT DEPART.MATRICULE) FROM DEPART ;

Exercice 17 Quelle est la capacit moyenne des avions, par entrept et par type ?
SELECT ENTREPOT, TYPE, AVG(CAPACITE) FROM AVION GROUP BY ENTREPOT, TYPE ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

217 / 277

5 Langage SQL

5.16 Correction des exercices

Exercice 18 Quelles sont les villes o sont entreposs plus de 2 avions de type ICBM ?
SELECT ENTREPOT FROM AVION WHERE TYPE = ICBM GROUP BY ENTREPOT HAVING COUNT(*) > 2 ;

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

218 / 277

Chapitre 6

Base de donnes ORACLE


Explications sur le pourquoi de ce chapitre

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

219 / 277

6 Base de donnes ORACLE

Chapitre 6 Base de donnes ORACLE

6.1 Introduction

6.1 Introduction

Plusieurs moteurs de bases de donnes disponibles : Oracle Microsoft SQL Server Microsoft MSDE (version light et gratuite de SQL Server) IBM DB2 Sybase MYSQL POSTGRESQL ORACLE est la rfrence en bases de donnes. Version de ORACLE disponible au moment de lcriture de ce document : 10g Site ociel : http://www.oracle.com

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

220 / 277

6 Base de donnes ORACLE

6.1 Introduction

A noter quOracle diuse maintenant des versions gratuites 100% fonctionnelles pour LINUX, pour SOLARIS, pour WINDOWS.

A noter le livre Oracle 9i sous Linux par Gilles Briard, diteur Eyrolles, prix 50 euros, livr avec la distribution Oracle 9i complte pour Linux. (je nai pas lu le livre)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

221 / 277

6 Base de donnes ORACLE

Chapitre 6 Base de donnes ORACLE

6.2 Outil TOAD

6.2 Outil TOAD

Outil de mise au point des requtes SQL : TOAD

Voir http://www.toadsoft.com

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

222 / 277

Chapitre 7

Base de donnes MYSQL


Explications sur le pourquoi de ce chapitre

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

223 / 277

7 Base de donnes MYSQL

Chapitre 7 Base de donnes MYSQL

7.1 Introduction

7.1 Introduction

Plusieurs moteurs de bases de donnes disponibles : Oracle Microsoft SQL Server Microsoft MSDE (version light et gratuite de SQL Server) IBM DB2 Sybase MYSQL POSTGRESQL Version de MYSQL disponible au moment de lcriture de ce document : 5.0.22 (2006-08-03) Site ociel : http://www.mysql.com Changement de la licence de MYSQL dans la version 4. Mal reu par la communaut des dveloppeurs Par exemple dans PHP 5, il ny a plus de support dorigine pour MYSQL.
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 224 / 277

7 Base de donnes MYSQL

Chapitre 7 Base de donnes MYSQL

7.2 Utilisateur UNIX ddi MYSQL : mysql

7.2 Utilisateur UNIX ddi MYSQL : mysql

Etape prliminaire linstallation mais indispensable.

Le bon fonctionnement de MYSQL ncessite la dnition dun utilisateur au sens UNIX qui sappelle mysql .

On crera aussi un groupe UNIX mysql .

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

225 / 277

7 Base de donnes MYSQL

Chapitre 7 Base de donnes MYSQL

7.3 Arborescence MYSQL

7.3 Arborescence MYSQL

Par dfaut, les sources de MYSQL sinstalleront dans /usr/local/mysql . On trouvera alors dans /usr/local/mysql : sous-rpertoire bin : binaires de lapplication sous-rpertoire include/mysql : headers de programmation C sous-rpertoire info : chiers de documentation sous-rpertoire lib/mysql : librairies partages sous-rpertoire libexec : binaires systme de lapplication sous-rpertoire share/mysql : chiers des textes des erreurs sous-rpertoire sql-bench : chiers de tests sous-rpertoire var : chiers de donnes et de log A noter le chier var/my.cnf qui dnit la conguration de MYSQL. Linstallation de MYSQL doit se complter de la cration des bases initiales de MYSQL.
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 226 / 277

7 Base de donnes MYSQL

7.4 Cration des bases initiales MYSQL : mysql_install_db Chapitre 7 Base de donnes MYSQL

7.4 Cration des bases initiales MYSQL : mysql_install_db

(en anglais MYSQL install databases ) Syntaxe : mysql_install_db Par dfaut, cest le rpertoire var dans larborescence MYSQL (par dfaut donc /usr/local/mysql/var ). La cration des bases initiales se fera sous lidentit de lutilisateur mysql .

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

227 / 277

7 Base de donnes MYSQL

7.4 Cration des bases initiales MYSQL : mysql_install_db

% id uid=6000(mysql) gid=6000(mysql) % mysql_install_db Installing all prepared tables Fill help tables To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/local/mysql/bin/mysqladmin -u root password new-password /usr/local/mysql/bin/mysqladmin -u root -h linux.example.com password new-password See the manual for more instructions. You can start the MySQL daemon with: cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe & You can test the MySQL daemon with the benchmarks in the sql-bench directory: cd sql-bench ; perl run-all-tests Please report any problems with the /usr/local/mysql/bin/mysqlbug script! The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at https://order.mysql.com
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 228 / 277

7 Base de donnes MYSQL

7.4 Cration des bases initiales MYSQL : mysql_install_db

ATTENTION : Finaliser linstallation par la mise en place dun mot de passe pour le compte SQL de nom root :
% /usr/local/mysql/bin/mysqladmin -u root password XXXXXXXX

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

229 / 277

7 Base de donnes MYSQL

Chapitre 7 Base de donnes MYSQL

7.5 lancement/arrt de MYSQL

7.5 lancement/arrt de MYSQL

Lancer sous lidentit de mysql le programme bin/mysqld_safe sous lidentit UNIX mysql .

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

230 / 277

7 Base de donnes MYSQL

Chapitre 7 Base de donnes MYSQL

7.6 Cration de bases MYSQL (1) : mysqladmin

7.6 Cration de bases MYSQL (1) : mysqladmin

La cration de bases normales MYSQL se fait par la commande mysqladmin . Syntaxe : mysqladmin [options] create base Exemple 1 : cration dune base
% mysqladmin -u root -p create ars Enter password: XXXXXXX

Exemple 2 : suppression dune base


% mysqladmin -u root -p drop ars Enter password: XXXXXXX Dropping the database is potentially a very bad thing to do. Any data stored in the database will be destroyed. Do you really want to drop the base database [y/N] y Database "base" dropped
c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

231 / 277

7 Base de donnes MYSQL

Chapitre 7 Base de donnes MYSQL

7.7 Cration de bases MYSQL (2) : commandes SQL

7.7 Cration de bases MYSQL (2) : commandes SQL

% mysql -u root -pXXXXXXXX mysql> create database ars ; Query OK, 1 row affected (0.01 sec) mysql> show databases ; +----------+ | Database | +----------+ | ars | | mysql | | test | +----------+ 3 rows in set (0.01 sec)

mysql> drop database ars ; Query OK, 0 rows affected (0.02 sec) mysql> show databases ; +----------+ | Database | +----------+ | mysql | | test | +----------+ 2 rows in set (0.01 sec)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

232 / 277

7 Base de donnes MYSQL

Chapitre 7 Base de donnes MYSQL 7.8 Dialogue interactif avec MYSQL en mode CLI : mysql
7.8 Dialogue interactif avec MYSQL en mode CLI : mysql

La commande mysql permet dinteragir avec MYSQL et de lui demander dexcuter des commandes SQL. Cela se prsente comme un shell spcialis en SQL. Syntaxe : mysql [options] base De nombreuses commandes sont ensuite disponibles. Exemple 1 : connexion et dconnexion
% mysql -u root -pXXXXXXXX ars ... mysql> quit ; Bye

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

233 / 277

7 Base de donnes MYSQL

7.8 Dialogue interactif avec MYSQL en mode CLI : mysql

Exemple 2 : liste des bases


% mysql -u root -pXXXXXXXX ... mysql> show databases ; +----------+ | Database | +----------+ | ars | | mysql | | test | +----------+ 3 rows in set (0.01 sec) mysql> quit ; Bye

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

234 / 277

7 Base de donnes MYSQL

7.8 Dialogue interactif avec MYSQL en mode CLI : mysql

Exemple 3 : liste des tables systmes


% mysql -u root -pXXXXXXXX mysql ... mysql> show tables ; +---------------------------+ | Tables_in_mysql | +---------------------------+ | columns_priv | | db | | func | | help_category | | help_keyword | | help_relation | | help_topic | | host | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | +---------------------------+ 15 rows in set (0.00 sec)
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 235 / 277

7 Base de donnes MYSQL

7.8 Dialogue interactif avec MYSQL en mode CLI : mysql

Exemple 4 : liste des utilisateurs


% mysql -u root -pXXXXXXXX mysql ... mysql> select User from user order by User asc ; +------+ | User | +------+ | | | | | root | | root | +------+ 4 rows in set (0.03 sec)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

236 / 277

7 Base de donnes MYSQL

Chapitre 7 Base de donnes MYSQL

7.9 Notion dutilisateurs MYSQL

7.9 Notion dutilisateurs MYSQL

Une requte SQL est mise au nom dun utilisateur ctif interne la base SQL. Un utilisateur SQL nest pas ncessairement un vrai utilisateur UNIX. La notion dutilisateurs SQL est utilise dans le contrle des requtes SQL :
GRANT privilge[,privilge...] ON table | * | *.* | base.* TO utilisateur [IDENTIFIED BY [PASSWORD] PASSWORD] [, utilisateur [IDENTIFIED BY [PASSWORD] PASSWORD]] ...

o : les privilges sont parmi les mots clef SELECT , INSERT , UPDATE , DELETE , RULE , ALL
utilisateur dsignera un utilisateur bien prcis qui obtient les

privilges indiqus

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

237 / 277

7 Base de donnes MYSQL

7.9 Notion dutilisateurs MYSQL

Exemple : ajout de droits pour un utilisateur


% mysql -u root -pXXXXXXXX mysql ... mysql> grant all on ars.* to besancon@localhost identified by XXXXXXXX ; Query OK, 0 rows affected (0.02 sec)

Exemple : rvocation de droits pour un utilisateur


% mysql -u root -pXXXXXXXX mysql ... mysql> revoke all privileges on ars.* from besancon@localhost ; Query OK, 0 rows affected (0.02 sec)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

238 / 277

7 Base de donnes MYSQL

Chapitre 7 Base de donnes MYSQL

7.10 Fichier de conguration : my.cnf

7.10 Fichier de conguration : my.cnf

A completer...

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

239 / 277

7 Base de donnes MYSQL

Chapitre 7 Base de donnes MYSQL

7.11 Sauvegarde : mysqldump

7.11 Sauvegarde : mysqldump

MYSQL fournit un outil pour sauvegarder au format SQL sous forme de commandes SQL une ou plusieurs bases. Pour sauver une base, utiliser la commande mysqldump . Syntaxe : mysqldump -u root -p [options] base Pour sauver toutes les bases, utiliser la commande mysqldump --all-databases . Syntaxe : mysqldumpall -u root -p [options] Attention : joindre la sauvegarde le chier my.cnf qui nest pas sauvegard par loutil SQL mysqldump.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

240 / 277

7 Base de donnes MYSQL

7.11 Sauvegarde : mysqldump

Exemple 1 : sauvegarde dune seule base


% mysqldump -u root -pXXXXXXXX base > /tmp/base.sql % ls -l /tmp/base.sql -rw-r--r-1 besancon adm

15054229 Oct 23 12:12 /tmp/base.sql

% head /tmp/base.sql -- MySQL dump 10.8 --- Host: localhost Database: ars -- ------------------------------------------------------- Server version 4.1.7-log ... DROP TABLE IF EXISTS t1; CREATE TABLE t1 ( ...

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

241 / 277

7 Base de donnes MYSQL

7.11 Sauvegarde : mysqldump

Exemple 2 : sauvegarde de toutes les bases


% mysqldump -u root -pXXXXXXXX --all-databases > /tmp/bases.sql % ls -l /tmp/bases.sql -rw-r--r-1 besancon adm

15064263 Oct 23 12:18 /tmp/bases.sql

% head /tmp/base.sql -- MySQL dump 10.8 --- Host: localhost Database: -- ------------------------------------------------------- Server version 4.1.7-log ... CREATE DATABASE /*!32312 IF NOT EXISTS*/ ars; USE ars; ...

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

242 / 277

7 Base de donnes MYSQL

Chapitre 7 Base de donnes MYSQL

7.12 Rechargement dune sauvegarde

7.12 Rechargement dune sauvegarde

Sil sagit de recharger la sauvegarde dune base, faire sous lidentit de lutilisateur mysql :
% mysql -u root -pXXXXXXXX < /tmp/base.sql

Sil sagit de recharger la sauvegarde de la totalit des bases, faire sous lidentit de lutilisateur mysql :
% mysql -u root -pXXXXXXXX < /tmp/bases.sql

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

243 / 277

7 Base de donnes MYSQL

Chapitre 7 Base de donnes MYSQL

7.13 Interface de gestion de MYSQL : phpmyadmin

7.13 Interface de gestion de MYSQL : phpmyadmin

A noter un interface WWW de conguration et dadministration : phpmyadmin

Cf http://www.phpmyadmin.net/

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

244 / 277

7 Base de donnes MYSQL

Chapitre 7 Base de donnes MYSQL

7.14 Outil TOAD

7.14 Outil TOAD

Outil de mise au point des requtes SQL : TOAD

Voir http://www.toadsoft.com

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

245 / 277

Chapitre 8

Base de donnes POSTGRESQL


Explications sur le pourquoi de ce chapitre

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

246 / 277

8 Base de donnes POSTGRESQL

Chapitre 8 Base de donnes POSTGRESQL

8.1 Introduction

8.1 Introduction

(On rencontre souvent le mot PGSQL pour POSTGRESQL)

Plusieurs moteurs de bases de donnes disponibles : Oracle Microsoft SQL Server Microsoft MSDE (version light et gratuite de SQL Server) IBM DB2 Sybase MYSQL POSTGRESQL Version de PGSQL disponible au moment de lcriture de ce document : 8.1.4 (2006-08-03) Site ociel : http://www.postgresql.org
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 247 / 277

8 Base de donnes POSTGRESQL

8.1 Introduction

Systme de rplication possible mais cela semble un produit jeune.

A completer...

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

248 / 277

8 Base de donnes POSTGRESQL

Chapitre 8 Base de donnes POSTGRESQL 8.2 Utilisateur UNIX ddi PGSQL : pgsql
8.2 Utilisateur UNIX ddi PGSQL : pgsql

Etape prliminaire linstallation mais indispensable. Le bon fonctionnement de PGSQL ncessite la dnition dun utilisateur au sens UNIX qui sappelle pgsql . On crera aussi un groupe UNIX pgsql .

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

249 / 277

8 Base de donnes POSTGRESQL

Chapitre 8 Base de donnes POSTGRESQL

8.3 Arborescence PGSQL

8.3 Arborescence PGSQL

Par dfaut, les sources de PGSQL sinstalleront dans /usr/local/pgsql. On trouvera alors dans /usr/local/pgsql : sous-rpertoire bin : rpertoire des binaires de lapplication sous-rpertoire data : rpertoire des chiers de conguration au premier niveau ; ce rpertoire devra tre la proprit de lutilisateur pgsql . sous-rpertoire data/base : rpertoire des chiers de stockage de la base de donnes sous-rpertoire doc : rpertoire de documentation (format HTML) sous-rpertoire include : rpertoire des headers de programmation C sous-rpertoire lib : rpertoire des librairies partages des binaires PGSQL sous-rpertoire man : rpertoire des pages de manuel sous-rpertoire share : rpertoire de chiers dexemples
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 250 / 277

8 Base de donnes POSTGRESQL

8.3 Arborescence PGSQL

A noter le chier data/pga_hba.conf qui dnit les accs autoriss.

Linstallation de PGSQL doit se complter de la cration des bases initiales de PGSQL.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

251 / 277

8 Base de donnes POSTGRESQL

8.4 Cration des bases initiales PGSQL : initdb Chapitre 8 Base de donnes POSTGRESQL

8.4 Cration des bases initiales PGSQL : initdb

(en anglais initialize database ) Syntaxe : initdb -D rpertoire-de-donnes Par dfaut, on prend le rpertoire data dans larborescence PGSQL (par dfaut donc /usr/local/pgsql/data ). La cration des bases initiales se fera sous lidentit de lutilisateur pgsql .

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

252 / 277

8 Base de donnes POSTGRESQL

Chapitre 8 Base de donnes POSTGRESQL

8.5 Lancement/arrt de PGSQL : pg_ctl

8.5 Lancement/arrt de PGSQL : pg_ctl

Deux processus sont en jeu :


postmaster : accepte les requtes de connexion postgres : excute les requtes SQL et renvoie les rsultats

Attention : les processus doivent tre lancs au nom de lutilisateur pgsql .

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

253 / 277

8 Base de donnes POSTGRESQL

8.5 Lancement/arrt de PGSQL : pg_ctl

Un script de lancement et darrt est fourni avec PGSQL : pg_ctl

Syntaxes : dmarrage de PGSQL : pg_ctl start :


# su pgsql -c "pg_ctl -D /chemin/vers/pgsql/data start" postmaster successfully started

arrt de PGSQL : pg_ctl stop :


# su pgsql -c "pg_ctl -D /chemin/vers/pgsql/data stop" waiting for postmaster to shut down......done postmaster successfully shut down

redmarrage de PGSQL : pg_ctl restart

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

254 / 277

8 Base de donnes POSTGRESQL

Chapitre 8 Base de donnes POSTGRESQL

8.6 Cration de bases PGSQL : createdb

8.6 Cration de bases PGSQL : createdb

La cration de bases normales PGSQL se fait par la commande createdb . Syntaxe : createdb [options] base La cration de toute nouvelle base se fait par duplication de la base initiale de nom template1 . Exemple
% createdb -e test CREATE DATABASE base; CREATE DATABASE

<-- commande interne lance <-- affichage du rsultat de cette commande

Loption -e sert acher les commandes internes SQL en fait ralises par le programme.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

255 / 277

8 Base de donnes POSTGRESQL

Chapitre 8 Base de donnes POSTGRESQL

8.7 Destruction de bases PGSQL : dropdb

8.7 Destruction de bases PGSQL : dropdb

La destruction de bases normales PGSQL se fait par la commande dropdb . Syntaxe : dropdb [options] base

Exemple
% dropdb -e test DROP DATABASE base; DROP DATABASE

<-- commande interne lance <-- affichage du rsultat de cette commande

Loption -e sert acher les commandes internes SQL en fait ralises par le programme.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

256 / 277

8 Base de donnes POSTGRESQL

8.8 Dialogue interactif avec PGSQL en mode CLI : psql Chapitre 8 Base de donnes POSTGRESQL

8.8 Dialogue interactif avec PGSQL en mode CLI : psql

La commande psql permet dinteragir avec PGSQL et de lui demander dexcuter des commandes SQL. Cela se prsente comme un shell spcialis en SQL. Syntaxe : psql base De nombreuses commandes sont ensuite disponibles. Exemple 1 : connexion et dconnexion
% psql template1 Welcome to psql 7.4.2, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help on internal slash commands \g or terminate with semicolon to execute query \q to quit

template1=# \q

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

257 / 277

8 Base de donnes POSTGRESQL

8.8 Dialogue interactif avec PGSQL en mode CLI : psql

Exemple 2 : liste des bases


% psql template1 ... template1=# \l List of databases Name | Owner | Encoding -----------+----------+----------template0 | pgsql | SQL_ASCII template1 | pgsql | SQL_ASCII (2 rows)

template1=# select * from pg_database ; datname | datdba | encoding | datistemplate | datallowconn | datlastsysoid | datvacuumx -----------+--------+----------+---------------+--------------+---------------+----------template1 | 1 | 0 | t | t | 17140 | 4 template0 | 1 | 0 | t | f | 17140 | 4 (2 rows)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

258 / 277

8 Base de donnes POSTGRESQL

8.8 Dialogue interactif avec PGSQL en mode CLI : psql

Exemple 3 : liste des tables systmes


% psql template1 ... template1=# \dS List of relations Schema | Name | Type | Owner ------------+--------------------------+---------+------... pg_catalog | pg_database | table | pgsql ... pg_catalog | pg_user | view | pgsql ... (54 rows)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

259 / 277

8 Base de donnes POSTGRESQL

8.8 Dialogue interactif avec PGSQL en mode CLI : psql

Exemple 4 : liste des utilisateurs

% psql template1 ... template1=# select * from pg_user ; usename | usesysid | usecreatedb | usesuper | usecatupd | passwd | valuntil | useconfi ----------+----------+-------------+----------+-----------+----------+----------+--------pgsql | 1 | t | t | t | ******** | | apache | 1002 | f | f | f | ******** | | besancon | 1003 | t | t | t | ******** | | (3 rows)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

260 / 277

8 Base de donnes POSTGRESQL

8.9 Cration de bases PGSQL : commandes SQL Chapitre 8 Base de donnes POSTGRESQL

8.9 Cration de bases PGSQL : commandes SQL

% psql template1 Welcome to psql 7.4.2, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help on internal slash commands \g or terminate with semicolon to execute query \q to quit

template1=# create database exemple ; CREATE DATABASE template1=# \l List of databases Name | Owner | Encoding -----------+----------+----------exemple | besancon | SQL_ASCII template0 | pgsql | SQL_ASCII template1 | pgsql | SQL_ASCII (3 rows)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

261 / 277

8 Base de donnes POSTGRESQL

8.10 Destruction de bases PGSQL : commandes SQL Chapitre 8 Base de donnes POSTGRESQL

8.10 Destruction de bases PGSQL : commandes SQL

% psql template1 Welcome to psql 7.4.2, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help on internal slash commands \g or terminate with semicolon to execute query \q to quit

template1=# drop database exemple ; DROP DATABASE template1=# \l List of databases Name | Owner | Encoding -----------+----------+----------template0 | pgsql | SQL_ASCII template1 | pgsql | SQL_ASCII (2 rows)

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

262 / 277

8 Base de donnes POSTGRESQL

Chapitre 8 Base de donnes POSTGRESQL

8.11 Notion dutilisateurs PGSQL

8.11 Notion dutilisateurs PGSQL

Une requte SQL est mise au nom dun utilisateur ctif interne la base SQL. Un utilisateur SQL nest pas ncessairement un vrai utilisateur UNIX. La notion dutilisateurs SQL est utilise dans le contrle des requtes SQL :
GRANT privilge[,...] ON objet[,...] TO {PUBLIC | utilisateur} ;

o : les privilges sont parmi les mots clef SELECT , INSERT , UPDATE , DELETE , RULE , ALL un objet dsigne une table, une vue ou une squence
PUBLIC indiquera que tous les utilisateurs SQL peuvent obtenir les

privilges indiqus
utilisateur dsignera un utilisateur bien prcis qui obtient les

privilges indiqus
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 263 / 277

8 Base de donnes POSTGRESQL

8.11 Notion dutilisateurs PGSQL

Exemple
% psql base ... base=# \d List of relations Schema | Name | Type | Owner --------+---------+-------+---------public | exemple | table | besancon (1 row) t=# \z Access privileges for database "base" Schema | Table | Access privileges --------+---------+------------------public | exemple | (1 row) t=# grant all on exemple to public ; GRANT t=# \z Access privileges for database "base" Schema | Table | Access privileges --------+---------+-----------------------------------------------------public | exemple | {besancon=a*r*w*d*R*x*t*/besancon,=arwdRxt/besancon} (1 row) ...
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 264 / 277

8 Base de donnes POSTGRESQL

8.12 Gestion dutilisateurs PGSQL (1) : createuser Chapitre 8 Base de donnes POSTGRESQL

8.12 Gestion dutilisateurs PGSQL (1) : createuser

Pour crer un utilisateur SQL, employer la commande createuser et rpondre aux diverses questions poses.

Syntaxe : createuser [options] [utilisateur-SQL]


-a -d -A -D

Cration de nouveaux utilisateurs ou pas Cration de nouvelles databases ou pas

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

265 / 277

8 Base de donnes POSTGRESQL

8.12 Gestion dutilisateurs PGSQL (1) : createuser

Exemple 1 : cration toute interactive


# createuser Enter name of user to add: ars Shall the new user be allowed to create databases? (y/n) n Shall the new user be allowed to create more new users? (y/n) n CREATE USER

Exemple 2 : cration non interactive


# createuser -D -A ars CREATE USER

Exemple 3 : cration non interactive et avec achage des instructions SQL internes
# createuser -D -A -e ars createuser -D -A -e ars SET autocommit TO on;CREATE USER "ars" NOCREATEDB NOCREATEUSER CREATE USER

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

266 / 277

8 Base de donnes POSTGRESQL

8.13 Gestion dutilisateurs PGSQL (2) : dropuser Chapitre 8 Base de donnes POSTGRESQL

8.13 Gestion dutilisateurs PGSQL (2) : dropuser

Pour supprimer un utilisateur SQL, employer la commande dropuser et rpondre aux diverses questions poses.

Syntaxe : dropuser [options] [utilisateur-SQL]

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

267 / 277

8 Base de donnes POSTGRESQL

8.13 Gestion dutilisateurs PGSQL (2) : dropuser

Exemple 1 : suppression toute interactive


# dropuser Enter name of user to drop: ars DROP USER

Exemple 2 : suppression non interactive


# dropuser ars DROP USER

Exemple 3 : suppression interactive avec garde fou et avec achage des instructions SQL internes
# dropuser -e -i ars User "ars" will be permanently removed. Are you sure? (y/n) y DROP USER ars; DROP USER

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

268 / 277

8 Base de donnes POSTGRESQL

8.14 Fichier de conguration : postgresql.conf Chapitre 8 Base de donnes POSTGRESQL

8.14 Fichier de conguration : postgresql.conf

Le chier data/postgresql.conf est cr aprs la phase du initdb . Il contiendra les paramtres de gestion mmoire pour PGSQL. Le paramtre tcpip_socket indiquera si PGSQL accepte les connexions rseau.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

269 / 277

8 Base de donnes POSTGRESQL

Chapitre 8 Base de donnes POSTGRESQL

8.15 Fichier de conguration : pg_hba.conf

8.15 Fichier de conguration : pg_hba.conf

Le chier data/pg_hba.conf est cr aprs la phase du initdb . Ce chier sert rgler les contrles daccs. Syntaxe :
local host hostssl hostnossl host hostssl hostnossl DATABASE DATABASE DATABASE DATABASE DATABASE DATABASE DATABASE USER USER USER USER USER USER USER METHOD [OPTION] IP-ADDRESS IP-MASK IP-ADDRESS IP-MASK IP-ADDRESS IP-MASK IP-ADDRESS/CIDR-MASK IP-ADDRESS/CIDR-MASK IP-ADDRESS/CIDR-MASK

METHOD METHOD METHOD METHOD METHOD METHOD

[OPTION] [OPTION] [OPTION] [OPTION] [OPTION] [OPTION]

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

270 / 277

8 Base de donnes POSTGRESQL

8.15 Fichier de conguration : pg_hba.conf

Syntaxe plus prcise :

The rst eld is the connection type : "local" is a Unix-domain socket, "host" is either a plain or SSL-encrypted TCP/IP socket, "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a plain TCP/IP socket.

DATABASE can be "all", "sameuser", "samegroup", a database name (or a comma-separated list thereof), or a le name prexed with "@".

USER can be "all", an actual user name or a group name prexed with "+" or a list containing either.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

271 / 277

8 Base de donnes POSTGRESQL

8.15 Fichier de conguration : pg_hba.conf

IP-ADDRESS and IP-MASK specify the set of hosts the record matches. CIDR-MASK is an integer between 0 and 32 (IPv6) or 128(IPv6) inclusive, that species the number of signicant bits in the mask, so an IPv4 CIDR-MASK of 8 is equivalent to an IP-MASK of 255.0.0.0, and an IPv6 CIDR-MASK of 64 is equivalent to an IP-MASK of ffff:ffff:ffff:ffff::. METHOD can be "trust", "reject", "md5", "crypt", "password", "krb4", "krb5", "ident", or "pam". Note that "password" uses clear-text passwords ; "md5" is preferred for encrypted passwords. OPTION is the ident map or the name of the PAM service.

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

272 / 277

8 Base de donnes POSTGRESQL

Chapitre 8 Base de donnes POSTGRESQL

8.16 Sauvegarde : pg_dump, pg_dumpall

8.16 Sauvegarde : pg_dump, pg_dumpall

PGSQL fournit un outil pour sauvegarder au format SQL sous forme de commandes SQL une ou plusieurs bases. Pour sauver une base, utiliser la commande pg_dump sous lidentit de lutilisateur pgsql . Syntaxe : pg_dump [options] base Pour sauver toutes les bases, utiliser la commande pg_dumpall sous lidentit de lutilisateur pgsql . Syntaxe : pg_dumpall [options] Attention : joindre la sauvegarde le chier pg_hba.conf qui contrle les accs et qui nest pas sauvegard par les 2 outil SQL pg_dump et pg_dumpall.
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 273 / 277

8 Base de donnes POSTGRESQL

8.16 Sauvegarde : pg_dump, pg_dumpall

Exemple 1 : sauvegarde dune seule base


% pg_dump base > /tmp/base.sql % ls -l /tmp/base.sql -rw-r--r-1 besancon adm % head /tmp/base.sql --- PostgreSQL database dump -SET client_encoding = SQL_ASCII; SET check_function_bodies = false; ...

15054229 Oct 23 12:12 /tmp/base.sql

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

274 / 277

8 Base de donnes POSTGRESQL

8.16 Sauvegarde : pg_dump, pg_dumpall

Exemple 2 : sauvegarde de toutes les bases


% pg_dumpall > /tmp/bases.sql % ls -l /tmp/bases.sql -rw-r--r-1 besancon adm 15064263 Oct 23 12:18 /tmp/bases.sql % head /tmp/base.sql --- PostgreSQL database cluster dump -\connect "template1" --- Users --

DELETE FROM pg_shadow WHERE usesysid <> (SELECT datdba FROM pg_database WHERE datname = t CREATE USER apache WITH SYSID 1002 NOCREATEDB NOCREATEUSER; CREATE USER besancon WITH SYSID 1003 CREATEDB CREATEUSER; ...

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

275 / 277

8 Base de donnes POSTGRESQL

Chapitre 8 Base de donnes POSTGRESQL

8.17 Rechargement dune sauvegarde

8.17 Rechargement dune sauvegarde

Sil sagit de recharger la sauvegarde dune base, faire sous lidentit de lutilisateur pgsql :
% dropdb base % psql < /tmp/base.sql

Sil sagit de recharger la sauvegarde de la totalit des bases, faire sous lidentit de lutilisateur pgsql :
% initdb -D /chemin/vers/pgsql/data/base % psql < /tmp/bases.sql

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

276 / 277

8 Base de donnes POSTGRESQL

8.18 Interface de gestion de PGSQL : phppgadmin Chapitre 8 Base de donnes POSTGRESQL

8.18 Interface de gestion de PGSQL : phppgadmin

A noter un interface WWW de conguration et dadministration : phppgadmin

Cf http://sourceforge.net/projects/phppgadmin/

c T.Besanon (v14.0.631)

Administration UNIX

ARS 2011 2012 Partie 4

277 / 277

Das könnte Ihnen auch gefallen