阿里雲 ECS服務器(CentOS 7)Jenkins安裝

前言

因項目須要安裝Jenkins作CI/CD,因此把安裝過程以及過程當中的填坑記錄下來分享給你們作參考。html

準備工做

在安裝jenkins前須要提早安裝jdk、maven、docker、git和nginx。java

安裝JDK

官網下載jdk8 rpm包或者.tar.gz包,安裝以下:linux

rpm包安裝nginx

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

以prefix進行安裝:

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

tar.gz包安裝(推薦)c++

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

設置軟連接:git

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

安裝Maven

官網下載maven3 .tar.gz包,安裝以下:docker

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

安裝Docker

使用官網推薦yum 安裝比較方便,安裝以下:apache

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包,安裝以下:centos

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

設置軟連接:bash

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

總結

一、安裝jenkins前要先安裝jdk、maven、docker和nginx
二、安裝若是慢就本地下載而後再上傳到ECS進行安裝
三、安裝好jenkins後要配置jdk、maven、docker和nginx

引用

centos安裝docker
CentOS7下安裝配置Jenkins
centos7.3安裝配置jenkins完整版
GitLab與JenKins的搭建以及二者之間的簡單結合

相關文章
相關標籤/搜索