centos7 安装jenkins

  • Post author:
  • Post category:其他


注:由于最新版本的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



版权声明:本文为weixin_43148701原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。