首页 » 工具&API » Jenkins使用(一)之CentOS上安装与配置

Jenkins使用(一)之CentOS上安装与配置

 

在工作中,存在着好多的项目,如果同同事们公用一套开发环境的话,容易造成缓存,队列什么的误读,

但是如果全部把服务搭建在自己的Mac笔记本上,也会造成很多不变,尤其是Java项目过多的情况下,

每次更新代码,再编译,运行都要花费很多时间。同时时刻占用自己Mac很多内存,很是不变。

没有充分利用虚拟机的作用。

简述下项目,一个PHP前端项目,两个Java后端处理逻辑项目,两个Java后台项目,一个Java统计项目,

(别的若干Java项目,暂时共用没问题,所以也不打算搭建)虽然PHP项目自己不用管理,但是Java项目需要管理,其中大部分是和别的同时共用的。

还不如自己搭建一个Jenkins来管理这些项目,部署到自己的CentOS工作机上面。

另外一个重要的原因,可以直接拉trunk的代码,顺带回归测试了生成的代码,一举两得。

安装前准备

  • 非Tomcat war包安装(war包也内置了jetty,安装了jdk就能运行,同yum安装)

  • jdk安装,最好1.6或者1.7

首先添加Jenkins的源


#(rpm --import 签名文件;wget -O 保存文件) sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key

yum安装Jenkins


yum install jenkins #安装完后,其实就是一个war包,由于内置了jetty,所以不需要tomcat也可启动 [root@localhost jenkins]# pwd /usr/lib/jenkins [root@localhost jenkins]# ll 总用量 63104 -rw-r--r-- 1 root root 64618097 3月 11 14:32 jenkins.war

配置Jenkins


# vim /etc/sysconfig/jenkins ## Path: Development/Jenkins ## Description: Configuration for the Jenkins continuous build server ## Type: string ## Default: "/var/lib/jenkins" ## ServiceRestart: jenkins # # Directory where Jenkins store its configuration and working # files (checkouts, build reports, artifacts, ...). # #默认的jenkinsHOME,存放war包和日志的地方 JENKINS_HOME="/var/lib/jenkins" ## Type: string ## Default: "" ## ServiceRestart: jenkins # # Java executable to run Jenkins # When left empty, we'll try to find the suitable Java. # JENKINS_JAVA_CMD="" ## Type: string ## Default: "jenkins" ## ServiceRestart: jenkins # # Unix user account that runs the Jenkins daemon # Be careful when you change this, as you need to update # permissions of $JENKINS_HOME and /var/log/jenkins. # JENKINS_USER="jenkins" ## Type: string ## Default: "-Djava.awt.headless=true" ## ServiceRestart: jenkins # # Options to pass to java when running Jenkins. # JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true" ## Type: integer(0:65535) ## Default: 8080 ## ServiceRestart: jenkins # # Port Jenkins is listening on. # Set to -1 to disable # #默认端口 JENKINS_PORT="8080" ## Type: integer(0:65535) ## Default: 8009 ## ServiceRestart: jenkins # # Ajp13 Port Jenkins is listening on. # Set to -1 to disable # JENKINS_AJP_PORT="8009" ## Type: integer(1:9) ## Default: 5 ## ServiceRestart: jenkins # # Debug level for logs -- the higher the value, the more verbose. # 5 is INFO. # #日志级别后期UI可调,5为info级别 JENKINS_DEBUG_LEVEL="5" ## Type: yesno ## Default: no ## ServiceRestart: jenkins # # Whether to enable access logging or not. # JENKINS_ENABLE_ACCESS_LOG="no" ## Type: integer ## Default: 100 ## ServiceRestart: jenkins # # Maximum number of HTTP worker threads. # JENKINS_HANDLER_MAX="100" ## Type: integer ## Default: 20 ## ServiceRestart: jenkins # # Maximum number of idle HTTP worker threads. # JENKINS_HANDLER_IDLE="20" ## Type: string ## Default: "" ## ServiceRestart: jenkins # # Pass arbitrary arguments to Jenkins. # Full option list: java -jar jenkins.war --help # JENKINS_ARGS=""

默认日志存放在/var/log/jenkins/jenkins.log


#启动Jenkins [root@localhost sahinn]# systemctl start jenkins.service #查看是否启动成功 [root@localhost sahinn]# netstat -anp | grep 8080 tcp6 0 0 :::8080 :::* LISTEN 6410/java #开机自启动Jenkins [root@localhost sahinn]# /sbin/chkconfig jenkins on

配置一个nginx反向代理

绑定一个域名到jenkins服务,也可以直接ip:8080访问。

绑定域名的话,后期修改下hosts就可以了。

添加ci.zuobin.net.conf


## 配置Jenkins的地址 ## upstream jenkins { server localhost:8080; #Apache } ## Start ci.zuobin.net ## server { listen 80; server_name ci.zuobin.net; access_log /var/log/nginx/jenkins/ci.access.log main; error_log /var/log/nginx/jenkins/ci.error.log; root html; index index.html index.htm index.php; ## send request back to apache ## location / { #反向代理到刚才配置的服务 proxy_pass http://jenkins; #Proxy Settings proxy_redirect off; 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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_max_temp_file_size 0; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } }

至此、Jenkins基础环境搭建完成,具体Jenkins打包教程后续...



原文链接:Jenkins使用(一)之CentOS上安装与配置,转载请注明来源!

1