返回顶部

Jenkins的部署安装

一、安装JDK

(1) 下载JDK1.8

 下载地址:https://www.oracle.com/java/technologies/javase-downloads.html

[root@jenkins ~]# ll jdk-8u251-linux-x64.tar.gz 
-rw-r--r-- 1 root root 195132576 Jun  4 14:10 jdk-8u251-linux-x64.tar.gz

(2) 解压安装包并配置环境变量

[root@jenkins ~]# mkdir /usr/java
[root@jenkins ~]# tar -xf jdk-8u251-linux-x64.tar.gz -C /usr/java
[root@jenkins ~]# vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/java/jdk1.8.0_251
export PATH=$JAVA_HOME/bin/:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH
[root@jenkins ~]# source /etc/profile.d/java.sh

(3) 验证是否安装成功

[root@jenkins ~]# java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)

二、安装git

[root@jenkins ~]# yum install -y git

三、安装maven

(1) 下载压缩包

 官网地址: https://maven.apache.org/download.cgi

(2) 解压安装包并配置环境变量

[root@jenkins ~]# tar -xf apache-maven-3.6.3-bin.tar.gz -C /usr/local/
[root@jenkins ~]# vim /etc/profile.d/maven.sh
#!/bin/bash
export MAVEN_HOME=/usr/local/apache-maven-3.6.3
export PATH=$MAVEN_HOME/bin:$PATH
[root@jenkins ~]# chmod +x /etc/profile.d/maven.sh
[root@jenkins ~]# source /etc/profile.d/maven.sh

(3) 验证是否安装成功

[root@jenkins ~]# mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/apache-maven-3.6.3
Java version: 1.8.0_251, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8.0_251-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-957.el7.x86_64", arch: "amd64", family: "unix"

(4) 配置镜像(如有需要)

[root@jenkins ~]# vim /usr/local/apache-maven-3.6.3/conf/settings.xml
#找到localRepository标签,在其下添加以下行:
<localRepository>/usr/local/apache-maven-3.6.3/repository</localRepository>
#找到<mirrors>标签,在其标签对<mirrors></mirrors>中添加以下内容:
    <mirror>
      <id>aliMaven</id>
      <mirrorOf>central</mirrorOf>
      <name>aliyun maven</name>
      <url>https://maven.aliyun.com/repository/public</url>
    </mirror>
[root@jenkins ~]# mvn help:system

四、安装docker

4.1、在线安装

(1) 设置仓库,安装所需的软件包。

 yum-utils 提供了 yum-config-manager ,并且 device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2。

[root@jenkins ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@jenkins ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

(2) 安装依赖包 container-selinux

[root@jenkins ~]# wget http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.119.1-1.c57a6f9.el7.noarch.rpm
[root@jenkins ~]# yum install -y ./container-selinux-2.119.1-1.c57a6f9.el7.noarch.rpm

(3) 安装Docker Engine-Community和containerd

[root@jenkins ~]# yum install -y docker-ce docker-ce-cli containerd.io

(4) 检查docker是否安装成功

[root@jenkins ~]# systemctl start docker
[root@jenkins ~]# docker version
Client: Docker Engine - Community
 Version:           19.03.12
 API version:       1.40
 Go version:        go1.13.10
 Git commit:        48a66213fe
 Built:             Mon Jun 22 15:46:54 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.12
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.10
  Git commit:       48a66213fe
  Built:            Mon Jun 22 15:45:28 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

4.2、离线安装

 使用离线yum安装的方式,需提前下载好相应的rpm包,这里以版本dockers-19.0.3.4为例。

(1) 下载docker-ce、docker-ce-cli、containerd.io安装包

 下载地址:https://download.docker.com/linux/centos/7/x86_64/stable/Packages/

相关包名:
docker-ce-19.03.4-3.el7.x86_64.rpm
docker-ce-cli-19.03.4-3.el7.x86_64.rpm
containerd.io-1.2.6-3.3.el7.x86_64.rpm

(2) 下载container-selinux安装包

 下载地址:https://pkgs.org/download/container-selinux

相关包名:container-selinux-2.107-3.el7.noarch.rpm

(3) 下载相关依赖包

相关包名:
audit-2.8.5-4.el7.x86_64.rpm
audit-libs-2.8.5-4.el7.x86_64.rpm
audit-libs-python-2.8.5-4.el7.x86_64.rpm
checkpolicy-2.5-8.el7.x86_64.rpm
libcgroup-0.41-21.el7.x86_64.rpm
libseccomp-2.3.1-4.el7.x86_64.rpm
libsemanage-python-2.5-14.el7.x86_64.rpm
libtool-ltdl-2.4.2-22.el7_3.x86_64.rpm
policycoreutils-2.5-34.el7.x86_64.rpm
policycoreutils-python-2.5-34.el7.x86_64.rpm
python-IPy-0.75-6.el7.noarch.rpm
setools-libs-3.3.8-4.el7.x86_64.rpm

 下载地址:http://mirror.centos.org/centos/7/extras/x86_64/Packages

相关包名:pigz-2.3.3-1.el7.centos.x86_64.rpm

(4) 安装

 将以上包放在一个文件夹里,如install_docker,然后进行安装即可。

yum install install_docker/*.rpm

(5) 启动

systemctl start docker
systemctl stop docker

(6) 安装docker-compose (非必需)

 首先访问 docker-compose 的 GitHub 版本发布页面:https://github.com/docker/compose/releases ,下载 Linux 版本的 docker-compose。

[root@localhost ~]# ll docker-compose-Linux-x86_64 
-rw-r--r-- 1 root root 12255808 Aug 13 14:14 docker-compose-Linux-x86_64

 再将文件移至/usr/local/bin/目录下,并加执行权限即可。

[root@localhost ~]# mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
[root@localhost ~]# chmod +x /usr/local/bin/docker-compose 
[root@localhost ~]# docker-compose -version
docker-compose version 1.26.1, build f216ddbf

五、安装Jenkins

(1) 安装仓库并导入验证密钥

[root@jenkins ~]# wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
[root@jenkins ~]# rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
[root@jenkins ~]# yum install -y jenkins

 如果出现 Delta RPMs disabled because /usr/bin/applydeltarpm not installed. 则安装以下包:

[root@jenkins ~]# yum -y  install deltarpm

 如果网络较慢,可以提前下载rpm包,使用离线安装方式。

[root@jenkins ~]# wget http://pkg.jenkins.io/redhat-stable/jenkins-2.235.3-1.1.noarch.rpm

(2) 修改jenkins的启动脚本 /etc/init.d/jenkins 中的java路径

[root@jenkins ~]# vim /etc/init.d/jenkins
candidates="
/etc/alternatives/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/lib/jvm/java-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/lib/jvm/java-11.0/bin/java
/usr/lib/jvm/jre-11.0/bin/java
/usr/lib/jvm/java-11-openjdk-amd64
/usr/bin/java
/usr/java/jdk1.8.0_251/bin/java            #添加此行
"
##如果不想改文件,可以对java路径做一个软链接##
[root@jenkins ~]# ln -sv /usr/java/jdk1.8.0_251/bin/java /usr/bin/java

(3) 启动

[root@jenkins ~]# systemctl daemon-reload
[root@jenkins ~]# systemctl start jenkins
[root@jenkins ~]# ss -nlt|grep 8080
LISTEN     0      50          :::8080                    :::*

(4) 修改默认镜像源

[root@jenkins ~]# vim /var/lib/jenkins/hudson.model.UpdateCenter.xml
#将<url>中的源为国内源
<?xml version='1.1' encoding='UTF-8'?>
<sites>
  <site>
    <id>default</id>
    <url>https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json</url>
  </site>
</sites>

(5) 加快jenkins初始化安装插件过程

[root@jenkins ~]# find / -name 'default.json'
/var/lib/jenkins/updates/default.json
[root@jenkins ~]# cp /var/lib/jenkins/updates/default.json /var/lib/jenkins/updates/default.json_bak
[root@jenkins ~]# sed -i 's/https:\/\/updates.jenkins.io\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' /var/lib/jenkins/updates/default.json && sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' /var/lib/jenkins/updates/default.json
[root@jenkins ~]# systemctl restart jenkins

(6) 在浏览器输入 http://IP:8080 进行下一步操作,页面提示初始密码在以下文件中/var/lib/jenkins/secrets/initialAdminPassword,在服务器上查看密码,并在浏览器登录即可

[root@jenkins ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
f79dacc653c4484bbab603bab1694b49

posted @ 2020-08-17 11:35  hovin  阅读(382)  评论(0编辑  收藏  举报