您的位置:首页 > 运维架构 > 网站架构

分布式架构学习之持续集成:012--Hudson(Jekins)持续集成服务器的安装、配置和使用

2017-05-10 17:50 926 查看
Hudson 持续集成服务器的安装配置与使用
 

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.d/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 的配置管理界面:

安全配置,启用安全配置,使用项目矩阵授权策略





 

 

 具体使用网上见
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: