Jenkins 简介
Jenkins 是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能。
Java 安装
首先我们需要准备 Java 环境,使用下面命令来安装 Java:
yum -y install java-1.8.0-openjdk-devel
Jenkins 安装
为了使用 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
如果您以前从 Jenkins 导入过 key,那么 rpm –import 将失败,因为您已经有一个 key。请忽略,继续下面步骤。
安装
接着我们可以使用 yum 安装 Jenkins:
yum -y install jenkins
启动 Jenkins
启动
启动 Jenkins 并设置为开机启动:
systemctl start jenkins.service
chkconfig jenkins on
测试访问
Jenkins 默认运行在 8080端口。
稍等片刻,打开测试访问。
进入 Jenkins
管理员密码
登入 Jenkins 需要输入管理员密码,按照提示,我们使用以下命令查看初始密码:
cat /var/lib/jenkins/secrets/initialAdminPassword
复制密码,填入,进入 Jenkins。
定制 Jenkins
我们选择默认的 install suggested plugins 来安装插件。
创建用户
请填入相应信息创建用户,然后即可登入 Jenkins 的世界。
nginx反向代理配置
server {
listen 80; # Listen on port 80 for IPv4 requests
server_name ci.xxx.xyz;
#this is the jenkins web root directory (mentioned in the /etc/default/jenkins file)
root /var/run/jenkins/war/;
access_log /var/log/nginx/jenkins/access.log;
error_log /var/log/nginx/jenkins/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}\/(.*)$” {
#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 @jenkins {
sendfile off;
proxy_pass http://127.0.0.1:8080;
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_request_buffering off; # Required for HTTP CLI commands in Jenkins > 2.54
}
location / {
# Optional configuration to detect and redirect iPhones
if ($http_user_agent ~* ‘(iPhone|iPod)’) {
rewrite ^/$ /view/iphone/ redirect;
}
try_files $uri @jenkins;
}
}