1D X Window System Survival Guide
- 格式:pdf
- 大小:273.69 KB
- 文档页数:11
APPENDIX1D X Window System Survival GuideWhen you log into a Unix system from the console(APPENDIX1C),you are typicallydropped into a graphical desktop environment that is similar,but not identical,to theMicrosoft Windows and Apple Macintosh desktops.From this desktop,you can runwindowing applications such as text editors,office productivity tools,and other familiartypes of applications.The Unix desktop uses aflexible windowing environment calledX Window System or X for short.Some Unix-based bioinformatics applications take advantage of this desktop environ-ment.Good examples include David Gordon’s Consed program(UNIT11.2)for editingsequence assemblies produced by the PHRAP assembler(see UNIT11.4).However,evenif you run text-only bioinformatics tools,it is liberating to be able to run them in anenvironment in which you can open multiple resizable terminal windows.A problem arises when you are logging into a Unix system remotely via an MS Windowsor Macintosh terminal emulator.This typically limits you to a small text-only window of24rows by80columns,and any attempt to launch graphical applications will terminatein the error message Can’t open display.For those who would like to keep anMS Windows or Macintosh machine on their desk and log into a Unix server from timeto time,this is a major annoyance.Fortunately,Unix provides a solution.The X Window System makes it possible to runapplications on the remote Unix machine and have multiple Unix terminal windowsappear on the local desktop.This works equally well for Macintosh and MS MicrosoftWindows computers and for connections from one Unix machine to another.RUNNING X APPLICATIONS LOCALLYX Window System applications can be run either locally or remotely.In thefirst case,the application runs on the same machine to which the screen,keyboard,and mouseare connected.In the latter case,the application runs on another machine located some-where else on the local area network or the Internet,but its windows and other userinterface elements appear on the screen of the local machine.If you are using Solaris,Linux,or other Unix-like operating system,X is already installedand running when you log in.To launch a bioinformatics application written for X,simplytype its name at the command line or click on its icon in your system’s desktop manager.Things are similar with MacOS X,except that X is not typically installed by default.If you are using MacOS X10.3or10.4,you will need tofirst install the“X11”application,located on disk#3of the MacOS X install disks.Alternatively,the X11application can be downloaded from /downloads/macosx/apple/x11formacosx.html.Once X11is installed,start it by double-clicking on its icon,locatedunder“Applications/Utilities...”This will bring up a simple terminal window named“xterm.”Within xterm,you can launch X Window applications by typing their names atthe command line.Alternatively,you can simply double-click on the application’s iconin the Finder and MacOS X will launch both the selected application and X to manage theapplication’s windows.This works because most graphical bioinformatics applicationshave been ported to MacOS X.Contributed by Lincoln D.SteinCurrent Protocols in Bioinformatics(2007)A.1D.1-A.1D.11 Copyright C 2007by John Wiley&Sons,er FundamentalsA.1D.1 Supplement17X Window System Survival GuideA.1D.2Supplement 17Current Protocols in BioinformaticsIt is more difficult to run bioinformatics X applications locally from within MS Windows systems,because few such applications have been ported to this environment.To access graphical X applications from a PC,you will usually need to run the application remotely on a Unix system and arrange for its windows to be displayed on the local PC.RUNNING X WINDOW SYSTEM APPLICATIONS REMOTELY There are two major options for running X applications remotely in such a way that their windows appear on the local machine:the VNC virtual desktop and the X Window System itself.The rest of this appendix describes these ing Virtual Computer Network (VNC)VNC (Virtual Network Computing)is a lightweight desktop sharing system that was created by the research division of AT&T U.K.and later taken over by RealVNC,Ltd.,a U.K.spinoff ( ).From here,you can download a fully functional free version of the software,as well as a pay version that adds encryption and other security features.The information in this appendix describes the free version.RealVNC does not provide a version of VNC for the Macintosh,but a version of the VNC viewer application that runs well on MacOS X can be found at /vnc.html.There is also a Java version of the VNC viewer that runs on MacOS X (and all other platforms)at RealVNC.If you have previously used desktop sharing systems like Timbuktu,the way VNC works will be familiar.On the Unix side of the connection,you install and run a server application called vncserver.The vncserver server program runs silently in the background,listening for incoming connections.On the desktop side of the connection,you run a viewer application called VNCViewer (the capitalization varies slightly among the different operating systems).When you use one of these applications to connect to a machine running vncserver,a graphical window appears on your desktop that contains an image of the Unix desktop.You can create windows,use menus,run programs,and interact with this remote desktop just as if you were using the Unix console directly.However,you might notice some jerkiness in screen updating,depending on the speed of the network unching vncserver Assuming that you have successfully downloaded and installed VNC,the first step is to launch e a terminal emulator to log into the Unix machine and run the following command:(∼)100%vncserver The vncserver program must be in a directory specified by your PATH environment variable (see APPENDIX 1C )or it will not be recognized.If vncserver is installed somewhere else,for example,under your home directory in a subdirectory named vnc-unix ,you would type:(∼)100%∼/vnc-unix/vncserver vncserver will now ask you to provide a password for accessing your desktop remotely:User Fundamentals A.1D.3Current Protocols in Bioinformatics Supplement 17You will require a password to access your desktops:Password:*******Verify:*******Choose a password that cannot easily be guessed.This can be the same as the password you use to log into Unix,or can be something different.Change the password later using the vncpasswd application.Before returning you to the command line prompt,vncserver will print out some useful messages:New ’X’desktop is pesto:1Starting applications specified in /home/lstein/.vnc/xstartup Log file is /home/lstein/.vnc/pesto:1.logThe important part of this message is the first line,which gives the name of the Unix machine and the “desktop number”on which the VNC server is listening.In the example,VNC is running on pesto:1,which is interpreted as desktop number 1on the machine named pesto .If other users are using vncserver on a multiuser machine,you might be assigned a higher-numbered desktop.Remember this information since you will need it to connect.You can now log out and shut down the terminal emulator.Vncserver will continue to run until the Unix machine is rebooted or you intentionally shut vncserver.Launching VNCViewerAssuming that you have successfully downloaded and installed VNCViewer,it can now be used to connect to the Unix unch VNCViewer from the Start menu (MS Windows)or the desktop (Macintosh).A small dialog box similar to the one shown in Figure A.1D.1will appear.Type in the name and desktop number that was assigned when you launched vncserver,e.g.,pesto:1.VNCViewer will try to establish a connection.If successful,it will now prompt you to provide a password.Type in the password that you selected when you launched the server.A window that contains a copy of the Unix desktop (Fig.A.1D.2)will appear.You can work inside the window just as if you were sitting at the Unix console.The MS Windows version of VNCViewer also offers a handy full-screen mode that will temporarily replace your desktop with the Unix desktop.To enter full-screen mode,right click on VNC’s window or taskbar icon in the MS Windows version and select Full-Screen Mode from the pop-up options menu.To get out of full-screen mode,press Control-Escape,and then the Escape key one more time.This will restore the Windowsdesktop.Figure A.1D.1When you launch VNCViewer on MS Windows or Macintosh desktops,a small dialog box prompts you to enter the host and desktop number for your Unix desktop.X Window System Survival GuideA.1D.4Supplement 17Current Protocols inBioinformaticsFigure A.1D.2VNCViewer opens up a single window that contains the Unix desktop and all windows created by Unix applications.When finished using VNC,just quit the VNCViewer application.The Unix desktop will continue to run,however,so the next time you reconnect to your desktop with VNCViewer,you will find it in exactly the state in which it was left.To bring down the VNC server completely,log into Unix and run vncserver with the -kill option:(∼)100%vncserver -kill pesto:1Notice that you must provide the hostname and desktop number in order for the -kill command to work.A number of things may go wrong while using VNC.One common problem is that the VNCViewer will report a connection failure when it tries to connect.If you are using VNCViewer across the Internet,you will probably need to use the full Internet address of the Unix machine.In the running example,the full address for “pesto”is ,so replace pesto:1with :1.Another possibility is that vncserver is no longer running.To check this,log into the Unix machine and run the ps -x command:(∼)100%ps -x This will list all the programs that are currently running under your user account.If one of the programs listed is Xvnc ,then the server is still running.Otherwise,you will have to relaunch the server.If all the problems described earlier have been checked and you are still unable to connect,it may be that there is a firewall in place between you and the Unix machine.To find out,talk to the network administrator for your organization.In many cases,it is possible forUser Fundamentals A.1D.5Current Protocols in Bioinformatics Supplement 17the administrator to create firewall exceptions that will allow VNC to run.Otherwise,the administrator may be able to offer a way to work around the problem using a product like Secure Shell (/).Finally,while working with VNCViewer,be careful not to log out of the Unix desktop manager.This will typically leave you unable to reconnect to the desktop again.If you do this inadvertently,simply log into Unix using a terminal emulator,kill the VNC server using vncserver -kill ,and restart it.Customizing VNCServerThe default desktop provided by vncserver is an early,primitive desktop manager called “twm.”Some people grow to like twm,but for most,it is nearly unusable.Fortunately the VNC desktop can be changed.To do this,you must have run vncserver at least once before.Kill vncserver,if it is still running,and then use a text editor to open and edit the file ∼/.vnc/xstartup .By default,this file contains the following lines:#!/bin/shxrdb $HOME/.Xresourcesxsetroot -solid greyxterm -geometry 80x24+10+10-ls -title ‘‘$VNCDESKTOP Desktop’’&twm &To change the desktop,replace twm on the last line with the command used to start up the desktop of choice.For example to start the KDE desktop manager,replace the last line with startkde &.The trick,of course,is knowing what command to put here.Table A.1D.1lists a number of popular desktop managers to try.Some may not be installed on the Unix machine that you work with.If you launch vncviewer and discover that no desktop manager is active (as indicated by “bare”windows without any frame or other decoration),you may need to indicate the full path to the window manager.For example,the Common Desktop Environment’s dtwm can be found at /usr/dt/bin/dtwm on many systems.Using the X Window SystemA more sophisticated way to establish a graphical connection to a remote Unix system is to use the X Window System ing X to connect to an application running on a remote machine is almost exactly the opposite of using VNC.Whereas in VNC you start by launching the VNC server application on the Unix machine and then connect to it using the VNC viewer client,X works by running an application on your desktop machine called the “X server.”When you launch graphical Unix applications,you then tell them to use your desktop machine for their windows,keyboard,and mouse.As described earlier,X is a standard part of Linux,Solaris,and other Unix systems,but must be installed as an option on MacOS X.For Microsoft Windows,the free Cygwin/X server,available from /,is recommended.This application provides bare-bones X functionality.For a richer set of configuration options,you may wish to purchase a commercial X server.The serversX Window System Survival GuideA.1D.6Supplement 17Current Protocols in BioinformaticsTable A.1D.1Some Popular Desktop Manager Programs Program Description blackbox An imitation of the NeXT desktop,found on some Linux systems.dtwm The Common Desktop Environment,found on many commercial Unix systems (but not Linux).fvwm2An uncluttered window manager commonly found on Linux systems.fvwm95An imitation of the MS Windows 95/98/ME desktop,commonly found on Linux systems.gnome-session The Gnome desktop environment,found on many Linux systems.mwm A basic desktop manager,commonly found on older Sun systems.startkde The K desktop environment,found on more recent Linux systems.olwm The Open Look desktop manager,found on many systems.wmaker Another imitation of the NeXT desktop,found on some Linux systems.that the author has used with the most success on Windows are Hummingbird Exceed ( )and WRQ ReflectionX ( ).Running remote X applications on MacOS X,Linux,and Solaris To launch a remote X application on a Unix system,open a shell window (the Terminal application on MacOS X).As described in APPENDIX 1C ,use SSH to log into the remote machine,but use the -Y option to tell SSH to forward the X session from the remote machine to the local machine:>ssh -Y login name@remote Replace login name and remote with your login name and the name or IP address of the remote machine.If you use the same account names on the local and remote machines,you can omit the login name.You will be prompted for a password.Once you are logged into the remote server,launch the desired application by typing its name on the command line.If all goes well,the application will start up and display its user interface on your local screen.You can then interact with it as though you were sitting on the remote desktop.On some older machines,SSH may not be installed.In this case,you can use telnet,but the recipe is more complex.First,determine the IP (internet)address of your local machine.From the command line,type:>/sbin/ifconfig This will display information about each of the network interfaces on the machine.This may include ethernet ports,wireless interfaces,and other interfaces.Embedded somewhere in that information is the IP address of your machine,which has the format XXX.XXX.XXX.XXX .There may be multiple such addresses;if you see an address of 127.0.0.1,you should ignore it (it is used internally)and use another one.For the purposes of this example,we will use 192.168.1.1as the IP address.Before telnetting to the remote machine,run the xhost command:>xhost +remote User Fundamentals A.1D.7Current Protocols in Bioinformatics Supplement17Figure A.1D.3In contrast to VNC,the default for most X servers is to open a different window for each running X application and to allow them to be displayed together on the desktop.This grants access to X applications running on the remote machine.Change remote to the name or address of the machine into which you will be logging.Now log into the remote machine using telnet,as described in APPENDIX 1C .Once you are logged in,type at the command line:>setenv DISPLAY 192.168.1.1:0Replace 192.168.1.1with the IP address of your desktop.This environment tells any X applications that you launch to use the indicated X server.The :0following the IP address tells the application to use the first X server found running on the machine (on a personal computer it is unlikely that there will ever be more than one X server running at a time).If you are using bash,ksh,or sh,set the environment variable like this:>bash$export DISPLAY=192.168.1.1:0Do not set DISPLAY if you logged in with SSH.SSH sets DISPLAY for you.Whether you logged in via SSH or telnet,you are now ready to launch a graphical application.From the shell,type xclock .This is a simple X application that shows a graphical clock.If everything is working,a clock will appear on your desktop screen.You can try this now with other graphical monly installed applications include xterm ,a command-line shell window,emacs ,a windowing text editor,and Mozilla Firefox,a Web browser.Figure A.1D.3shows a portion of a Windows desktop after launching the xclock and term applications.Notice that although the window frames follow normal MS Windows or Macintosh conventions,the window contents are decidedly Unix-like.When the author works with X remotely,he usually launches an xterm first and then launches other applications from within the xterm .The advantage of this is that the DISPLAY variable is inherited by the xterm shell,and does not need to be set again.X Window System Survival GuideA.1D.8Supplement 17Current Protocols in BioinformaticsIf your desktop machine has a stable DNS (Internet)name,like ,you can use that instead of the numeric IP address when you set the DISPLAY .However,most organizations and almost all home network connections assign IP addresses dynamically each time a personal computer is booted.This means that not only will your machine not have a DNS name,but it may have a different IP address each time you reboot it.In this case,you will have to look up the IP address each time you start a session with X.If X applications do not run,there are a number of things that might have gone wrong.If the command to launch the application terminates with a connection refused message or hangs indefinitely,chances are either that the IP address in the DISPLAY environment variable is incorrect or that the X server is not running on your desktop.Another possibility is there is a firewall system between the Unix host and your desk-top machine.Firewalls are typically configured to prevent incoming connections,and this usually includes blocking incoming connections from X applications.The best workaround for this is SSH with the --Y option,which usually circumvents firewall issues.You may need to discuss remote access options with your system unching an X session under Microsoft Windows Unlike the Macintosh,the Microsoft Windows operating system does not have a default X application,and you will have to install a third-party application.Details of using these X servers vary somewhat depending on the vendor.In the examples below,discussion will be provided on how to set up X connections using Cygwin/X,a free X server.Although the details will differ with other implementations,the general concepts will remain the same.To install Cygwin/X,go to and click “Install cygwin now”on the right-hand side of the page.This will take you to an installer for the Cygwin package.This application will prompt you for the location of the files to select (choose Install from Internet),and the place to install Cygwin (keep the default of C:\cygwin ).When prompted for the site to download from,choose an FTP site close to your region of the world.You will next be taken to a screen that prompts you to select which packages to install.The packages are organized hierarchically by topic.You may keep all the default selections,but you will need to add the “openssh”and “X11”packages to the list of packages to be installed.To add openssh,open up the Net section,scroll down until you see “openssh”,and click once on the icon that says Skip.The icon will change to show the version number of the openssh package,and a check box will appear to indicate that openssh will be installed (several other packages will also be activated—these are ones that openssh depends on).To install X11,scroll to the bottom of the package selection screen until you find the “X11”section.Click on the icon that says Default to change it to Install,then press Next at the bottom of the installer in order to begin installing the packages you selected.At the end of the install,you will be given the option to install icons on the desktop and the Start menu,which will be convenient to have.Once Cygwin/X is installed,starting the X server is a two-step process.First,double-click on the Cygwin icon on the desktop (or use the Start menu:select Start >All Programs >Cygwin >Cygwin Bash Shell).This will launch a small command window containing a Unix shell prompt on a black background.From this shell,start X by issuing the startx command:User Fundamentals A.1D.9Current Protocols in Bioinformatics Supplement 17>startx &Some diagnostic messages will print out,and after a brief pause another Unix shell window will appear.This one will have a white background.This is the xterm program running inside X.You can now safely minimize the black command window and issue all your commands from within the xterm window.To confirm that everything is working as expected,launch the xlock application from within the xterm window:>xclock&This will bring up the graphical X clock.You will find other standard X applications installed as menu items under the Start >All Programs >Cygwin-X menu.On MS Windows XP systems,the first time X is run,a dialog box will appear warning that the “Xwin”application has tried to open up a network port and that the built-in XP firewall has blocked it.Accept the offered option to unblock Xwin;otherwise remote X sessions will not work.If only accessing remote machines on your local area network (i.e.,inside your office LAN),then the firewall can be partially reactivated later by making the following selections from the Control Panel:Control Panel >Windows Firewall >Exceptions;next,double-click on Xwin,press the “Change Scope ...”button,and then select “My network (subnet)only.”This will allow Xwin to communicate with machines on your local area network,but not with machines elsewhere on the unching an xterm on a remote Unix machineThis example describes how to launch an xterm on a remote Unix machine using ssh.Assume the remote Unix machine is named remote and the user name on the remote machine is yourname .Type the following command at the xterm prompt:>ssh --f --Y login name@remote xterm yourname@remote host password:********This is similar to what was done previously when ssh was used to log into the remote machine from a Unix or Macintosh box,but now the --f switch is used to tell ssh to “fork”(Unix jargon)into the background and then run the “xterm”command on the remote machine.As before,the --Y switch causes the application’s X windows to be forwarded to the local machine.After being prompted for your password on the remote machine,if all goes well,a new xterm window will appear containing the command prompt from a shell running on the remote machine.You can now launch your favorite X Window System applications by typing the appropriate command lines in the xterm window.Obtaining a Unix desktopBy default,X runs in “multiple window”mode.In this mode,windows opened by remote X applications run on the regular PC desktop,intermixing with windows opened by local applications.An alternative is to run in “single”or “rooted”window mode.In this mode,the X server running on your local machine creates a single desktop window.You then connect to the remote machine and run a window manager on it.This will create the Unix desktop,its icons,and all the Unix application windows running inside the desktop window.This is handy if you want to access pop-up menus,icons and other niceties of the Unix desktopX Window System Survival GuideA.1D.10Supplement 17Current Protocols in Bioinformatics environment,but it does impose a noticeable demand upon performance,particularly when you are connecting across a slow network connection.The following recipe works with Cygwin/X on Microsoft Windows machines.First start Cygwin by clicking on its icon.When the black command window comes up,issue the xinit command rather than startx :>xinit A large window filled with an ugly herringbone pattern will appear.This is what the X root window looks like when no window manager is running inside it.The upper left corner of the root window will contain an xterm command window,but the window will lack a frame or title bar.You will now issue the command to start the window manager on the remote machine.Click on the root window to bring it to the front and type the command:>ssh --f --Y login name@remote startkde You will be prompted for your password on the remote machine as usual.After a brief pause,the KDE window manager will take control of the root window and add its menus,icons,and other user-interface elements.You can now launch applications from the start menu,or open up xterms on the remote machine.The original xterm will still be there,but it will take on the frame and title bar of given to it by the KDE window manager.You can safely minimize it to get it out of the way (but do not close the xterm window or the whole X server will exit).You can use the same recipe to launch other window managers.Simply replace startkde in the command above with any of the window managers listed in Table A.1D.1.On Macintosh and Unix machines,the recipe for obtaining a remote desktop is slightly different.First,open a terminal window on the local machine and type the following command:>Xnest :1--geometry 800x600&;xterm --display :1&Xnest is a X server “nested”inside the one the runs on your local machine.This command will bring up an 800×600–pixel root window with the default herringbone background and a frameless xterm.Switch to this window and type the ssh command to start the desktop manager of your choice on the remote machine:>ssh --f --Y login name@remote startkde As in the Cygwin/X recipe,the remote desktop manager will now take control and create its various icons,windows and menus.When you are finished,simply click the Close icon on the window title bar.Unfortunately the Xnest window cannot be resized once you create it.To work with a larger window,change the --geometry switch to something larger than 800×600.Standard monitors are now 1024×768and 1280×1024.If the Macintosh does not seem to recognize the Xnest or xterm commands,it may be because the directory that contains the corresponding executables is not in the PATH environment variable.Make sure that /usr/X11R6/bin is one of the directories listed in PATH and if necessary add it.User Fundamentals A.1D.11Current Protocols in Bioinformatics Supplement 17CONCLUSIONSUnix provides two popular solutions for running graphical programs across the network.VNC is easier to set up and use,but does not have the stunning array of features of the X Window System.The X Window System is quite powerful,but generally more difficult to set up and use.Contributed by Lincoln D.SteinCold Spring Harbor LaboratoryCold Spring Harbor,New York。