Hudson之——持续集成服务器的安装与配置(转)

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/71076496

IP:192.168.4.221 8G 内存(Hudson 多个工程在同时构建的情况下比较耗内存)
环境: CentOS 6.6、 JDK7
Hudson 不需要用到数据库
Hudson 只是一个持续集成服务器(持续集成工具), 要想搭建一套完整的持续集成管理平台,
还需要用到前面课程中所讲到的 SVNMaven、 Sonar等工具, 按需求整合则可。 

1、 安装 JDK并配置环境变量(略)

JAVA_HOME=/usr/local/Java/jdk1.7.0_72

2、 Maven本地仓库的安装(使用 Maven 作为项目构建与管理工具)

(1)下载 maven-3.0.5

注意: 建议不要下载3.1 或更高版本的Maven,因为与Hudson 进行集成时会有问题,之前有遇到过):

[plain] view plain copy
 
  1. # wget http://mirrors.hust.edu.cn/apache/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.tar.gz  

(2)解压

[plain] view plain copy
 
  1. # tar -zxvf apache-maven-3.0.5-bin.tar.gz  
  2. # mv apache-maven-3.0.5 maven-3.0.5  

(3)配置 Maven 环境变量 

 

[plain] view plain copy
 
  1. # vi /etc/profile  
  2. ## maven env  
  3. export MAVEN_HOME=/root/maven-3.0.5  
  4. export PATH=$PATH:$MAVEN_HOME/bin  
  5. # source /etc/profile  

(4)Maven 本地库配置

settings.xml文件内容如下:

 

 

[html] view plain copy
 
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.   
  3. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"   
  4.           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  5.           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">  
  6.     <localRepository>/root/maven-3.0.5/.m2/repository</localRepository>  
  7.     <interactiveMode>true</interactiveMode>  
  8.     <offline>false</offline>  
  9.     <pluginGroups>  
  10.         <pluginGroup>org.mortbay.jetty</pluginGroup>  
  11.         <pluginGroup>org.jenkins-ci.tools</pluginGroup>  
  12.     </pluginGroups>  
  13.       
  14.     <!--配置权限,使用默认用户-->  
  15.     <servers>  
  16.         <server>  
  17.             <id>nexus-releases</id>  
  18.             <username>deployment</username>  
  19.             <password>deployment123</password>  
  20.         </server>  
  21.         <server>   
  22.             <id>nexus-snapshots</id>  
  23.             <username>deployment</username>  
  24.             <password>deployment123</password>  
  25.         </server>  
  26.     </servers>  
  27.   
  28.     <mirrors>  
  29.   
  30.     </mirrors>  
  31.   
  32.     <profiles>  
  33.         <profile>  
  34.             <id>edu</id>  
  35.             <activation>  
  36.                 <activeByDefault>false</activeByDefault>  
  37.                 <jdk>1.6</jdk>  
  38.             </activation>  
  39.             <repositories>  
  40.                 <!-- 私有库地址-->  
  41.                 <repository>  
  42.                     <id>nexus</id>  
  43.                     <url>http://localhost:8081/nexus/content/groups/public/</url>  
  44.                     <releases>  
  45.                         <enabled>true</enabled>  
  46.                     </releases>  
  47.                     <snapshots>  
  48.                         <enabled>true</enabled>  
  49.                     </snapshots>  
  50.                 </repository>  
  51.             </repositories>        
  52.             <pluginRepositories>  
  53.                 <!--插件库地址-->  
  54.                 <pluginRepository>  
  55.                     <id>nexus</id>  
  56.                     <url>http://localhost:8081/nexus/content/groups/public/</url>  
  57.                     <releases>  
  58.                         <enabled>true</enabled>  
  59.                     </releases>  
  60.                     <snapshots>  
  61.                         <enabled>true</enabled>  
  62.                    </snapshots>  
  63.                 </pluginRepository>  
  64.             </pluginRepositories>  
  65.         </profile>  
  66.           
  67.         <profile>  
  68.             <id>sonar</id>  
  69.             <activation>  
  70.                 <activeByDefault>true</activeByDefault>  
  71.             </activation>  
  72.             <properties>  
  73.                 <!-- Example for MySQL-->  
  74.                 <sonar.jdbc.url>  
  75.                     jdbc:mysql://localhost:3306/sonarqube?useUnicode=true&characterEncoding=utf8  
  76.                 </sonar.jdbc.url>  
  77.                 <sonar.jdbc.username>root</sonar.jdbc.username>  
  78.                 <sonar.jdbc.password>wusc.123</sonar.jdbc.password>  
  79.   
  80.                 <!-- Optional URL to server. Default value is http://localhost:9000 -->  
  81.                 <sonar.host.url>  
  82.                     http://localhost:9090/sonarqube  
  83.                 </sonar.host.url>  
  84.             </properties>  
  85.         </profile>  
  86.           
  87.     </profiles>  
  88.       
  89.     <!--激活profile-->  
  90.     <activeProfiles>  
  91.         <activeProfile>edu</activeProfile>  
  92.     </activeProfiles>  
  93.       
  94. </settings>  

3、 配置HudsonHome

/root目录下创建 HudsonHome 目录,并配置到环境变量

[plain] view plain copy
 
  1. # mkdir HudsonHome  

切换到 root用户,在/etc/profile 中配置全局环境变量 

[plain] view plain copy
 
  1. # vi /etc/profile  
  2. ## hudson env  
  3. export HUDSON_HOME=/root/HudsonHome  
  4. # source /etc/profile  

4、 下载 Tomcat7

[plain] view plain copy
 
  1. wget http://apache.fayea.com/tomcat/tomcat-7/v7.0.77/bin/apache-tomcat-7.0.77.tar.gz  

5、 解压安装 Tomcat

[plain] view plain copy
 
  1. # tar -zxvf apache-tomcat-7.0.77.tar.gz  
  2. # mv apache-tomcat-7.0.77 hudson-tomcat  

移除/root/hudson-tomcat/webapps 目录下的所有文件:

[plain] view plain copy
 
  1. # rm -rf /root/hudson-tomcat/webapps/*  

将 Tomcat容器的编码设为 UTF-8:

[plain] view plain copy
 
  1. # vi /root/hudson-tomcat/conf/server.xml  
  2. <Connector port="8080" protocol="HTTP/1.1"  
  3. connectionTimeout="20000"  
  4. redirectPort="8443" URIEncoding="UTF-8" />  

如果不把 Tomcat容器的编码设为 UTF-8, 在以后配置Hudson 是有下面的提示:

设置 hudson-tomcat 的内存 

[plain] view plain copy
 
  1. # vi /root/hudson-tomcat/bin/catalina.sh  

#!/bin/sh 下面增加:

[plain] view plain copy
 
  1. JAVA_OPTS='-Xms512m -Xmx2048m'  

6、 下载 Hudson(这里是 3.2.2版) 包

[plain] view plain copy
 
  1. # wget http://mirror.bit.edu.cn/eclipse/hudson/war/hudson-3.2.2.war  

将 war 包拷贝到 hudson-tomcat/weapps目录,并重命名为 hudson.war

[plain] view plain copy
 
  1. # cp /root/hudson-3.2.2.war /root/hudson-tomcat/webapps/hudson.war  

7、配置防火墙

防火墙开启 8080 端口,用 root 用户修改/etc/sysconfig/iptables,

[plain] view plain copy
 
  1. # vi /etc/sysconfig/iptables  

增加: 

[plain] view plain copy
 
  1. ## hudson-tomcat port:8080  
  2. -A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT  

重启防火墙: 

[plain] view plain copy
 
  1. # service iptables restart  

8、 设置 hudson-tomcat 开机启动

在虚拟主机中编辑/etc/rc.local 文件 

[plain] view plain copy
 
  1. # vi /etc/rc.local  

加入: 

[plain] view plain copy
 
  1. /root/hudson-tomcat/bin/startup.sh  

9、 启动 hudson-tomcat

[plain] view plain copy
 
  1. # /root/hudson-tomcat/bin/startup.sh  

10、 配置 Hudson

(1)浏览器输入: http://192.168.4.221:8080/hudson/



初始化安装需要安装 3 个默认勾选中的插件(如上图红色部分), 其它插件可以等初始化安装完成之后再选择安装。点击“Install”安装按钮后,需要等待一会时间才能安装完成。 安装完成后按“Finish”按钮。安装的插件保存在 /root/HudsonHome/plugins 目录。
(2)初始化完成后就会进行 Hudson的配置管理界面: 

安全配置 


启用安全配置 

使用项目矩阵授权策略 

注册一个超级管理员账号 



系统设置 

配置系统信息、 JDKMaven 



保存后的效果 

插件安装 

结合我们想要实现的持续集成功能,需要安装如下几个插件。如想集成更多功能,自行添加插件并配置则可。(注意:现在我们使用了 SonarQube 质量管理不台,则不再需要在Hudson 中单独去安装 CheckStyle、 Findbugs、 PMD、 Cobertura 等 Sonar 中已有的插件)逐个搜索你想要安装的插件并点击安装,安装完之后重启 Hudson。如下图所示:


 

在 Hudson 中配置SonarQube 链接

以上就是 Hudson 的基本安装和配置, 更多其它配置和功能可自行扩展。

 

转自:http://blog.csdn.net/l1028386804/article/details/71076496

posted @ 2017-06-19 22:30  N神3  阅读(213)  评论(0编辑  收藏  举报