1. 程式人生 > >Jenkins~簡單部署及使用

Jenkins~簡單部署及使用

oracl www pan host bre 第三方 inux nvi local

在此註意:新版的jenkins.war包需要JDK1.8版本的支持,否則安裝失敗!
源碼包下載地址
  • JAVA:http://www.oracle.com/technetwork/java/downloads
  • MAVEN: http://maven.apache.org/download.cgi
  • Jenkins:http://updates.jenkins-ci.org/download/war
  • Nexus: http://www.sonatype.org/nexus/go

一、Linux系統
[root@localhost ~]# cat /etc/redhat-release
CentOS release 6.5
(Final) [root@localhost ~]# uname -r 2.6.32-431.el6.x86_64


二、安裝配置系統默認JAVA環境(Jenkins可配置多個java版本,供不同項目構建時的需求) 此處使用java版本為 -- jdk-8u151-linux-x64.tar.gz
[root@localhost soft]# tar xf jdk-8u151-linux-x64.tar.gz -C /usr/local/
[root@localhost soft]# mv /usr/local/jdk1.8.0_151/ /usr/local/java
[root@localhost soft]# echo 
-e "\nexport JAVA_HOME=/usr/local/java\nexport CLASSPATH=.:/usr/local/java/lib/tools.jre:/usr/local/java/lib/dt.jar\nexport JRE_HOME=/usr/local/java/jre\nexport PATH=$PATH:/usr/local/java/bin" >> /etc/profile #添加全局變量 [root@localhost soft]# source /etc/profile [root@localhost soft]# java -version java version "1.8.0_151
" Java(TM) SE Runtime Environment (build 1.8.0_151-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)


三、Maven的安裝部署 maven使用的版本 -- apache-maven-3.5.0-bin.tar.gz 技術分享圖片
[root@localhost soft]# tar xf apache-maven-3.5.0-bin.tar.gz -C /usr/local/             #解壓maven源碼包
[root@localhost soft]# mv /usr/local/apache-maven-3.5.0/ /usr/local/maven                #更改項目安裝的目錄名稱
[root@localhost soft]# echo -e "export MAVEN_HOME=/usr/local/maven\nPATH=$PATH:/usr/local/maven/bin">>/etc/profile     #添加全局變量
[root@localhost soft]# source /etc/profile              #聲明全局變量
[root@localhost soft]# mvn -v                   #查看maven版本號
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-04T03:39:06+08:00)
Maven home: /usr/local/maven
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/local/java/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-431.el6.x86_64", arch: "amd64", family: "unix"
View Code

maven配置文件<profiles>中添加 技術分享圖片
55   <localRepository>/data/maven/repository</localRepository>       #第55行開啟本地存儲目錄的路徑。倉庫下載方指定額位置 
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <jdk>1.7</jdk>
        </activation>
        <properties>
            <maven.compiler.source>1.7</maven.compiler.source>
            <maven.compiler.target>1.7</maven.compiler.target>
            <maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
        </properties>
        <repositories>
            <!--公共倉庫-->
            <repository>
            <id>public-nexus</id>
            <url>http://192.168.*.**:8081/repository/maven-public/</url>;
            <releases>
              <enabled>true</enabled>
            </releases>
            <snapshots>
              <enabled>true</enabled>
            </snapshots>
            </repository>
            <!--第三方倉庫-->
            <repository>
                <id>aliyun</id>
                    <name>Maven aliyun Repository</name>
                    <url>http://maven.aliyun.com/nexus/content/groups/public</url>;
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
            </repository>
            <repository>
                <id>lds</id>
                    <name>Maven lds Repository</name>
                    <url>https://code.lds.org/nexus/content/groups/main-repo/</url>;
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
            </repository>
            <repository>
                <id>uk</id>
                    <name>Maven uk Repository</name>
                    <url>http://uk.maven.org/maven2/</url>;
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
            </repository>
            <repository>
                <id>offical</id>
                    <name>Maven Official Repository</name>
                    <url>http://repo2.maven.org/maven2</url>;
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
            </repository>
            <repository>
                    <id>spring-milestones</id>
                    <name>Spring Milestones</name>
                    <url>http://repo.spring.io/libs-milestone-local</url>;
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
            </repository>
            <repository>
                    <id>spring-releases</id>
                    <name>Spring Releases</name>
                    <url>http://repo.spring.io/libs-release-local</url>;
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
            </repository>
        </repositories>
      </profile>
View Code


四、Tomcat的安裝部署 tomcat使用的版本 -- apache-tomcat-8.5.23.tar.gz(也可以使用7版本)
[root@localhost soft]# tar xf apache-tomcat-8.5.23.tar.gz -C /usr/local/
[root@localhost soft]# mv /usr/local/apache-tomcat-8.5.23/ /usr/local/tomcat
[root@localhost soft]# echo -e "export TOMCAT_HOME=/usr/local/tomcat\nPATH=$PATH:/usr/local/tomcat/bin" >>/etc/profile  #可以定義為TOMCAT_HOME也可以 CATALINA_PATH
[root@localhost soft]# source /etc/profile


五、上傳jenkins.war包並啟動tomcat 現在使用的jenkins包為當時最新的前兩個版本;將jenkins.war包上傳到tomcat家目錄中的webapps中
[root@localhost webapps]# pwd
/usr/local/tomcat/webapps
[root@localhost webapps]# ls
docs  examples  host-manager  jenkins.war  manager  ROOT
[root@localhost webapps]# cd ../bin/
[root@localhost bin]# ./startup.sh
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/java/jre
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@localhost bin]# ps -ef |grep tomcat
root      4575     1 99 14:51 pts/1    00:00:11 /usr/local/java/jre/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
[root@localhost bin]# cd ../webapps/
[root@localhost webapps]# ls
docs  examples  host-manager  jenkins  jenkins.war  manager  ROOT


六、通過瀏覽器訪問 訪問的地址:http://192.168.9.32:8080/jenkins《IP地址為搭建jenkins服務器的地址,8080此處為tomcat的默認端口,tomcat中端口更改後,此處需要更改》 技術分享圖片

[root@localhost ~]# cat /root/.jenkins/secrets/initialAdminPassword d7b45acbdb214475aa2ef15e36557904 輸入密碼點擊continue進入以下界面 技術分享圖片


技術分享圖片


**當出來如下界面,說明一切順利** 技術分享圖片

Jenkins~簡單部署及使用