樣例項目參考視頻教程:http://www.roncoo.com/course/view/85d6008fe77c4199b0cdd2885eaeee53
IP:192.168.4.221 8G內存(Hudson多個工程在同時構建的情況下比較耗內存)
環境:CentOS 6.6、JDK7
Hudson不需要用到數據庫
Hudson只是一個持續集成服務器(持續集成工具),要想搭建一套完整的持續集成管理平臺,還需要用到前面課程中所講到的SVN、Maven、Sonar等工具,按需求整合則可。
1、 安裝JDK並配置環境變量(略)
JAVA_HOME=/usr/local/java/jdk1.7.0_72
2、 Maven本地倉庫的安裝(使用Maven作爲項目構建與管理工具):
(1)下載maven-3.0.5
(注意:建議不要下載3.1或更高版本的Maven,因爲與Hudson進行集成時會有問題,之前有遇到過):
# wget http://mirrors.hust.edu.cn/apache/maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.tar.gz
(2)解壓:
# tar -zxvf apache-maven-3.0.5-bin.tar.gz
# mv apache-maven-3.0.5 maven-3.0.5
(3)配置Maven環境變量:
# vi /etc/profile
## maven env
export MAVEN_HOME=/root/maven-3.0.5
export PATH=$PATH:$MAVEN_HOME/bin
# source /etc/profile
(4)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>/root/maven-3.0.5/.m2/repository</localRepository>
<interactiveMode>true</interactiveMode>
<offline>false</offline>
<pluginGroups>
<pluginGroup>org.mortbay.jetty</pluginGroup>
<pluginGroup>org.jenkins-ci.tools</pluginGroup>
</pluginGroups>
<!--配置權限,使用默認用戶-->
<servers>
<server>
<id>nexus-releases</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>deployment</username>
<password>deployment123</password>
</server>
</servers>
<mirrors>
</mirrors>
<profiles>
<profile>
<id>edu</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.6</jdk>
</activation>
<repositories>
<!-- 私有庫地址-->
<repository>
<id>nexus</id>
<url>http://localhost:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<!--插件庫地址-->
<pluginRepository>
<id>nexus</id>
<url>http://localhost:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- Example for MySQL-->
<sonar.jdbc.url>
jdbc:mysql://localhost:3306/sonarqube?useUnicode=true&characterEncoding=utf8
</sonar.jdbc.url>
<sonar.jdbc.username>root</sonar.jdbc.username>
<sonar.jdbc.password>wusc.123</sonar.jdbc.password>
<!-- Optional URL to server. Default value is http://localhost:9000 -->
<sonar.host.url>
http://localhost:9090/sonarqube
</sonar.host.url>
</properties>
</profile>
</profiles>
<!--激活profile-->
<activeProfiles>
<activeProfile>edu</activeProfile>
</activeProfiles>
</settings>
3、 配置HudsonHome,在/root目錄下創建HudsonHome目錄,並配置到環境變量
# mkdir HudsonHome
切換到root用戶,在/etc/profile中配置全局環境變量
# vi /etc/profile
## hudson env
export HUDSON_HOME=/root/HudsonHome
# source /etc/profile
4、 下載最新版Tomcat7,當前最新版爲7.0.59:
# wget http://apache.fayea.com/tomcat/tomcat-7/v7.0.59/bin/apache-tomcat-7.0.59.tar.gz
5、 解壓安裝Tomcat:
# tar -zxvf apache-tomcat-7.0.59.tar.gz
# mv apache-tomcat-7.0.59 hudson-tomcat
移除/root/hudson-tomcat/webapps目錄下的所有文件:
# rm -rf /root/hudson-tomcat/webapps/*
將Tomcat容器的編碼設爲UTF-8:
# vi /root/hudson-tomcat/conf/server.xml
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
如果不把Tomcat容器的編碼設爲UTF-8,在以後配置Hudson是有下面的提示:
設置hudson-tomcat的內存
# vi /root/hudson-tomcat/bin/catalina.sh
#!/bin/sh 下面增加:
JAVA_OPTS='-Xms512m -Xmx2048m'
6、 下載最新版的Hudson(這裏是3.2.2版)包:
# wget http://mirror.bit.edu.cn/eclipse/hudson/war/hudson-3.2.2.war
將war包拷貝到hudson-tomcat/weapps目錄,並重命名爲hudson.war
# cp /root/hudson-3.2.2.war /root/hudson-tomcat/webapps/hudson.war
7、 防火牆開啓8080端口,用root用戶修改/etc/sysconfig/iptables,
# vi /etc/sysconfig/iptables
增加:
## hudson-tomcat port:8080
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
重啓防火牆:
# service iptables restart
8、 設置hudson-tomcat開機啓動:
在虛擬主機中編輯/etc/rc.local文件,
# vi /etc/rc.local
加入:
/root/hudson-tomcat/bin/startup.sh
9、 啓動hudson-tomcat
# /root/hudson-tomcat/bin/startup.sh
10、 配置Hudson:
(1)瀏覽器輸入:http://192.168.4.221:8080/hudson/
初始化安裝需要安裝3個默認勾選中的插件(如上圖紅色部分),其它插件可以等初始化安裝完成之後再選擇安裝。
點擊「Install」安裝按鈕後,需要等待一會時間才能安裝完成。安裝完成後按「Finish」按鈕。
安裝的插件保存在 /root/HudsonHome/plugins 目錄。
(2)初始化完成後就會進行Hudson的配置管理界面:
安全配置
啓用安全配置
使用項目矩陣授權策略
註冊一個超級管理員賬號
系統設置
配置系統信息、JDK、Maven
保存後的效果
插件安裝
結合我們想要實現的持續集成功能,需要安裝如下幾個插件。如想集成更多功能,自行添加插件並配置則可。(注意:現在我們使用了SonarQube質量管理不臺,則不再需要在Hudson中單獨去安裝CheckStyle、Findbugs、PMD、Cobertura等Sonar中已有的插件)
逐個搜索你想要安裝的插件並點擊安裝,安裝完之後重啓Hudson。
如下圖所示:
在Hudson中配置SonarQube鏈接
以上就是Hudson的基本安裝和配置,更多其它配置和功能可自行擴展。
Hudson的使用(使用Hudson來自動化編譯、分析、打包、發佈、部署項目)
添加項目