专业的编程技术博客社区

网站首页 > 博客文章 正文

jenkins2.222使用之一、安装配置(jenkins配置详解)

baijin 2024-08-18 13:30:15 博客文章 6 ℃ 0 评论

环境说明:CentOS Linux release 7.5.1804 (Core)

Jenkins介绍:Jenkins是开源CI&CD软件领导者, 提供超过1000个插件来支持构建、部署、自动化, 满足任何项目的需要


1、下载安装

1.1、下载

打开https://jenkins.io/zh/download/,根据操作系统选择下载链接,我这边 选择的是jenkins2.222.1版本

注意:不同jenkins版本需要匹配的java版本

2.164 (2019-02) and newer: Java 8 or Java 11

2.54 (2017-04) and newer: Java 8

1.612 (2015-05) and newer: Java 7

1.2、安装

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 -y jenkins


2、启动

2.1、查看jenkins路径

[root@VM_0_16_centos data]# rpm -ql jenkins

/etc/init.d/jenkins #服务器启动文件

/etc/logrotate.d/jenkins

/etc/sysconfig/jenkins #配置文件

/usr/lib/jenkins

/usr/lib/jenkins/jenkins.war #war包文件目录

/usr/sbin/rcjenkins

/var/cache/jenkins

/var/lib/jenkins

/var/log/jenkins #日志文件路径

分析:jenkins默认的端口是8080,可以在配置文件里面修改,启动方式也有两种,一种是使用系统服务启动,第二种是使用war包启动,这里面推荐使用系统服务启动。

2.2、启动方式

  • war包启动

nohup java -jar /usr/lib/jenkins/jenkins.war --httpPort=8080 &

  • 系统服务启动

systemctl start jenkins

Systemctl status jenkins


注意:启动会提示找不到java命令,这时候可以修改启动服务文件vim /etc/init.d/jenkins,找到java选项,修改为服务器上面的java路径(/usr/local/jdk1.8/bin/java),如下图:



3、jenkins配置代理

3.1、使用nginx配置https协议,注意域名和端口修改

upstream jenkinss {

keepalive 32; # keepalive connections

server 127.0.0.1:8080; # jenkins ip and port

}

server {

listen 443 ssl; # Listen on port 80 for IPv4 requests

server_name jenkins.work.com;

root /var/run/jenkins/war/;

ssl_certificate cert/2714038__iworkgo.com.pem;

ssl_certificate_key cert/2714038__iworkgo.com.key;

ssl_session_timeout 5m;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

ssl_prefer_server_ciphers on;

access_log /var/log/nginx/access.log;

error_log /var/log/nginx/error.log;

ignore_invalid_headers off; #pass through headers from Jenkins which are considered invalid by Nginx server.

location ~ "^/static/[0-9a-fA-F]{8}\/(.*)#34; {

#rewrite all static files into requests to the root

#E.g /static/12345678/css/something.css will become /css/something.css

rewrite "^/static/[0-9a-fA-F]{8}\/(.*)" /$1 last;

}

location /userContent {

#have nginx handle all the static requests to the userContent folder files

#note : This is the $JENKINS_HOME dir

root /var/lib/jenkins/;

if (!-f $request_filename){

#this file does not exist, might be a directory or a /**view** url

rewrite (.*) /$1 last;

break;

}

sendfile on;

}

location / {

sendfile off;

proxy_pass http://jenkinss;

proxy_redirect default;

proxy_http_version 1.1;

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_max_temp_file_size 0;

#this is the maximum upload size

client_max_body_size 10m;

client_body_buffer_size 128k;

proxy_connect_timeout 90;

proxy_send_timeout 90;

proxy_read_timeout 90;

proxy_buffering off;

proxy_request_buffering off; # Required for HTTP CLI commands in Jenkins > 2.54

proxy_set_header Connection ""; # Clear for keepalive

}

}

注意:在构建时间长的时候,控制台会报502 bad gateway,查看nginx的错误日志,提示:

upstream prematurely closed connection while reading response header from upstream

解决方法:增加了keepalive_timeout 0的配置

3.2、使用nginx配置http协议,注意域名和端口修改

upstream jenkins {

keepalive 32; # keepalive connections

server 127.0.0.1:8080; # jenkins ip and port

}

server {

listen 80; # Listen on port 80 for IPv4 requests

server_name jenkins.work.com;

#this is the jenkins web root directory (mentioned in the /etc/default/jenkins file)

root /var/run/jenkins/war/;

access_log /var/log/nginx/access.log;

error_log /var/log/nginx/error.log;

ignore_invalid_headers off; #pass through headers from Jenkins which are considered invalid by Nginx server.

location ~ "^/static/[0-9a-fA-F]{8}\/(.*)#34; {

#rewrite all static files into requests to the root

#E.g /static/12345678/css/something.css will become /css/something.css

rewrite "^/static/[0-9a-fA-F]{8}\/(.*)" /$1 last;

}

location /userContent {

#have nginx handle all the static requests to the userContent folder files

#note : This is the $JENKINS_HOME dir

root /var/lib/jenkins/;

if (!-f $request_filename){

#this file does not exist, might be a directory or a /**view** url

rewrite (.*) /$1 last;

break;

}

sendfile on;

}

location / {

sendfile off;

proxy_pass http://jenkins;

proxy_redirect default;

proxy_http_version 1.1;

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_max_temp_file_size 0;

#this is the maximum upload size

client_max_body_size 10m;

client_body_buffer_size 128k;

proxy_connect_timeout 90;

proxy_send_timeout 90;

proxy_read_timeout 90;

proxy_buffering off;

proxy_request_buffering off; # Required for HTTP CLI commands in Jenkins > 2.54

proxy_set_header Connection ""; # Clear for keepalive

}

}

4、图形化安装插件过程

浏览器输入服务器的ip地址+端口号或者域名,弹出getting Started页面,输入密码,初始化密码查看(cat /var/lib/jenkins/secrets/initialAdminPassword)


然后就选择“安装推荐的插件”,失败了可以重新尝试,多试几次,安装失败也没有关系,后面下载插件手动安装也可以,如下:



安装插件完成后,设置用户名:admin 密码:jenkins,登录后,如下图:


本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表