阿里云 ECS服务器(CentOS 7)Jenkins安装

前言

因项目需要安装Jenkins做CI/CD,所以把安装过程以及过程中的填坑记录下来分享给大家做参考。

准备工作

在安装jenkins前需要提前安装jdk、maven、docker、git和nginx。

安装JDK

官网下载jdk8 rpm包或者.tar.gz包,安装如下:

rpm包安装

以relocate进行安装:
rpm -ivh --relocate =/usr/local/java xxx.rpm;

以prefix进行安装:

rpm -ivh --prefix=/usr/local/java xxx.rpm

tar.gz包安装(推荐)

tar -zxvf xxx.tar.gz -C /usr/local/java

设置软链接:

ln -s /usr/local/java/jdk1.8.0_201/bin/java /usr/bin/java

安装Maven

官网下载maven3 .tar.gz包,安装如下:

tar -zxvf xxx.tar.gz -C /usr/local/maven

安装Docker

使用官网推荐yum 安装比较方便,安装如下:

sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

sudo yum install docker-ce docker-ce-cli containerd.io

安装Git

官网下载git2 .tar.gz包,安装如下:

sudo yum install -y gcc-c++

sudo yum install -y zlib-devel perl-ExtUtils-MakeMaker

wget https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.25.1.tar.gz

tar -zxvf xxx.tar.gz -C /usr/local/git

cd /usr/local/git/git-2.25.1/

./configure --prefix=/usr/local/git

make && make install

设置软链接:

ln -s /usr/local/git/bin/git /usr/bin/git

安装Nginx

官网下载nginx .tar.gz包,安装如下:

yum install -y gcc zlib zlib-devel openssl curl openssl-devel pcre-devel

groupadd nginx

useradd -g nginx nginx

tar -zxvf nginx-1.16.1.tar.gz -C /usr/local/nginx/

cd nginx/nginx-1.16.1/

configure_opts=( \
    --prefix=/usr/local/nginx \
    --user=nginx \
    --group=nginx \
    --with-http_ssl_module \
    --with-http_flv_module \
    --with-http_stub_status_module \
    --with-http_gzip_static_module )

./configure ${configure_opts[@]}

make && make install

设置环境变量

设置JAVA_HOME、MAVEN_HOME、CLASSPATH和PATH,~/.bashrc如下所示:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/java/jdk1.8.0_201/bin:/usr/local/nginx/sbin:/usr/local/maven/apache-maven-3.6.3/bin:/usr/local/git/bin"
JAVA_HOME=/usr/local/java/jdk1.8.0_201
CLASSPATH=.:%JAVA_HOME%/lib/dt.jar:%JAVA_HOME%/lib/tools.jar
MAVEN_HOME=/usr/local/maven/apache-maven-3.6.3

image.png

安装jenkins

按照官网说明安装,如下:

sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install jenkins

或者手动下载rpm安装包进行安装:

rpm -ivh jenkins-2.204.3-1.1.noarch.rpm

nginx代理jenkins:8080端口

server {
        listen       80;
        server_name jenkins.awbeci.com;
        return 301 https://jenkins.awbeci.com$request_uri;
        location / {
           proxy_pass http://127.0.0.1:8080;
           proxy_set_header Host $host;
           proxy_set_header X-Reql-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header X-Forwarded-Proto $scheme;
           proxy_set_header X-Forwarded-Port $server_port;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}


server {
        listen       443 ssl;
        server_name  jenkins.awbeci.com;

        ssl_certificate      /usr/local/nginx/cert/jenkins/jenkins.awbeci.com.pem;
        ssl_certificate_key  /usr/local/nginx/cert/jenkins/jenkins.awbeci.com.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
              proxy_pass http://127.0.0.1:8080; #这里的端口记得改成项目对应的哦
              proxy_set_header Host $host;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header X-Forwarded-Proto $scheme;
              proxy_set_header X-Forwarded-Port $server_port;
        }
    }

配置Jenkins网站

访问jenkins网站

image.png

安装推荐插件

在这里插入图片描述

进行安装

image.png

创建管理员用户

image.png

欢迎页面

image.png

配置jdk和git

配置jdk:选择Global Tool Configuration,并点击新建JDK,输入别名和JAVA_HOME:
配置git:git默认即可:
image.png

配置maven和docker

配置maven:点击新建Maven,输入别名和MAVEN_HOME:
配置docker:点击新建Docker,输入别名和Installation root:
image.png

总结

1、安装jenkins前要先安装jdk、maven、docker和nginx
2、安装如果慢就本地下载然后再上传到ECS进行安装
3、安装好jenkins后要配置jdk、maven、docker和nginx

引用

centos安装docker
CentOS7下安装配置Jenkins
centos7.3安装配置jenkins完整版
GitLab与JenKins的搭建以及两者之间的简单结合

你可能感兴趣的:(ecshop,jenkins,docker,java,maven3)