转载请注明出处:http://blog.csdn.net/l1028386804/article/details/71076496
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 本地库配置
settings.xml文件内容如下:<?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
wget http://apache.fayea.com/tomcat/tomcat-7/v7.0.77/bin/apache-tomcat-7.0.77.tar.gz
5、 解压安装 Tomcat
# tar -zxvf apache-tomcat-7.0.77.tar.gz # mv apache-tomcat-7.0.77 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 是有下面的提示:
# 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/
在 Hudson 中配置SonarQube 链接
以上就是 Hudson 的基本安装和配置, 更多其它配置和功能可自行扩展。
精彩评论