centos7 安装jenkins

注:由于最新版本的jenkins已经不支持jdk1.8了,由于本地很多项目还是基于jdk1.8的,所以这里我们下载之前的版本,这里选择下载的版本是2.332.4。 早期的版本在安装一些插件的时候会有一些坑。建议还是和本文一个版本。如果用的是jdk11的话可以下载最新版本。

简介:

Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件项目可以进行持续集成

相关地址:

官网地址: https://www.jenkins.io/

安装jenkins前的准备

1、安装 jdk1.8
2、安装 maven
3、安装 git

安装配置jdk
  1. 上传压缩包到服务器上,我这里使用的是 jdk-8u333-linux-x64.tar.gz
  2. 创建/usr/local/java目录,将压缩包内容解压过去
  3. 配置环境变量: vi /etc/profile, 在文件末尾添加下列内容
#JAVA_HOME
export JAVA_HOME=/usr/local/java/jdk1.8.0_333
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH  PATH
  1. 保存后退出,使环境变量生效 source /etc/profile, 然后输入 java -version, 出现下列内容,安装成功

image.png

安装配置maven
  1. 上传maven压缩包到服务器上, 我这里的版本是 maven-3.8.6
  2. 创建 /usr/local/maven目录, 将压缩包内容解压过去
  3. 配置环境变量: vi /etc/profile, 在文件末尾添加下列内容
#配置maven环境
MAVEN_HOME=/usr/local/maven/apache-maven-3.8.6
export PATH=${MAVEN_HOME}/bin:${PATH}
  1. 保存后退出,使环境变量生效 source /etc/profile, 然后输入 mvn -v, 出现下列内容,安装成功

image.png

  1. 创建镜像仓库, cd /usr/local/maven/apache-maven-3.8.6 mkdir repo
  2. 更改maven配置文件
<?xml version="1.0" encoding="UTF-8"?>
 
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
 
  <!--配置本地仓库-->
  <localRepository>/usr/local/maven/apache-maven-3.8.6/repo</localRepository>
 
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>
 
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>
 
  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
                <url>https://maven.aliyun.com/repository/public</url>
                <name>阿里云公共仓库</name>
                <mirrorOf>*</mirrorOf>
                <id>aliyunmaven</id>
        <mirror>
  </mirrors>
    -->
 
    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
  </servers>
 
  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
    <mirror>
        <id>aliyunmaven</id>
        <mirrorOf>*</mirrorOf>
        <name>阿里云公共仓库</name>
        <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
  </mirrors>
  
  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.4</id>
 
      <activation>
        <jdk>1.4</jdk>
      </activation>
 
      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->
    <profile>
        <id>jdk-1.8</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <jdk>1.8</jdk>
        </activation>    
        <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
            <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
        </properties>
    </profile>
 
    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>
 
      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>
 
      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
  </profiles>
 
  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>

安装git
  1. yum -y install git
  2. git --version
  3. 出现下面页面即安装成功

image.png

安装jenkins

  1. mkdir /jenkins, 上传jenkins war包, 一般安装jenkins有三种方式。 一是通过war包安装,二是通过rpm安装, 三是通过docker安装。 我这里选择的是通过war包来安装
  2. 上传完成war后,在/jenkins目录下运行 nohup java -jar jenkins.war > /jenkins/server.log 2>&1 &
  3. cat server.log查看日志, 注意有一串管理员的登录密码。

image.png

  1. jenkins启动端口默认为8080, 配置防火墙放行端口

firewall-cmd --add-port=8080/tcp --permanent
firewall-cmd --reload
浏览器访问 http://192.168.43.120:8080/
image.png

  1. 初始化配置

jenkins下载插件默认从国外镜像,速度很慢。这里我们选择第二个image.png
image.png
image.png
image.png

配置镜像源

上面我们启动了jenkins并进行了初始配置,这个时候不要急着使用,我们去修改下镜像源,这样后面jenkins从国内下载插件速度就会快很多

  1. jenkins war包启动后会生成对应的工作目录,目录在 /root/.jenkins, 注意这是个隐藏目录,而且和用rpm安装好的工作目录是不一致的
  2. cd /root/.jenkins

vi hudson.model.UpdateCenter.xml
将url 改为 http://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json

  1. cd /root/.jenkins/updates,修改default.json

sed -i ‘s/https://updates.jenkins.io/download/http://mirrors.tuna.tsinghua.edu.cn/jenkins/g’ default.json
sed -i ‘s/www.google.com/www.baidu.com/g’ default.json

  1. 重启jenkins服务, 直接在浏览器输入 http://ip:8080/restart 即可重启
安装需要的插件

image.png
image.png
image.png

全局配置和插件配置

jdk配置:
image.png
maven配置:
image.png
ssh配置:
image.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在CentOS 7上安装Jenkins,可以按照以下步骤进行操作: 1. 首先,将Jenkins库添加到yum库中。可以使用以下命令下载并添加Jenkins库: ``` wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key ``` 2. 安装Jenkins。使用以下命令安装Jenkins: ``` yum install jenkins ``` 3. 设置Jenkins缓存目录的所有者为root。可以使用以下命令更改所有者: ``` chgrp -R root /var/cache/jenkins ``` 4. 启动Jenkins服务。使用以下命令启动Jenkins: ``` systemctl start jenkins ``` 5. 访问Jenkins的Web界面,并进行初始化配置。在浏览器中输入服务器的IP地址或域名,加上Jenkins的默认端口号8080,例如:http://your_server_ip:8080。按照提示进行初始化配置。 在安装Jenkins之前,需要准备一台安装CentOS 7的虚拟机,并确保能够访问网络。还需要安装一些基础组件,如JDK、Maven、Git和Docker等。可以参考相关教程进行安装和配置。 请注意,以上步骤仅适用于CentOS 7操作系统。 #### 引用[.reference_title] - *1* [CentOS7安装Jenkins](https://blog.csdn.net/qq_21275565/article/details/123953465)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [CentOS7安装Jenkins教程](https://blog.csdn.net/ichen820/article/details/103461148)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Centos 7 安装jenkins教程](https://blog.csdn.net/youshowkm/article/details/130505752)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值