![找不到单位 jenkins.service](https://linux22.com/image/12507/%E6%89%BE%E4%B8%8D%E5%88%B0%E5%8D%95%E4%BD%8D%20jenkins.service.png)
我正在尝试在 Centos 7 机器上启动 Jenkins。我正在尝试将 Jenkins 文件夹从另一台计算机复制到这台计算机并在此处启动它而不是下载。我将整个 Jenkins 文件复制到var/lib/jenkins
新机器中的 / 文件夹中。我运行以下命令:
java -jar jenkins.war
我得到以下日志:
Running from: /var/lib/jenkins/jenkins.war
webroot: $user.home/.jenkins
2019-12-23 19:50:24.875+0000 [id=1] INFO org.eclipse.jetty.util.log.Log#initialized: Logging initialized @510ms to org.eclipse.jetty.util.log.JavaUtilLog
2019-12-23 19:50:25.019+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
2019-12-23 19:50:26.607+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2019-12-23 19:50:26.676+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: jetty-9.4.z-SNAPSHOT; built: 2019-05-02T00:04:53.875Z; git: e1bc35120a6617ee3df052294e433f3a25ce7097; jvm 1.8.0_232-b09
2019-12-23 19:50:27.038+0000 [id=1] INFO o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2019-12-23 19:50:27.111+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2019-12-23 19:50:27.111+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2019-12-23 19:50:27.116+0000 [id=1] INFO o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 660000ms
Jenkins home directory: /root/.jenkins found at: $user.home/.jenkins
2019-12-23 19:50:27.795+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started w.@782a4fff{Jenkins v2.190.1,/,file:///root/.jenkins/war/,AVAILABLE}{/root/.jenkins/war}
2019-12-23 19:50:27.818+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart: Started ServerConnector@1040be71{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
2019-12-23 19:50:27.818+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: Started @3454ms
2019-12-23 19:50:27.819+0000 [id=21] INFO winstone.Logger#logInternal: Winstone Servlet Engine v4.0 running: controlPort=disabled
2019-12-23 19:50:29.635+0000 [id=28] INFO jenkins.InitReactorRunner$1#onAttained: Started initialization
2019-12-23 19:50:29.674+0000 [id=28] INFO jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2019-12-23 19:50:31.654+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2019-12-23 19:50:31.666+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Started all plugins
2019-12-23 19:50:31.684+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2019-12-23 19:50:32.651+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2019-12-23 19:50:32.691+0000 [id=46] INFO hudson.model.AsyncPeriodicWork$1#run: Started Download metadata
2019-12-23 19:50:32.708+0000 [id=46] INFO hudson.util.Retrier#start: Attempt #1 to do the action check updates server
2019-12-23 19:50:33.763+0000 [id=32] INFO o.s.c.s.AbstractApplicationContext#prepareRefresh: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@3a900fc3: display name [Root WebApplicationContext]; startup date [Mon Dec 23 14:50:33 EST 2019]; root of context hierarchy
2019-12-23 19:50:33.764+0000 [id=32] INFO o.s.c.s.AbstractApplicationContext#obtainFreshBeanFactory: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@3a900fc3]: org.springframework.beans.factory.support.DefaultListableBeanFactory@44b26de3
2019-12-23 19:50:33.777+0000 [id=32] INFO o.s.b.f.s.DefaultListableBeanFactory#preInstantiateSingletons: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@44b26de3: defining beans [authenticationManager]; root of factory hierarchy
2019-12-23 19:50:33.986+0000 [id=32] INFO o.s.c.s.AbstractApplicationContext#prepareRefresh: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@16d60366: display name [Root WebApplicationContext]; startup date [Mon Dec 23 14:50:33 EST 2019]; root of context hierarchy
2019-12-23 19:50:33.987+0000 [id=32] INFO o.s.c.s.AbstractApplicationContext#obtainFreshBeanFactory: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@16d60366]: org.springframework.beans.factory.support.DefaultListableBeanFactory@53d5b029
2019-12-23 19:50:33.987+0000 [id=32] INFO o.s.b.f.s.DefaultListableBeanFactory#preInstantiateSingletons: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@53d5b029: defining beans [filter,legacy]; root of factory hierarchy
2019-12-23 19:50:34.237+0000 [id=32] INFO jenkins.install.SetupWizard#init:
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
This may also be found at: /root/.jenkins/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
2019-12-23 19:50:53.162+0000 [id=46] INFO hudson.util.Retrier#start: The attempt #1 to do the action check updates server failed with an allowed exception:
java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:607)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1162)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1056)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1570)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:268)
at hudson.model.DownloadService.loadJSON(DownloadService.java:167)
at hudson.model.UpdateSite.updateDirectlyNow(UpdateSite.java:189)
at hudson.PluginManager.checkUpdatesServer(PluginManager.java:1762)
at hudson.util.Retrier.start(Retrier.java:62)
at hudson.PluginManager.doCheckUpdatesServer(PluginManager.java:1733)
at jenkins.model.DownloadSettings$DailyCheck.execute(DownloadSettings.java:130)
at hudson.model.AsyncPeriodicWork$1.run(AsyncPeriodicWork.java:101)
at java.lang.Thread.run(Thread.java:748)
2019-12-23 19:50:53.163+0000 [id=46] INFO hudson.util.Retrier#start: Calling the listener of the allowed exception 'connect timed out' at the attempt #1 to do the action check updates server
2019-12-23 19:50:53.165+0000 [id=46] INFO hudson.util.Retrier#start: Attempted the action check updates server for 1 time(s) with no success
2019-12-23 19:50:53.166+0000 [id=46] SEVERE hudson.PluginManager#doCheckUpdatesServer: Error checking update sites for 1 attempt(s). Last exception was: SocketTimeoutException: connect timed out
2019-12-23 19:50:53.170+0000 [id=46] INFO hudson.model.AsyncPeriodicWork$1#run: Finished Download metadata. 20,477 ms
2019-12-23 19:50:54.258+0000 [id=32] WARNING hudson.model.UpdateCenter#updateDefaultSite: Upgrading Jenkins. Failed to update the default Update Site 'default'. Plugin upgrades may fail.
java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:607)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1162)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1056)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1570)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:268)
at hudson.model.DownloadService.loadJSON(DownloadService.java:167)
at hudson.model.UpdateSite.updateDirectlyNow(UpdateSite.java:189)
at hudson.model.UpdateCenter.updateDefaultSite(UpdateCenter.java:2456)
at jenkins.install.SetupWizard.init(SetupWizard.java:168)
at jenkins.install.InstallState$InitialSecuritySetup.initializeState(InstallState.java:166)
at jenkins.model.Jenkins.setInstallState(Jenkins.java:1089)
at jenkins.install.InstallUtil.proceedToNextStateFrom(InstallUtil.java:96)
at jenkins.install.InstallState$Unknown.initializeState(InstallState.java:84)
at jenkins.model.Jenkins$16.run(Jenkins.java:3277)
at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:169)
at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296)
at jenkins.model.Jenkins$5.runTask(Jenkins.java:1118)
at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214)
at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
2019-12-23 19:50:54.273+0000 [id=32] INFO jenkins.InitReactorRunner$1#onAttained: Completed initialization
2019-12-23 19:50:54.302+0000 [id=20] INFO hudson.WebAppMain$3#run: Jenkins is fully up and running
日志清楚地表明 Jenkins 已启动并正在运行。但是当我尝试检查状态时sudo service jenkins status
,出现以下错误:
Unit jenkins.service could not be found.
我不确定我错过了什么
答案1
它说找不到该单元,因为 Jenkins 包设置不正确。以下命令将解决您的问题..
$ sudo yum update –y
$ sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins.io/redhat/jenkins.repo
$ sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
$ sudo yum install jenkins -y
答案2
在 AWS ec2 实例上安装 Jenkins 时遇到了同样的问题。以下命令对我有用。
sudo amazon-linux-extras install epel -y
sudo yum update -y
sudo yum install jenkins java-1.8.0-openjdk-devel
答案3
我想在这个答案中提到一些我认为可以对您有所帮助的事情:
1)问题
您提到的问题:
Unit jenkins.service could not be found.
发生这种情况是因为当您运行 war 文件时,未创建单元文件。
如果您使用默认安装(此处定义:https://pkg.jenkins.io/redhat-stable/)在您以前的机器上,您可以在 处找到单元文件/etc/init.d/jenkins
。我不太确定仅将文件复制到新计算机是否可以解决您的所有问题。
2) CentOS 7 和 Systemd
CentOS 7 使用系统D单元文件而不是SysV 初始化脚本,如果您看一下,/etc/init.d/README
您可以获得有关 CentOS 如何管理放置在该目录中的 init 文件的更多详细信息。
...传统的初始化脚本继续在 systemd 系统上运行。初始化脚本 /etc/rc.d/init.d/foobar 在系统初始化期间隐式映射到服务单元 foobar.service 中。
将来,init 文件可能会转换为本机 systemd 单元文件,并放置在目录中/etc/systemd/system
。
3)我的推荐
我建议您安装 RPM 软件包或使用 docker 映像(我的首选)。所有细节都在官方文档中:
https://jenkins.io/doc/book/installing/
请告诉我这是否有帮助。
答案4
我已经从 Docker 安装了 Jenkins
- 直接从 docker 拉取 jenkins 镜像 - 不知何故无法工作
以下是我为使其正常工作而采取的步骤:
- docker 镜像-a
- 删除 jenkins 镜像 :: docker rmi -f image_id
现在,我们需要在我们的操作系统(这里是Linux)中安装jenkins
有效!干杯!