Jenkins自动化环境部署(1)
- Jenkins
-
- 1. 下载并配置环境变量
-
- 1. java
- 2. jenkins
- 1. 启动Jenkins
Jenkins
Jenkins是开源CI&CD软件领导者, 支持构建、部署、自动化的插件超过1000个, 满足任何项目的需要
1. 下载并配置环境变量
-
:
256MB可用内存 1GB可用磁盘空间(作为一个Docker容器运行jenkins的话推荐10GB)
-
小团队推荐的硬件配置:
1GB 可用内存 50 GB 磁盘空间可用
-
:
Java 8:—无论是Java运行时环境(JRE)还是Java开发工具包(JDK)都可以。
- 2.164 (2019-02) 更新版本:Java 8 或 Java 11
- 2.54 (2017-04) 和更新版:Java 8
- 1.612 (2015-05) 和更新版:Java 7 我们下载jenkins>2.164, java使用java11,PC系统Ubuntu20.04
1. java
-
:
https://www.oracle.com/java/technologies/javase/jdk11-archive-downloads.html
需要登录oracle 账号
-
下载后解压, 然后配置java到系统环境变量中,添加下面到~/.bashrc中
export JAVA_VERSION="jdk-11.0.13" export JAVA_HOME="${HOME}/Software/${JAVA_VERSION}" export JRE_HOME="${JAVA_HOME}/jre" export CLASSSPATH="${JAVA_HOME}/lib:${JRE_HOME}/lib" export PATH="${JAVA_HOME}/bin:${PATH}"
检查配置是否有效
user@pc:~$ source ~/.bashrc user@pc:~$ java --version java 11.0.13 2021-10-19 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.13 10-LTS-370) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.13 10-LTS-370, mixed mode)
2. jenkins
-
:
https://www.jenkins.io/download/
下载lts版本war包:
- 配置jenkins将以下添加到系统环境变量中~/.bashrc中
export JENKINS_HOME="${HOME}/ci/jenkins_master"
将jenkins.war放到JENKINS_HOME目录中
user@pc:~$ ls ci/jenkins_master/jenkins.war ci/jenkins_master/jenkins.war
1. 启动Jenkins
- 前台启动命令:java -jar jenkins.war
- 后台启动命令:nohup java -jar jenkins.war &
user@pc:~/ci/jenkins_master$ ~/ci/jenkins_master$ java -jar jenkins.war --help Running from: /home/user/ci/jenkins_master/jenkins.war webroot: EnvVars.masterEnvVars.get("JENKINS_HOME") Jenkins Automation Server Engine 2.346.1 Usage: java -jar jenkins.war [--option=value] [--option=value]
Options:
--webroot = folder where the WAR file is expanded into. Default is ${
JENKINS_HOME}/war
--pluginroot = folder where the plugin archives are expanded into. Default is ${
JENKINS_HOME}/plugins
(NOTE: this option does not change the directory where the plugin archives are stored)
--extractedFilesFolder = folder where extracted files are to be located. Default is the temp folder
--logfile = redirect log messages to this file
--enable-future-java = allows running with new Java versions which are not fully supported (class version 52 and above)
--javaHome = Override the JAVA_HOME variable
--toolsJar = The location of tools.jar. Default is JAVA_HOME/lib/tools.jar
--config = load configuration properties from here. Default is ./winstone.properties
--prefix = add this prefix to all URLs (eg http://localhost:8080/prefix/resource). Default is none
--commonLibFolder = folder for additional jar files. Default is ./lib
--extraLibFolder = folder for additional jar files to add to Jetty classloader
--logThrowingLineNo = show the line no that logged the message (slow). Default is false
--logThrowingThread = show the thread that logged the message. Default is false
--debug = set the level of debug msgs (1-9). Default is 5 (INFO level)
--httpPort = set the http listening port. -1 to disable, Default is 8080
--httpListenAddress = set the http listening address. Default is all interfaces
--httpKeepAliveTimeout = how long idle HTTP keep-alive connections are kept around (in ms; default 5000)?
--httpsPort = set the https listening port. -1 to disable, Default is disabled
--httpsListenAddress = set the https listening address. Default is all interfaces
--httpsKeepAliveTimeout = how long idle HTTPS keep-alive connections are kept around (in ms; default 5000)?
--httpsKeyStore = the location of the SSL KeyStore file. Default is ./winstone.ks
--httpsKeyStorePassword = the password for the SSL KeyStore file. Default is null
--httpsKeyManagerType = the SSL KeyManagerFactory type (eg SunX509, IbmX509). Default is SunX509
--httpsPrivateKey = this switch with --httpsCertificate can be used to run HTTPS with OpenSSL secret key
/ --httpsCertificate file and the corresponding certificate file
--httpsRedirectHttp = redirect http requests to https (requires both --httpPort and --httpsPort)
--http2Port = set the http2 listening port. -1 to disable, Default is disabled
--http2ListenAddress = set the http2 listening address. Default is all interfaces
--excludeCipherSuites = set the ciphers to exclude (comma separated, use blank quote " " to exclude none) (default is
// Exclude weak / insecure ciphers
"^.*_(MD5|SHA|SHA1)$",
// Exclude ciphers that don't support forward secrecy
"^TLS_RSA_.*$",
// The following exclusions are present to cleanup known bad cipher
// suites that may be accidentally included via include patterns.
// The default enabled cipher list in Java will not include these
// (but they are available in the supported list).
"^SSL_.*$",
"^.*_NULL_.*$",
"^.*_anon_.*$"
--controlPort = set the shutdown/control port. -1 to disable, Default disabled
--useJasper = enable jasper JSP handling (true/false). Default is false
--sessionTimeout = set the http session timeout value in minutes. Default to what webapp specifies, and then to 60 minutes
--sessionEviction = set the session eviction timeout for idle sessions in seconds. Default value is 180. -1 never evict, 0 evict on exit
--mimeTypes=ARG = define additional MIME type mappings. ARG would be EXT=MIMETYPE:EXT=MIMETYPE:...
(e.g., xls=application/vnd.ms-excel:wmf=application/x-msmetafile)
--requestHeaderSize=N = set the maximum size in bytes of the request header. Default is 8192.
--maxParamCount=N = set the max number of parameters allowed in a form submission to protect
against hash DoS attack (oCERT #2011-003). Default is 10000.
--useJmx = Enable Jetty Jmx
--qtpMaxThreadsCount = max threads number when using Jetty Queued Thread Pool
--jettyAcceptorsCount = Jetty Acceptors number
--jettySelectorsCount = Jetty Selectors number
--usage / --help = show this message
Security options:
--realmClassName = Set the realm class to use for user authentication. Defaults to ArgumentsRealm class
--argumentsRealm.passwd.<user> = Password for user <user>. Only valid for the ArgumentsRealm realm class
--argumentsRealm.roles.<user> = Roles for user <user> (comma separated). Only valid for the ArgumentsRealm realm class
--fileRealm.configFile = File containing users/passwds/roles. Only valid for the FileRealm realm class
Access logging:
--accessLoggerClassName = Set the access logger class to use for user authentication. Defaults to disabled
--simpleAccessLogger.format = The log format to use. Supports combined/common/resin/custom (SimpleAccessLogger only)
--simpleAccessLogger.file = The location pattern for the log file(SimpleAccessLogger only)
启动Jenkins
user@pc:~/ci$ java -jar ${
JENKINS_HOME}/jenkins.war --httpPort=8080 --prefix="jenkins"
Running from: /home/user/ci/jenkins_master/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
2022-07-07 03:31:05.987+0000 [id=1] INFO org.eclipse.jetty.util.log.Log#initialized: Logging initialized @338ms to org.eclipse.jetty.util.log.JavaUtilLog
2022-07-07 03:31:06.075+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
2022-07-07 03:31:06.914+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.13+10-LTS-370
2022-07-07 03:31:07.183+0000 [id=1] INFO o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for jenkins, did not find org.eclipse.jetty.jsp.JettyJspServlet
2022-07-07 03:31:07.209+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2022-07-07 03:31:07.209+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2022-07-07 03:31:07.209+0000 [id=1] INFO o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 600000ms
2022-07-07 03:31:07.658+0000 [id=1] INFO hudson.WebAppMain#contextInitialized: Jenkins home directory: /home/user/ci/jenkins_master found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
2022-07-07 03:31:08.578+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started w.@5fac521d{Jenkins v2.346.1,jenkins,file:///home/user/ci/jenkins_master/war/,AVAILABLE}{/home/cixi.geng1/ci/jenkins_master/war}
2022-07-07 03:31:08.608+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart: Started ServerConnector@3bcbb589{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2022-07-07 03:31:08.608+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: Started @2961ms
2022-07-07 03:31:08.609+0000 [id=25] INFO winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2022-07-07 03:31:08.938+0000 [id=32] INFO jenkins.InitReactorRunner$1#onAttained: Started initialization
2022-07-07 03:31:08.940+0000 [id=52] INFO jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2022-07-07 03:31:09.392+0000 [id=47] INFO jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2022-07-07 03:31:09.395+0000 [id=53] INFO jenkins.InitReactorRunner$1#onAttained: Started all plugins
2022-07-07 03:31:09.399+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2022-07-07 03:31:09.919+0000 [id=40] INFO jenkins.InitReactorRunner$1#onAttained: System config loaded
2022-07-07 03:31:09.919+0000 [id=45] INFO jenkins.InitReactorRunner$1#onAttained: System config adapted
2022-07-07 03:31:09.920+0000 [id=48] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2022-07-07 03:31:09.920+0000 [id=52] INFO jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2022-07-07 03:31:09.931+0000 [id=67] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$1: Started Download metadata
2022-07-07 03:31:09.988+0000 [id=67] 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:/home/user/ci/jenkins_master/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-07 03:31:10.652+0000 [id=42] 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:
ad116ced8c7e4f33896050cd2e420690
This may also be found at: /home/user/ci/jenkins_master/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
浏览器输入 http://ip:8080
输入管理员密码登录jenkins 安装默认插件 创建Admin用户 配置完成