目录

Life in Flow

知不知,尚矣;不知知,病矣。
不知不知,殆矣。

X

Continuous Integration

持续集成

持续集成
 持续集成是一种软件开发实践,即团队开发成员经常集成他们的工作,通过每个成员每天至少集成一次,也就意味着每天可能会发生多次集成。每次集成都通过自动化的构建(包括编译,发布,自动化测试)来验证,从而尽早地发现集成错误

JDK

[root@localhost test]# tar -zxvf jdk-8u91-linux-x64.tar.gz -C /usr/local/
[root@localhost jdk1.8.0_91]# pwd
[root@localhost jdk1.8.0_91]# vim /etc/profile
/usr/local/jdk1.8.0_91
JAVA_HOME=/usr/local/jdk1.8.0_91
export JAVA_HOME
CLASSPATH=.:$JAVA_HOME/lib
export CLASSPATH
PATH=$PATH:$JAVA_HOME/bin:$CLASSPATH
export PATH
[root@localhost jdk1.8.0_91]# source /etc/profile
[root@localhost jdk1.8.0_91]# java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Maven

[root@localhost test]# tar -zxvf apache-maven-3.5.3-bin.tar.gz -C /usr/local/
[root@localhost apache-maven-3.5.3]# pwd
/usr/local/apache-maven-3.5.3
[root@localhost apache-maven-3.5.3]# vim /etc/profile
MAVEN_HOME=/usr/local/apache-maven-3.5.3
export MAVEN_HOME/bin
PATH=$PATH:$MAVEN_HOME
export PATH
[root@localhost apache-maven-3.5.3]# source /etc/profile
[root@localhost apache-maven-3.5.3]# mvn --version
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-25T03:49:05+08:00)

Maven 私服 Nexus

下载链接

[root@localhost test]# tar -zxvf nexus-3.12.1-01-unix.tar.gz -C /usr/local/
[root@localhost nexus-3.12.1-01]# pwd
/usr/local/nexus-3.12.1-01

# 修改任意端口,避免与本地端口冲突
[root@localhost nexus-3.12.1-01]# vim etc/nexus-default.properties 
application-port=8090

# 防火墙开放8081端口
[root@localhost nexus-3.12.1-01]vim /etc/sysconfig/iptables​ 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT
[root@localhost nexus-3.12.1-01] service iptables restart

# 启动Nexus服务
[root@localhost nexus-3.12.1-01]# useradd nexus
[root@localhost bin]# chown -R nexus:nexus /usr/local/sonatype-work/
[root@localhost nexus-3.12.1-01]# chown -R nexus:nexus /usr/local/nexus-3.12.1-01/
[root@localhost nexus-3.12.1-01]# su nexus
[nexus@localhost nexus-3.12.1-01]$ cd bin/
[nexus@localhost bin]$ ./nexus start
Starting nexus

# Sign In
admin
admin123

# 修改ulimit
[root@localhost bin]# ulimit -a
[root@localhost bin]# vim /etc/security/limits.conf 
* soft nofile 65535
* hard nofile 65535

# 设置开机自动启
[root@localhost bin]# vim /etc/rc.d/rc.local 
su - nexus -c '/usr/local/nexus-3.12.1-01/bin/nexus start'

仓库类型
Nexus

proxy:代理仓库,用于代理远程仓库​ 
group:仓库组,通常包含了多个代理仓库和宿主仓库,在项目中只要引入仓库组就可以下载到代理仓库和宿主仓库中的包​ 
hosted:宿主仓库,内部项目、付费 jar​ releases 发布内部 release 版本的仓库​ snapshots 发布内部 snapshots 版本的仓库​ third 自建第三方 jar

配置代理

选择阿里云
http://maven.aliyun.com/nexus/content/groups/public/

使用 Nexus 私服作为代理下载
 修改 maven 目录下的 conf/setting.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">
  <pluginGroups/>
  <proxies/>
  <servers>
    <server>
      <id>xdclass-releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>xdclass-snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>
  <mirrors/>
  <profiles>
    <profile>
      <id>xdclass</id>
      <activation>
        <activeByDefault>false</activeByDefault>
      </activation>
      <!-- 私有库地址-->
      <repositories>
        <repository>
          <id>xdclass</id>
          <url>http://192.168.31.251:8090/repository/maven-public/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      <!--插件库地址-->
      <pluginRepositories>
        <pluginRepository>
          <id>xdclass</id>
          <url>http://192.168.31.251:8090/repository/maven-public/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>xdclass</activeProfile>
  </activeProfiles>
</settings>

项目工程上传至 Nexus 私服
 修改项目中的 pom.xml 文件
 deploy

<!--pom.xml 远程仓库的配置  id要跟本地maven的setting.xml相同 -->
    <distributionManagement>
        <repository>
            <id>xdclass-releases</id>
            <name>Ruizhi Release Repository</name>
            <url>http://192.168.31.251:8090/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>xdclass-snapshots</id>
            <name>Ruizhi Snapshot Repository</name>
            <url>http://192.168.31.251:8090/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

编译安装 Mysql5.7

下载地址

代码质量管理平台 sonarqube

下载链接

# 解压
[root@localhost software]# unzip sonarqube-6.7.4.zip 
[root@localhost software]# mv sonarqube-6.7.4 /usr/local/

# mysql里新增数据库
mysql> CREATE DATABASE sonar DEFAULT CHARACTER SET utf8;

# 修改sonarqube相应的配置
[root@localhost software]# vim /usr/local/sonarqube-6.7.4/conf/sonar.properties 
sonar.jdbc.username=root
sonar.jdbc.password=soulbo
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
sonar.web.context=/sonar
sonar.web.host=0.0.0.0

# 新增用户,并将目录所属权赋予该用户
[root@localhost software]# useradd sonar
[root@localhost software]# chown -R sonar:sonar /usr/local/sonarqube-6.7.4/

# 启动sonarque
[root@localhost software]# su sonar
[sonar@localhost bin]$ /usr/local/sonarqube-6.7.4/bin/linux-x86-64/sonar.sh start
Starting SonarQube...
Started SonarQube.

# 访问URL (默认账户名和密码都是 admin)
http://192.168.31.251:9000/sonar

# 生成令牌
soulboy: 6045fbb8fee168c51160a9753e0948952884d398

# 将项目代码使用以下命令进行提交由sonarqube进行分析,完成后,查看相应的分析结果
mvn sonar:sonar \
  -Dsonar.host.url=http://192.168.31.251:9000/sonar \
  -Dsonar.login=6045fbb8fee168c51160a9753e0948952884d398

Jenkins

前置条件

  • JDK
  • Tomcat

部署 Tomcat

[root@localhost software]# useradd tomcat
[root@localhost software]# passwd tomcat
[root@localhost software]# tar -zxvf apache-tomcat-9.0.8.tar.gz -C /usr/local/
[root@localhost software]# chown -R tomcat:tomcat /usr/local/apache-tomcat-9.0.8/
[root@localhost software]# su tomcat

部署 Jenkins

# 将Jenkins上传到tomcat的webapp目录​ chown tomcat:tomcat Jenkins.war
[root@localhost software]# mv jenkins.war /usr/local/apache-tomcat-9.0.8/webapps/
[root@localhost software]# chown tomcat:tomcat /usr/local/apache-tomcat-9.0.8/webapps/jenkins.war 

# 启动tomcat
[tomcat@localhost software]$ /usr/local/apache-tomcat-9.0.8/bin/startup.sh

# 访问URL
http://192.168.31.251:8080/

# 如果出现问题查看日志
[tomcat@localhost software]$ more /usr/local/apache-tomcat-9.0.8/logs/catalina.out 

# tomcat默认端口为8080,如果需要修改端口
[tomcat@localhost software]$ vim /usr/local/apache-tomcat-9.0.8/conf/server.xml 
<Connector port="9999" protocol="HTTP/1.1"

# 访问tomcat
http://192.168.31.251:9999/jenkins

# 查看默认内容
[tomcat@localhost software]$ more /home/tomcat/.jenkins/secrets/initialAdminPassword
83b24bc989d946529185de097756d205

# 将https改为http,之后提交,重启tomcat
http://192.168.31.251:9999/jenkins/pluginManager/advanced

# 重新安装
[tomcat@localhost software]$ /usr/local/apache-tomcat-
[tomcat@localhost software]$ /usr/local/apache-tomcat-9.0.8/bin/startup.sh 
http://192.168.31.251:9999/jenkins
more /home/tomcat/.jenkins/secrets/initialAdminPassword​ 选择默认安装
选择安装推荐插件

http://192.168.31.251:9999/jenkins

# 如果需要重新安装Jenkins
[root@localhost bin]# rm -rf /home/tomcat/.jenkins
[root@localhost bin]# rm -rf /usr/local/apache-tomcat-9.0.8/webapps/jenkins

Jenkins 插件安装及配置

插件安装(系统管理--》插件管理​)

​1.安装Maven Integration plugin​ 
2.安装SonarQube Scanner for Jenkins​ 
3.Publish Over SSH --发布到远程服务器

系统配置(系统管理--》全局工具配置)
1.配置 jdk​ 
2.配置 maven​ 
3.配置 sonar​ 
4.邮件配置​ 系统管理--》系统设置--》邮件通知--》​ smtp 服务器 smtp.qq.com​ 用户默认邮件后缀 @qq.com​ 勾选 ssl​ Reply-To Address 发件者邮箱​ 之后测试一下配置,无误即可

配置 sonarqube

配置 GitLab


作者:Soulboy