Jenkins+gitlab自动部署项目(二)

2. 部署Jenkins:

[root@node2 ~]# tar xf  jdk-8u231-linux-x64.tar.gz  -C   /usr/local/
[root@node2 ~]# tar xf apache-tomcat-9.0.36.tar.gz
[root@node2 ~]# mv apache-tomcat-9.0.36 /usr/local/tomcat

# 配置环境变量:
vim  /etc/profile
...省略部分内容
export JAVA_HOME=/usr/local/jdk1.8.0_231
export PATH=/usr/local/jdk1.8.0_231/bin:$PATH
# 使变量生效:
[root@node2 ~]# . /etc/profile

# 验证,看到Java的版本信息则表示配置成功:
[root@node2 ~]# java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)

# 启动tomcat:
[root@node2 ~]# wget -c https://mirrors.tuna.tsinghua.edu.cn/jenkins/war-stable/latest/jenkins.war
[root@node2 ~]# rm -rf /usr/local/tomcat/webapps/ROOT/*
[root@node2 ~]# unzip jenkins.war -d /usr/local/tomcat/webapps/ROOT/

[root@node2 ~]# /usr/local/tomcat/bin/startup.sh 
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/jdk1.8.0_231
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.

2.1 访问web:

访问75.122:8080,解锁Jenkins:

image-20211022140722812

image-20211022140911932

[root@node2 ~]# cat /root/.jenkins/secrets/initialAdminPassword
eb5f66f12d0948c2b13e2ac946baf3dc

2.2 选择插件安装:

Jenkins的插件下载地址默认是外网地址,下载速度会比较慢,可以先跟换源地址,在进行需要下载。所以这一步可以先选择插件安装:

image-20211022141400102

image-20211022141452957

image-20211022141650865

image-20211022141717550

image-20211022141733090

image-20211022141802961

# 换源:
[root@node2 ~]# sed -i -e 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' -e 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g'  /root/.jenkins/updates/default.json

2.2 安装插件:

安装git、Deploy to container等插件。git插件用于从gitlab拉取代码,Deploy to container插件用于将构建的war包部署到tomcat服务。

image-20211022143247495

image-20211022143307752

image-20211022143621226

image-20211022143914405

2.3 配置maven:

[root@node2 ~]# wget -c --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.8.3/binaries/apache-maven-3.8.3-bin.tar.gz
[root@node2 ~]# tar xf apache-maven-3.8.3-bin.tar.gz
[root@node2 ~]# mv apache-maven-3.8.3 /usr/local/maven

# 配置环境变量:
[root@node2 ~]# vim /etc/profile
...
export JAVA_HOME=/usr/local/jdk1.8.0_231
export MAVEN_HOME=/usr/local/maven
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH

# 使配置生效:
[root@node2 ~]# . /etc/profile
# 验证mvn:
[root@node2 ~]# mvn -v
Apache Maven 3.8.3 (ff8e977a158738155dc465c6a97ffaf31982d739)
Maven home: /usr/local/maven
Java version: 1.8.0_231, vendor: Oracle Corporation, runtime: /usr/local/jdk1.8.0_231/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1062.el7.x86_64", arch: "amd64", family: "unix"

2.4 配置jdk/maven环境:

image-20211022153231286

image-20211022153340516

image-20211022153534275

2.5 添加环境变量:

image-20211022153656627

image-20211022153941705

image-20211022154017608

2.6 修改maven的仓库:

[root@node2 ~]# mkdir -p /usr/local/repo
[root@node2 ~]# vim /usr/local/maven/conf/settings.xml
...
<localRepository>/usr/local/repo</localRepository>
...
 <mirrors>
        <mirror>
            <id>aliyunmaven</id>
            <mirrorOf>*</mirrorOf>
            <name>阿里云公共仓库</name>
            <url>https://maven.aliyun.com/repository/public</url>
        </mirror>
...

欢迎点赞,收藏,你的喜欢就是我原创的动力,Jenkins系列将会持续更新。

如果获取最新文章更新,以及常用软件,可以关注公众号: 运维朱工

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维朱工

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值