zoukankan      html  css  js  c++  java
  • gitlabCI/CD部署一个java项目

    1、环境准备

      1)安装jdk工具

    • 安装yum epel源
      [root@k8s-node02 ~]# yum install -y epel-release
    • 安装jdk
      [root@k8s-node02 ~]# yum install -y java-1.8.0-openjdk
      
    • 验证jdk
      [root@k8s-node02 ~]# java -version
      openjdk version "1.8.0_232"
      OpenJDK Runtime Environment (build 1.8.0_232-b09)
      OpenJDK 64-Bit Server VM (build 25.232-b09, mixed mode)

      2)安装maven工具

    • 安装maven官方源
      [root@k8s-node02 ~]# yum-config-manager --add-repo http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo
      [root@k8s-node02 ~]# yum-config-manager --enable epel-apache-maven
    • 安装maven
      [root@k8s-node02 ~]# yum install -y apache-maven
    • 验证maven
      [root@k8s-node02 ~]# mvn -version
      Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T03:58:13-04:00)
      Maven home: /usr/share/apache-maven
      Java version: 1.8.0_232, vendor: Oracle Corporation
      Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre
      Default locale: en_US, platform encoding: UTF-8
      OS name: "linux", version: "3.10.0-957.27.2.el7.x86_64", arch: "amd64", family: "unix"

    2、安装tomcat

    • 官网下载地址:http://tomcat.apache.org/
    • 下载tomcat
      [root@k8s-node02 tools]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.50/bin/apache-tomcat-8.5.50.tar.gz
    • 安装tomcat
      [root@k8s-node02 tools]# tar -zxf apache-tomcat-8.5.50.tar.gz -C /opt/
      [root@k8s-node02 tools]# ln -s /opt/apache-tomcat-8.5.50   /opt/tomcat
      [root@k8s-node02 tools]# echo 'export TOMCAT_HOME=/opt/tomcat'>>/etc/profile
      [root@k8s-node02 tools]# echo 'export  PATH=$PATH:$TOMCAT_HOME/bin' >>/etc/profile
      [root@k8s-node02 tools]# source /etc/profile
    • 启动tomcat
      [root@k8s-node02 tools]# /opt/tomcat/bin/startup.sh start
      Using CATALINA_BASE:   /opt/tomcat
      Using CATALINA_HOME:   /opt/tomcat
      Using CATALINA_TMPDIR: /opt/tomcat/temp
      Using JRE_HOME:        /usr
      Using CLASSPATH:       /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
      Tomcat started.
    • 设置权限
      [root@k8s-node02 java_demo]# chown -R staff:staff /opt/apache-tomcat-8.5.50
    • 浏览器验证: 192.168.200.134:8080 
e Inmp (l In... 
Wiki Mailing Lists 
Home Documentation Configuration Examples 
Apache Tomcat/8.5.50 
Find Help 
ÅPACHE 
If you're seeing this, you've successfully installed Tomcat. Congratulations! 
Recommended Reading: 
Security Considerations How-To 
Manager_Application How-To 
Clustering/Session Replication How-To 
Server Status 
Manager App 
Host Manager 
Developer Quick Start 
Tomcat Setup 
First Web Application 
Managing Tomcat 
Realms & AAA 
JDBC DataSources 
Examples 
For security, access to the manager webaQQ is 
restricted Users are defined in: 
In Tomcat 8.5 access to the manager 
application is split beüeen different users. 
Read more.. 
Release Notes 
Changelog 
Migration Guide 
Security Notices 
Documentation 
Tomcat 8.5 Documentation 
Tomcat 8.5 Configuration 
Tomcat Wiki 
Find additional important configuration 
information in: 
txt 
Developers may be interested in: 
Tomcat Bug Database 
Tomcat 8 5 JevaDocs 
Tomcat 8 5 Git 
Servlet Specifications 
Tomcat Versions 
Getting Help 
FAQ and Mailing Lists 
The following mailing lists are available: 
tomcat-announce 
Important announcements, releases, security 
vulnerability notifications. (Low volume). 
tomcat-users 
user support and discussion 
taglibs-user 
user support and discussion for Buacng_lagljns 
tomcat-dev 
Development mailing list, including commit 
messages

    3、准备gitlab的" .gitlab-ci.yml "配置文件

    [root@k8s-node02 java_demo]# vim .gitlab-ci.yml 
    # 定义stages
    stages:
      - build
      - install
    
    # 定义安装包的存放位置和Tomcat服务器的地址的变量,便于后续部署使用.
    variables:
      CIDEMO_PACKAGE_DIR: '/home/gitlab-runner/packages/cidemo'
      SERVER_HOME_DIR: '/home/gitlab-runner/tomcat/cidemo-tomcat'
    
    ###################### 构建编译和Maven打包编译 #######################
    
    #编译测试任务:
    deploy-build-test:
      stage: build
      only:
        - master
      script:
        - mvn clean package -Dmaven.test.skip=true
        - rm -rf $CIDEMO_PACKAGE_DIR/*.war
        - cp -a target/*.war $CIDEMO_PACKAGE_DIR/cidemo.war
    
    ###################### deploy部署安装 #######################
    
    #打包任务:
    deploy-install-test:
      stage: install
      script:
        - echo '准备将最新的war包复制、保存到某个目录里面供后续使用.'
        - rm -rf $SERVER_HOME_DIR/*.war
        - cp -a $CIDEMO_PACKAGE_DIR/cidemo.war   $SERVER_HOME_DIR/ROOT.war
        - /opt/tomcat/bin/startup.sh stop
        - rm -rf /opt/tomcat/webapps/*
        - cp -a $SERVER_HOME_DIR/ROOT.war /opt/tomcat/webapps/
        - /opt/tomcat/bin/startup.sh start

    把编写的“.gitlab-ci.yml”提交到master端

    4、 浏览器访问

     @Umbra

  • 相关阅读:
    如何编写CMakeLists.txt
    C++11 condition_variable
    TCP/IP 收发数据
    CLion 远程开发和调试C/C++代码
    Python unittest mock 在哪里打patch
    MVCC版本链
    数据无法修改?解密MVCC原理
    MVCC ReadView介绍
    正则表达式备忘(基于JavaScript)
    《C+编程规范 101条规则、准则与最佳实践》笔记
  • 原文地址:https://www.cnblogs.com/scajy/p/15661306.html
Copyright © 2011-2022 走看看