【CI/CD】Centos7 下载安装 Jenkins

 

一、Docker安装Jenkins

参考:

https://www.bilibili.com/video/BV11B4y1W7eH?p=5

  

安装Jenkins最新稳定版镜像:

[root@Centos8-1 ~]# docker pull jenkins/jenkins:lts
lts: Pulling from jenkins/jenkins
1339eaac5b67: Pull complete 
20401c7e91bc: Pull complete 
7138cd942003: Pull complete 
6d1b42f45e89: Pull complete 
98b0e135a912: Pull complete 
ed90436583b0: Pull complete 
b0b3716848f8: Pull complete 
4035b7550508: Pull complete 
e9a1c1f127f6: Pull complete 
6137d1289fb5: Pull complete 
213d8e7e603c: Pull complete 
42b46c55d38d: Pull complete 
8324f1380818: Pull complete 
2201f3ff6253: Pull complete 
Digest: sha256:c878e1aac1f5152a6234b33a10542c7f694b7c5c37de27191d1c173800853b93
Status: Downloaded newer image for jenkins/jenkins:lts
docker.io/jenkins/jenkins:lts
[root@Centos8-1 ~]#

  

创建Jenkins容器映射目录

[root@Centos8-1 ~]# mkdir -p  /docker-map/jenkins_home
[root@Centos8-1 ~]#

  

赋予可读写权限:

[root@Centos8-1 ~]# chown -R 1000 /docker-map/jenkins_home
[root@Centos8-1 ~]#

  

执行镜像创建容器和运行,并检查容器状态

[root@Centos8-1 ~]# docker run -di --name=jenkins -p 8080:8080 -v /docker-map/jenkins_home:/var/jenkins_home jenkins/jenkins:lts
853a6f8f7163120938a4746b6b59c88c9185093763d109603fe16a934e553a3f
[root@Centos8-1 ~]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS         PORTS                                                  NAMES
853a6f8f7163   jenkins/jenkins:lts   "/usr/bin/tini -- /u…"   5 seconds ago   Up 4 seconds   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp, 50000/tcp   jenkins
[root@Centos8-1 ~]#

  

获取admin用户初始密码:

注意是使用映射的目录访问获取,Jenkins页面提供的是容器的位置

[root@Centos8-1 ~]# cat /docker-map/jenkins_home/secrets/initialAdminPassword
7a13a207569a48018bab7f43ef15467b
[root@Centos8-1 ~]#

  

或者使用docker命令直接翻看容器日志:

[root@Centos8-1 ~]# docker logs jenkins
Running from: /usr/share/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2022-07-17 08:29:48.771+0000 [id=1]	INFO	org.eclipse.jetty.util.log.Log#initialized: Logging initialized @522ms to org.eclipse.jetty.util.log.JavaUtilLog
2022-07-17 08:29:48.863+0000 [id=1]	INFO	winstone.Logger#logInternal: Beginning extraction from war file
2022-07-17 08:29:49.836+0000 [id=1]	WARNING	o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2022-07-17 08:29:49.906+0000 [id=1]	INFO	org.eclipse.jetty.server.Server#doStart: jetty-9.4.45.v20220203; built: 2022-02-03T09:14:34.105Z; git: 4a0c91c0be53805e3fcffdcdcc9587d5301863db; jvm 11.0.15+10
2022-07-17 08:29:50.533+0000 [id=1]	INFO	o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2022-07-17 08:29:50.597+0000 [id=1]	INFO	o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2022-07-17 08:29:50.597+0000 [id=1]	INFO	o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2022-07-17 08:29:50.598+0000 [id=1]	INFO	o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 660000ms
2022-07-17 08:29:51.550+0000 [id=1]	INFO	hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2022-07-17 08:29:51.786+0000 [id=1]	INFO	o.e.j.s.handler.ContextHandler#doStart: Started w.@1c758545{Jenkins v2.346.2,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
2022-07-17 08:29:51.862+0000 [id=1]	INFO	o.e.j.server.AbstractConnector#doStart: Started ServerConnector@6492fab5{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2022-07-17 08:29:51.862+0000 [id=1]	INFO	org.eclipse.jetty.server.Server#doStart: Started @3615ms
2022-07-17 08:29:51.866+0000 [id=24]	INFO	winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2022-07-17 08:29:52.260+0000 [id=30]	INFO	jenkins.InitReactorRunner$1#onAttained: Started initialization
2022-07-17 08:29:52.319+0000 [id=29]	INFO	jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2022-07-17 08:29:53.441+0000 [id=28]	INFO	jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2022-07-17 08:29:53.446+0000 [id=28]	INFO	jenkins.InitReactorRunner$1#onAttained: Started all plugins
2022-07-17 08:29:53.472+0000 [id=29]	INFO	jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2022-07-17 08:29:54.163+0000 [id=30]	INFO	jenkins.InitReactorRunner$1#onAttained: System config loaded
2022-07-17 08:29:54.163+0000 [id=29]	INFO	jenkins.InitReactorRunner$1#onAttained: System config adapted
2022-07-17 08:29:54.163+0000 [id=29]	INFO	jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2022-07-17 08:29:54.164+0000 [id=29]	INFO	jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2022-07-17 08:29:54.242+0000 [id=44]	INFO	hudson.model.AsyncPeriodicWork#lambda$doRun$1: Started Download metadata
2022-07-17 08:29:54.255+0000 [id=44]	INFO	hudson.util.Retrier#start: Attempt #1 to do the action check updates server
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/var/jenkins_home/war/WEB-INF/lib/groovy-all-2.4.21.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2022-07-17 08:29:55.199+0000 [id=29]	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:

7a13a207569a48018bab7f43ef15467b

This may also be found at: /var/jenkins_home/secrets/initialAdminPassword

*************************************************************
*************************************************************
*************************************************************

2022-07-17 08:30:15.538+0000 [id=29]	INFO	jenkins.InitReactorRunner$1#onAttained: Completed initialization
2022-07-17 08:30:15.551+0000 [id=22]	INFO	hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and running
2022-07-17 08:32:20.809+0000 [id=44]	INFO	h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
2022-07-17 08:32:20.810+0000 [id=44]	INFO	hudson.util.Retrier#start: Performed the action check updates server successfully at the attempt #1
2022-07-17 08:32:20.812+0000 [id=44]	INFO	hudson.model.AsyncPeriodicWork#lambda$doRun$1: Finished Download metadata. 146,562 ms
[root@Centos8-1 ~]# 

 

二、普通War包安装Jenkins

https://www.jenkins.io

需要JDK环境,且配置了环境变量

在官网下载以后,可以直接使用java -jar的方式启动jenkins.war

也就是说可以向jar包的方式运行war包

为了方便启停Jenkins,这里编写Shell脚本来控制启停

 

start.sh

#!/bin/sh
PIDFILE="./jenkins.pid"
LOGFILE="./jenkins.log"
if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE"); then
echo "jenkins is already running..."
exit 1

fi
nohup java -jar jenkins.war > $LOGFILE & echo $! > $PIDFILE
echo "jenkins start..."

  

stop.sh

#!/bin/sh
PIDFILE="./jenkins.pid"

if [ ! -f "$PIDFILE" ] || ! kill -0 "$(cat "$PIDFILE")"; then
echo "jenkins not running..."

else
echo "stopping jenkins..."
PID="$(cat "$PIDFILE")"
kill -9 $PID
rm "$PIDFILE"

echo "....jenkins stopped"
fi

  

赋予可执行权限:

chmod +x start.sh
chmod +x stop.sh

  

初始化之后分配的随机密钥文件:

/root/.jenkins/secrets/initialAdminPassword

  

 

posted @ 2022-08-13 16:35  emdzz  阅读(358)  评论(0编辑  收藏  举报