Beruflich Dokumente
Kultur Dokumente
c T.Besanon (v14.0.631)
Administration UNIX
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
2 / 277
1 Courrier lectronique
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
3 / 277
1 Courrier lectronique
Rseau
MTA
MDA
Distribution personnalise Bote aux lettres Emission dun courrier
MUA
c T.Besanon (v14.0.631)
Administration UNIX
4 / 277
1 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
5 / 277
1 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
6 / 277
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
7 / 277
1 Courrier lectronique
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
8 / 277
1 Courrier lectronique
MILTER = communication entre SENDMAIL et des programmes externes via des sockets UNIX.
c T.Besanon (v14.0.631)
Administration UNIX
9 / 277
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
Internet
smtpd
virtual
deferred
relocated
pipe
UUCP, etc.
c T.Besanon (v14.0.631)
Administration UNIX
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
11 / 277
1 Courrier lectronique
c T.Besanon (v14.0.631)
Administration UNIX
12 / 277
1 Courrier lectronique
Deux formats classiques de folders sous UNIX : folder MBOX folder MAILDIR
c T.Besanon (v14.0.631)
Administration UNIX
13 / 277
1 Courrier lectronique
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
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
15 / 277
1 Courrier lectronique
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
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
17 / 277
1 Courrier lectronique
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
1 Courrier lectronique
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
20 / 277
1 Courrier lectronique
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
21 / 277
1 Courrier lectronique
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
1 Courrier lectronique
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
23 / 277
1 Courrier lectronique
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
24 / 277
1 Courrier lectronique
c T.Besanon (v14.0.631)
Administration UNIX
25 / 277
1 Courrier lectronique
SMTP
Serveur de mails
POP
c T.Besanon (v14.0.631)
Administration UNIX
26 / 277
1 Courrier lectronique
c T.Besanon (v14.0.631)
Administration UNIX
27 / 277
1 Courrier lectronique
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
28 / 277
1 Courrier lectronique
RFC 2060 (protocole IMAP4rev1), RFC 2086 (ACL, extension de IMAP4), RFC 2087 (quota, extension de IMAP4)
c T.Besanon (v14.0.631)
Administration UNIX
29 / 277
1 Courrier lectronique
. * * * * * * . . * * * .
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
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
. 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
31 / 277
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
32 / 277
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
33 / 277
1 Courrier lectronique
1.13 Antispam
Humour :
c T.Besanon (v14.0.631)
Administration UNIX
34 / 277
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
35 / 277
The following paper was originally published in the Proceedings of the USENIX Symposium on Internet Technologies and Systems Monterey, California, December 1997
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/
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
; ; ; ;
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.
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.
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
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.
Auth NFS
INTERNET
Authentication Service File Servers File Servers
Auth NFS
SMTP
SUBSCRIBERS
Figure 1
Chapitre 2
SAMBA
Explications sur le pourquoi de ce chapitre
c T.Besanon (v14.0.631)
Administration UNIX
36 / 277
2 SAMBA
Chapitre 2 SAMBA
2.1 Introduction
2.1 Introduction
c T.Besanon (v14.0.631)
Administration UNIX
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
38 / 277
3 Systmes dimpression
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
39 / 277
3 Systmes dimpression
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
3 Systmes dimpression
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
c T.Besanon (v14.0.631)
Administration UNIX
41 / 277
3 Systmes dimpression
%! /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
c T.Besanon (v14.0.631)
Administration UNIX
42 / 277
3 Systmes dimpression
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
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
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
45 / 277
3 Systmes dimpression
acher au format A4 :
gs -sPAPERSIZE=a4 fichier.ps
options)
c T.Besanon (v14.0.631)
Administration UNIX
46 / 277
3 Systmes dimpression
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
47 / 277
3 Systmes dimpression
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
48 / 277
3 Systmes dimpression
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
49 / 277
3 Systmes dimpression
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
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
51 / 277
3 Systmes dimpression
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
52 / 277
3 Systmes dimpression
Rsum des caractristiques des impressions sur ce type dimprimantes : connexion non rseau par voie srie (plus tard par voie parallle)
Dans cette logique, un logiciel dimpression est avant tout capable de grer des voies sries.
c T.Besanon (v14.0.631)
Administration UNIX
53 / 277
3 Systmes dimpression
c T.Besanon (v14.0.631)
Administration UNIX
54 / 277
3 Systmes dimpression
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
55 / 277
3 Systmes dimpression
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
56 / 277
3 Systmes dimpression
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
57 / 277
3 Systmes dimpression
c T.Besanon (v14.0.631)
Administration UNIX
58 / 277
3 Systmes dimpression
c T.Besanon (v14.0.631)
Administration UNIX
59 / 277
3 Systmes dimpression
c T.Besanon (v14.0.631)
Administration UNIX
60 / 277
3 Systmes dimpression
c T.Besanon (v14.0.631)
Administration UNIX
61 / 277
3 Systmes dimpression
c T.Besanon (v14.0.631)
Administration UNIX
62 / 277
3 Systmes 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
63 / 277
3 Systmes 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
64 / 277
3 Systmes dimpression
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
65 / 277
3 Systmes dimpression
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
66 / 277
Chapitre 4
Systme de multifentrage : X
Explications sur le pourquoi de ce chapitre
c T.Besanon (v14.0.631)
Administration UNIX
67 / 277
4 Systme de multifentrage : X
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
68 / 277
4 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
69 / 277
4 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
70 / 277
4 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
Erreur
c T.Besanon (v14.0.631)
Administration UNIX
71 / 277
4 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
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
73 / 277
4 Systme de multifentrage : X
4.3 Serveur X
4.3 Serveur X
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
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
75 / 277
4 Systme de multifentrage : X
4.4 Client X
4.4 Client X
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
76 / 277
4 Systme de multifentrage : X
c T.Besanon (v14.0.631)
Administration UNIX
77 / 277
4 Systme de multifentrage : X
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
c T.Besanon (v14.0.631)
Administration UNIX
79 / 277
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
80 / 277
4 Systme de multifentrage : X
4.7 Clavier
c T.Besanon (v14.0.631)
Administration UNIX
81 / 277
4 Systme de multifentrage : X
4.7 Clavier
Code clavier
1ere conversion
SERVEUR X
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
83 / 277
4 Systme de multifentrage : X
4.7 Clavier
c T.Besanon (v14.0.631)
Administration UNIX
84 / 277
4 Systme de multifentrage : X
4.7 Clavier
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
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
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
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
90 / 277
4 Systme de multifentrage : X
4.8 Souris
4.8 Souris
c T.Besanon (v14.0.631)
Administration UNIX
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
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
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
Pour copier, on slectionne avec le bouton gauche de la souris. Pour coller, on clique avec le bouton du milieu de la souris.
Modiable.
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 95 / 277
4 Systme de multifentrage : 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
$HOME/.Xdefaults
$XENVIRONMENT
ou
$HOME/.Xdefaults-nom-host
c T.Besanon (v14.0.631)
Administration UNIX
96 / 277
4 Systme de multifentrage : X
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
-200-200
+600-100 X -0-0
ARS 2011 2012 Partie 4 98 / 277
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
$HOME/.Xdefaults
$XENVIRONMENT
ou
$HOME/.Xdefaults-nom-host
Administration UNIX
99 / 277
4 Systme de multifentrage : X
4.14 Ressources
/usr/X11R6/lib/X11/app-defaults
$XUSERFILESEARCHPATH
ou ou
$XAPPLRESDIR $HOME
$HOME/.Xdefaults
$XENVIRONMENT
ou
$HOME/.Xdefaults-nom-host
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
100 / 277
4 Systme de multifentrage : X
4.14 Ressources
/usr/X11R6/lib/X11/app-defaults
$XUSERFILESEARCHPATH
ou ou
$XAPPLRESDIR $HOME
$HOME/.Xdefaults
$XENVIRONMENT
ou
$HOME/.Xdefaults-nom-host
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
101 / 277
4 Systme de multifentrage : X
4.14 Ressources
/usr/X11R6/lib/X11/app-defaults
$XUSERFILESEARCHPATH
ou ou
$XAPPLRESDIR $HOME
$HOME/.Xdefaults
$XENVIRONMENT
ou
$HOME/.Xdefaults-nom-host
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
102 / 277
4 Systme de multifentrage : X
4.14 Ressources
/usr/X11R6/lib/X11/app-defaults
$XUSERFILESEARCHPATH
ou ou
$XAPPLRESDIR $HOME
$HOME/.Xdefaults
$XENVIRONMENT
ou
$HOME/.Xdefaults-nom-host
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
103 / 277
4 Systme de multifentrage : X
4.14 Ressources
Par exemple :
xterm.background: black xterm.foreground: yellow
c T.Besanon (v14.0.631)
Administration UNIX
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.
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
106 / 277
4 Systme de multifentrage : X
4.14 Ressources
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
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
$HOME/.Xdefaults
$XENVIRONMENT
ou
$HOME/.Xdefaults-nom-host
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
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
110 / 277
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
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
4 Systme de multifentrage : X
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
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
114 / 277
4 Systme de multifentrage : X
On peut utiliser la commande xlsfonts pour avoir la liste des fontes utilisables sur son poste X.
c T.Besanon (v14.0.631)
Administration UNIX
115 / 277
4 Systme de multifentrage : X
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
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
117 / 277
4 Systme de multifentrage : X
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
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
119 / 277
4 Systme de multifentrage : X
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
120 / 277
4 Systme de multifentrage : X
c T.Besanon (v14.0.631)
Administration UNIX
121 / 277
4 Systme de multifentrage : X
c T.Besanon (v14.0.631)
Administration UNIX
122 / 277
4 Systme de multifentrage : X
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
123 / 277
4 Systme de multifentrage : X
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
c T.Besanon (v14.0.631)
Administration UNIX
125 / 277
4 Systme de multifentrage : X
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
126 / 277
4 Systme de multifentrage : X
Le dernier client X nest pas lanc en tche de fond (sinon le script sarrte tout de suite et la session se ferme brutalement).
c T.Besanon (v14.0.631)
Administration UNIX
127 / 277
4 Systme de multifentrage : X
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
128 / 277
4 Systme de multifentrage : X
c T.Besanon (v14.0.631)
Administration UNIX
129 / 277
4 Systme de multifentrage : X
c T.Besanon (v14.0.631)
Administration UNIX
130 / 277
4 Systme de multifentrage : X
c T.Besanon (v14.0.631)
Administration UNIX
131 / 277
4 Systme de multifentrage : X
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
132 / 277
4 Systme de multifentrage : X
CDE :
c T.Besanon (v14.0.631)
Administration UNIX
133 / 277
4 Systme de multifentrage : X
KDE :
c T.Besanon (v14.0.631)
Administration UNIX
134 / 277
4 Systme de multifentrage : X
GNOME :
c T.Besanon (v14.0.631)
Administration UNIX
135 / 277
4 Systme de multifentrage : X
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
136 / 277
4 Systme de multifentrage : X
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
137 / 277
4 Systme de multifentrage : X
c T.Besanon (v14.0.631)
Administration UNIX
138 / 277
4 Systme de multifentrage : X
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
139 / 277
4 Systme de multifentrage : X
4 Systme de multifentrage : X
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
141 / 277
4 Systme de multifentrage : X
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
142 / 277
4 Systme de multifentrage : X
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
143 / 277
4 Systme de multifentrage : X
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
1 xdm
$HOME/.Xauthority
rseau Serveur X
c T.Besanon (v14.0.631)
Administration UNIX
144 / 277
4 Systme de multifentrage : X
Qui peut connatre le cookie ? Celui qui peut accder au contenu du chier $HOME/.Xauthority
magic cookie A
ACCEPT
CLIENT X 1
~alice/.Xauthority
Transmission magic cookie B
REFUS
~bob/.Xauthority
CLIENT X 2
rseau Serveur X
c T.Besanon (v14.0.631)
Administration UNIX
145 / 277
4 Systme de multifentrage : X
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
c T.Besanon (v14.0.631)
Administration UNIX
146 / 277
4 Systme de multifentrage : X
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
147 / 277
4 Systme de multifentrage : X
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
148 / 277
4 Systme de multifentrage : X
rseau
Chiffrement Dechiffrement
S S H
S S H
Chiffrement Dechiffrement
client X
PSEUDO CLIENT X
$DISPLAY = stationA:0.0
client X
c T.Besanon (v14.0.631)
Administration UNIX
149 / 277
4 Systme de multifentrage : X
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 :
c T.Besanon (v14.0.631)
Administration UNIX
150 / 277
4 Systme de multifentrage : X
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
151 / 277
4 Systme de multifentrage : X
c T.Besanon (v14.0.631)
Administration UNIX
152 / 277
4 Systme de multifentrage : X
/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
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
154 / 277
4 Systme de multifentrage : X
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
c T.Besanon (v14.0.631)
Administration UNIX
155 / 277
4 Systme de multifentrage : X
Accs direct :
Requete XDMCP directe
Login:
xdm
c T.Besanon (v14.0.631)
Administration UNIX
156 / 277
4 Systme de multifentrage : X
Accs indirect :
xdm1 Login:
xdm2
c T.Besanon (v14.0.631)
Administration UNIX
157 / 277
4 Systme de multifentrage : X
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
chooser
xdm
X
c T.Besanon (v14.0.631) Administration UNIX ARS 2011 2012 Partie 4 159 / 277
4 Systme de multifentrage : X
c T.Besanon (v14.0.631)
Administration UNIX
160 / 277
4 Systme de multifentrage : X
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
161 / 277
4 Systme de multifentrage : X
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
162 / 277
4 Systme de multifentrage : X
4 Systme de multifentrage : X
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
164 / 277
4 Systme de multifentrage : X
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
165 / 277
4 Systme de multifentrage : X
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
166 / 277
4 Systme de multifentrage : X
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
167 / 277
4 Systme de multifentrage : X
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
168 / 277
4 Systme de multifentrage : X
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
169 / 277
4 Systme de multifentrage : X
c T.Besanon (v14.0.631)
Administration UNIX
170 / 277
4 Systme de multifentrage : X
c T.Besanon (v14.0.631)
Administration UNIX
171 / 277
4 Systme de multifentrage : X
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
172 / 277
4 Systme de multifentrage : X
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
173 / 277
4 Systme de multifentrage : X
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
174 / 277
4 Systme de multifentrage : X
Architecture rseau :
c T.Besanon (v14.0.631)
Administration UNIX
175 / 277
4 Systme de multifentrage : X
Architecture logicielle :
c T.Besanon (v14.0.631)
Administration UNIX
176 / 277
4 Systme de multifentrage : X
c T.Besanon (v14.0.631)
Administration UNIX
177 / 277
4 Systme de multifentrage : X
c T.Besanon (v14.0.631)
Administration UNIX
178 / 277
Chapitre 5
Langage SQL
Explications sur le pourquoi de ce chapitre
c T.Besanon (v14.0.631)
Administration UNIX
179 / 277
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
180 / 277
5 Langage SQL
14 345
25 75
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
181 / 277
5 Langage SQL
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
182 / 277
5 Langage SQL
c T.Besanon (v14.0.631)
Administration UNIX
183 / 277
5 Langage SQL
Cration dindex
CREATE UNIQUE INDEX IPL# ON Pilote(pl#);
5 Langage SQL
INSERT INTO Pilote values (1, Antoine, Annecy) ; INSERT INTO Pilote values (2, Arthur, Adge) ; INSERT INTO Pilote values (3, Jean, null) ;
c T.Besanon (v14.0.631)
Administration UNIX
185 / 277
5 Langage SQL
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
186 / 277
5 Langage SQL
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
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 ;
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
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
189 / 277
5 Langage SQL
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
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 ;
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
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
192 / 277
5 Langage SQL
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
193 / 277
5 Langage SQL
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
194 / 277
5 Langage SQL
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
195 / 277
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
c T.Besanon (v14.0.631)
Administration UNIX
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
198 / 277
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
199 / 277
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
200 / 277
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
201 / 277
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
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
203 / 277
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
204 / 277
5 Langage SQL
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
205 / 277
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
c T.Besanon (v14.0.631)
Administration UNIX
206 / 277
5 Langage SQL
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
207 / 277
5 Langage SQL
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
208 / 277
5 Langage SQL
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
209 / 277
5 Langage SQL
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
210 / 277
5 Langage SQL
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
211 / 277
5 Langage SQL
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
212 / 277
5 Langage SQL
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
213 / 277
5 Langage SQL
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
214 / 277
5 Langage SQL
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
215 / 277
5 Langage SQL
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
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
217 / 277
5 Langage SQL
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
218 / 277
Chapitre 6
c T.Besanon (v14.0.631)
Administration UNIX
219 / 277
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
220 / 277
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
221 / 277
Voir http://www.toadsoft.com
c T.Besanon (v14.0.631)
Administration UNIX
222 / 277
Chapitre 7
c T.Besanon (v14.0.631)
Administration UNIX
223 / 277
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
Le bon fonctionnement de MYSQL ncessite la dnition dun utilisateur au sens UNIX qui sappelle mysql .
c T.Besanon (v14.0.631)
Administration UNIX
225 / 277
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.4 Cration des bases initiales MYSQL : mysql_install_db Chapitre 7 Base de donnes MYSQL
(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
227 / 277
% 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
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
229 / 277
Lancer sous lidentit de mysql le programme bin/mysqld_safe sous lidentit UNIX mysql .
c T.Besanon (v14.0.631)
Administration UNIX
230 / 277
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
Administration UNIX
231 / 277
% 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
232 / 277
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
233 / 277
c T.Besanon (v14.0.631)
Administration UNIX
234 / 277
c T.Besanon (v14.0.631)
Administration UNIX
236 / 277
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
237 / 277
c T.Besanon (v14.0.631)
Administration UNIX
238 / 277
A completer...
c T.Besanon (v14.0.631)
Administration UNIX
239 / 277
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
240 / 277
% 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
241 / 277
% 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
242 / 277
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
243 / 277
Cf http://www.phpmyadmin.net/
c T.Besanon (v14.0.631)
Administration UNIX
244 / 277
Voir http://www.toadsoft.com
c T.Besanon (v14.0.631)
Administration UNIX
245 / 277
Chapitre 8
c T.Besanon (v14.0.631)
Administration UNIX
246 / 277
8.1 Introduction
8.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 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.1 Introduction
A completer...
c T.Besanon (v14.0.631)
Administration UNIX
248 / 277
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
249 / 277
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
c T.Besanon (v14.0.631)
Administration UNIX
251 / 277
8.4 Cration des bases initiales PGSQL : initdb Chapitre 8 Base de donnes POSTGRESQL
(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
252 / 277
c T.Besanon (v14.0.631)
Administration UNIX
253 / 277
c T.Besanon (v14.0.631)
Administration UNIX
254 / 277
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
Loption -e sert acher les commandes internes SQL en fait ralises par le programme.
c T.Besanon (v14.0.631)
Administration UNIX
255 / 277
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
Loption -e sert acher les commandes internes SQL en fait ralises par le programme.
c T.Besanon (v14.0.631)
Administration UNIX
256 / 277
8.8 Dialogue interactif avec PGSQL en mode CLI : psql Chapitre 8 Base de donnes POSTGRESQL
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
257 / 277
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
258 / 277
c T.Besanon (v14.0.631)
Administration UNIX
259 / 277
% 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
260 / 277
8.9 Cration de bases PGSQL : commandes SQL Chapitre 8 Base de donnes POSTGRESQL
% 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
261 / 277
8.10 Destruction de bases PGSQL : commandes SQL Chapitre 8 Base de donnes POSTGRESQL
% 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
262 / 277
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
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.12 Gestion dutilisateurs PGSQL (1) : createuser Chapitre 8 Base de donnes POSTGRESQL
Pour crer un utilisateur SQL, employer la commande createuser et rpondre aux diverses questions poses.
c T.Besanon (v14.0.631)
Administration UNIX
265 / 277
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
266 / 277
8.13 Gestion dutilisateurs PGSQL (2) : dropuser Chapitre 8 Base de donnes POSTGRESQL
Pour supprimer un utilisateur SQL, employer la commande dropuser et rpondre aux diverses questions poses.
c T.Besanon (v14.0.631)
Administration UNIX
267 / 277
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
268 / 277
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
269 / 277
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
c T.Besanon (v14.0.631)
Administration UNIX
270 / 277
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
271 / 277
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
272 / 277
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
c T.Besanon (v14.0.631)
Administration UNIX
274 / 277
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
275 / 277
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
276 / 277
Cf http://sourceforge.net/projects/phppgadmin/
c T.Besanon (v14.0.631)
Administration UNIX
277 / 277