Original: http://www.cnblogs.com/itech/archive/2011/11/11/2245849.html
A Jenkins master/slave architecture
Master/slave is equivalent to the concept of server and agent. Master provides a web interface for users to manage jobs and Slave,job can run on master native or be assigned to slave. A master can associate multiple slave to serve different configurations of a different job or the same job.
When the job is assigned to run on slave, at this time, master and slave are actually established two-way byte stream connection, where the connection method mainly has the following several:
1) master launches slave via SSH
Jenkins has a built-in SSH client implementation that can be used to communicate with the remote sshd to start the slave agent. This is the most convenient way to slave the *unix system, as the *unix system is generally installed with sshd by default. When creating SSH connection slave, you need to provide slave host name, username and SSH certificate. Create the Public/private keys, and then copy the public key to the ~/.ssh/authorized_keys in slave and save the private key to a PPK file on master. Jenkins will automatically complete other configuration tasks, such as binary for copy slave agent, start and stop slave. But your job runs depend on other projects that you set yourself.
2) master starts Windows slave via wmi+dcom
For Windows Slave,jenkins can use Windows2000 and later built-in remote management features (wmi+dcom), you only need to provide the slave have administrator access to the user name and password, Jenkins will be remote to create windows The service then remotely starts and stops them
This is the most convenient method for Windows systems, but this method does not allow GUI programs with display interaction to run.
Note: The name of this method slave (note) is important and will be used as the slave address to access the other types of links slave
3) Implement your own script to start the slave
If the above package is not flexible enough, you can implement your own script to start slave. You need to put the startup script in Master and tell Jenkins Master to invoke the script to start slave when needed.
Typically, your script uses a remote program execution mechanism, such as Ssh,rsh, or a similar method (in Windows, which can be done by Cygwin or psexec),
At the end of the script you need to perform similar java-jar slave.jar to start slave. Slave.jar can be downloaded from Http://yourjenkinsserver:port/jnlpjars/slave.jar, or you can download this slave.jar at the beginning of the script to ensure Slave.jar the correct version. However, if you use SSH slave plugin, this plugin will automatically update Slave.jar.
4) Start slave via Java Web start
Jave Web Start (JNLP) is another way to start slave. In this way you need to log in to slave, open the browser, open the Slave configuration page to connect. You can also install Windows service to make slave run in the background.
If you need to run a program that requires UI interaction, use the following method: Create a Jenkins user on a slave system, set up automatic login, add a shortcut to the slave jnlp file in the Startup items of the system, and enable slave to start automatically when the system logs in.
5) direct Start slave
This approach is similar to Java Web Start, which makes it easy to run slave as daemon on the *unix system. You need to configure slave to connect to the JNLP type and then execute it on the slave machine
Java-jar Slave.jar-jnlpurl HTTP://YOURSERVER:PORT/COMPUTER/SLAVE-NAME/SLAVE-AGENT.JNLP
Good advice for two slave configurations
* Each slave has a user Jenkins, all machines use the same UID and GID, making the management of slave easier;
* Each machine on the Jenkins user's home directory is the same/home/jenkins, with the same directory structure makes maintenance simple;
* All slave run sshd,windows run Cygwin sshd;
* All slave installed NTP client, used to synchronize with the same NTP server;
* Use the script sh to automatically configure the slave environment, such as creating Jenkins users, installing sshd, installing java,ant,maven, etc.;
* Use scripts to start slave, ensuring that slave always runs under the same parameters:
#!/bin/bash java_home=/opt/sun/jdk1.6.0_04 path= $PATH: $JAVA _home/bin export PATH Java-jar/var/jenkins/bin/slave.jar
Jenkins Master/slave Architecture