在Linux中进行Jenkins部署(maven-3.9.1+jdk11+jenkins-2.387)

Jenkins部署在公网IP为x.x.x.x的服务器上

maven-3.9.1要安装在jdk11环境中

环境准备

第一步,下载jdk-11.0.19_linux-x64_bin.tar.gz安装包。

登录地址:Java Downloads | Oracle

下载jdk-11.0.19_linux-x64_bin.tar.gz安装包,然后使用WinSCP将安装包上传到/usr/local/src文件夹中。

第二步,解压jdk-11.0.19_linux-x64_bin.tar.gz安装包。

命令:cd /usr/local/src

tar -zxvf jdk-11.0.19_linux-x64_bin.tar.gz -C /usr/local

第三步,配置环境变量。

配置/etc/profile文件,在文件添加下面的代码:

export JAVA_HOME=/usr/local/jdk-11.0.19
export CLASSPATH=$JAVA_HOME/lib/
export PATH=$PATH:$JAVA_HOME/bin

# 刷新profile文件

命令:source /etc/profile

第四步,测试jdk是否配置成功。

# 查看jdk版本

命令:java -version

若结果显示jdk的版本,则说明jdk配置成功。

第五步,安装maven。

# 下载maven安装包

命令:cd /usr/local/src

wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.9.1/binaries/apache-maven-3.9.1-bin.tar.gz

# 解压maven安装包

命令:tar -zxvf apache-maven-3.9.1-bin.tar.gz

第六步,配置maven。

配置/usr/local/src/apache-maven-3.9.1/conf/setting.xml文件,文件修改完成后显示如下:

  <mirror>

      <id>alimaven</id>

      <mirrorOf>central</mirrorOf>

      <name>aliyun maven</name>

      <url>https://maven.aliyun.com/repository/public</url>

  </mirror>

</mirrors>

第七步,配置环境变量。

配置文件/etc/profile,在文件最下面添加下面的代码:

export MAVEN_HOME=/usr/local/src/apache-maven-3.9.1

export PATH=${PATH}:${MAVEN_HOME}/bin

# 刷新profile文件

命令:source /etc/profile

第八步,验证maven。

命令:mvn -v

若结果显示“Apache Maven 3.9.1”,则maven配置成功。

第九步,安装git

# yum安装git

命令:yum install git

# 创建git用户组和用户

命令:groupadd git

useradd git -g git

# 使用ssh-keygen生成密钥文件/root/.ssh/id_rsa.pub

命令:ssh-keygen             #连续回车四下

cat /root/.ssh/id_rsa.pub    #结果显示生成的秘钥

Jenkins第一种安装方式

第一步,下载jenkins-2.387-1.1.noarch.rpm。

登录网址:https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat/jenkins-2.387-1.1.noarch.rpm下载jenkins-2.387-1.1.noarch.rpm,然后使用WinSCP将安装包上传到/usr/local/src文件夹中。也可以使用wget命令下载。

命令:cd /usr/local/src

wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat/jenkins-2.387-1.1.noarch.rpm

第二步,查看Linux系统中是否安装了jenkins。

命令:rpm -qa | grep jenkins

若已经安装了,则需要使用命令“rpm -e jenkins-2.387-1.1.noarch”进行卸载。若没有安装,则进行下一步。

第三步,解压安装jenkins-2.387文件。

命令:rpm -ivh jenkins-2.387-1.1.noarch.rpm

Jenkins第二种安装方式

第一步,导入镜像。

命令:yum -y install ca-certificates

wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo

若结果显示“100%”,则说明镜像导入成功。

第二步,导入公钥。

命令:rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key

第三步,查看Linux系统中是否安装了jenkins。

命令:rpm -qa | grep jenkins

若已经安装了,则需要使用命令“yum -y remove jenkins”进行卸载。若没有安装,则进行下一步。

第四步,安装jenkins

命令:yum install fontconfig java-11-openjdk

yum install jenkins

若结果显示“Upgraded:jenkins-2.387.2-1.1.noarch”,则说明安装的最新版本是jenkins-2.387。

Jenkins配置

第一步,编辑配置文件/etc/sysconfig/jenkins

做出修改如下:

JENKINS_PORT="8880"

第二步,编辑配置文件/etc/init.d/jenkins

做出修改如下:

candidates="/usr/local/jdk-11.0.19/bin/java"

注意:路径后面一定跟启动路径/bin/java

第三步,编辑配置文件/usr/lib/systemd/system/jenkins.service。

把“Environment="JENKINS_PORT=8080"”修改成“Environment="JENKINS_PORT=8880"”。

第四步,编辑文件/etc/systemd/system/jenkins.service.d/override.conf。

做出修改如下:

[Service]

Environment="JENKINS_PREFIX=/jenkins"

Jenkins启动

第一步,启动jenkins。

命令:systemctl daemon-reload

systemctl start jenkins

第二步,查看jenkins启动状态

命令:systemctl status jenkins

  

第三步,修改插件下载地址。

命令:cd /var/lib/jenkins/updates

sed -i "s/http:\/\/updates.jenkinsci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g" default.json && sed -i "s/http:\/\/www.google.com/https:\/\/www.baidu.com/g" default.json

第四步,关闭jenkins

命令:systemctl daemon-reload

systemctl stop jenkins

第五步,jenkins

命令:systemctl daemon-reload

systemctl restart jenkins

Jenkins访问

第一步,获取管理员密码

命令:cat /var/lib/jenkins/secrets/initialAdminPassword

在浏览器中登录网址:http://x.x.x.x:8880/,输入刚刚获得的管理员密码,点击“继续”即可。

  

第二步,自定义Jenkins。

在“自定义Jenkins”页面点击“安装推荐的插件”,就会跳转到“新手入门”页面进行插件安装,当插件安装完成时,页面就会显示绿√。

 

第三步,创建第一个管理员用户。

在“创建第一个管理员用户”页面中用户名输入“admin”,密码输入“zy@123456”,全名输入“管理员”,电子邮件地址写入自己的电子邮件地址。然后点击“保存并完成”即可。

  

第四步,实例配置。

在“实例配置”页面会显示Jenkins URL,确认Jenkins URL没有问题之后就可以点击“保存并完成”,然后会跳转到另一个显示“Jenkins已就绪!”的页面。最后点击“开始使用Jenkins”就可以了。

  

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Apache Maven What is it? ----------- Maven is a software project management and comprehension tool. Based on the concept of a Project Object Model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information. Documentation ------------- The most up-to-date documentation can be found at http://maven.apache.org/. Release Notes ------------- The full list of changes can be found at http://maven.apache.org/release-notes.html. System Requirements ------------------- JDK: 1.7 or above (this is to execute Maven - it still allows you to build against 1.3 and prior JDK's). Memory: No minimum requirement. Disk: Approximately 10MB is required for the Maven installation itself. In addition to that, additional disk space will be used for your local Maven repository. The size of your local repository will vary depending on usage but expect at least 500MB. Operating System: Windows: Windows 2000 or above. Unix based systems (Linux, Solaris and Mac OS X) and others: No minimum requirement. Installing Maven ---------------- 1) Unpack the archive where you would like to store the binaries, eg: Unix-based operating systems (Linux, Solaris and Mac OS X) tar zxvf apache-maven-3.x.y.tar.gz Windows unzip apache-maven-3.x.y.zip 2) A directory called "apache-maven-3.x.y" will be created. 3) Add the bin directory to your PATH, eg: Unix-based operating systems (Linux, Solaris and Mac OS X) export PATH=/usr/local/apache-maven-3.x.y/bin:$PATH Windows set PATH="c:\program files\apache-maven-3.x.y\bin";%PATH% 4) Make sure JAVA_HOME is set to the location of your JDK 5) Run "mvn --version" to verify that it is correctly installed. For complete documentation, see http://maven.apache.org/download.html#Installation Licensing --------- Please see the file called LICENSE.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值