官方文档:https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Red+Hat+distributions#InstallingJenkinsonRedHatdistributions-ImportantNoteonCentOSJava
安装jenkins
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
sudo yum install jenkins
这里需要注意的是java的版本要求。
类似于
java -version
java version "1.5.0"
gij (GNU libgcj) version 4.4. (Red Hat 4.4.-)
jenkins需要GCJ版本的Java,不支持GNU版本的Java。因而需要注意
正确的版本
java -version
java version "1.7.0_79"
OpenJDK Runtime Environment (rhel-2.5.5.1.el6_6-x86_64 u79-b14)
OpenJDK -Bit Server VM (build 24.79-b02, mixed mode)
启动、关闭和重启jenkins
sudo service jenkins start/stop/restart
sudo chkconfig jenkins on
启动时报如下异常:
SEVERE: Container startup failed
java.io.IOException: Failed to start Jetty
at winstone.Launcher.<init>(Launcher.java:)
at winstone.Launcher.main(Launcher.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at Main._main(Main.java:)
at Main.main(Main.java:)
Caused by: java.net.BindException: 地址已在使用
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:)
at sun.nio.ch.Net.bind(Net.java:)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:)
at org.eclipse.jetty.server.nio.SelectChannelConnector.open(SelectChannelConnector.java:)
at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:)
at org.eclipse.jetty.server.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:)
at org.eclipse.jetty.server.Server.doStart(Server.java:)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:)
at winstone.Launcher.<init>(Launcher.java:)
... more
查找jenkins配置文件
[root@xxxxxxx ~]# find / -name jenkins
/usr/lib/jenkins
/etc/rc.d/init.d/jenkins
/etc/logrotate.d/jenkins
/etc/sysconfig/jenkins
/var/lib/jenkins
/var/lib/yum/repos/x86_64//jenkins
/var/cache/jenkins
/var/cache/yum/x86_64//jenkins
/var/log/jenkins
修改jenkins端口
vi /etc/sysconfig/jenkins
JENKINS_PORT修改为指定端口
重启
service jenkins start
将端口添加到防火墙并重启
通过http://ip:端口,进行访问即可