Skip to content

Jenkins运行需要jdk环境,实现自动打包部署我们需要maven,因此我们除了安装jenkins还需要安装jdk和maven。自动化构建需要我们从代码仓库获取代码,因此Git也是必须的。

安装JDK8

shell
yum install java-1.8.0-openjdk
yum install -y java-devel
java #检查是否安装成功

安装jenkins

首先我们需要下载Jenkins的war包,并上传到服务器中,我下载后上传到了我服务器的/usr/local/software/jenkins目录下

shell
nohup java -jar jenkins.war >jenkinslog.log 2>&1 &  #运行jenkins

image-20220903104557211

运行后,浏览器输入ip:8080访问jenkins

image-20220903105054982

或者查看日志 cat nohup.out

image-20220903105133936

等待两分钟左右出现安装插件的页面,然后安装推荐的插件,安装完成后按照提示创建第一个管理员用户

image-20220903105332683

安装Maven

我们访问Maven官网下载maven的安装包,并上传到/usr/local/software/maven目录下

image-20220903105816367

shell
cd /usr/local/software/maven
tar zxvf apache-maven-3.8.6-bin.tar.gz
mv apache-maven-3.8.6 maven
/usr/local/software/maven/maven/bin/mvn
/usr/local/software/maven/maven/bin/mvn -v #如果有版本信息代表安装成功

配置maven镜像

shell
vim /usr/local/software/maven/maven/conf/settings.xml

mirrors标签包裹的内容替换为如下内容

xml
<mirror>
    <!--This sends everything else to /public -->
    <id>nexus</id>
    <mirrorOf>*</mirrorOf> 
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
<mirror>
    <!--This is used to direct the public snapshots repo in the 
          profile below over to a different nexus group -->
    <id>nexus-public-snapshots</id>
    <mirrorOf>public-snapshots</mirrorOf> 
    <url>http://maven.aliyun.com/nexus/content/repositories/snapshots/</url>
</mirror>
<mirror>
    <!--This is used to direct the public snapshots repo in the 
          profile below over to a different nexus group -->
    <id>nexus-public-snapshots1</id>
    <mirrorOf>public-snapshots1</mirrorOf> 
    <url>https://artifacts.alfresco.com/nexus/content/repositories/public/</url>
</mirror>

安装git

shell
yum install git