安装Jenkins
注: 此部分内容是持续更新的.
重要:
此部分是入门手册的一部分。提供了在不同平台上的Jendins的基本配置。但是它没有完全覆盖Jenkins安装的选项,可以参考Jenkins高级安装。
概述
安装前准备
系统需求
警告:这些是开始的入口。完整的讨论请参考“硬件建议讨论”
推荐的最小配置:
• Java 8 (JRE 或 JDK)
• 256MB内存
• 1GB+磁盘空间
推荐的小团队配置:
• Java 8
• 1GB+内存
• 50GB+磁盘空间
试验,分期或生产?
如何配置Jenkins取决于在何种场景下使用。本部分的目标是讲述Jenkins的初级用户和试验用法。其他情况,请查看Jenkins高级安装。
单机或服务程序?
Jenkins可以在内置的web服务器(Jetty)中独立运行。其也可以在已有框架中做为servlet运行,例如Tomcat或Glassfish应用服务器。本部分以独立安装和运行为例。其他情况,请查看Jenkins高级安装。
安装
警告:这里的非生产环境的干净安装指导。如果你有一个非生产环境的Jenkins服务在系统中运行,想要更新,请参考“更新Jenkins”部分。如果要安装或更新生产环境的Jenkins服务器,请参考Jenkins高级安装。
Unix/Linux
Debian/Ubuntu
在Debian系的系统上,例如Ubuntu, 可以通过apt安装Jenkins.
在apt仓库中,有最新版本的Jenkins和以前的稳定版本.
wget -q -O -
https://pkg.jenkins.io/debian/jenkins.io.key
| sudo apt-key add -
sudo sh -c 'echo deb
http://pkg.jenkins.io/debian-stable
binary/ >
/etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins
这个安装包将:
• 安装Jenkins,在启动时运行的守护进程。要获取更多细节,请参考/etc/init.d/jenkins。
• 创建一个‘jenkins’用户来运行服务。
• 将控制台日志输出指向/var/log/jenkins/jenkins.log日志文件。使用Jenkins时遇到问题时,请检查文件。
• 设置/etc/default/jenkins使用的配置参数,例如:JENKINS_HOME
• 设置Jenkins在端口8080监听。 在浏览器中访问这个端口,来启动配置。
注意:如果使用/etc/init.d/jenkins文件启动Jenkins失败,可以修改/etc/default/jenkins文件,使用----HTTP_PORT=8081替换----HTTP_PORT=8080这行,这里,“8081”表示使用的是其他可用的端口。
OpenIndiana Hipster
在OpenIndiana Hipster系统上运行Jenkins,可以使用IPS安装在本地或者全局区。
注意:免责声明: 此平台不受Jenkins团队的官方支持,需要自行承担风险。本节讲述的打包和集成,是由OpenIndiana Hipster团队提供的,在操作环境中打包到通用的jenkins.war包中使用。
一般情况下,每周会打包独立服务器的最新版本,只运行如下命令:
pkg install jenkins
svcadm enable jenkins
独立服务的常规集成打包将会执行如下操作:
• 创建jenkins用户运行服务,并设置/var/lib/jenkins目录所属人.
• 下载OpenJDK8和运行Jenkins需要的其他包,包括最新版的jenkins.war包,包括每周的jenkins包。
注意安全:长期支持的Jenkins发布版目前不支持基于OpenZFS系统,因此,当前不提供包。
• 安装Jenkins做为SMF服务实例 (svc:/network/http:jenkins) which can then be
enabled with the svcadm command demonstrated above.
• 启动Jenkins在8080口监听.
• Configure the log output to be managed by SMF at /var/svc/log/network-http:jenkins.log.
Once Jenkins is running, consult the log (/var/svc/log/network-http:jenkins.log) to retrieve the
generated administrator password for the initial set up of Jenkins, usually it will be found at
/var/lib/jenkins/home/secrets/initialAdminPassword. Then navigate to localhost:8080 to complete
configuration of the Jenkins instance.
To change attributes of the service, such as environment variables like JENKINS_HOME or the port
number used for the Jetty web server, use the svccfg utility:
svccfg -s svc:/network/http:jenkins editprop
svcadm refresh svc:/network/http:jenkins
You can also refer to /lib/svc/manifest/network/jenkins-standalone.xml for more details and
comments about currently supported tunables of the SMF service. Note that the jenkins user
account created by the packaging is specially privileged to allow binding to port numbers under
1024.
The current status of Jenkins-related packages available for the given release of OpenIndiana can
be queried with:
pkg info -r '*jenkins*'
Upgrades to the package can be performed by updating the entire operating environment with pkg
update, or specifically for Jenkins core software with:
pkg update jenkins-core-weekly
CAUTION
Procedure for updating the package will restart the currently running Jenkins
process. Make sure to prepare it for shutdown and finish all running jobs
before updating, if needed.
Solaris, OmniOS, SmartOS, and other siblings
Generally it should suffice to install Java 8 and download the jenkins.war and run it as a standalone
process or under an application server such as Apache Tomcat.
Some caveats apply:
• Headless JVM and fonts: For OpenJDK builds on minimalized-footprint systems, there may be
issues running the headless JVM, because Jenkins needs some fonts to render certain pages.
• ZFS-related JVM crashes: When Jenkins runs on a system detected as a SunOS, it tries to load
integration for advanced ZFS features using the bundled libzfs.jar which maps calls from Java
to native libzfs.so routines provided by the host OS. Unfortunately, that library was made for
binary utilities built and bundled by the OS along with it at the same time, and was never
intended as a stable interface exposed to consumers. As the forks of Solaris legacy, including
ZFS and later the OpenZFS initiative evolved, many different binary function signatures were
provided by different host operating systems - and when Jenkins libzfs.jar invoked the wrong
signature, the whole JVM process crashed. A solution was proposed and integrated in
jenkins.war since weekly release 2.55 (and not yet in any LTS to date) which enables the
administrator to configure which function signatures should be used for each function known
to have different variants, apply it to their application server initialization options and then run
and update the generic jenkins.war without further workarounds. See the libzfs4j Git repository
for more details, including a script to try and "lock-pick" the configuration needed for your
particular distribution (in particular if your kernel updates bring a new incompatible
libzfs.so).
Also note that forks of the OpenZFS initiative may provide ZFS on various BSD, Linux, and macOS
distributions. Once Jenkins supports detecting ZFS capabilities, rather than relying on the SunOS
check, the above caveats for ZFS integration with Jenkins should be considered.
macOS
从网站安装,使用安装包:
• 下载最新安装包;
• 打开安装包,根据指导安装。
Jenkins也可以使用brew安装:
• 安装最新的发布版:
brew install jenkins
• 安装LTS版:
brew install jenkins-lts
Windows
从网站安装,使用安装包:
• 下载最新安装包;
• 打开安装包,根据指导安装。
Docker
使用前,要求必须已经在机器上正确的安装了Docker. 查看Docker安装手册查看细节。
首先,从Docker仓库中下载官方的Jenkins镜像:
docker pull jenkins/jenkins
下一步,使用这个镜像运行一个容器,映射容器中的数据目录到主机目录中,例如,下面例子中容器的/var/jenkins_home目录映射到主机的当前路径的jenkins/目录。Jenkins的8080端口暴露在主机的49001端口。
docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home -t jenkins/jenkins
其他
参考高级Jenkins安装。
安装后操作 (安装向导)
为Jenkins创建管理员账号和密码
Jenkins在第一次运行时,初始配置是安全的。不配置用户名和密码是不能访问的,端口开放也是受限的。 在初次运行Jenkins时,Jenkins会在控制台日志中产生和打印一个安全token:
*************************************************************
Jenkins initial setup is required. A security token is required to proceed.
Please use the following security token to proceed to installation:
41d2b60b0e4cb5bf2025d33b21cb
*************************************************************
上面的每个平台的安装向导都在默认位置包含上面的信息,可以到日志输出文件中查找。在第一次打开Jenkins的界面时,需要输入此token. 如果在安装向导中跳过用户创建步骤,则此token也将做为用户‘admin’的默认密码。
初始化插件安装
安装向导会为Jenkins服务器安装初始的插件。大部分应用场景的基本推荐插件都是可用的。用户也可以在安装向导或安装后根据需要随时增加插件。