centos 7中安装jenkins

1.安装java11

[root@localhost ~]# yum install -y java-11-openjdk-devel
[root@localhost ~]# java --version
openjdk 11.0.23 2024-04-16 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.23.0.9-2.el7_9) (build 11.0.23+9-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.23.0.9-2.el7_9) (build 11.0.23+9-LTS, mixed mode, sharing)
[root@localhost ~]# which java
/usr/bin/java

2.安装jenkins

[root@localhost ~]# wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.516.2-1.1.noarch.rpm
[root@localhost ~]# rpm -ivh jenkins-2.516.2-1.1.noarch.rpm 
warning: jenkins-2.516.2-1.1.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID ef5975ca: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:jenkins-2.516.2-1.1              ################################# [100%]
[root@localhost ~]# rpm -ql jenkins 
/usr/bin/jenkins
/usr/lib/systemd/system/jenkins.service
/usr/lib/tmpfiles.d/jenkins.conf
/usr/share/java/jenkins.war
/usr/share/jenkins/migrate
/var/cache/jenkins
/var/lib/jenkins


3.修改jenkins配置

[root@localhost ~]# vi /usr/lib/systemd/system/jenkins.service

  • 把user和Group改成root, 也可以修改端口(默认是8080)
# Unix account that runs the Jenkins daemon
# Be careful when you change this, as you need to update the permissions of
# $JENKINS_HOME, $JENKINS_LOG, and (if you have already run Jenkins)
# $JENKINS_WEBROOT.
#User=jenkins
#Group=jenkins
User=root
Group=root


# Directory where Jenkins stores its configuration and workspaces
Environment="JENKINS_HOME=/var/lib/jenkins"
WorkingDirectory=/var/lib/jenkins

# Location of the Jenkins WAR
#Environment="JENKINS_WAR=/usr/share/java/jenkins.war"

# Location of the exploded WAR
Environment="JENKINS_WEBROOT=%C/jenkins/war"

# Location of the Jenkins log. By default, systemd-journald(8) is used.
#Environment="JENKINS_LOG=%L/jenkins/jenkins.log"

# The Java home directory. When left empty, JENKINS_JAVA_CMD and PATH are consulted.
#Environment="JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64"

# The Java executable. When left empty, JAVA_HOME and PATH are consulted.
#Environment="JENKINS_JAVA_CMD=/etc/alternatives/java"

# Arguments for the Jenkins JVM
Environment="JAVA_OPTS=-Djava.awt.headless=true"

# Unix Domain Socket to listen on for local HTTP requests. Default is disabled.
#Environment="JENKINS_UNIX_DOMAIN_PATH=/run/jenkins/jenkins.socket"

# IP address to listen on for HTTP requests.
# The default is to listen on all interfaces (0.0.0.0).
#Environment="JENKINS_LISTEN_ADDRESS="

# Port to listen on for HTTP requests. Set to -1 to disable.
# To be able to listen on privileged ports (port numbers less than 1024),
# add the CAP_NET_BIND_SERVICE capability to the AmbientCapabilities
# directive below.
Environment="JENKINS_PORT=8080"

# 重新加载配置
[root@localhost ~]# systemctl daemon-reload 

4.安装失败需卸载

[root@localhost ~]# rpm -e jenkins
[root@localhost ~]# rpm -ql jenkins
[root@localhost ~]# find / -iname jenkins | xargs -n 1000 rm -rf

5.启动jenkins

[root@localhost ~]# systemctl start jenkins.service
Redirecting to /bin/systemctl start jenkins.service
[root@localhost ~]# systemctl status jenkins.service 
● jenkins.service - Jenkins Continuous Integration Server
   Loaded: loaded (/usr/lib/systemd/system/jenkins.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2025-09-18 17:17:15 CST; 1min 26s ago
 Main PID: 20933 (java)
   CGroup: /system.slice/jenkins.service
           └─20933 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=%C/jenkins/war --httpPort=8080

Sep 18 17:17:04 localhost jenkins[20933]: 16c7038972324a8992d96f8c78686739
Sep 18 17:17:04 localhost jenkins[20933]: This may also be found at: /var/lib/jenkins/secrets/initialAdminPassword
Sep 18 17:17:04 localhost jenkins[20933]: *************************************************************
Sep 18 17:17:04 localhost jenkins[20933]: *************************************************************
Sep 18 17:17:04 localhost jenkins[20933]: *************************************************************
Sep 18 17:17:15 localhost jenkins[20933]: 2025-09-18 09:17:15.860+0000 [id=92]        INFO        jenkins.InitReactorRunner$1#onAttained: Completed initialization
Sep 18 17:17:15 localhost jenkins[20933]: 2025-09-18 09:17:15.872+0000 [id=32]        INFO        hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and running
Sep 18 17:17:15 localhost systemd[1]: Started Jenkins Continuous Integration Server.
Sep 18 17:17:17 localhost jenkins[20933]: 2025-09-18 09:17:17.526+0000 [id=108]        INFO        h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
Sep 18 17:17:17 localhost jenkins[20933]: 2025-09-18 09:17:17.527+0000 [id=108]        INFO        hudson.util.Retrier#start: Performed the action check updates server successfully at the attempt #1

6. 操作jenkins

[root@localhost ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
16c7038972324a8992d96f8c78686739

表示jenkins已经启动成功,这时可以去外面机器访问这个jenkins
image

image

image

7. 修改管理员密码

[root@localhost ~]# cd /var/lib/jenkins
[root@localhost jenkins]# ls
%C                             identity.key.enc                               jenkins.install.UpgradeWizard.state             jobs              plugins                   secrets      users
config.xml                     jenkins.install.InstallUtil.installingPlugins  jenkins.model.JenkinsLocationConfiguration.xml  nodeMonitors.xml  secret.key                updates
hudson.model.UpdateCenter.xml  jenkins.install.InstallUtil.lastExecVersion    jenkins.telemetry.Correlator.xml                nodes             secret.key.not-so-secret  userContent
[root@localhost jenkins]# vi config.xml
  • config.xml
  <useSecurity>false</useSecurity>
  <authorizationStrategy class="hudson.security.FullControlOnceLoggedInAuthorizationStrategy">
    <denyAnonymousReadAccess>true</denyAnonymousReadAccess>
  </authorizationStrategy>
  <securityRealm class="hudson.security.HudsonPrivateSecurityRealm">
    <disableSignup>true</disableSignup>
    <enableCaptcha>false</enableCaptcha>
  </securityRealm>
  <disableRememberMe>false</disableRememberMe>
  <projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/>
  <workspaceDir>${JENKINS_HOME}/workspace/${ITEM_FULL_NAME}</workspaceDir>
  <buildsDir>${ITEM_ROOTDIR}/builds</buildsDir>
  <jdks/>
  <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
  <myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/>
  <clouds/>
  <scmCheckoutRetryCount>0</scmCheckoutRetryCount>
  <views>
    <hudson.model.AllView>
      <owner class="hudson" reference="../../.."/>
      <name>all</name>
      <filterExecutors>false</filterExecutors>
      <filterQueue>false</filterQueue>
      <properties class="hudson.model.View$PropertyList"/>
    </hudson.model.AllView>
  </views>
  <primaryView>all</primaryView>
  <slaveAgentPort>-1</slaveAgentPort>
  <label></label>
  <crumbIssuer class="hudson.security.csrf.DefaultCrumbIssuer">
    <excludeClientIPFromCrumb>false</excludeClientIPFromCrumb>
  </crumbIssuer>
  <nodeProperties/>
  <globalNodeProperties/>
  <nodeRenameMigrationNeeded>false</nodeRenameMigrationNeeded>
</hudson>


posted @ 2025-09-18 17:04  codetodo  阅读(11)  评论(0)    收藏  举报