一、背景
公司的CI/CD环境出现了故障,影响项目联调测试,于是协调运维给了台服务器,准备自己来玩
初步设想是通过脚本一键自动从git拉代码、maven自动打包、自动启动项目
二、服务器环境
已装好Centos、有外网
三、环境准备
先建好目录
cd /data
# 在/data目录下建一个project目录,用于存放项目相关文件
mkdir project
# 切换到project,再创建一个gitlab目录,用于存在git clone下载的代码
cd project
mkdir gitlab
1. 安装Java
参考网上资料,jdk要求建议1.8+
我安装的是 jdk-8u341-linux-x64.tar.gz
,先把包下载下来,然后上传到服务器(我是在/usr/local
目录下建了个java目录,然后把包上传到这个目录),然后执行如下命令解压
tar -xzvf jdk-8u341-linux-x64.tar.gz
然后配置一下环境变量
vim /etc/profile
在最后面加上
#java environment
export JAVA_HOME=/usr/local/java/jdk1.8.0_341
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
然后执行如下命令让环境变量生效
source /etc/profile
最后验证一下,输入:java -version
,看到如下则代表成功
2. 安装Git
我是先移除了服务器自带的git
yum -y remove git
然后重新安装了下
yum -y install git
执行完检查下,看到如下则ok
3. 安装Maven
切换到/data/apps
目录
先下载maven包
wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.8.2/binaries/apache-maven-3.8.2-bin.tar.gz
然后解压
tar -xzvf apache-maven-3.8.2-bin.tar.gz
cd apache-maven-3.8.2/
# 查看当前目录,复制下来
pwd
获取到目录
然后去配置maven的环境变量
也是先vim /etc/profile
,在最后输入如下
#maven enviroment
export MAVEN_HOME=/data/apps/apache-maven-3.8.2
export PATH=${
PATH}:${MAVEN_HOME}/bin
然后执行如下命令让环境变量生效
source /etc/profile
验证一下:mvn -v
, 看到如下代表成功
在/data
目录下建一个目录,名为:mvnrepository
用于存放jar包
进入到:/data/apps/apache-maven-3.8.2/conf
目录,先将默认的settings.xml文件备份
mv settings.xml settings.xml.bak
然后新建一下包含公司私服的配置文件,取名:settings.xml,内容参考如下:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
| This is the configuration file for Maven. It can be specified at two levels:
|
| 1. User Level. This settings.xml file provides configuration for a single user,
| and is normally provided in ${user.home}/.m2/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -s /path/to/user/settings.xml
|
| 2. Global Level. This settings.xml file provides configuration for all Maven
| users on a machine (assuming they're all using the same Maven
| installation). It's normally provided in
| ${maven.conf}/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -gs /path/to/global/settings.xml
|
| The sections in this sample file are intended to give you a running start at
| getting the most out of your Maven installation. Where appropriate, the default
| values (values used when the setting is not specified) are provided.
|
|-->
<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
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>-->
<!-- 这里改成上一步建好的maven仓库地址-->
<localRepository>/data/mvnrepository</localRepository>
<!-- interactiveMode
| This will determine whether maven prompts you when it needs input. If set to false,
| maven will use a sensible default value, perhaps based on some other setting, for
| the parameter in question.
|
| Default: true
<interactiveMode>true</interactiveMode>-->
<!-- offline
| Determines whether maven should attempt to connect to the network when executing a build.
| This will have an effect on artifact downloads, artifact deployment, and others.
|
| Default: false
<offline>false</offline>-->
<!-- pluginGroups
| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
|-->
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>-->
</pluginGroups>
<!-- proxies
| This is a list of proxies which can be used on this machine to connect to the network.
| Unless otherwise specified (by system property or command-line switch), the first proxy
| specification in this list marked as active will be used.
|-->
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
<proxy><id>optional</id><active>true</active><protocol>http</protocol><username>proxyuser</username><password>proxypass</password><host>proxy.host.net</host><port>80</port><nonProxyHosts>local.net|some.host.com</nonProxyHosts></proxy>-->
</proxies>
<!-- servers
| This is a list of authentication profiles, keyed by the server-id used within the system.
| Authentication profiles can be used whenever maven must make a connection to a remote server.
|-->
<servers>
<!-- server
| Specifies the authentication information to use when connecting to a particular server, identified by
| a unique name within the system (referred to by the 'id' attribute below).
|
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
| used together.
|
<server><id>deploymentRepo</id><username>repouser</username><password>repopwd</password></server>-->
<!-- Another sample, using keys to authenticate.
<server><id>siteServer</id><privateKey>/path/to/private/key</privateKey><passphrase>optional; leave empty if not used.</passphrase></server>-->
<server>
<id>nexus</id